)]}'
{
  "commit": "05f5f4f2746c2ee1346baaa58a0719e48fe84cc3",
  "tree": "0ccec8ba194993188b98ede89eb6b163f5674beb",
  "parents": [
    "daf53ffeaa968694f783d4ad6ee0531b9f2bd9a6"
  ],
  "author": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Wed Feb 12 14:29:01 2025 +0000"
  },
  "committer": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Fri Mar 21 15:20:26 2025 +0000"
  },
  "message": "gdb: check styled status of source cache entries\n\nCurrently GDB\u0027s source cache doesn\u0027t track whether the entries within\nthe cache are styled or not.  This is pretty much fine, the assumption\nis that any time we are fetching source code, we do so in order to\nprint it to the terminal, so where possible we always want styling\napplied, and if styling is not applied, then it is because that file\ncannot be styled for some reason.\n\nChanges to \u0027set style enabled\u0027 cause the source cache to be flushed,\nso future calls to fetch source code will regenerate the cache entries\nwith styling enabled or not as appropriate.\n\nBut this all assumes that styling is either on or off, and that\nswitching between these two states isn\u0027t done very often.\n\nHowever, the Python API allows for individual commands to be executed\nwith styling turned off via gdb.execute().  See commit:\n\n  commit e5348a7ab3f11f4c096ee4ebcdb9eb2663337357\n  Date:   Thu Feb 13 15:39:31 2025 +0000\n\n      gdb/python: new styling argument to gdb.execute\n\nCurrently the source cache doesn\u0027t handle this case. Consider this:\n\n  (gdb) list main\n  ... snip, styled source code displayed here ...\n  (gdb) python gdb.execute(\"list main\", True, False, False)\n  ... snip, styled source code is still shown here ...\n\nIn the second case, the final `False` passed to gdb.execute() is\nasking for unstyled output.\n\nThe problem is that, `get_source_lines` calls `ensure` to prime the\ncache for the file in question, then `extract_lines` just pulls the\nlines of interest from the cached contents.\n\nIn `ensure`, if there is a cache entry for the desired filename, then\nthat is considered good enough.  There is no consideration about\nwhether the cache entry is styled or not.\n\nThis commit aims to fix this, after this commit, the `ensure` function\nwill make sure that the cache entry used by `get_source_lines` is\nstyled correctly.\n\nI think there are two approaches I could take:\n\n  1. Allow multiple cache entries for a single file, a styled, and\n     non-styled entry.  The `ensure` function would then place the\n     correct cache entry into the last position so that\n     `get_source_lines` would use the correct entry, or\n\n  2. Have `ensure` recalculate entries if the required styling mode is\n     different to the styling mode of the current entry.\n\nApproach #1 is better if we are rapidly switching between styling\nmodes, while #2 might be better if we want to keep more files in the\ncache and we only rarely switch styling modes.\n\nIn the end I chose approach #2, but the good thing is that the changes\nare all contained within the `ensure` function.  If in the future we\nwanted to change to strategy #1, this could be done transparently to\nthe rest of GDB.\n\nSo after this commit, the `ensure` function checks if styling is\ncurrently possible or not.  If it is not, and the current entry is\nstyled, then the current entry only is dropped from the cache, and a\nnew, unstyled entry is created.  Likewise, if the current entry is\nnon-styled, but styling is required, we drop one entry and\nrecalculate.\n\nWith this change in place, I have updated set_style_enabled (in\ncli/cli-style.c) so the source cache is no longer flushed when the\nstyle settings are changed, the source cache will automatically handle\nchanges to the style settings now.\n\nThis problem was discovered in PR gdb/32676.\n\nBug: https://sourceware.org/bugzilla/show_bug.cgi?id\u003d32676\n\nApproved-By: Tom Tromey \u003ctom@tromey.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "b4362752bcba92493d235762c7e0b9115a3033ba",
      "old_mode": 33188,
      "old_path": "gdb/cli/cli-style.c",
      "new_id": "548424506bc5664806efe60f2e92b9286e3d5aae",
      "new_mode": 33188,
      "new_path": "gdb/cli/cli-style.c"
    },
    {
      "type": "modify",
      "old_id": "f08c872ed8c77c19bc2906381ec3a2a994ed8b5c",
      "old_mode": 33188,
      "old_path": "gdb/source-cache.c",
      "new_id": "30c9e619dae0ff8c3574e6906c91a791fa622b4c",
      "new_mode": 33188,
      "new_path": "gdb/source-cache.c"
    },
    {
      "type": "modify",
      "old_id": "03f4b79778f9a5b1117681d2cfd659296d561370",
      "old_mode": 33188,
      "old_path": "gdb/source-cache.h",
      "new_id": "c7d204b54d93ca96c5ce3dbffd1bfc964f6e58aa",
      "new_mode": 33188,
      "new_path": "gdb/source-cache.h"
    },
    {
      "type": "modify",
      "old_id": "ba7e795fe61cc29bef2607d2b4e33c183743421c",
      "old_mode": 33188,
      "old_path": "gdb/testsuite/gdb.python/py-source-styling.exp",
      "new_id": "8eed56b3b8007784e4a6055cf7b9f3a8957291f5",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.python/py-source-styling.exp"
    }
  ]
}
