)]}'
{
  "commit": "ddff2a2dea5261789e1f281f3ee1b33dd5fd8892",
  "tree": "37514b75acd1febbdba715e397f3f6f6af59fd94",
  "parents": [
    "acc175a6b3bf6dfefde88fac78e34ac0625343c6"
  ],
  "author": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Mon Nov 21 12:12:11 2022 -0500"
  },
  "committer": {
    "name": "Simon Marchi",
    "email": "simon.marchi@polymtl.ca",
    "time": "Mon Nov 28 08:02:29 2022 -0500"
  },
  "message": "gdb: fix assert when quitting GDB while a thread is stepping\n\nThis commit addresses one of the issues identified in PR gdb/28275.\n\nBug gdb/28275 identifies a number of situations in which this assert:\n\n  Assertion `!proc_target-\u003ecommit_resumed_state\u0027 failed.\n\ncould be triggered.  There\u0027s actually a number of similar places where\nthis assert is found in GDB, the two of interest in gdb/28275 are in\ntarget_wait and target_stop.\n\nIn one of the comments:\n\n  https://sourceware.org/bugzilla/show_bug.cgi?id\u003d28275#c1\n\nsteps to trigger the assertion within target_stop were identified when\nusing a modified version of the gdb.threads/detach-step-over.exp test\nscript.\n\nIn the gdb.threads/detach-step-over.exp test, we attach to a\nmulti-threaded inferior, and continue the inferior in asynchronous\n(background) mode.  Each thread is continuously hitting a conditional\nbreakpoint where the condition is always false.  While the inferior is\nrunning we detach.  The goal is that we detach while GDB is performing a\nstep-over for the conditional breakpoint in at least one thread.\n\nWhile detaching, if a step-over is in progress, then GDB has to\ncomplete the step over before we can detach.  This involves calling\ntarget_stop and target_wait (see prepare_for_detach).\n\nAs far as gdb/28275 is concerned, the interesting part here, is the\nthe process_stratum_target::commit_resumed_state variable must be\nfalse when target_stop and target_wait are called.\n\nThis is currently ensured because, in detach_command (infrun.c), we\ncreate an instance of scoped_disable_commit_resumed, this ensures that\nwhen target_detach is called, ::commit_resumed_state will be false.\n\nThe modification to the test that I propose here, and which exposed\nthe bug, is that, instead of using \"detach\" to detach from the\ninferior, we instead use \"quit\".  Quitting GDB after attaching to an\ninferior will cause GDB to first detach, and then exit.\n\nWhen we quit GDB we end up calling target_detach via a different code\npath, the stack looks like:\n\n  #0 target_detach\n  #1 kill_or_detach\n  #2 quit_force\n  #3 quit_command\n\nAlong this path there is no scoped_disable_commit_resumed created.\n::commit_resumed_state can be true when we reach prepare_for_detach,\nwhich calls target_wait and target_stop, so the assertion will trigger.\n\nIn this commit, I propose fixing this by adding the creation of a\nscoped_disable_commit_resumed into target_detach.  This will ensure\nthat ::commit_resumed_state is false when calling prepare_for_detach\nfrom within target_detach.\n\nI did consider placing the scoped_disable_commit_resumed in\nprepare_for_detach, however, placing it in target_detach ensures that\nthe target\u0027s commit_resumed_state flag is left to false if the detached\ninferior was the last one for that target.  It\u0027s the same rationale as\nfor patch \"gdb: disable commit resumed in target_kill\" that comes later\nin this series, but for detach instead of kill.\n\ndetach_command still includes a scoped_disable_commit_resumed too, but I\nthink it is still relevant to cover the resumption at the end of the\nfunction.\n\nCo-Authored-By: Simon Marchi \u003csimon.marchi@efficios.com\u003e\nBug: https://sourceware.org/bugzilla/show_bug.cgi?id\u003d28275\nChange-Id: Ie128f7aba6ef0e018859275eca372e6ea738e96f\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "b88df0f678b50946132a9f04d32afd90f950ca12",
      "old_mode": 33188,
      "old_path": "gdb/target.c",
      "new_id": "9b937b0e8b47aaaf99165cb37749bfa4eb7b2ec3",
      "new_mode": 33188,
      "new_path": "gdb/target.c"
    },
    {
      "type": "modify",
      "old_id": "ad9b08f549eaedc11d3254239fbbdab4d8badb8b",
      "old_mode": 33188,
      "old_path": "gdb/testsuite/gdb.threads/detach-step-over.exp",
      "new_id": "d2cb52423d984237b189f4e2d2f4e661f4d83535",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.threads/detach-step-over.exp"
    }
  ]
}
