Created
December 6, 2012 21:01
-
-
Save mshroyer/4228342 to your computer and use it in GitHub Desktop.
Python GDB adventures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from os import kill, getpid | |
from signal import SIGINT | |
def factorial(n): | |
if n == 0: | |
# Break into GDB | |
kill(getpid(), SIGINT) | |
return 1 | |
else: | |
return n * factorial(n-1) | |
if __name__ == "__main__": | |
n = 10 | |
print("factorial({0}) = {1}".format(n, factorial(n))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GNU gdb (GDB) 7.5 | |
Copyright (C) 2012 Free Software Foundation, Inc. | |
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> | |
This is free software: you are free to change and redistribute it. | |
There is NO WARRANTY, to the extent permitted by law. Type "show copying" | |
and "show warranty" for details. | |
This GDB was configured as "x86_64-unknown-linux-gnu". | |
For bug reporting instructions, please see: | |
<http://www.gnu.org/software/gdb/bugs/>... | |
Reading symbols from /home/mshroyer/sw/Python-2.7.3/python...done. | |
warning: File "/home/mshroyer/sw/Python-2.7.3/python-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". | |
(gdb) source ~/sw/Python-2.7.3/python-gdb.py | |
(gdb) run ~/scratch/factorial.py | |
Starting program: /home/mshroyer/sw/Python-2.7.3/python ~/scratch/factorial.py | |
[Thread debugging using libthread_db enabled] | |
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". | |
Program received signal SIGINT, Interrupt. | |
0x00007ffff7131707 in kill () from /lib/x86_64-linux-gnu/libc.so.6 | |
(gdb) py-bt | |
#4 (unable to read python frame information) | |
#8 (unable to read python frame information) | |
#12 (unable to read python frame information) | |
#16 (unable to read python frame information) | |
#20 (unable to read python frame information) | |
#24 (unable to read python frame information) | |
#28 (unable to read python frame information) | |
#32 (unable to read python frame information) | |
#36 (unable to read python frame information) | |
#40 (unable to read python frame information) | |
#44 (unable to read python frame information) | |
#48 (unable to read python frame information) | |
(gdb) py-up | |
#8 (unable to read python frame information) | |
(gdb) py-print n | |
Unable to read information on python frame | |
(gdb) bt | |
#0 0x00007ffff7131707 in kill () from /lib/x86_64-linux-gnu/libc.so.6 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#1 0x0000000000524a89 in posix_kill (self=0x0, args=) at ./Modules/posixmodule.c:4124 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#2 0x000000000055fec6 in PyCFunction_Call (func=<built-in function kill>, arg=, kw=0x0) at Objects/methodobject.c:81 | |
#3 0x00000000004d4446 in call_function (pp_stack=0x7fffffffa730, oparg=0x2) at Python/ceval.c:4021 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0xe': | |
#4 0x00000000004cf312 in PyEval_EvalFrameEx (f=, throwflag=0x0) at Python/ceval.c:2666 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#5 0x00000000004d1c1a in PyEval_EvalCodeEx (co=0x9c8e00, globals=, locals=0x0, args=0xa90600, argcount=0x1, kws=0xa90608, kwcount=0x0, defs=0x0, defcount=0x0, closure=0x0) at Python/ceval.c:3253 | |
#6 0x00000000004d4a2e in fast_function (func=<function at remote 0xa46300>, pp_stack=0x7fffffffabf0, n=0x1, na=0x1, nk=0x0) at Python/ceval.c:4117 | |
#7 0x00000000004d461d in call_function (pp_stack=0x7fffffffabf0, oparg=0x1) at Python/ceval.c:4042 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0xe': | |
#8 0x00000000004cf312 in PyEval_EvalFrameEx (f=, throwflag=0x0) at Python/ceval.c:2666 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#9 0x00000000004d1c1a in PyEval_EvalCodeEx (co=0x9c8e00, globals=, locals=0x0, args=0xa90400, argcount=0x1, kws=0xa90408, kwcount=0x0, defs=0x0, defcount=0x0, closure=0x0) at Python/ceval.c:3253 | |
#10 0x00000000004d4a2e in fast_function (func=<function at remote 0xa46300>, pp_stack=0x7fffffffb0b0, n=0x1, na=0x1, nk=0x0) at Python/ceval.c:4117 | |
#11 0x00000000004d461d in call_function (pp_stack=0x7fffffffb0b0, oparg=0x1) at Python/ceval.c:4042 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0xe': | |
#12 0x00000000004cf312 in PyEval_EvalFrameEx (f=, throwflag=0x0) at Python/ceval.c:2666 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#13 0x00000000004d1c1a in PyEval_EvalCodeEx (co=0x9c8e00, globals=, locals=0x0, args=0xa90200, argcount=0x1, kws=0xa90208, kwcount=0x0, defs=0x0, defcount=0x0, closure=0x0) at Python/ceval.c:3253 | |
#14 0x00000000004d4a2e in fast_function (func=<function at remote 0xa46300>, pp_stack=0x7fffffffb570, n=0x1, na=0x1, nk=0x0) at Python/ceval.c:4117 | |
#15 0x00000000004d461d in call_function (pp_stack=0x7fffffffb570, oparg=0x1) at Python/ceval.c:4042 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0xe': | |
#16 0x00000000004cf312 in PyEval_EvalFrameEx (f=, throwflag=0x0) at Python/ceval.c:2666 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#17 0x00000000004d1c1a in PyEval_EvalCodeEx (co=0x9c8e00, globals=, locals=0x0, args=0xa90000, argcount=0x1, kws=0xa90008, kwcount=0x0, defs=0x0, defcount=0x0, closure=0x0) at Python/ceval.c:3253 | |
#18 0x00000000004d4a2e in fast_function (func=<function at remote 0xa46300>, pp_stack=0x7fffffffba30, n=0x1, na=0x1, nk=0x0) at Python/ceval.c:4117 | |
#19 0x00000000004d461d in call_function (pp_stack=0x7fffffffba30, oparg=0x1) at Python/ceval.c:4042 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0xe': | |
#20 0x00000000004cf312 in PyEval_EvalFrameEx (f=, throwflag=0x0) at Python/ceval.c:2666 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#21 0x00000000004d1c1a in PyEval_EvalCodeEx (co=0x9c8e00, globals=, locals=0x0, args=0xa8e920, argcount=0x1, kws=0xa8e928, kwcount=0x0, defs=0x0, defcount=0x0, closure=0x0) at Python/ceval.c:3253 | |
#22 0x00000000004d4a2e in fast_function (func=<function at remote 0xa46300>, pp_stack=0x7fffffffbef0, n=0x1, na=0x1, nk=0x0) at Python/ceval.c:4117 | |
#23 0x00000000004d461d in call_function (pp_stack=0x7fffffffbef0, oparg=0x1) at Python/ceval.c:4042 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0xe': | |
#24 0x00000000004cf312 in PyEval_EvalFrameEx (f=, throwflag=0x0) at Python/ceval.c:2666 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#25 0x00000000004d1c1a in PyEval_EvalCodeEx (co=0x9c8e00, globals=, locals=0x0, args=0xa8e720, argcount=0x1, kws=0xa8e728, kwcount=0x0, defs=0x0, defcount=0x0, closure=0x0) at Python/ceval.c:3253 | |
#26 0x00000000004d4a2e in fast_function (func=<function at remote 0xa46300>, pp_stack=0x7fffffffc3b0, n=0x1, na=0x1, nk=0x0) at Python/ceval.c:4117 | |
#27 0x00000000004d461d in call_function (pp_stack=0x7fffffffc3b0, oparg=0x1) at Python/ceval.c:4042 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0xe': | |
#28 0x00000000004cf312 in PyEval_EvalFrameEx (f=, throwflag=0x0) at Python/ceval.c:2666 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#29 0x00000000004d1c1a in PyEval_EvalCodeEx (co=0x9c8e00, globals=, locals=0x0, args=0xa8e520, argcount=0x1, kws=0xa8e528, kwcount=0x0, defs=0x0, defcount=0x0, closure=0x0) at Python/ceval.c:3253 | |
#30 0x00000000004d4a2e in fast_function (func=<function at remote 0xa46300>, pp_stack=0x7fffffffc870, n=0x1, na=0x1, nk=0x0) at Python/ceval.c:4117 | |
#31 0x00000000004d461d in call_function (pp_stack=0x7fffffffc870, oparg=0x1) at Python/ceval.c:4042 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0xe': | |
#32 0x00000000004cf312 in PyEval_EvalFrameEx (f=, throwflag=0x0) at Python/ceval.c:2666 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#33 0x00000000004d1c1a in PyEval_EvalCodeEx (co=0x9c8e00, globals=, locals=0x0, args=0xa79290, argcount=0x1, kws=0xa79298, kwcount=0x0, defs=0x0, defcount=0x0, closure=0x0) at Python/ceval.c:3253 | |
#34 0x00000000004d4a2e in fast_function (func=<function at remote 0xa46300>, pp_stack=0x7fffffffcd30, n=0x1, na=0x1, nk=0x0) at Python/ceval.c:4117 | |
#35 0x00000000004d461d in call_function (pp_stack=0x7fffffffcd30, oparg=0x1) at Python/ceval.c:4042 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0xe': | |
#36 0x00000000004cf312 in PyEval_EvalFrameEx (f=, throwflag=0x0) at Python/ceval.c:2666 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#37 0x00000000004d1c1a in PyEval_EvalCodeEx (co=0x9c8e00, globals=, locals=0x0, args=0xa79090, argcount=0x1, kws=0xa79098, kwcount=0x0, defs=0x0, defcount=0x0, closure=0x0) at Python/ceval.c:3253 | |
#38 0x00000000004d4a2e in fast_function (func=<function at remote 0xa46300>, pp_stack=0x7fffffffd1f0, n=0x1, na=0x1, nk=0x0) at Python/ceval.c:4117 | |
#39 0x00000000004d461d in call_function (pp_stack=0x7fffffffd1f0, oparg=0x1) at Python/ceval.c:4042 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0xe': | |
#40 0x00000000004cf312 in PyEval_EvalFrameEx (f=, throwflag=0x0) at Python/ceval.c:2666 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#41 0x00000000004d1c1a in PyEval_EvalCodeEx (co=0x9c8e00, globals=, locals=0x0, args=0xa78e90, argcount=0x1, kws=0xa78e98, kwcount=0x0, defs=0x0, defcount=0x0, closure=0x0) at Python/ceval.c:3253 | |
#42 0x00000000004d4a2e in fast_function (func=<function at remote 0xa46300>, pp_stack=0x7fffffffd6b0, n=0x1, na=0x1, nk=0x0) at Python/ceval.c:4117 | |
#43 0x00000000004d461d in call_function (pp_stack=0x7fffffffd6b0, oparg=0x1) at Python/ceval.c:4042 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0xe': | |
#44 0x00000000004cf312 in PyEval_EvalFrameEx (f=, throwflag=0x0) at Python/ceval.c:2666 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#45 0x00000000004d1c1a in PyEval_EvalCodeEx (co=0x9c8e00, globals=, locals=0x0, args=0xa6a6a8, argcount=0x1, kws=0xa6a6b0, kwcount=0x0, defs=0x0, defcount=0x0, closure=0x0) at Python/ceval.c:3253 | |
#46 0x00000000004d4a2e in fast_function (func=<function at remote 0xa46300>, pp_stack=0x7fffffffdb70, n=0x1, na=0x1, nk=0x0) at Python/ceval.c:4117 | |
#47 0x00000000004d461d in call_function (pp_stack=0x7fffffffdb70, oparg=0x1) at Python/ceval.c:4042 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x9': | |
#48 0x00000000004cf312 in PyEval_EvalFrameEx (f=, throwflag=0x0) at Python/ceval.c:2666 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#49 0x00000000004d1c1a in PyEval_EvalCodeEx (co=0xa20040, globals=, locals=, args=0x0, argcount=0x0, kws=0x0, kwcount=0x0, defs=0x0, defcount=0x0, closure=0x0) at Python/ceval.c:3253 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#50 0x00000000004c7db6 in PyEval_EvalCode (co=0xa20040, globals=, locals=) at Python/ceval.c:667 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#51 0x00000000005044b0 in run_mod (mod=0xa73730, filename=0x7fffffffe655 "/home/mshroyer/scratch/factorial.py", globals=, locals=, flags=0x7fffffffe170, arena=0x8b8c20) at Python/pythonrun.c:1353 | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
Python Exception <type 'exceptions.ValueError'> invalid literal for int() with base 10: '0x2': | |
#52 0x0000000000504436 in PyRun_FileExFlags (fp=0x8b2980, filename=0x7fffffffe655 "/home/mshroyer/scratch/factorial.py", start=0x101, globals=, locals=, closeit=0x1, flags=0x7fffffffe170) at Python/pythonrun.c:1339 | |
#53 0x0000000000502cd0 in PyRun_SimpleFileExFlags (fp=0x8b2980, filename=0x7fffffffe655 "/home/mshroyer/scratch/factorial.py", closeit=0x1, flags=0x7fffffffe170) at Python/pythonrun.c:943 | |
#54 0x0000000000502314 in PyRun_AnyFileExFlags (fp=0x8b2980, filename=0x7fffffffe655 "/home/mshroyer/scratch/factorial.py", closeit=0x1, flags=0x7fffffffe170) at Python/pythonrun.c:747 | |
#55 0x0000000000415c52 in Py_Main (argc=0x2, argv=0x7fffffffe2b8) at Modules/main.c:639 | |
#56 0x0000000000414794 in main (argc=0x2, argv=0x7fffffffe2b8) at ./Modules/python.c:23 | |
(gdb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you resolved this problem?