question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GDB: Error with the command disassemble after manually breaking from the target

See original GitHub issue

Describe the bug I use a target GDB stub that allows to manually break which allows GDB to gain control back. The stub seems to behave properly by sending a correct stop reply response, GDB does gain back control and Ghidra sees everything as if I just broke manually, but it displays an error that a NullPointerException happened while processing the command disassemble.

To Reproduce Steps to reproduce the behavior:

  1. This bug was reproduced with the mgba’s GDB stub, a GameBoy Advance emulator. I wrote a guide on setting this up on a Linux machine which you can follow here: https://gist.github.com/aldelaro5/d532b21b5e2ec48d5f78e81846c1c1b7 I would mostly do the static analysis and debugging section, you at least need to have a GDB connexion going, have your static listing open after first analysis and map the modules identically with the red button. You can use this freely available ROM to reproduce this: https://itch.io/jam/gbajam21/rate/1120303
  2. Once everything is setup, go to the objects window and click play
  3. On mgba, click “Break” on the GDB server window. This will send a stop reply pack so GDB can stop.
  4. Repeat steps 2-3 until an error pops up. This is inconsistent: you MAY see the error, but it’s not guaranteed (see notes at the bottom as to why I think this is happening).

Expected behavior To not see the error. It happens often enough to be distracting. If I need to disassemble manually, I can do it so it’s not even necessary for the disassemble to work first try, but it would be a bonus.

Screenshots This is how my Ghidra looked right as I got the error (after I pressed ok) Screenshot from 2022-03-19 22-59-44

Environment (please complete the following information):

  • OS: Arch Linux kernel 5.16.15-arch1-1
  • Java Version: openjdk 11.0.15 2022-04-19
  • Ghidra Version: 10.1.1
  • Ghidra Origin: official ghidra-sre.org distro

Additional context This is my personal speculation here, but the GameBoy Advance is a little unconventional target because although its CPU is an armv4t, it is mostly used in thumb mode and only sometimes in ARM mode. What seems to happen is it seems Ghidra guesses the mode it’s in wrong so it tries to disassemble, but fails. This could explain the inconsistency of the issue (you may need to land in code with a specific thumbness or specific layout).

This is the full error message text:

java.lang.NullPointerException
	at ghidra.trace.database.context.DBTraceRegisterContextSpace.setValue(DBTraceRegisterContextSpace.java:269)
	at ghidra.trace.database.listing.DBTraceInstructionsView.doSetContexts(DBTraceInstructionsView.java:175)
	at ghidra.trace.database.listing.DBTraceInstructionsView.doCreate(DBTraceInstructionsView.java:214)
	at ghidra.trace.database.listing.DBTraceInstructionsView$InstructionBlockAdder.doCreateInstruction(DBTraceInstructionsView.java:73)
	at ghidra.trace.database.listing.DBTraceInstructionsView$InstructionBlockAdder.doAddInstructions(DBTraceInstructionsView.java:146)
	at ghidra.trace.database.listing.DBTraceInstructionsView.addInstructionSet(DBTraceInstructionsView.java:387)
	at ghidra.trace.database.listing.DBTraceInstructionsMemoryView.addInstructionSet(DBTraceInstructionsMemoryView.java:78)
	at ghidra.trace.database.program.AbstractDBTraceProgramViewListing.addInstructions(AbstractDBTraceProgramViewListing.java:739)
	at ghidra.program.disassemble.Disassembler.disassemble(Disassembler.java:625)
	at ghidra.program.disassemble.Disassembler.disassemble(Disassembler.java:489)
	at ghidra.app.cmd.disassemble.DisassembleCommand.doDisassemblySeeds(DisassembleCommand.java:327)
	at ghidra.app.cmd.disassemble.DisassembleCommand.doDisassembly(DisassembleCommand.java:309)
	at ghidra.app.cmd.disassemble.DisassembleCommand.applyTo(DisassembleCommand.java:155)
	at ghidra.app.plugin.core.debug.workflow.DisassembleAtPcDebuggerBot$ForDisassemblyTraceListener$1.applyTo(DisassembleAtPcDebuggerBot.java:306)
	at ghidra.framework.plugintool.mgr.BackgroundCommandTask.run(BackgroundCommandTask.java:102)
	at ghidra.framework.plugintool.mgr.ToolTaskManager.run(ToolTaskManager.java:319)
	at java.base/java.lang.Thread.run(Thread.java:829)

---------------------------------------------------
Build Date: 2021-Dec-21 1319 EST
Ghidra Version: 10.1.1
Java Home: /usr/lib/jvm/java-11-openjdk
JVM Version: Oracle Corporation 11.0.15
OS: Linux 5.16.15-arch1-1 amd64
Workstation: aldelaro5-PC.localdomain

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
d-millarcommented, Mar 23, 2022

cool - thanks. have everything I need now except Ghidra, which I’m having trouble building (LOL)

0reactions
aldelaro5commented, Mar 28, 2022

Ok I just upgraded and restested both versions and yeah, it appears it’s fixed as of 10.1.2 so I will be closing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GDB Command Reference - disassemble command
Specifies starting and ending addresses to disassemble. If this form is used, the command won't disassemble the entire function, but only the instructions ......
Read more >
Debugging with gdb - The gdb/mi Interface - Apple Developer
Listing breakpoints and watchpoints, at different points in the program execution. Note that once the watchpoint goes out of scope, it is deleted....
Read more >
Debugging with GDB - Documentation
If gdb has not been configured to included core file support, such as for most embedded targets, then it will complain about a...
Read more >
Software Debugging :: TEMU Documentation
CLI Based Software Debugging; Source Level Debugging; GDB Server; Example ... The TEMU command line interface will when reading ELF files, also load...
Read more >
General Commands (OpenOCD User's Guide)
To issue commands from within a GDB session, use the monitor command, ... this indicates commands which are only available after the configuration...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found