-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add custom pdb and custom debug trigger
- Loading branch information
1 parent
027a408
commit 1ca5c5a
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"version": "1.0", | ||
"data": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pdb | ||
import sys | ||
|
||
class CustomPdb(pdb.Pdb): | ||
def __init__(self, prev_stdin, conn, *args, **kwargs): | ||
""" | ||
Custom Pdb constructor to accept the stdin and connection. | ||
""" | ||
super().__init__(*args, **kwargs) # Initialize the base Pdb class | ||
self.prev_stdin = prev_stdin # Store the original stdin | ||
self.conn = conn # Store the connection for parent communication | ||
|
||
def do_continue(self, arg): | ||
""" | ||
Override the 'continue' (c) command to perform cleanup after continuing. | ||
""" | ||
self.cleanup_before_exit() | ||
return super().do_continue(arg) | ||
|
||
do_c = do_cont = do_continue | ||
|
||
def do_quit(self, arg): | ||
""" | ||
Override the 'quit' (q) command to perform cleanup before quitting. | ||
""" | ||
self.cleanup_before_exit() | ||
return super().do_quit(arg) | ||
|
||
do_q = do_exit = do_quit | ||
|
||
def cleanup_before_exit(self): | ||
""" | ||
This function performs the cleanup before exiting the debugger. | ||
""" | ||
print("Performing cleanup before exiting the debugger...") | ||
sys.stdin = self.prev_stdin # Restore stdin to its original state | ||
self.conn.send(("breakpoint_handled",)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters