)]}'
{
  "commit": "3e87f196c5c35e3e071ef0cdd14666d2c97d3f51",
  "tree": "c4e1be8f6672b4e4e3e36bb632b199315311b574",
  "parents": [
    "614806c7c2a3978211f65c13f30b5a90ee9e814d"
  ],
  "author": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Fri Apr 11 16:01:02 2025 +0100"
  },
  "committer": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Tue May 13 14:22:22 2025 +0100"
  },
  "message": "gdb/python/guile: check for invalid prefixes in Command/Parameter creation\n\nThe manual for gdb.Parameter says:\n\n  If NAME consists of multiple words, and no prefix parameter group\n  can be found, an exception is raised.\n\nThis makes sense; we cannot create a parameter within a prefix group,\nif the prefix doesn\u0027t exist.  And this almost works, so:\n\n  (gdb) python gdb.Parameter(\"xxx foo\", gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)\n  Python Exception \u003cclass \u0027RuntimeError\u0027\u003e: Could not find command prefix xxx.\n  Error occurred in Python: Could not find command prefix xxx.\n\nThe prefix \u0027xxx\u0027 doesn\u0027t exist, and we get an error.  But, if we try\nmultiple levels of prefix:\n\n  (gdb) python gdb.Parameter(\"print xxx foo\", gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)\n\nThis completes without error, however, we didn\u0027t get what we were\nmaybe expecting:\n\n  (gdb) show print xxx foo\n  Undefined show print command: \"xxx foo\".  Try \"help show print\".\n\nBut we did get:\n\n  (gdb) show print foo\n  The current value of \u0027print foo\u0027 is \"off\".\n\nGDB stopped scanning the prefix string at the unknown \u0027xxx\u0027, and just\ncreated the parameter there.  I don\u0027t think this makes sense, nor is\nit inline with the manual.\n\nAn identical problem exists with gdb.Command creation; GDB stops\nparsing the prefix at the first unknown prefix, and just creates the\ncommand there.  The manual for gdb.Command says:\n\n  NAME is the name of the command.  If NAME consists of multiple\n  words, then the initial words are looked for as prefix commands.\n  In this case, if one of the prefix commands does not exist, an\n  exception is raised.\n\nSo again, the correct action is, I believe, to raise an exception.\n\nThe problem is in gdbpy_parse_command_name (python/py-cmd.c), GDB\ncalls lookup_cmd_1 to look through the prefix string and return the\nlast prefix group.  If the very first prefix word is invalid then\nlookup_cmd_1 returns NULL, and this case is handled.  However, if\nthere is a valid prefix, followed by an invalid prefix, then\nlookup_cmd_1 will return a pointer to the last valid prefix list, and\nwill update the input argument to point to the start of the invalid\nprefix word.  This final case, where the input is left pointing to an\nunknown prefix, was previously not handled.\n\nI\u0027ve fixed gdbpy_parse_command_name, and added tests for command and\nparameter creation to cover this case.\n\nThe exact same error is present in the guile API too.  The guile\ndocumentation for make-parameter and make-command says the same things\nabout unknown prefixes resulting in an exception, but the same error\nis present in gdbscm_parse_command_name (guile/scm-cmd.c), so I\u0027ve\nfixed that too, and added some tests.\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "47578729425dc37e99b7bb45898157420b527492",
      "old_mode": 33188,
      "old_path": "gdb/guile/scm-cmd.c",
      "new_id": "453394ccb19fe00cfb2ebf4f719b980a087e9b5f",
      "new_mode": 33188,
      "new_path": "gdb/guile/scm-cmd.c"
    },
    {
      "type": "modify",
      "old_id": "5d98d03e3636c7f6e8250485bb7faae984deef36",
      "old_mode": 33188,
      "old_path": "gdb/python/py-cmd.c",
      "new_id": "c53138a525f8c4194615c882c7fd9731cce71548",
      "new_mode": 33188,
      "new_path": "gdb/python/py-cmd.c"
    },
    {
      "type": "modify",
      "old_id": "9caca247cb39bf8b82e2f93ec885dc8fd13b0350",
      "old_mode": 33188,
      "old_path": "gdb/testsuite/gdb.guile/scm-cmd.exp",
      "new_id": "3709cb19042c78fa92437246b18c14654b478b88",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.guile/scm-cmd.exp"
    },
    {
      "type": "modify",
      "old_id": "8ab5d939e2ab8aceab1a9ca16c1b2bf1481f6808",
      "old_mode": 33188,
      "old_path": "gdb/testsuite/gdb.guile/scm-parameter.exp",
      "new_id": "94db5a7a12ff34e0bc08a8904c0b1389638731d9",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.guile/scm-parameter.exp"
    },
    {
      "type": "modify",
      "old_id": "f76c17622fa2656c451578647e5bb829c5f942e1",
      "old_mode": 33188,
      "old_path": "gdb/testsuite/gdb.python/py-cmd.exp",
      "new_id": "5ed52a2fc67f63f3fc5bef5353d7f48b2d4d1c01",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.python/py-cmd.exp"
    },
    {
      "type": "modify",
      "old_id": "c15bef15a2bb336d2a559ac4a850b6f3c26b0ddb",
      "old_mode": 33188,
      "old_path": "gdb/testsuite/gdb.python/py-parameter.exp",
      "new_id": "39a24ca1663ea4f0da1a4864f76974d29758937f",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.python/py-parameter.exp"
    }
  ]
}
