From ebbb653599c9b56af92bbb3ede7299f9156d31d4 Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 1 Oct 2024 10:07:02 -0400 Subject: [PATCH] Add post-mortem debugging via trepan3k --- mathics/main.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/mathics/main.py b/mathics/main.py index 2b10b394b..c418cd059 100755 --- a/mathics/main.py +++ b/mathics/main.py @@ -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( @@ -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( @@ -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)