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

pdb not working/set_trace throws "IOError: The handle is invalid" #6619

Open raduicaiulian opened 3 weeks ago

raduicaiulian commented 3 weeks ago

I have the following script in which I'm trying to get pdb working

print "I work"
import pdb
pdb.set_trace()
print "I don't"

But for whatever reason jython is throwing me the following exception

my_script.py> Running...
I work
> c:\users\test\ghidra_scripts\my_script.py(20)<module>()
-> print "I don't"
(Pdb) Traceback (most recent call last):
  File "C:\Users\test\ghidra_scripts\my_script.py", line 20, in <module>
    print "I don't"
  File "C:\Users\test\Documents\ghidra_11.0.3_PUBLIC\Ghidra\Features\Python\data\jython-2.7.3\Lib\bdb.py", line 49, in trace_dispatch
    return self.dispatch_line(frame)
  File "C:\Users\test\Documents\ghidra_11.0.3_PUBLIC\Ghidra\Features\Python\data\jython-2.7.3\Lib\bdb.py", line 67, in dispatch_line
    self.user_line(frame)
  File "C:\Users\test\Documents\ghidra_11.0.3_PUBLIC\Ghidra\Features\Python\data\jython-2.7.3\Lib\pdb.py", line 158, in user_line
    self.interaction(frame, None)
  File "C:\Users\test\Documents\ghidra_11.0.3_PUBLIC\Ghidra\Features\Python\data\jython-2.7.3\Lib\pdb.py", line 210, in interaction
    self.cmdloop()
  File "C:\Users\test\Documents\ghidra_11.0.3_PUBLIC\Ghidra\Features\Python\data\jython-2.7.3\Lib\cmd.py", line 130, in cmdloop
    line = raw_input(self.prompt)
  File "C:\Users\test\Documents\ghidra_11.0.3_PUBLIC\Ghidra\Features\Python\data\jython-2.7.3\Lib\cmd.py", line 130, in cmdloop
    line = raw_input(self.prompt)
IOError: The handle is invalid
my_script.py> Finished!

I tried searching jython issues/google but didn't find anything useful. Could you help me to get pdb working?

ryanmkurtz commented 3 weeks ago

I'm not reproducing this. How are you running the script? Through the Script Manager? Headless? Interactive interpreter?

raduicaiulian commented 3 weeks ago

Yes, I was running it in Script Manager.

raduicaiulian commented 3 weeks ago

Just tested(Ghidra 11.0.3/openjdk 17.0.2) and found out that headless and interactive interpreter works just fine. I think those two options are good enough for what I need, but fixing the problem for Script Manager it might be desirable.