This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[0/6] make catchpoints a bit more OO: intro


I wanted to add some new catchpoints types.  Since these
catchpoints are specific to a target I'm working on,
I wanted to implement them completely outside of
breakpoint.c.  But, I found out that while catchpoints
all use the breakpoint_ops infrustructure, you can't
get away without adding fields to struct breakpoint
directly, and, the function
that creates the catchpoint and actually implements
the corresponding "catch foo" command needs to be
implemented in breakpoint.c, unless we export functions
like "mention" and "update_global_location_list". 

This is because we install catchpoints like:

{
  struct breakpoint *b;

  b = create_catchpoint_without_mention ()

  b->extra_catchpoint_specific_field1 = ...;
  b->extra_catchpoint_specific_field2 = ...;

  mention ();
  observer_notify_breakpoint_created ();
  update_global_location_list ();
}

Since these are pretty much internal functions
to breakpoint.c, I didn't want to do that.  I could
perhaps get away with adding a "void* data" field to
`struct breakpoint', and pass a pointer to
breakpoint-type specific object to `create_catchpoint',
but that doesn't seem like the clean approach to me, given
that we've abstracted pretty much everything else with
the breakpoint_ops "vtable".

I'd rather split object allocation, from construction/initialization,
and allocate specific breakpoint-type structures that inherit
`struct breakpoint' instead, allowing a scheme like:

 #1 - allocate breakpoint (possibly of a type that inherits
   struct breakpoint. e.g.,
   struct catchpoint { struct breakpoint base; int more_fields; ... };)

 #2 - Initialize the breakpoint bits that need initializing
   for all breakpoint types (like a `class breakpoint' constructor
   would if this was C++).  initialize whatever needs initializing,
   to complete the breakpoint-type-specific breakpoint struct.

 #3 - install the breakpoint in the breakpoint list, give it
   a number, and let the user, target, and all new breakpoint
   observers learn about the new breakpoint.

That's what this series does.  Well end up with a function to
do the common bits of #2, and another for #3.  To implement a
catchpoint outside breakpoint.c, we'll just need to make
_those_ public.

The series has been tested regression free on x86_64-linux.

Comments?

Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]