-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to debug a Ghidra Python script from Eclipse? #2713
Comments
This issue has been reported in an unrelated old ticket. We can use this new ticket to focus solely on the debugger not connecting. An important thing to note from the old ticket is:
|
as a workaround, you can try add the following to your code (run as early as possible). It will depend on your version of import pydevd;pydevd.threadingCurrentThread().__pydevd_main_thread = True or import pydevd;pydevd.get_global_debugger().has_user_threads_alive=lambda:True or import pydevd;pydevd.get_global_debugger().has_threads_alive=lambda:True |
Yes, I think it is better that we open a new ticket, because I had the issue (I actually had installed PyDev inside a On this topic, I can see something strange in the threads of Thanks @jpleasu, but with PyDev 6.3.1 it does not change anything (EDIT: I tested the |
I checked the source for 6.3.1, and the You may want to upgrade.. with pydev 8.1.0 (and the workaround above), I'm not having any issues with breakpoints before and after dialogs. |
I've confirmed that adding
to the start of your Python script will make the breakpoint catch using Pydev 8.1.0. Nice find @jpleasu! This is something that should be added to the below code so the user doesn't have to worry about adding that line themselves. ghidra/Ghidra/Features/Python/src/main/java/ghidra/python/GhidraPythonInterpreter.java Lines 218 to 223 in 6fd7f6d
We'll also need to test older versions of PyDev with this change to see if we need to tweak our oldest supported version. |
Yes. @ryanmkurtz you're welcome to make the change -- the workaround should come before the |
Thank you very much @jpleasu for the workaround. It works perfectly with both PyDev 6.3.1 and 8.1.0 and I have no problems with dialogs anymore and I am able to connect to a running debug server without starting Ghidra from Eclipse, which allows me to work around the potential racing condition you mention (even though I have never encounter it in my many tests) While waiting for the fix in the official version, I will use the following function at the beginning of my scripts, it ensures that PyDev tracing function is correctly setup in all cases (running Ghidra from Eclipse or connecting to a running debug server) from java.lang import ClassCastException
import sys
PYSRC_PATH = '/path/to/pydev.core/pysrc'
def setupPyDev():
# Ensure that PyDev pysrc directory is in Python path
if PYSRC_PATH not in sys.path:
sys.path.append(PYSRC_PATH)
import pydevd
pydevd.threadingCurrentThread().__pydevd_main_thread = True
# Ensure that PyDev is tracing
try:
sys.gettrace()
except ClassCastException :
pydevd.settrace(suspend=False) Thank you both for your help |
Change has been merged into patch and master branch for release with 9.2.3 |
Hello, I do not manage to set breakpoints in a Ghidra Python script from Eclipse (with PyDev and GhidraDev). Is this really supported or did I misunderstand?
What I have done so far:
I start Ghidra from Eclipse using (Debug As). For testing purposes I have made a simple script which only prints some variables and set beak points on all the
print
lines and the lines with function calls:It runs well and I get in Ghidra console:
In the debug pane, I see that the debug server gets a connection and that threads are created under
ghidra.GhidraLauncher
, but no breakpoint is hit.Did I overlook something? Is this unsupported? Anyway, thank you for any help you could provide. I could do without a debugger, but it would be very helpful to have one.
The text was updated successfully, but these errors were encountered: