)]}'
{
  "commit": "d7cb0ef35b112e35a3e9b4dc30ffd800c9d0a4fe",
  "tree": "cf5045d53819bb81fbb83ca462f31189f625eb39",
  "parents": [
    "6b66b5a5a29e18e1c1ddd29ea0749050d532de65"
  ],
  "author": {
    "name": "Pedro Alves",
    "email": "pedro@palves.net",
    "time": "Mon Jul 12 17:10:48 2021 +0100"
  },
  "committer": {
    "name": "Pedro Alves",
    "email": "pedro@palves.net",
    "time": "Tue Jul 13 15:30:04 2021 +0100"
  },
  "message": "Fix detach with target remote (PR gdb/28080)\n\nCommit 408f66864a1a823591b26420410c982174c239a2 (\"detach in all-stop\nwith threads running\") regressed \"detach\" with \"target remote\":\n\n (gdb) detach\n Detaching from program: target:/any/program, process 3671843\n Detaching from process 3671843\n Ending remote debugging.\n [Inferior 1 (process 3671843) detached]\n In main\n terminate called after throwing an instance of \u0027gdb_exception_error\u0027\n Aborted (core dumped)\n\nHere\u0027s the exception above being thrown:\n\n (top-gdb) bt\n #0  throw_error (error\u003dTARGET_CLOSE_ERROR, fmt\u003d0x555556035588 \"Remote connection closed\") at src/gdbsupport/common-exceptions.cc:222\n #1  0x0000555555bbaa46 in remote_target::readchar (this\u003d0x555556a11040, timeout\u003d10000) at src/gdb/remote.c:9440\n #2  0x0000555555bbb9e5 in remote_target::getpkt_or_notif_sane_1 (this\u003d0x555556a11040, buf\u003d0x555556a11058, forever\u003d0, expecting_notif\u003d0, is_notif\u003d0x0) at src/gdb/remote.c:9928\n #3  0x0000555555bbbda9 in remote_target::getpkt_sane (this\u003d0x555556a11040, buf\u003d0x555556a11058, forever\u003d0) at src/gdb/remote.c:10030\n #4  0x0000555555bc0e75 in remote_target::remote_hostio_send_command (this\u003d0x555556a11040, command_bytes\u003d13, which_packet\u003d14, remote_errno\u003d0x7fffffffcfd0, attachment\u003d0x0, attachment_len\u003d0x0) at src/gdb/remote.c:12137\n #5  0x0000555555bc1b6c in remote_target::remote_hostio_close (this\u003d0x555556a11040, fd\u003d8, remote_errno\u003d0x7fffffffcfd0) at src/gdb/remote.c:12455\n #6  0x0000555555bc1bb4 in remote_target::fileio_close (During symbol reading: .debug_line address at offset 0x64f417 is 0 [in module build/gdb/gdb]\n this\u003d0x555556a11040, fd\u003d8, remote_errno\u003d0x7fffffffcfd0) at src/gdb/remote.c:12462\n #7  0x0000555555c9274c in target_fileio_close (fd\u003d3, target_errno\u003d0x7fffffffcfd0) at src/gdb/target.c:3365\n #8  0x000055555595a19d in gdb_bfd_iovec_fileio_close (abfd\u003d0x555556b9f8a0, stream\u003d0x555556b11530) at src/gdb/gdb_bfd.c:439\n #9  0x0000555555e09e3f in opncls_bclose (abfd\u003d0x555556b9f8a0) at src/bfd/opncls.c:599\n #10 0x0000555555e0a2c7 in bfd_close_all_done (abfd\u003d0x555556b9f8a0) at src/bfd/opncls.c:847\n #11 0x0000555555e0a27a in bfd_close (abfd\u003d0x555556b9f8a0) at src/bfd/opncls.c:814\n #12 0x000055555595a9d3 in gdb_bfd_close_or_warn (abfd\u003d0x555556b9f8a0) at src/gdb/gdb_bfd.c:626\n #13 0x000055555595ad29 in gdb_bfd_unref (abfd\u003d0x555556b9f8a0) at src/gdb/gdb_bfd.c:715\n #14 0x0000555555ae4730 in objfile::~objfile (this\u003d0x555556515540, __in_chrg\u003d\u003coptimized out\u003e) at src/gdb/objfiles.c:573\n #15 0x0000555555ae955a in std::_Sp_counted_ptr\u003cobjfile*, (__gnu_cxx::_Lock_policy)2\u003e::_M_dispose (this\u003d0x555556c20db0) at /usr/include/c++/9/bits/shared_ptr_base.h:377\n #16 0x000055555572b7c8 in std::_Sp_counted_base\u003c(__gnu_cxx::_Lock_policy)2\u003e::_M_release (this\u003d0x555556c20db0) at /usr/include/c++/9/bits/shared_ptr_base.h:155\n #17 0x00005555557263c3 in std::__shared_count\u003c(__gnu_cxx::_Lock_policy)2\u003e::~__shared_count (this\u003d0x555556bf0588, __in_chrg\u003d\u003coptimized out\u003e) at /usr/include/c++/9/bits/shared_ptr_base.h:730\n #18 0x0000555555ae745e in std::__shared_ptr\u003cobjfile, (__gnu_cxx::_Lock_policy)2\u003e::~__shared_ptr (this\u003d0x555556bf0580, __in_chrg\u003d\u003coptimized out\u003e) at /usr/include/c++/9/bits/shared_ptr_base.h:1169\n #19 0x0000555555ae747e in std::shared_ptr\u003cobjfile\u003e::~shared_ptr (this\u003d0x555556bf0580, __in_chrg\u003d\u003coptimized out\u003e) at /usr/include/c++/9/bits/shared_ptr.h:103\n #20 0x0000555555b1c1dc in __gnu_cxx::new_allocator\u003cstd::_List_node\u003cstd::shared_ptr\u003cobjfile\u003e \u003e \u003e::destroy\u003cstd::shared_ptr\u003cobjfile\u003e \u003e (this\u003d0x5555564cdd60, __p\u003d0x555556bf0580) at /usr/include/c++/9/ext/new_allocator.h:153\n #21 0x0000555555b1bb1d in std::allocator_traits\u003cstd::allocator\u003cstd::_List_node\u003cstd::shared_ptr\u003cobjfile\u003e \u003e \u003e \u003e::destroy\u003cstd::shared_ptr\u003cobjfile\u003e \u003e (__a\u003d..., __p\u003d0x555556bf0580) at /usr/include/c++/9/bits/alloc_traits.h:497\n #22 0x0000555555b1b73e in std::__cxx11::list\u003cstd::shared_ptr\u003cobjfile\u003e, std::allocator\u003cstd::shared_ptr\u003cobjfile\u003e \u003e \u003e::_M_erase (this\u003d0x5555564cdd60, __position\u003dstd::shared_ptr\u003cobjfile\u003e (expired, weak count 1) \u003d {get() \u003d 0x555556515540}) at /usr/include/c++/9/bits/stl_list.h:1921\n #23 0x0000555555b1afeb in std::__cxx11::list\u003cstd::shared_ptr\u003cobjfile\u003e, std::allocator\u003cstd::shared_ptr\u003cobjfile\u003e \u003e \u003e::erase (this\u003d0x5555564cdd60, __position\u003dstd::shared_ptr\u003cobjfile\u003e (expired, weak count 1) \u003d {get() \u003d 0x555556515540}) at /usr/include/c++/9/bits/list.tcc:158\n #24 0x0000555555b19576 in program_space::remove_objfile (this\u003d0x5555564cdd20, objfile\u003d0x555556515540) at src/gdb/progspace.c:210\n #25 0x0000555555ae4502 in objfile::unlink (this\u003d0x555556515540) at src/gdb/objfiles.c:487\n #26 0x0000555555ae5a12 in objfile_purge_solibs () at src/gdb/objfiles.c:875\n #27 0x0000555555c09686 in no_shared_libraries (ignored\u003d0x0, from_tty\u003d1) at src/gdb/solib.c:1236\n #28 0x00005555559e3f5f in detach_command (args\u003d0x0, from_tty\u003d1) at src/gdb/infcmd.c:2769\n\nSo frame #28 already detached the remote process, and then we\u0027re\npurging the shared libraries.  GDB had opened remote shared libraries\nvia the target: sysroot, so it tries closing them.  GDBserver is\ntearing down already, so remote communication breaks down and we close\nthe remote target and throw TARGET_CLOSE_ERROR.\n\nNote frame #14:\n\n #14 0x0000555555ae4730 in objfile::~objfile (this\u003d0x555556515540, __in_chrg\u003d\u003coptimized out\u003e) at src/gdb/objfiles.c:573\n\nThat\u0027s a dtor, thus noexcept.  That\u0027s the reason for the\nstd::terminate.\n\nStepping back a bit, why do we still have open remote files if we\u0027ve\nmanaged to detach already, and, we\u0027re debugging with \"target remote\"?\nThe reason is that commit 408f66864a1a823591b26420410c982174c239a2\nmakes detach_command hold a reference to the target, so the remote\ntarget won\u0027t be finally closed until frame #28 returns.  It\u0027s closing\nthe target that invalidates target file I/O handles.\n\nThis commit fixes the issue by not relying on target_close to\ninvalidate the target file I/O handles, instead invalidate them\nimmediately in remote_unpush_target.  So when GDB purges the solibs,\nand we end up in target_fileio_close (frame #7 above), there\u0027s nothing\nto do, and we don\u0027t try to talk with the remote target anymore.\n\nThe regression isn\u0027t seen when testing with\n--target_board\u003dnative-gdbserver, because that does \"set sysroot\" to\ndisable the \"target:\" sysroot, for test run speed reasons.  So this\ncommit adds a testcase that explicitly tests detach with \"set sysroot\ntarget:\".\n\ngdb/ChangeLog:\nyyyy-mm-dd  Pedro Alves  \u003cpedro@palves.net\u003e\n\n\tPR gdb/28080\n\t* remote.c (remote_unpush_target): Invalidate file I/O target\n\thandles.\n\t* target.c (fileio_handles_invalidate_target): Make extern.\n\t* target.h (fileio_handles_invalidate_target): Declare.\n\ngdb/testsuite/ChangeLog:\nyyyy-mm-dd  Pedro Alves  \u003cpedro@palves.net\u003e\n\n\tPR gdb/28080\n\t* gdb.base/detach-sysroot-target.exp: New.\n\t* gdb.base/detach-sysroot-target.c: New.\n\nReported-By: Jonah Graham \u003cjonah@kichwacoders.com\u003e\n\nChange-Id: I851234910172f42a1b30e731161376c344d2727d\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "6d674c8139f02bd96f37649df7777423cf905033",
      "old_mode": 33188,
      "old_path": "gdb/remote.c",
      "new_id": "96e2750cd3228fb74b7624fa049ab366b8a6408d",
      "new_mode": 33188,
      "new_path": "gdb/remote.c"
    },
    {
      "type": "modify",
      "old_id": "767685fbca39bf9906bf10f1c480371e62b9fd89",
      "old_mode": 33188,
      "old_path": "gdb/target.c",
      "new_id": "787528981917570d24038c1129c1c4c276906473",
      "new_mode": 33188,
      "new_path": "gdb/target.c"
    },
    {
      "type": "modify",
      "old_id": "e22f9038197c55d93dc1b10db3926aa30c613a07",
      "old_mode": 33188,
      "old_path": "gdb/target.h",
      "new_id": "ddd4f3803cb853197ad16d529057299b7058a78b",
      "new_mode": 33188,
      "new_path": "gdb/target.h"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "9811b15f06d5a78008ab6a6c585ff933e234aea8",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.base/detach-sysroot-target.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "9ae1eb6277aed40ac128f314d7d0fa3a34c4ca51",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.base/detach-sysroot-target.exp"
    }
  ]
}
