)]}'
{
  "commit": "8f87fcb1daf1af1dd2d332f7303b02e391fa6b6c",
  "tree": "5652603d2b95302782f39e6723eb237152059ed3",
  "parents": [
    "f2f866c6ca80e3f98deae2f2faabddab70a2163b"
  ],
  "author": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Sat Feb 24 20:23:18 2024 +0000"
  },
  "committer": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Sat Sep 07 20:28:58 2024 +0100"
  },
  "message": "gdb: improve gdb_rl_find_completion_word for quoted words\n\nThe function gdb_rl_find_completion_word is very similar to the\nreadline function _rl_find_completion_word, but was either an older\nversion of that function, or was trimmed when copying to remove code\nwhich was considered unnecessary.\n\nWe maintain this copy because the _rl_find_completion_word function is\nnot part of the public readline API, and we need to replicate the\nfunctionality of that function as part of the \u0027complete\u0027 command.\n\nWithin gdb_rl_find_completion_word when looking for the completion\nword, if we don\u0027t find a unclosed quoted string (which would become\nthe completion word) then we scan backwards looking for a word break\ncharacter.  For example, given:\n\n  (gdb) complete file /tmp/foo\n\nThere is no unclosed quoted string so we end up scanning backwards\nfrom the end looking for a word break character.  In this case the\nspace after \u0027file\u0027 and before \u0027/tmp/foo\u0027 is found, so \u0027/tmp/foo\u0027\nbecomes the completion word.\n\nHowever, given this:\n\n  (gdb) complete file /tmp/foo\\\"\n\nThere is still no unclosed quoted string, however, when we can\nbackwards the \u0027\"\u0027 (double quotes) are treated as a word break\ncharacter, and so we end up using the empty string as the completion\nword.\n\nThe readline function _rl_find_completion_word avoids this mistake by\nusing the rl_char_is_quoted_p hook.  This function will return true\nfor the double quote character as it is preceded by a backslash.  An\nearlier commit in this series supplied a rl_char_is_quoted_p function\nfor the filename completion case, however, gdb_rl_find_completion_word\ndoesn\u0027t call rl_char_is_quoted_p so this doesn\u0027t help for the\n\u0027complete\u0027 case.\n\nIn this commit I\u0027ve copied the code to call rl_char_is_quoted_p from\n_rl_find_completion_word into gdb_rl_find_completion_word.\n\nThis half solves the problem.  In the case:\n\n  (gdb) complete file /tmp/foo\\\"\n\nWe do now try to complete on the string \u0027/tmp/foo\\\"\u0027, however, when we\nreach filename_completer we call back into readline to actually\nperform filename completion.  However, at this point the WORD variable\npoints to a string that still contains the backslash.  The backslash\nisn\u0027t part of the actual filename, that\u0027s just an escape character.\n\nOur expectation is that readline will remove the backslash when\nlooking for matching filenames.  However, readline contains an\noptimisation to avoid unnecessary work trying to remove escape\ncharacters.\n\nThe readline variable rl_completion_found_quote is set in the readline\nfunction gen_completion_matches before the generation of completion\nmatches.  This variable is set to true (non-zero) if there is (or\nmight be) escape characters within the completion word.\n\nThe function rl_filename_completion_function, which generates the\nfilename matches, only removes escape characters when\nrl_completion_found_quote is true.  When GDB generates completions\nthrough readline (e.g. tab completion) then rl_completion_found_quote\nis set correctly.\n\nBut when we use the \u0027complete\u0027 command we don\u0027t pass through readline,\nand so gen_completion_matches is never called and\nrl_completion_found_quote is not set.  In this case when we call\nrl_filename_completion_function readline doesn\u0027t remove the escapes\nfrom the completion word, and so in our case above, readline looks for\ncompletions of the exact filename \u0027/tmp/foo\\\"\u0027, that is, the filename\nincluding the backslash.\n\nTo work around this problem I\u0027ve added a new flag to our function\ngdb_rl_find_completion_word which is set true when we find any quoting\nor escaping.  This matches what readline does.\n\nThen in the \u0027complete\u0027 function we can set rl_completion_found_quote\nprior to generating completion matches.\n\nWith this done the \u0027complete\u0027 command now works correctly when trying\nto complete filenames that contain escaped word break characters.  The\ntests have been updated accordingly.\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "7435532954f9c236ff9f767335a5097bbeadf255",
      "old_mode": 33188,
      "old_path": "gdb/completer.c",
      "new_id": "b0e999ef514b0560b0a1cf71554cd3b94d8c5d33",
      "new_mode": 33188,
      "new_path": "gdb/completer.c"
    },
    {
      "type": "modify",
      "old_id": "c852b56f86a35c7f1ca3e7f8a54d16f30940c36d",
      "old_mode": 33188,
      "old_path": "gdb/testsuite/gdb.base/filename-completion.exp",
      "new_id": "a4b411c1c6766eefbb953e9dffa763b39f160921",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.base/filename-completion.exp"
    }
  ]
}
