)]}'
{
  "commit": "7893943879cedcc6520d0849fa3d10375dda0333",
  "tree": "55636d84d95e4bdc4a388ea2a347aa55cf0c25f5",
  "parents": [
    "0623a1a5365bbb373a802dc12208a3a98943ce9b"
  ],
  "author": {
    "name": "Simon Marchi",
    "email": "simon.marchi@polymtl.ca",
    "time": "Wed Dec 04 15:07:32 2024 -0500"
  },
  "committer": {
    "name": "Simon Marchi",
    "email": "simon.marchi@polymtl.ca",
    "time": "Sat Dec 07 15:48:50 2024 -0500"
  },
  "message": "gdbserver: simplify win32 process removal\n\nIn the spirit of encapsulation, I\u0027m looking to remove the need for\nexternal code to access the \"ptid -\u003e thread\" map of process_info, making\nit an internal implementation detail.  The only remaining use is in\nfunction clear_inferiors, and it led me down this rabbit hole:\n\n - clear_inferiors is really only used by the Windows port and doesn\u0027t\n   really make sense in the grand scheme of things, I think (when would\n   you want to remove all threads of all processes, without removing\n   those processes?)\n\n - ok, so let\u0027s remove clear_inferiors and inline the code where it\u0027s\n   called, in function win32_clear_inferiors\n\n - the Windows port does not support multi-process, so it\u0027s not really\n   necessary to loop over all processes like this:\n\n       for_each_process ([] (process_info *process)\n         {\n           process-\u003ethread_list ().clear ();\n           process-\u003ethread_map ().clear ();\n         });\n\n   We could just do:\n\n     current_process ()-\u003ethread_list ().clear ();\n     current_process ()-\u003ethread_map ().clear ();\n\n   (or pass down the process from the caller, but it\u0027s not important\n   right now)\n\n - so, the code that we\u0027ve inlined in win32_clear_inferiors does 3\n   things:\n\n    - clear the process\u0027 thread list and map (which deletes the\n      thread_info objects)\n\n    - clear the dll list, which just basically frees some objects\n\n    - switch to no current process / no current thread\n\n - let\u0027s now look at where this win32_clear_inferiors function is used:\n\n     - in win32_process_target::kill, where the process is removed just\n       after\n\n     - in win32_process_target::detach, where the process is removed\n       just after\n\n     - in win32_process_target::wait, when handling a process exit.\n       After this returns, we could be in handle_target_event (if async)\n       or resume (if sync), both in `server.cc`.  In both of these\n       cases, target_mourn_inferior gets called, we end up in\n       win32_process_target::mourn, which removes the process\n\n - in all 3 cases above, we end up removing the process, which takes\n   care of the 3 actions listed above:\n\n     - the thread list and map get cleared when the process gets\n       destroyed\n\n     - same with the dll list\n\n     - remove_process switches to no current process / current thread\n       if the process being removed is the current one\n\n - I conclude that it\u0027s probably unnecessary to do the cleanup in\n   win32_clear_inferiors, because it\u0027s going to get done right after\n   anyway.\n\nTherefore, this patch does:\n\n - remove clear_inferiors, remove the call in win32_clear_inferiors\n\n - remove clear_dlls, which is now unused\n\n - remove process_info::thread_map, which is now unused\n\n - rename win32_clear_inferiors to win32_clear_process, which seems more\n   accurate\n\nwin32_clear_inferiors also does:\n\n    for_each_thread (delete_thread_info);\n\nwhich also makes sure to delete all threads, but it also deletes the\nWindows private data object (windows_thread_info), so I\u0027ll leave this\none there for now.  But if we could make the thread private data\ndestruction automatic, on thread destruction, it could be removed, I\nthink.\n\nThere should be no user-visible change with this patch.  Of course,\noperations don\u0027t happen in the same order as before, so there might be\nsome important detail I\u0027m missing.  I\u0027m only able to build-test this, if\nsomeone could give it a test run on Windows, it would be appreciated.\n\nChange-Id: I4a560affe763a2c965a97754cc02f3083dbe6fbf\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "ff637a03fed14360e8236486e8a807c2473ae554",
      "old_mode": 33188,
      "old_path": "gdbserver/dll.cc",
      "new_id": "f49aa560aec57e246948d944ec377b0beb8d1dc5",
      "new_mode": 33188,
      "new_path": "gdbserver/dll.cc"
    },
    {
      "type": "modify",
      "old_id": "30c6a2c65d06b946489e42d7ee0612d54971f872",
      "old_mode": 33188,
      "old_path": "gdbserver/dll.h",
      "new_id": "e603df4be2b26017fa5b795f861d8d4111779d85",
      "new_mode": 33188,
      "new_path": "gdbserver/dll.h"
    },
    {
      "type": "modify",
      "old_id": "7a0209b167365747dd0503828d1207efdd1cc6c5",
      "old_mode": 33188,
      "old_path": "gdbserver/inferiors.cc",
      "new_id": "7bb322b0787fbe85ea7a4c2928bea39726964667",
      "new_mode": 33188,
      "new_path": "gdbserver/inferiors.cc"
    },
    {
      "type": "modify",
      "old_id": "2f3d42b8308171b2864de671d67f3c76d88ee332",
      "old_mode": 33188,
      "old_path": "gdbserver/inferiors.h",
      "new_id": "890e9b92a9c46158041d9bde535d15412d599f21",
      "new_mode": 33188,
      "new_path": "gdbserver/inferiors.h"
    },
    {
      "type": "modify",
      "old_id": "dab57f7256b2ab9e89494c0efbaa4deac033034f",
      "old_mode": 33188,
      "old_path": "gdbserver/win32-low.cc",
      "new_id": "49f0ed3b1f4d2b2ac1d1c194d3910e4918568241",
      "new_mode": 33188,
      "new_path": "gdbserver/win32-low.cc"
    }
  ]
}
