gdb 'call' / 'print' commands don't work properly when attaching to R
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gdb (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Sorry for the somewhat weird / vague title; hopefully the rest of this issue will make it more concrete ...
First, to set the stage; gdb and R both installed from apt repositories:
$ /usr/bin/gdb --version
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ /usr/bin/R --version
R version 4.0.5 (2021-03-31) -- "Shake and Throw"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https:/
Now, I can use gdb in batch mode to introspect a bash process; e.g. print the SHELL environment variable:
$ /usr/bin/gdb -batch -p $(pgrep -nx bash) -ex 'print (char*) getenv("SHELL")'
0x00007f5623d8c1db in __pselect (nfds=1, readfds=
48 ../sysdeps/
$1 = 0x5615ffc825d0 "/bin/bash"
[Inferior 1 (process 640102) detached]
But, if I try to do the same with a running R process, I see:
$ R -s -e "Sys.sleep(100)" &
[1] 643585
$ /usr/bin/gdb -batch -p $(pgrep -nx R) -ex 'print (char*) getenv("SHELL")'
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_
0x00007f47944050da in select () from /usr/lib/
Invalid character '"' in expression.
[Inferior 1 (process 643585) detached]
Note the very confusing 'Invalid character '"' in expression.' error, implying that gdb was for some reason unable to handle the double-quoted string passed to getenv().
I cannot reproduce this in a version of gdb 9.2 built from sources locally; e.g.
$ gdb --version
GNU gdb (GDB) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ gdb -batch -p $(pgrep -nx R) -ex 'print (char*) getenv("SHELL")'
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_
0x00007fba31ad60da in select () from /usr/lib/
$1 = 0x7fff4dc9adfe "/bin/bash"
[Inferior 1 (process 701827) detached]
So it seems like something specifically is broken in the version of GDB packaged for Ubuntu 20.04.
summary: |
- gdb doesn't work properly when attaching to R + gdb 'call' / 'print' commands don't work properly when attaching to R |
In addition, I get a segfault if I use a single-quoted string rather than a double-quoted string. (My understanding is that single-quoted strings are normally used to reference symbols, so this should be an error but not a crash)
$ /usr/bin/gdb -batch -p $(pgrep -nx R) -ex "print (char*) getenv('oops')" 64-linux- gnu/libthread_ db.so.1" . x86_64- linux-gnu/ libc.so. 6
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_
0x00007f69b4c870da in select () from /usr/lib/
Aborted (core dumped)