-
Notifications
You must be signed in to change notification settings - Fork 197
Add trigger_exception_handler() for post-mortem debugging of caught exceptions #1996
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
base: main
Are you sure you want to change the base?
Changes from all commits
5d2e8ad
cfb2695
835e93c
e643277
da7c378
2444836
ce5949d
33bd8dc
64d1a3f
4cc8eb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| "listen", | ||
| "log_to", | ||
| "trace_this_thread", | ||
| "trigger_exception_handler", | ||
| "wait_for_client", | ||
| ] | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1866,6 +1866,51 @@ def stop_monitoring(all_threads=False): | |
| thread_info.trace = False | ||
|
|
||
|
|
||
| # fmt: off | ||
| # IFDEF CYTHON | ||
| # cpdef bint suspend_current_thread_tracing(): | ||
| # cdef ThreadInfo thread_info | ||
| # ELSE | ||
| def suspend_current_thread_tracing(): | ||
| # ENDIF | ||
| # fmt: on | ||
| """ | ||
| Suspends tracing for the current thread and returns the previous state, | ||
| to be restored with resume_current_thread_tracing(). | ||
| """ | ||
| try: | ||
| thread_info = _thread_local_info.thread_info | ||
| except: | ||
| # Create the ThreadInfo if missing; monitoring events create it with | ||
| # tracing enabled by default, which would defeat the suspension. | ||
| thread_info = _get_thread_info(True, 1) | ||
| if thread_info is None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📍 src/debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring.py:1875
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think how it is currently is actually correct. True is the default state (for everything except pydevd-daemon threads), in the sense that every other monitoring event sets thread_info like that if it doesn't exist. So that's what we should restore.
nshepperd marked this conversation as resolved.
|
||
| return False | ||
| previous_state = thread_info.trace | ||
|
nshepperd marked this conversation as resolved.
|
||
| thread_info.trace = False | ||
| return previous_state | ||
|
|
||
|
|
||
| # fmt: off | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📍 src/debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring.py:1887 [verified] |
||
| # IFDEF CYTHON | ||
| # cpdef resume_current_thread_tracing(): | ||
| # cdef ThreadInfo thread_info | ||
| # ELSE | ||
| def resume_current_thread_tracing(): | ||
| # ENDIF | ||
| # fmt: on | ||
| """ | ||
| Resumes tracing for the current thread. | ||
| """ | ||
| try: | ||
| thread_info = _thread_local_info.thread_info | ||
| except: | ||
| thread_info = _get_thread_info(True, 1) | ||
| if thread_info is None: | ||
| return | ||
| thread_info.trace = True | ||
|
|
||
|
|
||
| def update_monitor_events(suspend_requested: Optional[bool]=None) -> None: | ||
| """ | ||
| This should be called when breakpoints change. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm wondering if we can just stick the exception on the frame as an attribute. Modifying the locals is usually not so great because then the user sees it in the locals list (and the potential conflict). Although it did that before. But that might explain the error you were talking about with 3.14.
Something like this instead:
Then removing it would just be deleting that attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I'm not sure what
__exception__is used for. I assumed the point was for users to see it in the locals list (eg. vscode debugging terminal). Or maybe it's a legacy thing used by Eclipse?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at it, it seems it takes special precautions to remove it from the locals just for that reason. So that users don't see it. I think we can probably just change addExceptionToFrame and removeExceptionFromFrame by just adding an attribute on it. Then we wouldn't have to special case locals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That can't be the case because in actual fact I do see it when i use the debugger (with vanilla debugpy release). For example, in vscode's python debugger,
__exception__appears as "special variable" under the locals in the Variables pane. And afaict it's not used for anything internally, so if we were going to make it a frame attribute (no longer visible externally) we might as well delete it entirely. The purpose of the cleanup after the stop is so when the thread continues running (eg. userUnhandled exception path where it's not fatal) it doesn't clutter your locals during unrelated later stops.