Avoid another inferior_ptid reference in gdb/remote.c
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Fri, 10 Jan 2020 20:05:52 +0000 (20:05 +0000)
committerPedro Alves <palves@redhat.com>
Fri, 10 Jan 2020 20:05:52 +0000 (20:05 +0000)
The multi-target patch makes inferior_ptid point to null_ptid before
calling into target_wait, which catches bad uses of inferior_ptid,
since the current selected thread in gdb shouldn't have much relation
to the thread that reports an event.

One such bad use is found in remote_target::remote_parse_stop_reply,
where we handle the 'W' or 'X' packets (process exit), and the remote
target does not support the multi-process extensions, i.e., it does
not report the PID of the process that exited.

With the multi-target patch, that would result in a failed assertion,
trying to find the inferior for process pid 0.

gdb/ChangeLog:
2020-01-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
    Pedro Alves  <palves@redhat.com>

* remote.c (remote_target::remote_parse_stop_reply) <W/X packets>:
If no process is specified, return null_ptid instead of
inferior_ptid.
(remote_target::wait_as): Handle TARGET_WAITKIND_EXITED /
TARGET_WAITKIND_SIGNALLED with no pid.

gdb/testsuite/ChangeLog:
2020-01-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
    Pedro Alves  <palves@redhat.com>

* gdb.server/connect-without-multi-process.exp: Also test
continuing to end.

gdb/ChangeLog
gdb/remote.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.server/connect-without-multi-process.exp

index 9d63febea0fe8ce78eb7db662c5ae70793bc8cdb..78922021681c4646766da4aaee7549def8fc2ab8 100644 (file)
@@ -1,3 +1,12 @@
+2020-01-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+           Pedro Alves  <palves@redhat.com>
+
+       * remote.c (remote_target::remote_parse_stop_reply) <W/X packets>:
+       If no process is specified, return null_ptid instead of
+       inferior_ptid.
+       (remote_target::wait_as): Handle TARGET_WAITKIND_EXITED /
+       TARGET_WAITKIND_SIGNALLED with no pid.
+
 2020-01-10  Pedro Alves  <palves@redhat.com>
 
        * remote.c (first_remote_resumed_thread): New.
index fa940dff7201e2aeac7deb0241e335f310fa05b3..ffdeede7af5330777f60c3f5136863eb13be7f1f 100644 (file)
@@ -7441,7 +7441,6 @@ Packet: '%s'\n"),
     case 'W':          /* Target exited.  */
     case 'X':
       {
-       int pid;
        ULONGEST value;
 
        /* GDB used to accept only 2 hex chars here.  Stubs should
@@ -7465,8 +7464,9 @@ Packet: '%s'\n"),
              event->ws.value.sig = GDB_SIGNAL_UNKNOWN;
          }
 
-       /* If no process is specified, assume inferior_ptid.  */
-       pid = inferior_ptid.pid ();
+       /* If no process is specified, return null_ptid, and let the
+          caller figure out the right process to use.  */
+       int pid = 0;
        if (*p == '\0')
          ;
        else if (*p == ';')
@@ -7842,8 +7842,16 @@ remote_target::wait_as (ptid_t ptid, target_waitstatus *status, int options)
        event_ptid = first_remote_resumed_thread ();
     }
   else
-    /* A process exit.  Invalidate our notion of current thread.  */
-    record_currthread (rs, minus_one_ptid);
+    {
+      /* A process exit.  Invalidate our notion of current thread.  */
+      record_currthread (rs, minus_one_ptid);
+      /* It's possible that the packet did not include a pid.  */
+      if (event_ptid == null_ptid)
+       event_ptid = first_remote_resumed_thread ();
+      /* EVENT_PTID could still be NULL_PTID.  Double-check.  */
+      if (event_ptid == null_ptid)
+       event_ptid = magic_null_ptid;
+    }
 
   return event_ptid;
 }
index 4b38c214daf52f5a0c5668cff23bce99d8c31664..52d52d15f6cd48b29be5b5c0ec3e9fe3bb314ffe 100644 (file)
@@ -1,3 +1,9 @@
+2020-01-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+           Pedro Alves  <palves@redhat.com>
+
+       * gdb.server/connect-without-multi-process.exp: Also test
+       continuing to end.
+
 2020-01-10  Pedro Alves  <palves@redhat.com>
 
        * gdb.base/remote-exec-file.exp: New file.
index 6c7d162492f05453ec4eaa847a85838610d24d53..123089260dde2613b49e1d9ccabef49fca95cb5d 100644 (file)
@@ -14,7 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 # Check that we can connect to GDBserver with the multiprocess
-# extensions disabled, and run to main.
+# extensions disabled, run to main, and finish the process.
 
 load_lib gdbserver-support.exp
 
@@ -52,6 +52,11 @@ proc do_test {multiprocess} {
        "target $gdbserver_protocol"
 
     gdb_test "continue" "main .*" "continue to main"
+
+    # The W/X packets do not include the PID of the exiting process
+    # without the multi-process extensions.  Check that we handle
+    # process exit correctly in that case.
+    gdb_continue_to_end
 }
 
 foreach multiprocess { "off" "auto" } {
This page took 0.036702 seconds and 4 git commands to generate.