This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Misc/.gdbinit uses preprocessor macro
Type: Stage: resolved
Components: Demos and Tools Versions: Python 3.6, Python 3.4, Python 3.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Some gdb macros are broken in 3.6
View: 29673
Assigned To: Nosy List: pablogsal, philtweir, vstinner
Priority: normal Keywords: patch

Created on 2015-10-22 15:13 by philtweir, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
gdbinit-PyUnicode_AsUTF8.patch philtweir, 2015-10-22 15:13 Patch changing preprocessor macros in .gdbinit to C functions review
Pull Requests
URL Status Linked Edit
PR 25473 merged pablogsal, 2021-04-19 20:02
Messages (4)
msg253333 - (view) Author: Phil Weir (philtweir) Date: 2015-10-22 15:13
When using the sample .gdbinit, use of the _PyUnicode_AsString macro gives "No symbol "_PyUnicode_AsString" in current context." from GDB.

This was first noticed when using downstream (Ubuntu) CPython 3.4/3.5 with debug symbols, and was reproduced by building current HEAD without optimization (to ensure co object not optimized out) 'CFLAGS="-g -O0" ./configure --with-pydebug && make -j2', based on instructions here [1].

This is fixable by switching _PyUnicode_AtString to PyUnicode_AsUTF8, the target of the macro in './Include/unicodeobject.h' (see attached patch)

1 - https://docs.python.org/devguide/setup.html#unix

====

TEST FILE (loop.py)
=========
import time

time.sleep(100)


GDB OUTPUT WITHOUT PATCH
========================

> gdb -args /usr/local/bin/python3.6dm loop.py

GNU gdb (GDB) 7.9.50.20150218-cvs
Copyright (C) 2015 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".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/local/bin/python3.6dm...done.
(gdb) r
Starting program: /usr/local/bin/python3.6dm loop.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
^C
Program received signal SIGINT, Interrupt.
0x00007ffff71df723 in select () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x00007ffff71df723 in select () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x000000000065f9eb in pysleep (secs=100000000000) at ./Modules/timemodule.c:1408
#2  0x000000000065d9a1 in time_sleep (self=0x7ffff6d318d8, obj=0x9ce7f0 <small_ints+5040>) at ./Modules/timemodule.c:231
#3  0x00000000005d8c96 in call_function (pp_stack=0x7fffffffbde0, oparg=1) at Python/ceval.c:4636
#4  0x00000000005d0a59 in PyEval_EvalFrameEx (f=0xa82198, throwflag=0) at Python/ceval.c:3181
#5  0x00000000005d6154 in _PyEval_EvalCodeWithName (_co=0x7ffff7e1c280, globals=0x7ffff7f1de58, locals=0x7ffff7f1de58, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0,
    name=0x0, qualname=0x0) at Python/ceval.c:3962
#6  0x00000000005d629d in PyEval_EvalCodeEx (_co=0x7ffff7e1c280, globals=0x7ffff7f1de58, locals=0x7ffff7f1de58, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0)
    at Python/ceval.c:3983
#7  0x00000000005c05aa in PyEval_EvalCode (co=0x7ffff7e1c280, globals=0x7ffff7f1de58, locals=0x7ffff7f1de58) at Python/ceval.c:777
#8  0x0000000000428790 in run_mod (mod=0xac0968, filename=0x7ffff6dd7c08, globals=0x7ffff7f1de58, locals=0x7ffff7f1de58, flags=0x7fffffffd690, arena=0xade380) at Python/pythonrun.c:970
#9  0x00000000004284c3 in PyRun_FileExFlags (fp=0xab8210, filename_str=0x7ffff7f0bd80 "loop.py", start=257, globals=0x7ffff7f1de58, locals=0x7ffff7f1de58, closeit=1, flags=0x7fffffffd690)
    at Python/pythonrun.c:923
#10 0x00000000004263c1 in PyRun_SimpleFileExFlags (fp=0xab8210, filename=0x7ffff7f0bd80 "loop.py", closeit=1, flags=0x7fffffffd690) at Python/pythonrun.c:396
#11 0x0000000000425127 in PyRun_AnyFileExFlags (fp=0xab8210, filename=0x7ffff7f0bd80 "loop.py", closeit=1, flags=0x7fffffffd690) at Python/pythonrun.c:80
#12 0x0000000000441b4b in run_file (fp=0xab8210, filename=0x9ee270 L"loop.py", p_cf=0x7fffffffd690) at Modules/main.c:318
#13 0x0000000000442aeb in Py_Main (argc=2, argv=0x9ec020) at Modules/main.c:768
#14 0x000000000041c26f in main (argc=2, argv=0x7fffffffd948) at ./Programs/python.c:69
(gdb) f 4
#4  0x00000000005d0a59 in PyEval_EvalFrameEx (f=0xa82198, throwflag=0) at Python/ceval.c:3181
3181                res = call_function(&sp, oparg);
(gdb) pystack
No symbol "_PyUnicode_AsString" in current context.
(gdb)


GDB OUTPUT WITH PATCH
=====================

> gdb -args /usr/local/bin/python3.6dm loop.py 


GNU gdb (GDB) 7.9.50.20150218-cvs
Copyright (C) 2015 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".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/local/bin/python3.6dm...done.
(gdb) r
Starting program: /usr/local/bin/python3.6dm loop.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
^C
Program received signal SIGINT, Interrupt.
0x00007ffff71df723 in select () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x00007ffff71df723 in select () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x000000000065f9eb in pysleep (secs=100000000000) at ./Modules/timemodule.c:1408
#2  0x000000000065d9a1 in time_sleep (self=0x7ffff6d318d8, obj=0x9ce7f0 <small_ints+5040>) at ./Modules/timemodule.c:231
#3  0x00000000005d8c96 in call_function (pp_stack=0x7fffffffbde0, oparg=1) at Python/ceval.c:4636
#4  0x00000000005d0a59 in PyEval_EvalFrameEx (f=0xa82198, throwflag=0) at Python/ceval.c:3181
#5  0x00000000005d6154 in _PyEval_EvalCodeWithName (_co=0x7ffff7e1c280, globals=0x7ffff7f1de58, locals=0x7ffff7f1de58, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0,
    name=0x0, qualname=0x0) at Python/ceval.c:3962
#6  0x00000000005d629d in PyEval_EvalCodeEx (_co=0x7ffff7e1c280, globals=0x7ffff7f1de58, locals=0x7ffff7f1de58, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0)
    at Python/ceval.c:3983
#7  0x00000000005c05aa in PyEval_EvalCode (co=0x7ffff7e1c280, globals=0x7ffff7f1de58, locals=0x7ffff7f1de58) at Python/ceval.c:777
#8  0x0000000000428790 in run_mod (mod=0xac0928, filename=0x7ffff6dd7c08, globals=0x7ffff7f1de58, locals=0x7ffff7f1de58, flags=0x7fffffffd690, arena=0xab9470) at Python/pythonrun.c:970
#9  0x00000000004284c3 in PyRun_FileExFlags (fp=0xab81d0, filename_str=0x7ffff7f0bd80 "loop.py", start=257, globals=0x7ffff7f1de58, locals=0x7ffff7f1de58, closeit=1, flags=0x7fffffffd690)
    at Python/pythonrun.c:923
#10 0x00000000004263c1 in PyRun_SimpleFileExFlags (fp=0xab81d0, filename=0x7ffff7f0bd80 "loop.py", closeit=1, flags=0x7fffffffd690) at Python/pythonrun.c:396
#11 0x0000000000425127 in PyRun_AnyFileExFlags (fp=0xab81d0, filename=0x7ffff7f0bd80 "loop.py", closeit=1, flags=0x7fffffffd690) at Python/pythonrun.c:80
#12 0x0000000000441b4b in run_file (fp=0xab81d0, filename=0x9ee270 L"loop.py", p_cf=0x7fffffffd690) at Modules/main.c:318
#13 0x0000000000442aeb in Py_Main (argc=2, argv=0x9ec020) at Modules/main.c:768
#14 0x000000000041c26f in main (argc=2, argv=0x7fffffffd948) at ./Programs/python.c:69
(gdb) f 4
#4  0x00000000005d0a59 in PyEval_EvalFrameEx (f=0xa82198, throwflag=0) at Python/ceval.c:3181
3181                res = call_function(&sp, oparg);
(gdb) pystack
loop.py (3): <module>
loop.py (3): <module>
(gdb)
msg253334 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-10-22 15:15
> GNU gdb (GDB) 7.9.50.20150218-cvs

Since you have using a recent version of gdb supporting python scripting, you must test python-gdb.py which is more reliable and has more features.
msg253353 - (view) Author: Phil Weir (philtweir) Date: 2015-10-22 20:59
Many thanks, Victor - python-gdb does work for GDB 7 (after a little confusion with python/python3.6dm naming and auto-load). That is very helpful. For reference, can confirm the error described above for GDB 6.8 and Python 3.6 (with DWARF-2 flags) and that the patch restores expected behaviour.
msg391411 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-04-19 22:36
New changeset 7a041162468b83f6cad667b78ed5c786286aed2b by Pablo Galindo in branch 'master':
bpo-25460: Surround suggestions by quotes (GH-25473)
https://github.com/python/cpython/commit/7a041162468b83f6cad667b78ed5c786286aed2b
History
Date User Action Args
2022-04-11 14:58:23adminsetgithub: 69646
2021-04-19 22:36:05pablogsalsetmessages: + msg391411
2021-04-19 20:02:17pablogsalsetnosy: + pablogsal

pull_requests: + pull_request24199
2020-11-11 19:22:04iritkatrielsetstatus: open -> closed
superseder: Some gdb macros are broken in 3.6
resolution: duplicate
stage: resolved
2015-10-22 20:59:15philtweirsetmessages: + msg253353
2015-10-22 15:15:04vstinnersetnosy: + vstinner
messages: + msg253334
2015-10-22 15:13:55philtweircreate