gdb: return early if no execution in darwin_solib_create_inferior_hook
authorSimon Marchi <simon.marchi@polymtl.ca>
Sun, 4 Jul 2021 22:50:02 +0000 (18:50 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sun, 4 Jul 2021 22:50:02 +0000 (18:50 -0400)
When loading a file using the file command on macOS, we get:

    $ ./gdb -nx --data-directory=data-directory -q -ex "file ./test"
    Reading symbols from ./test...
    Reading symbols from /Users/smarchi/build/binutils-gdb/gdb/test.dSYM/Contents/Resources/DWARF/test...
    /Users/smarchi/src/binutils-gdb/gdb/thread.c:72: internal-error: struct thread_info *inferior_thread(): Assertion `current_thread_ != nullptr' failed.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    Quit this debugging session? (y or n)

The backtrace is:

    * frame #0: 0x0000000101fcb826 gdb`internal_error(file="/Users/smarchi/src/binutils-gdb/gdb/thread.c", line=72, fmt="%s: Assertion `%s' failed.") at errors.cc:52:3
      frame #1: 0x00000001018a2584 gdb`inferior_thread() at thread.c:72:3
      frame #2: 0x0000000101469c09 gdb`get_current_regcache() at regcache.c:421:31
      frame #3: 0x00000001015f9812 gdb`darwin_solib_get_all_image_info_addr_at_init(info=0x0000603000006d00) at solib-darwin.c:464:34
      frame #4: 0x00000001015f7a04 gdb`darwin_solib_create_inferior_hook(from_tty=1) at solib-darwin.c:515:5
      frame #5: 0x000000010161205e gdb`solib_create_inferior_hook(from_tty=1) at solib.c:1200:3
      frame #6: 0x00000001016d8f76 gdb`symbol_file_command(args="./test", from_tty=1) at symfile.c:1650:7
      frame #7: 0x0000000100abab17 gdb`file_command(arg="./test", from_tty=1) at exec.c:555:3
      frame #8: 0x00000001004dc799 gdb`do_const_cfunc(c=0x000061100000c340, args="./test", from_tty=1) at cli-decode.c:102:3
      frame #9: 0x00000001004ea042 gdb`cmd_func(cmd=0x000061100000c340, args="./test", from_tty=1) at cli-decode.c:2160:7
      frame #10: 0x00000001018d4f59 gdb`execute_command(p="t", from_tty=1) at top.c:674:2
      frame #11: 0x0000000100eee430 gdb`catch_command_errors(command=(gdb`execute_command(char const*, int) at top.c:561), arg="file ./test", from_tty=1, do_bp_actions=true)(char const*, int), char const*, int, bool) at main.c:523:7
      frame #12: 0x0000000100eee902 gdb`execute_cmdargs(cmdarg_vec=0x00007ffeefbfeba0 size=1, file_type=CMDARG_FILE, cmd_type=CMDARG_COMMAND, ret=0x00007ffeefbfec20) at main.c:618:9
      frame #13: 0x0000000100eed3a4 gdb`captured_main_1(context=0x00007ffeefbff780) at main.c:1322:3
      frame #14: 0x0000000100ee810d gdb`captured_main(data=0x00007ffeefbff780) at main.c:1343:3
      frame #15: 0x0000000100ee8025 gdb`gdb_main(args=0x00007ffeefbff780) at main.c:1368:7
      frame #16: 0x00000001000044f1 gdb`main(argc=6, argv=0x00007ffeefbff8a0) at gdb.c:32:10
      frame #17: 0x00007fff20558f5d libdyld.dylib`start + 1

The solib_create_inferior_hook call in symbol_file_command was added by
commit ea142fbfc9c1 ("Fix breakpoints on file reloads for PIE
binaries").  It causes solib_create_inferior_hook to be called while
the inferior is not running, which darwin_solib_create_inferior_hook
does not expect.  darwin_solib_get_all_image_info_addr_at_init, in
particular, assumes that there is a current thread, as it tries to get
the current thread's regcache.

Fix it by adding a target_has_execution check and returning early.  Note
that there is a similar check in svr4_solib_create_inferior_hook.

gdb/ChangeLog:

* solib-darwin.c (darwin_solib_create_inferior_hook): Return
early if no execution.

Change-Id: Ia11dd983a1e29786e5ce663d0fcaa6846dc611bb

gdb/ChangeLog
gdb/solib-darwin.c

index 409ff9954db753adf6c646ba5d10a9f6a049ca73..8bcf63d755c12cc52bf1ef3b5be1d74dd4c7d771 100644 (file)
@@ -1,3 +1,8 @@
+2021-07-04  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * solib-darwin.c (darwin_solib_create_inferior_hook): Return
+       early if no execution.
+
 2021-07-03  Joel Brobecker  <brobecker@adacore.com>
 
        * version.in: Set GDB version number to 11.0.90.DATE-git.
index 152afc21b9df93e389a1e2ed266203d86ac2406e..e10a6dda776b9d1c9bc0d7bd02ba05775822d197 100644 (file)
@@ -504,6 +504,10 @@ darwin_solib_read_all_image_info_addr (struct darwin_info *info)
 static void
 darwin_solib_create_inferior_hook (int from_tty)
 {
+  /* Everything below only makes sense if we have a running inferior.  */
+  if (!target_has_execution ())
+    return;
+
   struct darwin_info *info = get_darwin_info ();
   CORE_ADDR load_addr;
 
This page took 0.029477 seconds and 4 git commands to generate.