)]}'
{
  "commit": "2f761de2bab729dcd010057f153d73f2c01396b4",
  "tree": "b69226909471feeb222aaf5fee731f11a57481b7",
  "parents": [
    "47b8bb38fcb8ea1df70a932f7fe9fedca8993ec7"
  ],
  "author": {
    "name": "Tankut Baris Aktemur",
    "email": "tankut.baris.aktemur@intel.com",
    "time": "Tue Mar 29 16:19:10 2022 +0200"
  },
  "committer": {
    "name": "Tankut Baris Aktemur",
    "email": "tankut.baris.aktemur@intel.com",
    "time": "Tue Mar 29 16:19:10 2022 +0200"
  },
  "message": "gdb/remote: use current_inferior in read_ptid if multi-process not supported\n\nWhen parsing the ptid out of a reply package, if the multi-process\nextensions are not supported, use current_inferior\u0027s pid as the pid of\nthe reported thread, instead of inferior_ptid.  This is needed because\nthe inferior_ptid may be null_ptid although a legit context exists,\ndue to a prior context switch via switch_to_inferior_no_thread.\n\nBelow is a scenario that illustrates what could go wrong.  First,\nsetup a multi-target scenario.  This is needed, because in a\nmulti-target setting, the inferior_ptid is cleared out before waiting\non targets.  The second inferior below sits on top of a remote target.\nMulti-process packets are disabled.\n\n  $ # First, spawn a process with PID 26253 to attach to later.\n  $ gdb-up a.out\n  Reading symbols from a.out...\n  (gdb) maint set target-non-stop on\n  (gdb) set remote multiprocess-feature-packet off\n  (gdb) start\n  ...\n  (gdb) add-inferior -no-connection\n  [New inferior 2]\n  Added inferior 2\n  (gdb) inferior 2\n  [Switching to inferior 2 [\u003cnull\u003e] (\u003cnoexec\u003e)]\n  (gdb) target extended-remote | gdbserver --multi -\n  Remote debugging using | gdbserver --multi -\n  Remote debugging using stdio\n  (gdb) attach 26253\n  Attaching to Remote target\n  Attached; pid \u003d 26253\n  [New Thread 26253]\n  [New inferior 3]\n  Reading /tmp/a.out from remote target...\n  ...\n  [New Thread 26253]\n  ...\n  Reading /usr/local/lib/debug/....debug from remote target...\n  \u003e\u003e\u003e GDB seems to hang here.\n\nAfter attaching to a process and reading some library files, GDB\nseems to hang.  One interesting thing to note is that\n\n  [New Thread 26253]\n\nappears twice.  We also see\n\n  [New inferior 3]\n\nRunning the same scenario with \"debug infrun on\" reveals more details.\n\n  ...\n  (gdb) attach 26253\n  [infrun] scoped_disable_commit_resumed: reason\u003dattaching\n  Attaching to Remote target\n  Attached; pid \u003d 26253\n  [New Thread 26253]\n  [infrun] infrun_async: enable\u003d1\n  [infrun] attach_command: immediately after attach:\n  [infrun] attach_command:   thread 26253.26253.0, executing \u003d 1, resumed \u003d 0, state \u003d RUNNING\n  [infrun] clear_proceed_status_thread: 26253.26253.0\n  [infrun] reset: reason\u003dattaching\n  [infrun] maybe_set_commit_resumed_all_targets: not requesting commit-resumed for target native, no resumed threads\n  [infrun] maybe_set_commit_resumed_all_targets: enabling commit-resumed for target extended-remote\n  [infrun] fetch_inferior_event: enter\n    [infrun] scoped_disable_commit_resumed: reason\u003dhandling event\n    [infrun] do_target_wait: Found 2 inferiors, starting at #1\n    [infrun] random_pending_event_thread: None found.\n    [infrun] print_target_wait_results: target_wait (-1.0.0 [Thread 0], status) \u003d\n    [infrun] print_target_wait_results:   26253.26253.0 [Thread 26253],\n    [infrun] print_target_wait_results:   status-\u003ekind \u003d STOPPED, sig \u003d GDB_SIGNAL_0\n    [infrun] handle_inferior_event: status-\u003ekind \u003d STOPPED, sig \u003d GDB_SIGNAL_0\n    [infrun] start_step_over: enter\n      [infrun] start_step_over: stealing global queue of threads to step, length \u003d 0\n      [infrun] operator(): step-over queue now empty\n    [infrun] start_step_over: exit\n    [infrun] context_switch: Switching context from 0.0.0 to 26253.26253.0\n    [infrun] handle_signal_stop: stop_pc\u003d0x7f849d8cf151\n    [infrun] stop_waiting: stop_waiting\n    [infrun] stop_all_threads: starting\n    [infrun] stop_all_threads: pass\u003d0, iterations\u003d0\n  [New inferior 3]\n  Reading /tmp/a.out from remote target...\n  warning: File transfers from remote targets can be slow. Use \"set sysroot\" to access files locally instead.\n  Reading /tmp/a.out from remote target...\n  Reading symbols from target:/tmp/a.out...\n  [New Thread 26253]\n    [infrun] stop_all_threads:   4723.4723.0 not executing\n    [infrun] stop_all_threads:   26253.26253.0 not executing\n    [infrun] stop_all_threads:   42000.26253.0 executing, need stop\n    [infrun] print_target_wait_results: target_wait (-1.0.0 [Thread 0], status) \u003d\n    [infrun] print_target_wait_results:   -1.0.0 [Thread 0],\n    [infrun] print_target_wait_results:   status-\u003ekind \u003d IGNORE\n    [infrun] print_target_wait_results: target_wait (-1.0.0 [Thread 0], status) \u003d\n    [infrun] print_target_wait_results:   -1.0.0 [Thread 0],\n    [infrun] print_target_wait_results:   status-\u003ekind \u003d IGNORE\n\nGDB tried to stop Thread 42000.26253.0, which does not exist, and we\nare waiting for a stop event that will never happen.  The PID in\n\u002742000.26253.0\u0027, namely 42000, is the PID of magic_null_ptid.\nIt comes from gdb/remote.c:read_ptid:\n\n  /* Since the stub is not sending a process id, then default to\n     what\u0027s in inferior_ptid, unless it\u0027s null at this point.  If so,\n     then since there\u0027s no way to know the pid of the reported\n     threads, use the magic number.  */\n  if (inferior_ptid \u003d\u003d null_ptid)\n    pid \u003d magic_null_ptid.pid ();\n  else\n    pid \u003d inferior_ptid.pid ();\n\n  if (obuf)\n    *obuf \u003d pp;\n  return ptid_t (pid, tid);\n\nBecause multi-process was turned off, GDB did not parse an explicitly\nspecified PID.  Furthermore, inferior_ptid \u003d\u003d null_ptid, and\neventually GDB picked the PID from magic_null_ptid.\n\nIf target-non-stop is not turned on at the beginning, the same bug\nreveals itself as a duplicated thread as shown below.\n\n  # Same setup as above, without \u0027maint set target-non-stop on\u0027.\n  ...\n  (gdb) attach 26253\n  Attaching to Remote target\n  Attached; pid \u003d 26253\n  [New inferior 3]\n  ...\n  [New Thread 26253]\n  ...\n  (gdb) info threads\n    Id   Target Id             Frame\n    1.1  process 13517 \"a.out\" main () at test.c:3\n  * 2.1  Thread 26253 \"a.out\"  0x00007f12750c5151 in read () from target:/lib/x86_64-linux-gnu/libc.so.6\n    3.1  Thread 26253 \"a.out\"  Remote \u0027g\u0027 packet reply is too long (expected 560 bytes, got 2496 bytes): 00feffffffffffff000a3a75127f000051510c75127f0000000400000000000060d24ef6af5500000000000000000000680d000000000000b85b31e3fc7f0000c0283a75127f000000e55b75127f000010d04ef6af550000460200000000000060c73975127f0000a0d23975127f0000000a3a75127f0000000000000000000051510c75127f000046020000330000002b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007f03000000000000ffff0000000000000000000000000000000000000000000080143a75127f000080143a75127f000040143a75127f000040143a75127f00007d0000007e0000007f00000080000000300c3a75127f0000300c3a75127f00000e000000000000000e0000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffff0400000004000000040000000400000020143a75127f000020143a75127f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000801f0000000000000000000000e55b75127f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n  (gdb)\n\nFix the problem by preferring current_inferior()\u0027s pid instead of\nmagic_null_ptid.\n\nRegression-tested on X86-64 Linux.\n\nCo-authored-by: Aleksandar Paunovic \u003caleksandar.paunovic@intel.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "aa6a67a96e0a5be78243729611566358a20e96f4",
      "old_mode": 33188,
      "old_path": "gdb/remote.c",
      "new_id": "219e7203a9474585938fed9f1dfb2285ae78931d",
      "new_mode": 33188,
      "new_path": "gdb/remote.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "cdcc2afc7b0f2cc572314707f6dc9ae3f3b1a1e8",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.multi/attach-no-multi-process.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "081579fb964c5731c7e023ced6058d0bd230daf5",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.multi/attach-no-multi-process.exp"
    }
  ]
}
