@@ -376,28 +376,43 @@ If you experience a segfault, it's recommended to use a debugger that supports
376
376
C, such as gdb or lldb, to look into the segfault.
377
377
378
378
If a test case segfaults, you can run tests using the debugger, so
379
- you can inspect the stack:
379
+ you can inspect the stack. Example of inspecting the C stack when a
380
+ test case segfaults (user input after ` $ ` and ` (gdb) ` prompts):
380
381
381
382
```
382
383
$ pytest mypyc -n0 -s --mypyc-debug=gdb -k <name-of-test>
384
+ ...
385
+ (gdb) r
386
+ ...
387
+ Program received signal SIGSEGV, Segmentation fault.
388
+ ...
389
+ (gdb) bt
390
+ #0 0x00005555556ed1a2 in _PyObject_HashFast (op=0x0) at ./Include/object.h:336
391
+ #1 PyDict_GetItemWithError (op=0x7ffff6c894c0, key=0x0) at Objects/dictobject.c:2394
392
+ ...
383
393
```
384
394
385
395
You must use ` -n0 -s ` to enable interactive input to the debugger.
386
- Instad of ` gdb ` , you can also try ` lldb ` .
396
+ Instad of ` gdb ` , you can also try ` lldb ` (especially on macOS) .
387
397
388
398
To get better C stack tracebacks and more assertions in the Python
389
- runtime, you can build Python in debug mode and use that to run tests
390
- or debug outside the test framework.
399
+ runtime, you can build Python in debug mode and use that to run tests,
400
+ or to manually run the debugger outside the test framework.
391
401
392
- Here are some hints that may help (for Ubuntu):
402
+ ** Note:** You may need to build Python yourself on macOS, as official
403
+ Python builds may not have sufficient entitlements to use a debugger.
404
+
405
+ Here are some hints about building a debug version of CPython that may
406
+ help (for Ubuntu, macOS is mostly similar except for installing build
407
+ dependencies):
393
408
394
409
```
395
410
$ sudo apt install gdb build-essential libncursesw5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev libbz2-dev libffi-dev libgdbm-compat-dev
396
411
$ <download Python tarball and extract it>
397
412
$ cd Python-3.XX.Y
398
413
$ ./configure --with-pydebug
399
414
$ make -s -j16
400
- $ ./python -m venv ~/<venv-location>
415
+ $ ./python -m venv ~/<venv-location> # Use ./python.exe -m venv ... on macOS
401
416
$ source ~/<venv-location>/bin/activate
402
417
$ cd <mypy-repo-dir>
403
418
$ pip install -r test-requirements.txt
0 commit comments