Skip to content
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

Add post-mortem debugging via trepan3k #1114

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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