diff options
author | Alan Hayward <alan.hayward@arm.com> | 2019-07-08 10:00:25 +0100 |
---|---|---|
committer | Alan Hayward <alan.hayward@arm.com> | 2019-07-08 10:13:46 +0100 |
commit | ea142fbfc9c1708a83d3532257d6728e1f5c142e (patch) | |
tree | f352e1434244ad934830c0a0fc50ea63e835a9ae /gdb/symfile.c | |
parent | 62a47958bd6e3cbd909c2f19cd4669a9670ce4f1 (diff) | |
download | gdb-ea142fbfc9c1708a83d3532257d6728e1f5c142e.zip gdb-ea142fbfc9c1708a83d3532257d6728e1f5c142e.tar.gz gdb-ea142fbfc9c1708a83d3532257d6728e1f5c142e.tar.bz2 |
Fix breakpoints on file reloads for PIE binaries
When a binary is built using PIE, reloading the file will cause GDB to error
on restart. For example:
gdb ./a.out
(gdb) break main
(gdb) run
(gdb) file ./a.out
(gdb) continue
Will cause GDB to error with:
Continuing.
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x9e0
Command aborted.
This is due to the symbol offsets not being relocated after reloading the file.
Fix is to ensure solib_create_inferior_hook is called, in the same manner as
infrun.c:follow_exec().
Expand the idempotent test to cover PIE scenarios.
gdb/ChangeLog:
* symfile.c (symbol_file_command): Call solib_create_inferior_hook.
gdb/testsuite/ChangeLog:
* gdb.base/break-idempotent.exp: Test both PIE and non PIE.
Diffstat (limited to 'gdb/symfile.c')
-rw-r--r-- | gdb/symfile.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gdb/symfile.c b/gdb/symfile.c index 59647bf..dc6bdf3 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1672,7 +1672,19 @@ symbol_file_command (const char *args, int from_tty) validate_readnow_readnever (flags); + /* Set SYMFILE_DEFER_BP_RESET because the proper displacement for a PIE + (Position Independent Executable) main symbol file will only be + computed by the solib_create_inferior_hook below. Without it, + breakpoint_re_set would fail to insert the breakpoints with the zero + displacement. */ + add_flags |= SYMFILE_DEFER_BP_RESET; + symbol_file_add_main_1 (name, add_flags, flags, offset); + + solib_create_inferior_hook (from_tty); + + /* Now it's safe to re-add the breakpoints. */ + breakpoint_re_set (); } } |