ghidra icon indicating copy to clipboard operation
ghidra copied to clipboard

dsPIC30F6014 Emulation Error

Open lYlantis opened this issue 2 years ago • 7 comments

Describe the bug Attempting to emulate a dsPIC30F6014 file causes:

java.lang.IllegalArgumentException: Memory-mapped register PC does not map to space register:

To Reproduce Steps to reproduce the behavior:

  1. Compile program with the XC16 compiler:
#include <stdio.h>
  
int main()
{
  
    printf("Hello World");
  
    return 0;
}
  1. Compile for dsPIC30F6014:
xc16-gcc -mcpu=30f6014 -o hello_world2.elf hello_world2.c
  1. Load program into Ghidra and analyze.
  2. Navigate to _main
  3. Right click on instruction and click Emulate Program in new Trace

Expected behavior The ability to emulate the instructions.

Screenshots If applicable, add screenshots to help explain your problem.

Attachments error2.log

Environment (please complete the following information):

  • OS: Ubuntu 20.04 Linux 5.15.0-71-generic amd64
  • Java Version: openjdk 17.0.7
  • Ghidra Version: 10.2.3
  • Ghidra Origin: Official GitHub distro

Let me know if you need me to provide anything else.

lYlantis avatar Jun 02 '23 18:06 lYlantis

Can you tell which instruction this is occurring at?

GhidorahRex avatar Jun 02 '23 19:06 GhidorahRex

It has occurred on every instruction I have tested (I think). The main instructions I have tried are the first ones in _main:

0x0B86 lnk 0x0B88 mov.w 0x0B8A push

lYlantis avatar Jun 02 '23 19:06 lYlantis

The emulator has changed quite a bit from 10.2.3 to 10.3. Can you confirm this is still an issue in 10.3?

nsadeveloper789 avatar Jun 05 '23 13:06 nsadeveloper789

Yes, the same issue happens when I try it using 10.3.

Here is the error: error10.3.txt

lYlantis avatar Jun 05 '23 15:06 lYlantis

Anything else I can test or assist with/any pointers on how I can work to solve this? I am not a Java guy, but this is a blocker for me at work, so I am planning to try and debug if possible.

lYlantis avatar Jun 07 '23 15:06 lYlantis

Interesting. Thanks for the full stack trace, as it explains why (perhaps) this error isn't caught in our unit tests. The error is actually produced by the "Stack" window. For emulation, that window doesn't (yet) produce anything useful anyway, so you might try disabling it and seeing if things improve:

  1. Open the Debugger or Emulator tool (probably Emulator).
  2. Select File -> Configure in the menus.
  3. Click the "Configure" link in the "Debugger" category.
  4. Un-check the "DebuggerStackPlugin" and confirm/dismiss all the dialogs.
  5. Try emulating your program again.

(Sorry for the delay. I was out the last 2 weeks.)

nsadeveloper789 avatar Jun 23 '23 17:06 nsadeveloper789

OK. Nevermind my previous advice. It happens in a lot of UI components. I've started working on a patch.

nsadeveloper789 avatar Jun 23 '23 20:06 nsadeveloper789

Great! Thanks so much!

lYlantis avatar Jun 26 '23 15:06 lYlantis