Dear maintainer,

I noticed this problem as soon as I upgraded to Debian Stretch on a
couple of my machines.  While preparing an update to this bug
report, I discovered additional information: It is a long-standing
bug or limitation in gdb that relates to PIE executables.  However,
as PIE is the default on Debian Stretch, this is the first time
that most developers will encounter it.

First, let me show you an affected (debian stretch) and unaffected
(debian jessie) session, since it has so far been unclear exactly
what sequence of operations the original reporter is talking about,
namely that the command that changes/updates the debugged
executable is run during the gdb session; relinking the program
will trigger it, but even "touch" suffices:

[Typical unaffected section, debian jessie]
$ echo 'extern int puts(const char *); int main() { puts("hello world"); }' > 
hello.c
$ gcc -g hello.c
$ gdb a.out
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
[snip]
Reading symbols from a.out...done.
(gdb) b main
Breakpoint 1 at 0x40050a: file hello.c, line 1.
(gdb) r
Starting program: /tmp/a.out 

Breakpoint 1, main () at hello.c:1
1       extern int puts(const char *); int main() { puts("hello world"); }
(gdb) kill
Kill the program being debugged? (y or n) y
(gdb) shell touch a.out
(gdb) r
`/tmp/a.out' has changed; re-reading symbols.
Starting program: /tmp/a.out 

Breakpoint 1, main () at hello.c:1
1       extern int puts(const char *); int main() { puts("hello world"); }

[typial affected session, debian stretch]
$ echo 'extern int puts(const char *); int main() { puts("hello world"); }' > 
hello.c
$ gcc -g hello.c
$ gdb a.out
GNU gdb (Debian 7.12-6) 7.12.0.20161007-git
[snip]
Reading symbols from a.out...done.
(gdb) b main
Breakpoint 1 at 0x6b4: file hello.c, line 1.
(gdb) r
Starting program: /tmp/a.out 

Breakpoint 1, main () at hello.c:1
1       extern int puts(const char *); int main() { puts("hello world"); }
(gdb) kill
Kill the program being debugged? (y or n) y
(gdb) shell touch a.out
(gdb) r
`/tmp/a.out' has changed; re-reading symbols.
Error in re-setting breakpoint 1: Cannot access memory at address 0x5555555546b0
Starting program: /tmp/a.out 
hello world
[Inferior 1 (process 30228) exited normally]
(gdb) 


However, the problem reproduces on Debian Jessie when
DEB_BUILD_MAINT_OPTIONS=hardening=+pie flags are used:

[affected session, debian jessie, position independent executable]
$ echo 'extern int puts(const char *); int main() { puts("hello world"); }' > 
hello.c
$ gcc -g -fPIE -pie -Wl,-z,relro hello.c
$ gdb a.out
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
[snip]
(gdb) b main
Breakpoint 1 at 0x794: file hello.c, line 1.
(gdb) r
Starting program: /tmp/a.out 

Breakpoint 1, main () at hello.c:1
1       extern int puts(const char *); int main() { puts("hello world"); }
(gdb) shell touch a.out
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
`/tmp/a.out' has changed; re-reading symbols.
Error in re-setting breakpoint 1: Cannot access memory at address 0x555555554790
Starting program: /tmp/a.out 
hello world
[Inferior 1 (process 12780) exited with code 014]

As a workaround, build software you want to debug with PIE
disabled.  On stretch, this is accomplished with different flags:
$ gcc -specs=/usr/share/dpkg/no-pie-compile.specs 
-specs=/usr/share/dpkg/no-pie-link.specs -g hello.c
discoverable e.g., with 
$ DEB_BUILD_MAINT_OPTIONS=hardening=-pie dpkg-buildflags --get CFLAGS
-g -O2 -fdebug-prefix-map=/tmp/src/binutils-gdb=.  
-specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat 
-Werror=format-security

You can check that an executable is 'pie' by running 'file' on it,
as it will report "ELF shared object" rather than "ELF executable".
https://wiki.debian.org/Hardening#DEB_BUILD_HARDENING_PIE_.28gcc.2Fg.2B-.2B-_-fPIE_-pie.29

I checked, and this problem affects the master branch of gdb
development as of this date.  I tested at ref 9949827bea from
git://sourceware.org/git/binutils-gdb.git

Based on this information, I have filed upstream bug
https://sourceware.org/bugzilla/show_bug.cgi?id=21555

Please forgive my unfamiliarity with Debian BTS, I am not confident
enough to update this bug's metadata with this new information.

Thank you for your time!
Jeff

Reply via email to