Skip to content

Commit

Permalink
Trac #31568: Add commands "sage --lldb", "sage -t --lldb"
Browse files Browse the repository at this point in the history
... for debugging on macOS, similar to `sage --gdb` and `sage -t --gdb`

URL: https://trac.sagemath.org/31568
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): John Palmieri
  • Loading branch information
Release Manager committed Jul 28, 2022
2 parents 7f0a555 + 2f4717b commit dcd778b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/bin/sage
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ usage_advanced() {
echo " --simple-prompt -- pass the option through to IPython: use"
echo " this option with sage-shell mode in emacs"
echo " --gdb -- run Sage under the control of gdb"
echo " --gdb-ipython -- run Sage's IPython under the control of gdb"
echo " --lldb -- run Sage under the control of lldb"
else
echo "Running Sage:"
echo " (not installed currently, "
Expand Down Expand Up @@ -1080,6 +1080,12 @@ if [ "$1" = '-gdb' -o "$1" = "--gdb" ]; then
exit $?
fi

if [ "$1" = '-lldb' -o "$1" = "--lldb" ]; then
shift
sage_setup
lldb --one-line "process launch --tty" --one-line "cont" -- python "${SELF}-ipython" "$@"
fi

if [ "$1" = '-valgrind' -o "$1" = "--valgrind" -o "$1" = '-memcheck' -o "$1" = "--memcheck" ]; then
shift
sage_setup
Expand Down
1 change: 1 addition & 0 deletions src/bin/sage-runtests
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ if __name__ == "__main__":
parser.add_argument("--only-errors", action="store_true", default=False, help="only output failures, not test successes")

parser.add_argument("--gdb", action="store_true", default=False, help="run doctests under the control of gdb")
parser.add_argument("--lldb", action="store_true", default=False, help="run doctests under the control of lldb")
parser.add_argument("--valgrind", "--memcheck", action="store_true", default=False,
help="run doctests using Valgrind's memcheck tool. The log "
"files are named sage-memcheck.PID and can be found in " +
Expand Down
15 changes: 10 additions & 5 deletions src/sage/doctest/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def __init__(self, **kwds):
self.debug = False
self.only_errors = False
self.gdb = False
self.lldb = False
self.valgrind = False
self.massif = False
self.cachegrind = False
Expand Down Expand Up @@ -365,7 +366,7 @@ def __init__(self, options, args):
# account and check compatibility of the user's specified
# options.
if options.timeout < 0:
if options.gdb or options.debug:
if options.gdb or options.lldb or options.debug:
# Interactive debuggers: "infinite" timeout
options.timeout = 0
elif options.valgrind or options.massif or options.cachegrind or options.omega:
Expand Down Expand Up @@ -1142,7 +1143,7 @@ def _optional_tags_string(self):

def _assemble_cmd(self):
"""
Assembles a shell command used in running tests under gdb or valgrind.
Assembles a shell command used in running tests under gdb, lldb, or valgrind.
EXAMPLES::
Expand All @@ -1154,7 +1155,7 @@ def _assemble_cmd(self):
cmd = "sage-runtests --serial "
opt = dict_difference(self.options.__dict__, DocTestDefaults().__dict__)
if "all" in opt:
raise ValueError("You cannot run gdb/valgrind on the whole sage library")
raise ValueError("You cannot run gdb/lldb/valgrind on the whole sage library")
for o in ("all", "long", "force_lib", "verbose", "failed", "new"):
if o in opt:
cmd += "--%s "%o
Expand All @@ -1167,7 +1168,7 @@ def _assemble_cmd(self):

def run_val_gdb(self, testing=False):
"""
Spawns a subprocess to run tests under the control of gdb or valgrind.
Spawns a subprocess to run tests under the control of gdb, lldb, or valgrind.
INPUT:
Expand Down Expand Up @@ -1205,6 +1206,10 @@ def run_val_gdb(self, testing=False):
flags = ""
if opt.logfile:
sage_cmd += f" --logfile {shlex.quote(opt.logfile)}"
elif opt.lldb:
sage_cmd = sage_cmd.replace('sage-runtests', '$(command -v sage-runtests)')
cmd = f'''exec lldb --one-line "process launch" --one-line "cont" -- {sys.executable} '''
flags = ""
else:
if opt.logfile is None:
default_log = os.path.join(DOT_SAGE, "valgrind")
Expand Down Expand Up @@ -1325,7 +1330,7 @@ def run(self):
"""
opt = self.options
L = (opt.gdb, opt.valgrind, opt.massif, opt.cachegrind, opt.omega)
L = (opt.gdb, opt.lldb, opt.valgrind, opt.massif, opt.cachegrind, opt.omega)
if any(L):
if L.count(True) > 1:
self.log("You may only specify one of gdb, valgrind/memcheck, massif, cachegrind, omega")
Expand Down

0 comments on commit dcd778b

Please sign in to comment.