)]}'
{
  "commit": "59912fb2d22f8a4bb0862487f12a5cc65b6a013f",
  "tree": "4182332efd20a98c91c92453cb0efeae22675e21",
  "parents": [
    "bd93891c9ae1adda01631459eb8da8309a2f9d60"
  ],
  "author": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Tue Sep 19 11:45:36 2023 +0100"
  },
  "committer": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Mon Oct 02 17:06:40 2023 +0100"
  },
  "message": "gdb: add Python events for program space addition and removal\n\nInitially I just wanted a Python event for when GDB removes a program\nspace, I\u0027m writing a Python extension that caches information for each\nprogram space, and need to know when I should discard entries for a\nparticular program space.\n\nBut, it seemed easy enough to also add an event for when GDB adds a\nnew program space, so I went ahead and added both new events.\n\nOf course, we don\u0027t currently have an observable for program space\naddition or removal, so I first needed to add these.  After that it\u0027s\npretty simple to add two new Python events and have these trigger.\n\nThe two new event registries are:\n\n  events.new_progspace\n  events.free_progspace\n\nThese emit NewProgspaceEvent and FreeProgspaceEvent objects\nrespectively, each of these new event types has a \u0027progspace\u0027\nattribute that contains the relevant gdb.Progspace object.\n\nThere\u0027s a couple of things to be mindful of.\n\nFirst, it is not possible to catch the NewProgspaceEvent for the very\nfirst program space, the one that is created when GDB first starts, as\nthis program space is created before any Python scripts are sourced.\n\nIn order to allow this event to be caught we would need to defer\ncreating the first program space, and as a consequence the first\ninferior, until some later time.  But, existing scripts could easily\ndepend on there being an initial inferior, so I really don\u0027t think we\nshould change that -- and so, we end up with the consequence that we\ncan\u0027t catch the event for the first program space.\n\nThe second, I think minor, issue, is that GDB doesn\u0027t clean up its\nprogram spaces upon exit -- or at least, they are not cleaned up\nbefore Python is shut down.  As a result, any program spaces in use at\nthe time GDB exits don\u0027t generate a FreeProgspaceEvent.  I\u0027m not\nparticularly worried about this for my use case, I\u0027m using the event\nto ensure that a cache doesn\u0027t hold stale entries within a single GDB\nsession.  It\u0027s also easy enough to add a Python at-exit callback which\ncan do any final cleanup if needed.\n\nFinally, when testing, I did hit a slightly weird issue with some of\nthe remote boards (e.g. remote-stdio-gdbserver).  As a consequence of\nthis issue I see some output like this in the gdb.log:\n\n  (gdb) PASS: gdb.python/py-progspace-events.exp: inferior 1\n  step\n  FreeProgspaceEvent: \u003cgdb.Progspace object at 0x7fb7e1d19c10\u003e\n  warning: cannot close \"target:/lib64/libm.so.6\": Cannot execute this command while the target is running.\n  Use the \"interrupt\" command to stop the target\n  and then try again.\n  warning: cannot close \"target:/lib64/libc.so.6\": Cannot execute this command while the target is running.\n  Use the \"interrupt\" command to stop the target\n  and then try again.\n  warning: cannot close \"target:/lib64/ld-linux-x86-64.so.2\": Cannot execute this command while the target is running.\n  Use the \"interrupt\" command to stop the target\n  and then try again.\n  do_parent_stuff () at py-progspace-events.c:41\n  41        ++global_var;\n  (gdb) PASS: gdb.python/py-progspace-events.exp: step\n\nThe \u0027FreeProgspaceEvent ...\u0027 line is expected, that\u0027s my test Python\nextension logging the event.  What isn\u0027t expected are all the blocks\nlike:\n\n  warning: cannot close \"target:/lib64/libm.so.6\": Cannot execute this command while the target is running.\n  Use the \"interrupt\" command to stop the target\n  and then try again.\n\nIt turns out that this has nothing to do with my changes, this is just\na consequence of reading files over the remote protocol.  The test\nforks a child process which GDB stays attached too.  When the child\nexits, GDB cleans up by calling prune_inferiors, which in turn can\nresult in GDB trying to close some files that are open because of the\ninferior being deleted.\n\nIf the prune_inferiors call occurs when the remote target is\nrunning (and in non-async mode) then GDB will try to send a fileio\npacket while the remote target is waiting for a stop reply, and the\nremote target will throw an error, see remote_target::putpkt_binary in\nremote.c for details.\n\nI\u0027m going to look at fixing this, but, as I said, this is nothing to\ndo with this change, I just mention it because I ended up needing to\naccount for these warning messages in one of my tests, and it all\nlooks a bit weird.\n\nApproved-By: Tom Tromey \u003ctom@tromey.com\u003e\nReviewed-By: Eli Zaretskii \u003celiz@gnu.org\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "6523ad1d6aa37efafdae43e5c468e14b54d3e60f",
      "old_mode": 33188,
      "old_path": "gdb/NEWS",
      "new_id": "20f53a0d542d9ebc129a51c9f96cee27e404aee4",
      "new_mode": 33188,
      "new_path": "gdb/NEWS"
    },
    {
      "type": "modify",
      "old_id": "0471e78aa19a69df4446d23b12e839901ca0fbf4",
      "old_mode": 33188,
      "old_path": "gdb/doc/python.texi",
      "new_id": "a97e445189751ffaaa05fcb74b796dd093663eef",
      "new_mode": 33188,
      "new_path": "gdb/doc/python.texi"
    },
    {
      "type": "modify",
      "old_id": "33e51223cf41ec9d6fe7f4973bf05ad979fda7e2",
      "old_mode": 33188,
      "old_path": "gdb/observable.c",
      "new_id": "93a842e911fe0ee643776cb40d441705f35edc05",
      "new_mode": 33188,
      "new_path": "gdb/observable.c"
    },
    {
      "type": "modify",
      "old_id": "62882acca4e42ab84bac58ca3f6989f1f004d4a2",
      "old_mode": 33188,
      "old_path": "gdb/observable.h",
      "new_id": "d9fc5cbcc8bc930a222fb6cf581dae75210a173c",
      "new_mode": 33188,
      "new_path": "gdb/observable.h"
    },
    {
      "type": "modify",
      "old_id": "5cf8334ee677fd24e5f0923278da359e7307efbc",
      "old_mode": 33188,
      "old_path": "gdb/progspace.c",
      "new_id": "1dbcd5875ddbd9ee6cc981ca7e8f6cc3bd7a6865",
      "new_mode": 33188,
      "new_path": "gdb/progspace.c"
    },
    {
      "type": "modify",
      "old_id": "04a12e1bdf083b4291835db398fcf76622d073a4",
      "old_mode": 33188,
      "old_path": "gdb/python/py-all-events.def",
      "new_id": "b1decc772319a32ac9b9b195b235bc42230b1ebe",
      "new_mode": 33188,
      "new_path": "gdb/python/py-all-events.def"
    },
    {
      "type": "modify",
      "old_id": "b862094650d42d5bd5463b37c6988d45f5e794f1",
      "old_mode": 33188,
      "old_path": "gdb/python/py-event-types.def",
      "new_id": "c6225115027ff477a27481f5b2221d4598aa65bf",
      "new_mode": 33188,
      "new_path": "gdb/python/py-event-types.def"
    },
    {
      "type": "modify",
      "old_id": "082509b2b5b31aad3713538463f175d05559d0aa",
      "old_mode": 33188,
      "old_path": "gdb/python/py-progspace.c",
      "new_id": "72a5d4f4c625f9dfbf2490dd664fff4d139a3e13",
      "new_mode": 33188,
      "new_path": "gdb/python/py-progspace.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "6684cf8ac0a89c0527144219421e5721e151ca1c",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.python/py-progspace-events.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "60ae290c0b2781b4d4b21745282263c7405835fe",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.python/py-progspace-events.exp"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "3abb421cffa5a54c22d852a805e1a8a7685f55f9",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.python/py-progspace-events.py"
    }
  ]
}
