NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
49.06k stars 5.65k forks source link

Continuing from a breakpoint in GDB 9.2 fails. #6666

Open forky2 opened 5 days ago

forky2 commented 5 days ago

Describe the bug Following on from #6656, when using the gdb debugger profile with GDB 9.2, on continue from a breakpoint the python hook on_stop fails with the following error:

Traceback (most recent call last):
  File "/home/forky2/ghidra_11.1.1_PUBLIC/Ghidra/Debug/Debugger-agent-gdb/pypkg/src/ghidragdb/hooks.py", line 161, in _func
    return func(*args, **kwargs)
  File "/home/forky2/ghidra_11.1.1_PUBLIC/Ghidra/Debug/Debugger-agent-gdb/pypkg/src/ghidragdb/hooks.py", line 311, in on_stop
    state.record("Stopped")
  File "/home/forky2/ghidra_11.1.1_PUBLIC/Ghidra/Debug/Debugger-agent-gdb/pypkg/src/ghidragdb/hooks.py", line 89, in record
    commands.put_frames()
  File "/home/forky2/ghidra_11.1.1_PUBLIC/Ghidra/Debug/Debugger-agent-gdb/pypkg/src/ghidragdb/commands.py", line 1400, in put_frames
    f = newest_frame(gdb.selected_frame())
gdb.error: No frame is currently selected.
Python Exception <class 'gdb.error'> No frame is currently selected.: 

To Reproduce Steps to reproduce the behavior:

  1. Create an x86_64 helloworld:

    gcc -x c -o helloworld - <<EOF
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
        printf("Hello, world!\n");
        return 0;
    }
    EOF
  2. Run Ghidra 11.1.1 with the python patch from #6656 applied.
  3. Import helloworld to Ghidra project
  4. Start a gdb debugger session with the default parameters
  5. GDB breaks on _start()
  6. Press F5 or enter continue into GDB Terminal
  7. Exception as above is thrown

Expected behavior Program should run to termination with no exception.

Environment (please complete the following information):

Additional context Apologies for raising multiple issues that affect an older version of GDB. No offense will be taken if you decide that GDB 9.2 is too old. I'm mainly raising because I like Ghidra and many people's initial experience of the debugger will be using it against these older versions due to them being the default in LTS releases of certain distros.

So far I have confirmed that the issue doesn't occur in GDB 13.2 which I built for testing. I think GDB 9.2 is erroneously calling the on_stop hook.

qvipin commented 4 days ago

yo congrats ur issue 6666