Cannot run GDB at all: error message cannot import module site


#1

EDIT: I can’t run gdb at all, even when I set HOME to something else. A transcript of me running strace on gdb (at the bottom) indicates it is loading a python2.7 even though I have no python2.7 installed voluntarily (I use python 3.6.6 here).

When I run python, it works, but when I run gdb python it fails.


[henry@watson:~/Projects/eyeserver/dserver/src]$ python
Python 3.6.6 (default, Jun 27 2018, 05:47:41) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 


[henry@watson:~/Projects/eyeserver/dserver/src]$ 
[henry@watson:~/Projects/eyeserver/dserver/src]$ gdb python
ImportError: No module named site

[henry@watson:~/Projects/eyeserver/dserver/src]$ 

Trying to work around it with various unrapping also fails:

[henry@watson:~/Projects/eyeserver/dserver/src]$ /nix/store/bwfygfcdvis9wd1c1v51xwnwhw1hx0a0-python3-3.6.6/bin/python
Python 3.6.6 (default, Jun 27 2018, 05:47:41) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 


[henry@watson:~/Projects/eyeserver/dserver/src]$ 
[henry@watson:~/Projects/eyeserver/dserver/src]$ gdb /nix/store/bwfygfcdvis9wd1c1v51xwnwhw1hx0a0-python3-3.6.6/bin/python
ImportError: No module named site

Nothing I do to the environment helps. I’m happy to compile a new python, etc. I just want to know where to look.

Here’s the a snipped strace of me running GDB at all. it fails and seems to load python2.7 stuff.


[henry@watson:~/Projects/eyeserver/dserver/src]$ HOME=/tmp gdb
ImportError: No module named site

[henry@watson:~/Projects/eyeserver/dserver/src]$ HOME=/tmp strace gdb
execve("/home/henry/.nix-profile/bin/gdb", ["gdb"], 0x7ffc32a4f420 /* 91 vars */) = 0
brk(NULL)                               = 0x2070000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3ea92b5000
access("/etc/ld-nix.so.preload", R_OK)  = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/run/opengl-driver/lib/tls/haswell/x86_64/libreadline.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

<snip>

"/nix/store/6gapz5mrsr917ljsl7brz"..., 4095) = 61
lstat("/nix", {st_mode=S_IFDIR|0755, st_size=16, ...}) = 0
lstat("/nix/store", {st_mode=S_IFDIR|S_ISVTX|0775, st_size=1015774, ...}) = 0
lstat("/nix/store/6gapz5mrsr917ljsl7brzilnmyr7arn5-gdb-8.1.1", {st_mode=S_IFDIR|0555, st_size=58, ...}) = 0
lstat("/nix/store/6gapz5mrsr917ljsl7brzilnmyr7arn5-gdb-8.1.1/bin", {st_mode=S_IFDIR|0555, st_size=34, ...}) = 0
lstat("/nix/store/6gapz5mrsr917ljsl7brzilnmyr7arn5-gdb-8.1.1/bin/gdb", {st_mode=S_IFREG|0555, st_size=27746568, ...}) = 0
stat("/nix/store/6gapz5mrsr917ljsl7brzilnmyr7arn5-gdb-8.1.1/bin/../share/gdb", {st_mode=S_IFDIR|0555, st_size=56, ...}) = 0
lstat("/nix", {st_mode=S_IFDIR|0755, st_size=16, ...}) = 0
lstat("/nix/store", {st_mode=S_IFDIR|S_ISVTX|0775, st_size=1015774, ...}) = 0
lstat("/nix/store/6gapz5mrsr917ljsl7brzilnmyr7arn5-gdb-8.1.1", {st_mode=S_IFDIR|0555, st_size=58, ...}) = 0
lstat("/nix/store/6gapz5mrsr917ljsl7brzilnmyr7arn5-gdb-8.1.1/bin", {st_mode=S_IFDIR|0555, st_size=34, ...}) = 0
lstat("/nix/store/6gapz5mrsr917ljsl7brzilnmyr7arn5-gdb-8.1.1/share", {st_mode=S_IFDIR|0555, st_size=32, ...}) = 0
lstat("/nix/store/6gapz5mrsr917ljsl7brzilnmyr7arn5-gdb-8.1.1/share/gdb", {st_mode=S_IFDIR|0555, st_size=56, ...}) = 0
stat("/nix/store/2brlr94ahy3a9mvcjy0qbqpv8zrb7b7s-python-2.7.15/lib", {st_mode=S_IFDIR|0555, st_size=104, ...}) = 0
lstat("/nix", {st_mode=S_IFDIR|0755, st_size=16, ...}) = 0
lstat("/nix/store", {st_mode=S_IFDIR|S_ISVTX|0775, st_size=1015774, ...}) = 0
lstat("/nix/store/2brlr94ahy3a9mvcjy0qbqpv8zrb7b7s-python-2.7.15", {st_mode=S_IFDIR|0555, st_size=58, ...}) = 0
lstat("/nix/store/2brlr94ahy3a9mvcjy0qbqpv8zrb7b7s-python-2.7.15/lib", {st_mode=S_IFDIR|0555, st_size=104, ...}) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0

<snip>

fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
fstat(2, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
readlink("/nix/store/2brlr94ahy3a9mvcjy0qbqpv8zrb7b7s-python-2.7.15/bin/python", "python2", 4096) = 7
readlink("/nix/store/2brlr94ahy3a9mvcjy0qbqpv8zrb7b7s-python-2.7.15/bin/python2", "python2.7", 4096) = 9
readlink("/nix/store/2brlr94ahy3a9mvcjy0qbqpv8zrb7b7s-python-2.7.15/bin/python2.7", 0x7ffc0f2436b0, 4096) = -1 EINVAL (Invalid argument)
mmap(NULL, 262144, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3ea922f000
brk(0x21fc000)                          = 0x21fc000
brk(0x21fb000)                          = 0x21fb000
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f3ea85adf10}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGXFSZ, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f3ea85adf10}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
getpid()                                = 8161
rt_sigaction(SIGHUP, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0

<snip>

sigaction(SIGINT, {sa_handler=0x7f3ea7d39960, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f3ea85adf10}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python27.zip", 0x7ffc0f2400e0) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib", {st_mode=S_IFDIR|0555, st_size=134, ...}) = 0
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python27.zip", 0x7ffc0f243160) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7", 0x7ffc0f2400e0) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib", {st_mode=S_IFDIR|0555, st_size=134, ...}) = 0
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7", 0x7ffc0f243160) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7/plat-linux2", 0x7ffc0f2400e0) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7", 0x7ffc0f2400e0) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib", {st_mode=S_IFDIR|0555, st_size=134, ...}) = 0
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7/plat-linux2", 0x7ffc0f243160) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7/lib-tk", 0x7ffc0f2400e0) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7", 0x7ffc0f2400e0) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib", {st_mode=S_IFDIR|0555, st_size=134, ...}) = 0
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7/lib-tk", 0x7ffc0f243160) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7/lib-old", 0x7ffc0f2400e0) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7", 0x7ffc0f2400e0) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib", {st_mode=S_IFDIR|0555, st_size=134, ...}) = 0
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7/lib-old", 0x7ffc0f243160) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7/lib-dynload", 0x7ffc0f2400e0) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7", 0x7ffc0f2400e0) = -1 ENOENT (No such file or directory)
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib", {st_mode=S_IFDIR|0555, st_size=134, ...}) = 0
stat("/nix/store/nw1pvz9y3imjjgs4icxy6yslhy9fxs2z-python3-3.6.6-env/lib/python2.7/lib-dynload", 0x7ffc0f243160) = -1 ENOENT (No such file or directory)
write(2, "ImportError", 11ImportError)             = 11
write(2, ": ", 2: )                       = 2
write(2, "No module named site", 20No module named site)    = 20
write(2, "\n", 1
)                       = 1
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f3ea85adf10}, {sa_handler=0x7f3ea7d39960, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f3ea85adf10}, 8) = 0
exit_group(1)                           = ?
+++ exited with 1 +++

[henry@watson:~/Projects/eyeserver/dserver/src]$ V

#2

You have a python2 binary in a python3 environment? That does not seem right.
How about?

$ gdb python3

#3

The fact that the python I GDB’d:
[henry@watson:~/Projects/eyeserver/dserver/src]$ gdb /nix/store/bwfygfcdvis9wd1c1v51xwnwhw1hx0a0-python3-3.6.6/bin/python

is in a python3-3.6.6 directory, makes me think it is a python3 binary. It certainly self identifies a python3 binary when run. The reason for all this extra work with hardcoded nix paths is that python3 is a script and gdb’ing it directly gives me “file format not recognized”. Apparently GDB doesn’t like shell scripts :slight_smile:.


#4

No it does not. You could either run the unwrapped binary with PYTHONPATH set or you make python break in a script and then attach to the pid instead.


#5

Right, that’s what i did. You can see that in the way I run my attempts to gdb python. But the overall concern here is that when I include gdb in the environment that has python, it doesn’t run at all. It isn’t that it fails to handle a shell script, or that I am gdbing the wrong python. It is that it fails on startup, with no executable specified.


#6

Since it also is linked against python2, it might get confused when PYTHONPATH points to python3.


#7

Thanks! That did the trick… I used

(gdb.override ( python = python36Packages.python; }) 

and that totally did the trick. Makes me very happy with nix!


#8

We probably should migrate gdb to python3 anyway.