[PATCH 00/36] C++-ify breakpoints

Tom Tromey tom@tromey.com
Tue Jan 18 19:39:31 GMT 2022


This series somewhat C++-ifies breakpoints.  It turns most
breakpoint_ops function pointers into virtual methods, and introduces
a class hierarchy for breakpoints.

The series starts with a few minor cleanups and clarifications.  Then
it introduces a new vtable-based breakpoint_ops structure.  This is
used to convert breakpoint types one-by-one, to avoid having a monster
patch.  Then, near the end, this is removed again and some final
cleanups applied.

I built and regression tested each patch in this series on x86-64
Fedora 34.

There is still more work that could be done to improve this code in
the future:

* Right now, if you want to add a new breakpoint type, you may need a
  new bptype enumerator constant.  However, these can be a pain to
  add.  I think it would be better to remove this enum entirely, in
  favor of ordinary object-oriented techniques like methods.
  Similarly, perhaps create_breakpoint could be replaced with
  constructors.

* breakpoint_ops isn't fully removed, as it has a couple of "static
  virtual" methods -- methods that vary by breakpoint type, but which
  can't be methods on the breakpoint itself.  This could probably be
  fixed somehow.

* I left the base class name as "breakpoint" to avoid rewriting a lot
  of code.  However, this isn't really the best name, so this could be
  changed.

* Some methods on the base class could probably be made pure virtual.
  This is currently faked, following the approach already used in the
  source: the methods abort when called.  Changing this to use the
  real C++ feature would be an improvement.

* Relatedly, some members of 'breakpoint' could be pushed into the
  relevant subclasses.  For example, breakpoint::location_range_end is
  only used by ranged breakpoints, and so could be moved to struct
  ranged_breakpoint.  This same idea probably applies to some methods
  as well.

Tom




More information about the Gdb-patches mailing list