)]}'
{
  "commit": "1d7fe7f01b93ecaeb3e481ed09d3deac7890a97f",
  "tree": "18849feb1ba77bfe2be1cce3e95c75c981cec765",
  "parents": [
    "39d53d04357606a15efd400147fa7369d71baf2c"
  ],
  "author": {
    "name": "Lancelot SIX",
    "email": "lsix@lancelotsix.com",
    "time": "Mon Sep 13 22:32:19 2021 +0100"
  },
  "committer": {
    "name": "Lancelot SIX",
    "email": "lsix@lancelotsix.com",
    "time": "Sun Oct 03 17:53:16 2021 +0100"
  },
  "message": "gdb: Introduce setting construct within cmd_list_element\n\ncmd_list_element can contain a pointer to data that can be set and / or\nshown.  This is achieved with the void* VAR member which points to the\ndata that can be accessed, while the VAR_TYPE member (of type enum\nvar_types) indicates how to interpret the data pointed to.\n\nWith this pattern, the user of the cmd_list_element needs to know what\nis the storage type associated with a given VAR_TYPES in order to do\nthe proper casting.  No automatic safeguard is available to prevent\nmiss-use of the pointer.  Client code typically looks something like:\n\n\tswitch (c-\u003evar_type)\n\t{\n\t  case var_zuinteger:\n\t    unsigned int v \u003d *(unsigned int*) c-\u003evar;\n\t    ...\n\t    break;\n\t  case var_boolean:\n\t    bool v \u003d *(bool *) c-\u003evar;\n\t    ...\n\t    break;\n\t  ...\n\t}\n\nThis patch proposes to add an abstraction around the var_types and void*\npointer pair.  The abstraction is meant to prevent the user from having\nto handle the cast and verify that the data is read or written as a type\nthat is coherent with the setting\u0027s var_type.  This is achieved by\nintroducing the struct setting which exposes a set of templated get /\nset member functions.  The template parameter is the type of the\nvariable that holds the referred variable.\n\nUsing those accessors allows runtime checks to be inserted in order to\nensure that the data pointed to has the expected type.  For example,\ninstantiating the member functions with bool will yield something\nsimilar to:\n\n\tconst bool \u0026get\u003cbool\u003e () const\n\t{\n\t  gdb_assert (m_var_type \u003d\u003d var_boolean);\n\t  gdb_assert (m_var !\u003d nullptr);\n\t  return *static_cast\u003cbool *\u003e (m_var);\n\t}\n\tvoid set\u003cbool\u003e (const bool \u0026var)\n\t{\n\t  gdb_assert (m_var_type \u003d\u003d var_boolean);\n\t  gdb_assert (m_var !\u003d nullptr);\n\t  *static_cast\u003cbool *\u003e (m_var) \u003d var;\n\t}\n\nUsing the new abstraction, our initial example becomes:\n\n\tswitch (c-\u003evar_type)\n\t{\n\t  case var_zuinteger:\n\t    unsigned int v \u003d c-\u003evar-\u003eget\u003cunsigned int\u003e ();\n\t    ...\n\t    break;\n\t  case var_boolean:\n\t    bool v \u003d c-\u003evar-\u003eget\u003cbool\u003e ();\n\t    ...\n\t    break;\n\t  ...\n\t}\n\nWhile the call site is still similar, the introduction of runtime checks\nhelp ensure correct usage of the data.\n\nIn order to avoid turning the bulk of add_setshow_cmd_full into a\ntemplated function, and following a suggestion from Pedro Alves, a\nsetting can be constructed from a pre validated type erased reference to\na variable.  This is what setting::erased_args is used for.\n\nIntroducing an opaque abstraction to describe a setting will also make\nit possible to use callbacks to retrieve or set the value of the setting\non the fly instead of pointing to a static chunk of memory.  This will\nbe done added in a later commit.\n\nGiven that a cmd_list_element may or may not reference a setting, the\nVAR and VAR_TYPES members of the struct are replaced with a\ngdb::optional\u003csetting\u003e named VAR.\n\nFew internal function signatures have been modified to take into account\nthis new abstraction:\n\n-The functions value_from_setting, str_value_from_setting and\n get_setshow_command_value_string used to have a \u0027cmd_list_element *\u0027\n parameter but only used it for the VAR and VAR_TYPE member. They now\n take a \u0027const setting \u0026\u0027 parameter instead.\n- Similarly, the \u0027void *\u0027 and a \u0027enum var_types\u0027 parameters of\n  pascm_param_value and gdbpy_parameter_value have been replaced with a\n  \u0027const setting \u0026\u0027 parameter.\n\nNo user visible change is expected after this patch.\n\nTested on GNU/Linux x86_64, with no regression noticed.\n\nCo-authored-by: Simon Marchi \u003csimon.marchi@polymtl.ca\u003e\nChange-Id: Ie1d08c3ceb8b30b3d7bf1efe036eb8acffcd2f34\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "9cd70f174c3c3c19f381c35a45000428d6a9cbd8",
      "old_mode": 33188,
      "old_path": "gdb/auto-load.c",
      "new_id": "7f0bb74c32ad918c73497b54ddb07bef1307ef4e",
      "new_mode": 33188,
      "new_path": "gdb/auto-load.c"
    },
    {
      "type": "modify",
      "old_id": "dfe429ea44a5b2ef45cad195e859529bee140bd8",
      "old_mode": 33188,
      "old_path": "gdb/bt-utils.c",
      "new_id": "8110f10e1e9e5c6e9b77cf68e6e985336d6a4e75",
      "new_mode": 33188,
      "new_path": "gdb/bt-utils.c"
    },
    {
      "type": "modify",
      "old_id": "e5c7152ba7a5e670ab557be848cddc998546f52e",
      "old_mode": 33188,
      "old_path": "gdb/cli/cli-cmds.c",
      "new_id": "ecbe5a4b43cfa818ca3f2d7413e81109a9b33945",
      "new_mode": 33188,
      "new_path": "gdb/cli/cli-cmds.c"
    },
    {
      "type": "modify",
      "old_id": "06f3de0f038a31c90569e8f1ca6995d6988e6163",
      "old_mode": 33188,
      "old_path": "gdb/cli/cli-decode.c",
      "new_id": "56befc979dcf2a1c4e7851766cd607eb90ba9b9a",
      "new_mode": 33188,
      "new_path": "gdb/cli/cli-decode.c"
    },
    {
      "type": "modify",
      "old_id": "651d1ef8abb742b9d9f2c70a5667c82026fae5e6",
      "old_mode": 33188,
      "old_path": "gdb/cli/cli-decode.h",
      "new_id": "f7945ba2bf5fd21c1d132ae1666fb7944cb6688c",
      "new_mode": 33188,
      "new_path": "gdb/cli/cli-decode.h"
    },
    {
      "type": "modify",
      "old_id": "1025ed2f620d330d3f8e39a5e02ff4b21b38d1ef",
      "old_mode": 33188,
      "old_path": "gdb/cli/cli-setshow.c",
      "new_id": "86ab553f48cc389dbe584dc9d20c3505051436de",
      "new_mode": 33188,
      "new_path": "gdb/cli/cli-setshow.c"
    },
    {
      "type": "modify",
      "old_id": "05f11b170eb6773268a4becec3f56c3c1d7bcb2c",
      "old_mode": 33188,
      "old_path": "gdb/cli/cli-setshow.h",
      "new_id": "5a8f32189faa4b67b9d03f2aa4430ae734de065e",
      "new_mode": 33188,
      "new_path": "gdb/cli/cli-setshow.h"
    },
    {
      "type": "modify",
      "old_id": "baf34401a0700e3dd28a35a8fd1a76a38248bd6c",
      "old_mode": 33188,
      "old_path": "gdb/command.h",
      "new_id": "e7b81100f26e98cee7c4822b5be2edbc848bf389",
      "new_mode": 33188,
      "new_path": "gdb/command.h"
    },
    {
      "type": "modify",
      "old_id": "44ea167be277f1738913e491f37b46bec0b50de5",
      "old_mode": 33188,
      "old_path": "gdb/guile/scm-param.c",
      "new_id": "0ae368a1e64c4c4ae27b66253e6a7c26abe9ba16",
      "new_mode": 33188,
      "new_path": "gdb/guile/scm-param.c"
    },
    {
      "type": "modify",
      "old_id": "c6d13a3a732ccd0c2fadcf7502990e19d4459461",
      "old_mode": 33188,
      "old_path": "gdb/maint.c",
      "new_id": "8aae53bdd657a0f01a606832bb791a61c9d5eb40",
      "new_mode": 33188,
      "new_path": "gdb/maint.c"
    },
    {
      "type": "modify",
      "old_id": "f9dcb076c60396de56a4dd52bfd147dad9145b67",
      "old_mode": 33188,
      "old_path": "gdb/python/py-param.c",
      "new_id": "1dd716bba145227977e613e1f66108acd821d888",
      "new_mode": 33188,
      "new_path": "gdb/python/py-param.c"
    },
    {
      "type": "modify",
      "old_id": "368681b797cb146a73658c9fac5352ba17c537f5",
      "old_mode": 33188,
      "old_path": "gdb/python/python-internal.h",
      "new_id": "022d4a67172c295db3cfbf001b7aa9f095b79ddd",
      "new_mode": 33188,
      "new_path": "gdb/python/python-internal.h"
    },
    {
      "type": "modify",
      "old_id": "37eacefd8fcf8afc6cdb4a0c9e86a6bb852951bc",
      "old_mode": 33188,
      "old_path": "gdb/python/python.c",
      "new_id": "a26c37352ff02d2bd2a4fabe86c852acb2667dd2",
      "new_mode": 33188,
      "new_path": "gdb/python/python.c"
    },
    {
      "type": "modify",
      "old_id": "c4a31e0c2f874896b7e0ce0c8a2cecb7a6014069",
      "old_mode": 33188,
      "old_path": "gdb/remote.c",
      "new_id": "29b18c9427f67b7dc518a94002d5e886f53335ea",
      "new_mode": 33188,
      "new_path": "gdb/remote.c"
    }
  ]
}
