Skip to content

Instantly share code, notes, and snippets.

@mikesart
Created August 13, 2014 00:37
Show Gist options
  • Save mikesart/dbee9d3787c409974cd1 to your computer and use it in GitHub Desktop.
Save mikesart/dbee9d3787c409974cd1 to your computer and use it in GitHub Desktop.
GDB Python Print not working.
I'm trying to figure out why 'python print "hello"' is giving me invalid syntax.
(gdb) python import gdb
(gdb) python print "hello"
File "<string>", line 1
print "hello"
^
SyntaxError: invalid syntax
Error while executing Python code.
(gdb) python gdb.execute("p 1 + 2")
$3 = 3
mikesart@mikesart-petra:~/valvesrc/ValveGames/staging/game$ gdb --version
GNU gdb (Ubuntu 7.7-0ubuntu3.2) 7.7
Copyright (C) 2014 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-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".
mikesart@mikesart-petra:~/valvesrc/ValveGames/staging/game$ gdb --configuration
This GDB was configured as follows:
configure --host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-auto-load-dir=$debugdir:$datadir/auto-load
--with-auto-load-safe-path=$debugdir:$datadir/auto-load
--with-expat
--with-gdb-datadir=/usr/share/gdb (relocatable)
--with-jit-reader-dir=/usr/lib/gdb (relocatable)
--without-libunwind-ia64
--with-lzma
--with-python=/usr (relocatable)
--with-separate-debug-dir=/usr/lib/debug (relocatable)
--with-system-gdbinit=/etc/gdb/gdbinit
--with-zlib
--without-babeltrace
("Relocatable" means the directory can be moved with the GDB installation
tree, and GDB will still find it.)
mikesart@mikesart-petra:~/valvesrc/ValveGames/staging/game$ lsb_release -a
No LSB modules are available.
Distributor ID: LinuxMint
Description: Linux Mint 17 Qiana
Release: 17
Codename: qiana
mikesart@mikesart-petra:~/valvesrc/ValveGames/staging/game$ uname -a
Linux mikesart-petra 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
@teajob
Copy link

teajob commented Dec 6, 2017

Debian, for example, has different gdb packages for different python versions.

https://packages.debian.org/stretch/gdb

apt install gdb
ldd $(which gdb) | grep python
        libpython3.5m.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 (0x00007f138b5e0000)
apt remove gdb && apt install gdb-python2
ldd $(which gdb) | grep python
        libpython2.7.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 (0x00007f02f77dd000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment