)]}'
{
  "commit": "e5348a7ab3f11f4c096ee4ebcdb9eb2663337357",
  "tree": "08553fbfbe84aa2c57cfdd646608b96f89b29bbb",
  "parents": [
    "65addfb0e40e2057ab0bbfee017fa967e16f2e82"
  ],
  "author": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Thu Feb 13 15:39:31 2025 +0000"
  },
  "committer": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Wed Mar 19 14:31:53 2025 +0000"
  },
  "message": "gdb/python: new styling argument to gdb.execute\n\nCurrently, gdb.execute emits styled output when the command is sending\nits output to GDB\u0027s stdout, and produces unstyled output when the\noutput is going to a string.\n\nBut it is not unreasonable that a user might wish to capture styled\noutput from a gdb.execute call, for example, the user might want to\ndisplay the styled output are part of some larger UI output block.\n\nAt the same time, I don\u0027t think it makes sense to always produce\nstyled output when capturing the output in a string; if what the user\nwants is to parse the output, then the style escape sequences make\nthis far harder.\n\nI propose that gdb.execute gain a new argument \u0027styling\u0027.  When False\nwe would always produce unstyled output, and when True we would\nproduce styled output if styling is not disabled by some other means.\n\nFor example, if GDB\u0027s \u0027set style enabled\u0027 is off, then I think\ngdb.execute() should respect that.  My assumption here is that\ngdb.execute() might be executed by some extension.  If the extension\nthinks \"styled output world work here\", but the user hates styled\noutput, and has turned it off, then the extension should not be\nforcing styled output on the user.\n\nI chose \u0027styling\u0027 instead of \u0027styled\u0027 as the Python argument name\nbecause we already use \u0027styling\u0027 in gdb.Value.format_string, and we\ndon\u0027t use \u0027styled\u0027 anywhere else.  This is only a little bit of\nconsistency, but I still think it\u0027s a good thing.\n\nThe default for \u0027styling\u0027 will change depending on where the output is\ngoing.  When gdb.execute is sending the output to GDB\u0027s stdout then\nthe default for \u0027styling\u0027 is True.  When the output is going to a\nstring, then the default for \u0027styling\u0027 will be False.  Not only does\nthis match the existing behaviour, but I think this makes sense.  By\ndefault we assume that output captured in a string is going to be\nparsed, and therefore styling markup is unhelpful, while output going\nto stdout should receive styling.\n\nThis fixes part of the problem described in PR gdb/32676.  That bug\ntries to capture styled source listing in a string, which wasn\u0027t\npreviously possible.\n\nThere are some additional issues with capturing source code; GDB\ncaches the source code in the source code cache.  However, GDB doesn\u0027t\ncheck if the cached content is styled or not.  As a consequence, if\nthe first time the source of a file is shown it is unstyled, then the\ncached will hold the unstyled source code, and future requests will\nreturn that unstyled source.  I\u0027ll address this issue in a separate\npatch.\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": "42e6de6313d689f7c8db5604f4e1c3522a57c1f4",
      "old_mode": 33188,
      "old_path": "gdb/NEWS",
      "new_id": "2fdb849a81b8ab64ec8a9b7fb12d2964b05e3d46",
      "new_mode": 33188,
      "new_path": "gdb/NEWS"
    },
    {
      "type": "modify",
      "old_id": "9131768e27ca79e9a6d56ea2ed0b54a5e93fada1",
      "old_mode": 33188,
      "old_path": "gdb/cli/cli-script.c",
      "new_id": "5decf3b9d5c3803977468ea8bef52985384b3ddd",
      "new_mode": 33188,
      "new_path": "gdb/cli/cli-script.c"
    },
    {
      "type": "modify",
      "old_id": "23bd83e0b2b5576a484b9ba7e954e7ab2c58045f",
      "old_mode": 33188,
      "old_path": "gdb/cli/cli-script.h",
      "new_id": "df7316e62a3969f47c04bff8f4267050fedeb9cd",
      "new_mode": 33188,
      "new_path": "gdb/cli/cli-script.h"
    },
    {
      "type": "modify",
      "old_id": "3ca30a4fa7f7a01895b8f39e68297878d20b8276",
      "old_mode": 33188,
      "old_path": "gdb/cli/cli-style.c",
      "new_id": "b4362752bcba92493d235762c7e0b9115a3033ba",
      "new_mode": 33188,
      "new_path": "gdb/cli/cli-style.c"
    },
    {
      "type": "modify",
      "old_id": "18827ce9d54d4c8f98a666f28ea0c3642676770a",
      "old_mode": 33188,
      "old_path": "gdb/cli/cli-style.h",
      "new_id": "e94b48d35bea56d968d77e12f283cf9eda1879d8",
      "new_mode": 33188,
      "new_path": "gdb/cli/cli-style.h"
    },
    {
      "type": "modify",
      "old_id": "0dbb37bb8ddfd65ee8a0582ac0eab93a0f8bde8b",
      "old_mode": 33188,
      "old_path": "gdb/doc/python.texi",
      "new_id": "50342bbba5f52d9b03605adcb7698317a7d5a51c",
      "new_mode": 33188,
      "new_path": "gdb/doc/python.texi"
    },
    {
      "type": "modify",
      "old_id": "8f8030cfcbcff19ecb71928da86e973b46efeb62",
      "old_mode": 33188,
      "old_path": "gdb/python/python.c",
      "new_id": "2aaa30c7d8eeadb10ffbc9aa1a4552a195cf4f4e",
      "new_mode": 33188,
      "new_path": "gdb/python/python.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "0b27c638eb6d18cd5904fe7417dd4fd3f823b887",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.python/py-styled-execute.exp"
    }
  ]
}
