[PATCH 0/4] gdb: Refactor cmd_list_element.var

Lancelot SIX lsix@lancelotsix.com
Wed Jul 28 19:50:39 GMT 2021


This patch series proposes to refactor the way cmd_list_element.var is
handled.  It is meant to be a cleanup series and is intended to offer
a basis on which to solve PR/28085.

Some commands contain a reference to a variable (param) that can be set
or shown.  To do that, the command element contains pieces of
information: a void* pointer to global variable, and a var_types field
to indicate the type of the parameter, the type of the variable the
previously mentioned pointer points to and how they should be handled.

When any piece of code within GDB tries to interact with such variable,
it first checks the type field and then casts the void* pointer into
whatever type pointer it needs to and dereferences it.  There are few
limitations with this approach I try to address in this patch series:

- All code that interact with a cmd_list_element.var needs to do some
  cast to the appropriate type.  This is done in multiple places in the
  codebase and is quite easy to get wrong.  The first patch tries to
  cover that by introducing a typesafe abstraction around the void*
  pointer.
- The source of truth for any parameter needs to be the variable pointed
  to.  However, as pointed out by Simon in PR/28085 this is not always
  true, and there are bugs linked to this.  In order to solve this
  problem, patch 3 allows getter and setter callbacks to be embedded in
  the abstraction introduced in patch 1 in order replace the pointer to
  a global variable.

Patch 2, which was originally proposed by Simon Marchi[1] proposes to
change the variable type from char* to std::string for string like
parameters.  Finally Patch 4 does some more refactoring on how we detect
and notify observers when a given parameter is updated.

None of those patches should introduce user visible changes.

The entire series have been tested on x86_64 and no regression have been
observed on the testsuite.

All feedbacks are welcome.

[1] https://sourceware.org/pipermail/gdb-patches/2021-July/180921.html

Lancelot SIX (3):
  gdb: Add typesafe getter/setter for cmd_list_element.var
  gdb: Have setter and getter callbacks for params
  gdb: Param setter return a bool to tell if the value changed

Simon Marchi (1):
  gdb: make string-like set show commands use std::string variable

 gdb/auto-load.c              |  50 ++--
 gdb/breakpoint.c             |  22 +-
 gdb/build-id.c               |   4 +-
 gdb/cli/cli-cmds.c           |  88 +++---
 gdb/cli/cli-decode.c         | 428 ++++++++++++++++++++++-----
 gdb/cli/cli-decode.h         |   6 +-
 gdb/cli/cli-logging.c        |  23 +-
 gdb/cli/cli-option.c         |   9 +-
 gdb/cli/cli-option.h         |   4 +-
 gdb/cli/cli-setshow.c        | 190 +++++-------
 gdb/command.h                | 544 ++++++++++++++++++++++++++++++++++-
 gdb/compile/compile.c        |  46 +--
 gdb/corefile.c               |  17 +-
 gdb/defs.h                   |   4 +-
 gdb/disasm.c                 |  11 +-
 gdb/disasm.h                 |   2 +-
 gdb/dwarf2/dwz.c             |   2 +-
 gdb/dwarf2/index-cache.c     |  10 +-
 gdb/dwarf2/read.c            |  10 +-
 gdb/event-top.c              |  12 +-
 gdb/fork-child.c             |   7 +-
 gdb/guile/scm-param.c        | 173 ++++++-----
 gdb/infcmd.c                 |  14 +-
 gdb/linux-thread-db.c        |  17 +-
 gdb/main.c                   |  17 +-
 gdb/maint-test-options.c     |  11 +-
 gdb/maint-test-settings.c    |   8 +-
 gdb/maint.c                  |   2 +-
 gdb/mi/mi-cmd-env.c          |  18 +-
 gdb/proc-api.c               |   5 +-
 gdb/python/py-param.c        |  58 ++--
 gdb/python/python-internal.h |   2 +-
 gdb/python/python.c          |  35 ++-
 gdb/remote-sim.c             |   7 +-
 gdb/remote.c                 |  12 +-
 gdb/serial.c                 |   8 +-
 gdb/solib.c                  |  20 +-
 gdb/source.c                 |  66 +++--
 gdb/source.h                 |   5 +-
 gdb/stack.c                  |  22 +-
 gdb/symfile.c                |  49 ++--
 gdb/symtab.c                 |  46 ++-
 gdb/target-descriptions.c    |   2 +-
 gdb/top.c                    | 112 ++++----
 gdb/top.h                    |   2 +-
 gdb/tracepoint.c             |  29 +-
 gdb/tracepoint.h             |   2 +-
 47 files changed, 1533 insertions(+), 698 deletions(-)

-- 
2.31.1



More information about the Gdb-patches mailing list