Skip to content

Commit dcd778b

Browse files
author
Release Manager
committed
Trac #31568: Add commands "sage --lldb", "sage -t --lldb"
... 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
2 parents 7f0a555 + 2f4717b commit dcd778b

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/bin/sage

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ usage_advanced() {
343343
echo " --simple-prompt -- pass the option through to IPython: use"
344344
echo " this option with sage-shell mode in emacs"
345345
echo " --gdb -- run Sage under the control of gdb"
346-
echo " --gdb-ipython -- run Sage's IPython under the control of gdb"
346+
echo " --lldb -- run Sage under the control of lldb"
347347
else
348348
echo "Running Sage:"
349349
echo " (not installed currently, "
@@ -1080,6 +1080,12 @@ if [ "$1" = '-gdb' -o "$1" = "--gdb" ]; then
10801080
exit $?
10811081
fi
10821082

1083+
if [ "$1" = '-lldb' -o "$1" = "--lldb" ]; then
1084+
shift
1085+
sage_setup
1086+
lldb --one-line "process launch --tty" --one-line "cont" -- python "${SELF}-ipython" "$@"
1087+
fi
1088+
10831089
if [ "$1" = '-valgrind' -o "$1" = "--valgrind" -o "$1" = '-memcheck' -o "$1" = "--memcheck" ]; then
10841090
shift
10851091
sage_setup

src/bin/sage-runtests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ if __name__ == "__main__":
6868
parser.add_argument("--only-errors", action="store_true", default=False, help="only output failures, not test successes")
6969

7070
parser.add_argument("--gdb", action="store_true", default=False, help="run doctests under the control of gdb")
71+
parser.add_argument("--lldb", action="store_true", default=False, help="run doctests under the control of lldb")
7172
parser.add_argument("--valgrind", "--memcheck", action="store_true", default=False,
7273
help="run doctests using Valgrind's memcheck tool. The log "
7374
"files are named sage-memcheck.PID and can be found in " +

src/sage/doctest/control.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def __init__(self, **kwds):
120120
self.debug = False
121121
self.only_errors = False
122122
self.gdb = False
123+
self.lldb = False
123124
self.valgrind = False
124125
self.massif = False
125126
self.cachegrind = False
@@ -365,7 +366,7 @@ def __init__(self, options, args):
365366
# account and check compatibility of the user's specified
366367
# options.
367368
if options.timeout < 0:
368-
if options.gdb or options.debug:
369+
if options.gdb or options.lldb or options.debug:
369370
# Interactive debuggers: "infinite" timeout
370371
options.timeout = 0
371372
elif options.valgrind or options.massif or options.cachegrind or options.omega:
@@ -1142,7 +1143,7 @@ def _optional_tags_string(self):
11421143

11431144
def _assemble_cmd(self):
11441145
"""
1145-
Assembles a shell command used in running tests under gdb or valgrind.
1146+
Assembles a shell command used in running tests under gdb, lldb, or valgrind.
11461147
11471148
EXAMPLES::
11481149
@@ -1154,7 +1155,7 @@ def _assemble_cmd(self):
11541155
cmd = "sage-runtests --serial "
11551156
opt = dict_difference(self.options.__dict__, DocTestDefaults().__dict__)
11561157
if "all" in opt:
1157-
raise ValueError("You cannot run gdb/valgrind on the whole sage library")
1158+
raise ValueError("You cannot run gdb/lldb/valgrind on the whole sage library")
11581159
for o in ("all", "long", "force_lib", "verbose", "failed", "new"):
11591160
if o in opt:
11601161
cmd += "--%s "%o
@@ -1167,7 +1168,7 @@ def _assemble_cmd(self):
11671168

11681169
def run_val_gdb(self, testing=False):
11691170
"""
1170-
Spawns a subprocess to run tests under the control of gdb or valgrind.
1171+
Spawns a subprocess to run tests under the control of gdb, lldb, or valgrind.
11711172
11721173
INPUT:
11731174
@@ -1205,6 +1206,10 @@ def run_val_gdb(self, testing=False):
12051206
flags = ""
12061207
if opt.logfile:
12071208
sage_cmd += f" --logfile {shlex.quote(opt.logfile)}"
1209+
elif opt.lldb:
1210+
sage_cmd = sage_cmd.replace('sage-runtests', '$(command -v sage-runtests)')
1211+
cmd = f'''exec lldb --one-line "process launch" --one-line "cont" -- {sys.executable} '''
1212+
flags = ""
12081213
else:
12091214
if opt.logfile is None:
12101215
default_log = os.path.join(DOT_SAGE, "valgrind")
@@ -1325,7 +1330,7 @@ def run(self):
13251330
13261331
"""
13271332
opt = self.options
1328-
L = (opt.gdb, opt.valgrind, opt.massif, opt.cachegrind, opt.omega)
1333+
L = (opt.gdb, opt.lldb, opt.valgrind, opt.massif, opt.cachegrind, opt.omega)
13291334
if any(L):
13301335
if L.count(True) > 1:
13311336
self.log("You may only specify one of gdb, valgrind/memcheck, massif, cachegrind, omega")

0 commit comments

Comments
 (0)