diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2018-04-07 13:51:59 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2018-04-07 13:51:59 -0400 |
commit | b2e586e850dbf1dafc10beea3250d22e70add4b5 (patch) | |
tree | 51d6b473b6c5c39453e34b5ad045c57f7591f214 /gdb | |
parent | 7c4e78cf63f6436ae43e8289badba78d81e2eb2c (diff) | |
download | gdb-b2e586e850dbf1dafc10beea3250d22e70add4b5.zip gdb-b2e586e850dbf1dafc10beea3250d22e70add4b5.tar.gz gdb-b2e586e850dbf1dafc10beea3250d22e70add4b5.tar.bz2 |
Defer breakpoint reset when cloning progspace for fork child
Using this simple test:
static void
break_here ()
{
}
int
main (int argc, char *argv[])
{
fork ();
break_here();
return 0;
}
compiled as a PIE:
$ gcc test.c -g3 -O0 -o test -pie
and running this:
$ ./gdb -nx -q --data-directory=data-directory ./test -ex "b break_here" -ex "set detach-on-fork off" -ex r
gives:
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x64a
Note that GDB might get stopped by SIGTTOU because of this issue:
https://sourceware.org/bugzilla/show_bug.cgi?id=23020
In that case, just use "fg" to continue.
This issue happens only with position-independent executables. Adding
the main objfile for the new inferior (the fork child) causes GDB to try
to reset the breakpoints. However, that new objfile has not been
relocated yet. So the breakpoint on "break_here" resolves to an
unrelocated address, from which we are trying to read/write to set a
breakpoint. Passing SYMFILE_DEFER_BP_RESET avoids that problem. The
executable is relocated just after, in the follow_fork_inferior
function.
The buildbot seems happy with this patch. I don't think it's necessary
to add a new test. Just changing this made many tests go from FAIL to
PASS on my machine, where gcc produces PIE executables by default. If
anything, I think we would need to add a board file that produces
position-independent executables, so that we can run all the tests with
PIE, even on machines where that is not the default.
gdb/ChangeLog:
* progspace.c (clone_program_space): Pass SYMFILE_DEFER_BP_RESET
to symbol_file_add_main.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/progspace.c | 3 |
2 files changed, 7 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4ffa4e7..47d28e3 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2018-04-07 Simon Marchi <simon.marchi@polymtl.ca> + * progspace.c (clone_program_space): Pass SYMFILE_DEFER_BP_RESET + to symbol_file_add_main. + +2018-04-07 Simon Marchi <simon.marchi@polymtl.ca> + PR mi/22299 * mi/mi-console.c (do_fputc_async_safe): New. (mi_console_file::write_async_safe): New. diff --git a/gdb/progspace.c b/gdb/progspace.c index e0bcc5a..ba400d4 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -166,7 +166,8 @@ clone_program_space (struct program_space *dest, struct program_space *src) exec_file_attach (src->pspace_exec_filename, 0); if (src->symfile_object_file != NULL) - symbol_file_add_main (objfile_name (src->symfile_object_file), 0); + symbol_file_add_main (objfile_name (src->symfile_object_file), + SYMFILE_DEFER_BP_RESET); return dest; } |