Skip to content

Commit

Permalink
Add post-mortem debugging via trepan3k (#1114)
Browse files Browse the repository at this point in the history
Adds post-mortem debugging on a fatal exception via trepan3k. There may
be a way to also support pdb, but I didn't see done as easily.
  • Loading branch information
rocky authored Oct 2, 2024
1 parent 1ee6520 commit 7583fdc
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions mathics/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,12 @@ def main() -> int:
action="store_true",
)

# --initfile is different from the combination FILE --persist since the first one
# leaves the history empty and sets the current $Line to 1.
argparser.add_argument(
"--pyextensions",
"-l",
action="append",
metavar="PYEXT",
help="directory to load extensions in python",
"--initfile",
help="the same that FILE and --persist together",
type=argparse.FileType("r"),
)

argparser.add_argument(
Expand All @@ -333,12 +333,18 @@ def main() -> int:
action="store_true",
)

# --initfile is different from the combination FILE --persist since the first one
# leaves the history empty and sets the current $Line to 1.
argparser.add_argument(
"--initfile",
help="the same that FILE and --persist together",
type=argparse.FileType("r"),
"--post-mortem",
help="go to post-mortem debug on a terminating system exception (needs trepan3k)",
action="store_true",
)

argparser.add_argument(
"--pyextensions",
"-l",
action="append",
metavar="PYEXT",
help="directory to load extensions in python",
)

argparser.add_argument(
Expand Down Expand Up @@ -447,6 +453,17 @@ def dump_tracing_stats():
eval_loop(feeder, shell)
definitions.set_line_no(0)

if args.post_mortem:
try:
from trepan.post_mortem import post_mortem_excepthook
except ImportError:
print(
"trepan3k is needed for post-mortem debugging --post-mortem option ignored."
)
print("And you may want also trepan3k-mathics3-plugin as well.")
else:
sys.excepthook = post_mortem_excepthook

if args.FILE is not None:
set_input_var(args.FILE.name)
definitions.set_inputfile(args.FILE.name)
Expand Down

0 comments on commit 7583fdc

Please sign in to comment.