aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2017-06-02 23:16:21 +0200
committerSimon Marchi <simon.marchi@ericsson.com>2017-06-02 23:16:21 +0200
commitc1fc2657206188767cb66813d07b9ecbb5e9ec51 (patch)
treed38faab12cc15c6954b51ae5b0ec9c225cbf1174 /gdb/ada-lang.c
parent3b0871f44a3402f4e1e811ae81c8ba1293c1c7be (diff)
downloadgdb-c1fc2657206188767cb66813d07b9ecbb5e9ec51.zip
gdb-c1fc2657206188767cb66813d07b9ecbb5e9ec51.tar.gz
gdb-c1fc2657206188767cb66813d07b9ecbb5e9ec51.tar.bz2
C++ify breakpoint class hierarchy (destructors only)
Breakpoints are currently in a limbo state between C and C++. There is a pseudo class hierarchy implemented using struct fields. Taking watchpoint as an example: struct watchpoint { /* The base class. */ struct breakpoint base; ... } and it is instantianted with "new watchpoint ()". When destroyed, a destructor is first invoked through the breakpoint_ops, and then the memory is freed by calling delete through a pointer to breakpoint. Address sanitizer complains about this, for example, because we new and delete the same memory using different types. This patch takes the logical step of making breakpoint subclasses extend the breakpoint class for real, and converts their destructors to actual C++ destructors. Regtested on the buildbot. gdb/ChangeLog: * breakpoint.h (struct breakpoint_ops) <dtor>: Remove. (struct breakpoint) <~breakpoint>: New. (struct watchpoint): Inherit from breakpoint. <~watchpoint>: New. <base>: Remove. (struct tracepoint): Inherit from breakpoint. <base>: Remove. * breakpoint.c (longjmp_breakpoint_ops): Remove. (struct longjmp_breakpoint): Inherit from breakpoint. <~longjmp_breakpoint>: New. <base>: Remove. (new_breakpoint_from_type): Remove casts. (watchpoint_in_thread_scope): Remove reference to base field. (watchpoint_del_at_next_stop): Likewise. (update_watchpoint): Likewise. (watchpoint_check): Likewise. (bpstat_check_watchpoint): Likewise. (set_longjmp_breakpoint): Likewise. (struct fork_catchpoint): Inherit from breakpoint. <base>: Remove. (struct solib_catchpoint): Inherit from breakpoint. <~solib_catchpoint>: New. <base>: Remove. (dtor_catch_solib): Change to ... (solib_catchpoint::~solib_catchpoint): ... this. (breakpoint_hit_catch_solib): Remove reference to base field. (add_solib_catchpoint): Likewise. (create_fork_vfork_event_catchpoint): Likewise. (struct exec_catchpoint): Inherit from breakpoint. <~exec_catchpoint>: New. <base>: Remove. (dtor_catch_exec): Change to ... (exec_catchpoint::~exec_catchpoint): ... this. (dtor_watchpoint): Change to ... (watchpoint::~watchpoint): ... this. (watch_command_1): Remove reference to base field. (catch_exec_command_1): Likewise. (base_breakpoint_dtor): Change to ... (breakpoint::~breakpoint): ... this. (base_breakpoint_ops): Remove dtor field value. (longjmp_bkpt_dtor): Change to ... (longjmp_breakpoint::~longjmp_breakpoint): ... this. (strace_marker_create_breakpoints_sal): Remove reference to base field. (delete_breakpoint): Don't manually call breakpoint destructor. (create_tracepoint_from_upload): Remove reference to base field. (trace_pass_set_count): Likewise. (initialize_breakpoint_ops): Don't initialize momentary_breakpoint_ops, don't set dtors. * ada-lang.c (struct ada_catchpoint): Inherit from breakpoint. <~ada_catchpoint>: New. <base>: Remove. (create_excep_cond_exprs): Remove reference to base field. (dtor_exception): Change to ... (ada_catchpoint::~ada_catchpoint): ... this. (dtor_catch_exception): Remove. (dtor_catch_exception_unhandled): Remove. (dtor_catch_assert): Remove. (create_ada_exception_catchpoint): Remove reference to base field. (initialize_ada_catchpoint_ops): Don't set dtors. * break-catch-sig.c (struct signal_catchpoint): Inherit from breakpoint. <~signal_catchpoint>: New. <base>: Remove. (signal_catchpoint_dtor): Change to ... (signal_catchpoint::~signal_catchpoint): ... this. (create_signal_catchpoint): Remove reference to base field. (initialize_signal_catchpoint_ops): Don't set dtor. * break-catch-syscall.c (struct syscall_catchpoint): Inherit from breakpoint. <~syscall_catchpoint>: New. <base>: Remove. (dtor_catch_syscall): Change to ... (syscall_catchpoint::~syscall_catchpoint): ... this. (create_syscall_event_catchpoint): Remove reference to base field. (initialize_syscall_catchpoint_ops): Don't set dtor. * break-catch-throw.c (struct exception_catchpoint): Inherit from breakpoint. <~exception_catchpoint>: New. <base>: Remove. (dtor_exception_catchpoint): Change to ... (exception_catchpoint::~exception_catchpoint): ... this. (handle_gnu_v3_exceptions): Remove reference to base field. (initialize_throw_catchpoint_ops): Don't set dtor. * ctf.c (ctf_get_traceframe_address): Remove reference to base field. * remote.c (remote_get_tracepoint_status): Likewise. * tracefile-tfile.c (tfile_get_traceframe_address): Likewise. * tracefile.c (tracefile_fetch_registers): Likewise. * tracepoint.c (actions_command): Likewise. (validate_actionline): Likewise. (tfind_1): Likewise. (get_traceframe_location): Likewise. (find_matching_tracepoint_location): Likewise. (parse_tracepoint_status): Likewise. * mi/mi-cmd-break.c (mi_cmd_break_passcount): Likewise.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c54
1 files changed, 12 insertions, 42 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 25c49c5..f90907a 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12257,14 +12257,11 @@ static const struct bp_location_ops ada_catchpoint_location_ops =
ada_catchpoint_location_dtor
};
-/* An instance of this type is used to represent an Ada catchpoint.
- It includes a "struct breakpoint" as a kind of base class; users
- downcast to "struct breakpoint *" when needed. */
+/* An instance of this type is used to represent an Ada catchpoint. */
-struct ada_catchpoint
+struct ada_catchpoint : public breakpoint
{
- /* The base class. */
- struct breakpoint base;
+ ~ada_catchpoint () override;
/* The name of the specific exception the user specified. */
char *excep_string;
@@ -12285,7 +12282,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c)
return;
/* Same if there are no locations... */
- if (c->base.loc == NULL)
+ if (c->loc == NULL)
return;
/* Compute the condition expression in text form, from the specific
@@ -12295,7 +12292,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c)
/* Iterate over all the catchpoint's locations, and parse an
expression for each. */
- for (bl = c->base.loc; bl != NULL; bl = bl->next)
+ for (bl = c->loc; bl != NULL; bl = bl->next)
{
struct ada_catchpoint_location *ada_loc
= (struct ada_catchpoint_location *) bl;
@@ -12316,7 +12313,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c)
{
warning (_("failed to reevaluate internal exception condition "
"for catchpoint %d: %s"),
- c->base.number, e.message);
+ c->number, e.message);
}
END_CATCH
}
@@ -12327,17 +12324,11 @@ create_excep_cond_exprs (struct ada_catchpoint *c)
do_cleanups (old_chain);
}
-/* Implement the DTOR method in the breakpoint_ops structure for all
- exception catchpoint kinds. */
+/* ada_catchpoint destructor. */
-static void
-dtor_exception (enum ada_exception_catchpoint_kind ex, struct breakpoint *b)
+ada_catchpoint::~ada_catchpoint ()
{
- struct ada_catchpoint *c = (struct ada_catchpoint *) b;
-
- xfree (c->excep_string);
-
- bkpt_breakpoint_ops.dtor (b);
+ xfree (this->excep_string);
}
/* Implement the ALLOCATE_LOCATION method in the breakpoint_ops
@@ -12623,12 +12614,6 @@ print_recreate_exception (enum ada_exception_catchpoint_kind ex,
/* Virtual table for "catch exception" breakpoints. */
-static void
-dtor_catch_exception (struct breakpoint *b)
-{
- dtor_exception (ada_catch_exception, b);
-}
-
static struct bp_location *
allocate_location_catch_exception (struct breakpoint *self)
{
@@ -12675,12 +12660,6 @@ static struct breakpoint_ops catch_exception_breakpoint_ops;
/* Virtual table for "catch exception unhandled" breakpoints. */
-static void
-dtor_catch_exception_unhandled (struct breakpoint *b)
-{
- dtor_exception (ada_catch_exception_unhandled, b);
-}
-
static struct bp_location *
allocate_location_catch_exception_unhandled (struct breakpoint *self)
{
@@ -12729,12 +12708,6 @@ static struct breakpoint_ops catch_exception_unhandled_breakpoint_ops;
/* Virtual table for "catch assert" breakpoints. */
-static void
-dtor_catch_assert (struct breakpoint *b)
-{
- dtor_exception (ada_catch_assert, b);
-}
-
static struct bp_location *
allocate_location_catch_assert (struct breakpoint *self)
{
@@ -13060,13 +13033,13 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch,
= ada_exception_sal (ex_kind, excep_string, &addr_string, &ops);
c = new ada_catchpoint ();
- init_ada_exception_breakpoint (&c->base, gdbarch, sal, addr_string,
+ init_ada_exception_breakpoint (c, gdbarch, sal, addr_string,
ops, tempflag, disabled, from_tty);
c->excep_string = excep_string;
create_excep_cond_exprs (c);
if (cond_string != NULL)
- set_breakpoint_condition (&c->base, cond_string, from_tty);
- install_breakpoint (0, &c->base, 1);
+ set_breakpoint_condition (c, cond_string, from_tty);
+ install_breakpoint (0, c, 1);
}
/* Implement the "catch exception" command. */
@@ -14090,7 +14063,6 @@ initialize_ada_catchpoint_ops (void)
ops = &catch_exception_breakpoint_ops;
*ops = bkpt_breakpoint_ops;
- ops->dtor = dtor_catch_exception;
ops->allocate_location = allocate_location_catch_exception;
ops->re_set = re_set_catch_exception;
ops->check_status = check_status_catch_exception;
@@ -14101,7 +14073,6 @@ initialize_ada_catchpoint_ops (void)
ops = &catch_exception_unhandled_breakpoint_ops;
*ops = bkpt_breakpoint_ops;
- ops->dtor = dtor_catch_exception_unhandled;
ops->allocate_location = allocate_location_catch_exception_unhandled;
ops->re_set = re_set_catch_exception_unhandled;
ops->check_status = check_status_catch_exception_unhandled;
@@ -14112,7 +14083,6 @@ initialize_ada_catchpoint_ops (void)
ops = &catch_assert_breakpoint_ops;
*ops = bkpt_breakpoint_ops;
- ops->dtor = dtor_catch_assert;
ops->allocate_location = allocate_location_catch_assert;
ops->re_set = re_set_catch_assert;
ops->check_status = check_status_catch_assert;