#include "source.h"
#include "linespec.h"
#include "completer.h"
-#include "gdb.h"
#include "ui-out.h"
#include "cli/cli-script.h"
#include "block.h"
/* Prototypes for local functions. */
-static void enable_delete_command (char *, int);
-
-static void enable_once_command (char *, int);
-
-static void enable_count_command (char *, int);
-
-static void disable_command (char *, int);
-
-static void enable_command (char *, int);
-
static void map_breakpoint_numbers (const char *,
gdb::function_view<void (breakpoint *)>);
static void ignore_command (char *, int);
-static int breakpoint_re_set_one (void *);
-
static void breakpoint_re_set_default (struct breakpoint *);
static void
static void clear_command (char *, int);
-static void catch_command (char *, int);
-
static int can_use_hardware_watchpoint (struct value *);
-static void break_command_1 (char *, int, int);
-
static void mention (struct breakpoint *);
static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
struct bp_location *loc2);
static int breakpoint_location_address_match (struct bp_location *bl,
- struct address_space *aspace,
+ const struct address_space *aspace,
CORE_ADDR addr);
static int breakpoint_location_address_range_overlap (struct bp_location *,
- struct address_space *,
+ const address_space *,
CORE_ADDR, int);
static void info_breakpoints_command (char *, int);
static void info_watchpoints_command (char *, int);
-static int breakpoint_1 (char *, int,
- int (*) (const struct breakpoint *));
-
-static int breakpoint_cond_eval (void *);
-
-static void cleanup_executing_breakpoints (void *);
-
static void commands_command (char *, int);
static void condition_command (char *, int);
static enum print_stop_action print_bp_stop_message (bpstat bs);
-static int watchpoint_check (void *);
-
-static void maintenance_info_breakpoints (char *, int);
-
static int hw_breakpoint_used_count (void);
static int hw_watchpoint_use_count (struct breakpoint *);
static void stop_command (char *arg, int from_tty);
-static void stopin_command (char *arg, int from_tty);
-
-static void stopat_command (char *arg, int from_tty);
-
-static void tcatch_command (char *arg, int from_tty);
-
static void free_bp_location (struct bp_location *loc);
static void incref_bp_location (struct bp_location *loc);
static void decref_bp_location (struct bp_location **loc);
static void info_tracepoints_command (char *, int);
-static void delete_trace_command (char *, int);
-
static void enable_trace_command (char *, int);
static void disable_trace_command (char *, int);
/* Called at the start an "rbreak" command to record the first
breakpoint made. */
-void
-start_rbreak_breakpoints (void)
+scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
{
rbreak_start_breakpoint_count = breakpoint_count;
}
/* Called at the end of an "rbreak" command to record the last
breakpoint made. */
-void
-end_rbreak_breakpoints (void)
+scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
{
prev_breakpoint_count = rbreak_start_breakpoint_count;
}
cmd = copy_command_lines (control->body_list[0]);
else
{
- struct cleanup *old_chain;
- char *str;
-
- str = xstrprintf (_("Type commands for breakpoint(s) "
- "%s, one per line."),
- arg);
+ std::string str
+ = string_printf (_("Type commands for breakpoint(s) "
+ "%s, one per line."),
+ arg);
- old_chain = make_cleanup (xfree, str);
-
- cmd = read_command_lines (str,
+ cmd = read_command_lines (&str[0],
from_tty, 1,
(is_tracepoint (b)
? check_tracepoint_command : 0),
b);
-
- do_cleanups (old_chain);
}
}
return 0;
}
-int
-reattach_breakpoints (int pid)
-{
- struct bp_location *bl, **blp_tmp;
- int val;
- int dummy1 = 0, dummy2 = 0, dummy3 = 0;
- struct inferior *inf;
- struct thread_info *tp;
-
- tp = any_live_thread_of_process (pid);
- if (tp == NULL)
- return 1;
-
- inf = find_inferior_pid (pid);
-
- scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
- inferior_ptid = tp->ptid;
-
- string_file tmp_error_stream;
-
- ALL_BP_LOCATIONS (bl, blp_tmp)
- {
- if (bl->pspace != inf->pspace)
- continue;
-
- if (bl->inserted)
- {
- bl->inserted = 0;
- val = insert_bp_location (bl, &tmp_error_stream, &dummy1, &dummy2, &dummy3);
- if (val != 0)
- return val;
- }
- }
- return 0;
-}
-
static int internal_breakpoint_number = -1;
/* Set the breakpoint number of B, depending on the value of INTERNAL.
struct breakpoint_objfile_data
{
/* Minimal symbol for "_ovly_debug_event" (if any). */
- struct bound_minimal_symbol overlay_msym;
+ struct bound_minimal_symbol overlay_msym {};
/* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
- struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES];
+ struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {};
/* True if we have looked for longjmp probes. */
- int longjmp_searched;
+ int longjmp_searched = 0;
- /* SystemTap probe points for longjmp (if any). */
- VEC (probe_p) *longjmp_probes;
+ /* SystemTap probe points for longjmp (if any). These are non-owning
+ references. */
+ std::vector<probe *> longjmp_probes;
/* Minimal symbol for "std::terminate()" (if any). */
- struct bound_minimal_symbol terminate_msym;
+ struct bound_minimal_symbol terminate_msym {};
/* Minimal symbol for "_Unwind_DebugHook" (if any). */
- struct bound_minimal_symbol exception_msym;
+ struct bound_minimal_symbol exception_msym {};
/* True if we have looked for exception probes. */
- int exception_searched;
+ int exception_searched = 0;
- /* SystemTap probe points for unwinding (if any). */
- VEC (probe_p) *exception_probes;
+ /* SystemTap probe points for unwinding (if any). These are non-owning
+ references. */
+ std::vector<probe *> exception_probes;
};
static const struct objfile_data *breakpoint_objfile_key;
objfile_data (objfile, breakpoint_objfile_key));
if (bp_objfile_data == NULL)
{
- bp_objfile_data =
- XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data);
-
- memset (bp_objfile_data, 0, sizeof (*bp_objfile_data));
+ bp_objfile_data = new breakpoint_objfile_data ();
set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
}
return bp_objfile_data;
}
static void
-free_breakpoint_probes (struct objfile *obj, void *data)
+free_breakpoint_objfile_data (struct objfile *obj, void *data)
{
struct breakpoint_objfile_data *bp_objfile_data
= (struct breakpoint_objfile_data *) data;
- VEC_free (probe_p, bp_objfile_data->longjmp_probes);
- VEC_free (probe_p, bp_objfile_data->exception_probes);
+ delete bp_objfile_data;
}
static void
if (!bp_objfile_data->longjmp_searched)
{
- VEC (probe_p) *ret;
+ std::vector<probe *> ret
+ = find_probes_in_objfile (objfile, "libc", "longjmp");
- ret = find_probes_in_objfile (objfile, "libc", "longjmp");
- if (ret != NULL)
+ if (!ret.empty ())
{
/* We are only interested in checking one element. */
- struct probe *p = VEC_index (probe_p, ret, 0);
+ probe *p = ret[0];
if (!can_evaluate_probe_arguments (p))
{
/* We cannot use the probe interface here, because it does
not know how to evaluate arguments. */
- VEC_free (probe_p, ret);
- ret = NULL;
+ ret.clear ();
}
}
bp_objfile_data->longjmp_probes = ret;
bp_objfile_data->longjmp_searched = 1;
}
- if (bp_objfile_data->longjmp_probes != NULL)
+ if (!bp_objfile_data->longjmp_probes.empty ())
{
- int i;
- struct probe *probe;
struct gdbarch *gdbarch = get_objfile_arch (objfile);
- for (i = 0;
- VEC_iterate (probe_p,
- bp_objfile_data->longjmp_probes,
- i, probe);
- ++i)
+ for (probe *p : bp_objfile_data->longjmp_probes)
{
struct breakpoint *b;
b = create_internal_breakpoint (gdbarch,
- get_probe_address (probe,
- objfile),
+ get_probe_address (p, objfile),
bp_longjmp_master,
&internal_breakpoint_ops);
b->location = new_probe_location ("-probe-stap libc:longjmp");
/* We prefer the SystemTap probe point if it exists. */
if (!bp_objfile_data->exception_searched)
{
- VEC (probe_p) *ret;
-
- ret = find_probes_in_objfile (objfile, "libgcc", "unwind");
+ std::vector<probe *> ret
+ = find_probes_in_objfile (objfile, "libgcc", "unwind");
- if (ret != NULL)
+ if (!ret.empty ())
{
/* We are only interested in checking one element. */
- struct probe *p = VEC_index (probe_p, ret, 0);
+ probe *p = ret[0];
if (!can_evaluate_probe_arguments (p))
{
/* We cannot use the probe interface here, because it does
not know how to evaluate arguments. */
- VEC_free (probe_p, ret);
- ret = NULL;
+ ret.clear ();
}
}
bp_objfile_data->exception_probes = ret;
bp_objfile_data->exception_searched = 1;
}
- if (bp_objfile_data->exception_probes != NULL)
+ if (!bp_objfile_data->exception_probes.empty ())
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
- int i;
- struct probe *probe;
-
- for (i = 0;
- VEC_iterate (probe_p,
- bp_objfile_data->exception_probes,
- i, probe);
- ++i)
+
+ for (probe *p : bp_objfile_data->exception_probes)
{
struct breakpoint *b;
b = create_internal_breakpoint (gdbarch,
- get_probe_address (probe,
- objfile),
+ get_probe_address (p, objfile),
bp_exception_master,
&internal_breakpoint_ops);
b->location = new_probe_location ("-probe-stap libgcc:unwind");
the target, to advance the PC past the breakpoint. */
enum breakpoint_here
-breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
+breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
{
struct bp_location *bl, **blp_tmp;
int any_breakpoint_here = 0;
/* See breakpoint.h. */
int
-breakpoint_in_range_p (struct address_space *aspace,
+breakpoint_in_range_p (const address_space *aspace,
CORE_ADDR addr, ULONGEST len)
{
struct bp_location *bl, **blp_tmp;
/* Return true if there's a moribund breakpoint at PC. */
int
-moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc)
+moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc)
{
struct bp_location *loc;
int ix;
static int
bp_location_inserted_here_p (struct bp_location *bl,
- struct address_space *aspace, CORE_ADDR pc)
+ const address_space *aspace, CORE_ADDR pc)
{
if (bl->inserted
&& breakpoint_address_match (bl->pspace->aspace, bl->address,
/* Returns non-zero iff there's a breakpoint inserted at PC. */
int
-breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc)
+breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc)
{
struct bp_location **blp, **blp_tmp = NULL;
inserted at PC. */
int
-software_breakpoint_inserted_here_p (struct address_space *aspace,
+software_breakpoint_inserted_here_p (const address_space *aspace,
CORE_ADDR pc)
{
struct bp_location **blp, **blp_tmp = NULL;
/* See breakpoint.h. */
int
-hardware_breakpoint_inserted_here_p (struct address_space *aspace,
+hardware_breakpoint_inserted_here_p (const address_space *aspace,
CORE_ADDR pc)
{
struct bp_location **blp, **blp_tmp = NULL;
}
int
-hardware_watchpoint_inserted_in_range (struct address_space *aspace,
+hardware_watchpoint_inserted_in_range (const address_space *aspace,
CORE_ADDR addr, ULONGEST len)
{
struct breakpoint *bpt;
breakpoint_proceeded = 1;
}
-/* Stub for cleaning up our state if we error-out of a breakpoint
- command. */
-static void
-cleanup_executing_breakpoints (void *ignore)
-{
- executing_breakpoint_commands = 0;
-}
-
/* Return non-zero iff CMD as the first line of a command sequence is `silent'
or its equivalent. */
bpstat_do_actions_1 (bpstat *bsp)
{
bpstat bs;
- struct cleanup *old_chain;
int again = 0;
/* Avoid endless recursion if a `source' command is contained
if (executing_breakpoint_commands)
return 0;
- executing_breakpoint_commands = 1;
- old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
+ scoped_restore save_executing
+ = make_scoped_restore (&executing_breakpoint_commands, 1);
scoped_restore preventer = prevent_dont_repeat ();
break;
}
}
- do_cleanups (old_chain);
return again;
}
return PRINT_UNKNOWN;
}
-/* Evaluate the expression EXP and return 1 if value is zero.
- This returns the inverse of the condition because it is called
- from catch_errors which returns 0 if an exception happened, and if an
- exception happens we want execution to stop.
- The argument is a "struct expression *" that has been cast to a
- "void *" to make it pass through catch_errors. */
+/* Evaluate the boolean expression EXP and return the result. */
-static int
-breakpoint_cond_eval (void *exp)
+static bool
+breakpoint_cond_eval (expression *exp)
{
struct value *mark = value_mark ();
- int i = !value_true (evaluate_expression ((struct expression *) exp));
+ bool res = value_true (evaluate_expression (exp));
value_free_to_mark (mark);
- return i;
+ return res;
}
/* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
return 1;
}
-/* Possible return values for watchpoint_check (this can't be an enum
- because of check_errors). */
-/* The watchpoint has been deleted. */
-#define WP_DELETED 1
-/* The value has changed. */
-#define WP_VALUE_CHANGED 2
-/* The value has not changed. */
-#define WP_VALUE_NOT_CHANGED 3
-/* Ignore this watchpoint, no matter if the value changed or not. */
-#define WP_IGNORE 4
+/* Possible return values for watchpoint_check. */
+enum wp_check_result
+ {
+ /* The watchpoint has been deleted. */
+ WP_DELETED = 1,
+
+ /* The value has changed. */
+ WP_VALUE_CHANGED = 2,
+
+ /* The value has not changed. */
+ WP_VALUE_NOT_CHANGED = 3,
+
+ /* Ignore this watchpoint, no matter if the value changed or not. */
+ WP_IGNORE = 4,
+ };
#define BP_TEMPFLAG 1
#define BP_HARDWAREFLAG 2
/* Evaluate watchpoint condition expression and check if its value
- changed.
+ changed. */
- P should be a pointer to struct bpstat, but is defined as a void *
- in order for this function to be usable with catch_errors. */
-
-static int
-watchpoint_check (void *p)
+static wp_check_result
+watchpoint_check (bpstat bs)
{
- bpstat bs = (bpstat) p;
struct watchpoint *b;
struct frame_info *fr;
int within_current_scope;
static int
bpstat_check_location (const struct bp_location *bl,
- struct address_space *aspace, CORE_ADDR bp_addr,
+ const address_space *aspace, CORE_ADDR bp_addr,
const struct target_waitstatus *ws)
{
struct breakpoint *b = bl->owner;
if (must_check_value)
{
- char *message
- = xstrprintf ("Error evaluating expression for watchpoint %d\n",
- b->number);
- struct cleanup *cleanups = make_cleanup (xfree, message);
- int e = catch_errors (watchpoint_check, bs, message,
- RETURN_MASK_ALL);
- do_cleanups (cleanups);
+ wp_check_result e;
+
+ TRY
+ {
+ e = watchpoint_check (bs);
+ }
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ exception_fprintf (gdb_stderr, ex,
+ "Error evaluating expression "
+ "for watchpoint %d\n",
+ b->number);
+
+ SWITCH_THRU_ALL_UIS ()
+ {
+ printf_filtered (_("Watchpoint %d deleted.\n"),
+ b->number);
+ }
+ watchpoint_del_at_next_stop (b);
+ e = WP_DELETED;
+ }
+ END_CATCH
+
switch (e)
{
case WP_DELETED:
break;
default:
/* Can't happen. */
- case 0:
- /* Error from catch_errors. */
- {
- SWITCH_THRU_ALL_UIS ()
- {
- printf_filtered (_("Watchpoint %d deleted.\n"),
- b->number);
- }
- watchpoint_del_at_next_stop (b);
- /* We've already printed what needs to be printed. */
- bs->print_it = print_it_done;
- }
break;
}
}
{
const struct bp_location *bl;
struct breakpoint *b;
- int value_is_zero = 0;
+ /* Assume stop. */
+ bool condition_result = true;
struct expression *cond;
gdb_assert (bs->stop);
within_current_scope = 0;
}
if (within_current_scope)
- value_is_zero
- = catch_errors (breakpoint_cond_eval, cond,
- "Error in testing breakpoint condition:\n",
- RETURN_MASK_ALL);
+ {
+ TRY
+ {
+ condition_result = breakpoint_cond_eval (cond);
+ }
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ exception_fprintf (gdb_stderr, ex,
+ "Error in testing breakpoint condition:\n");
+ }
+ END_CATCH
+ }
else
{
warning (_("Watchpoint condition cannot be tested "
"in the current scope"));
/* If we failed to set the right context for this
watchpoint, unconditionally report it. */
- value_is_zero = 0;
}
/* FIXME-someday, should give breakpoint #. */
value_free_to_mark (mark);
}
- if (cond && value_is_zero)
+ if (cond && !condition_result)
{
bs->stop = 0;
}
commands, FIXME??? fields. */
bpstat
-bpstat_stop_status (struct address_space *aspace,
+bpstat_stop_status (const address_space *aspace,
CORE_ADDR bp_addr, ptid_t ptid,
const struct target_waitstatus *ws)
{
uiout->field_string ("what", event_location_to_string (b->location.get ()));
else if (loc && loc->symtab)
{
- struct symbol *sym
- = find_pc_sect_function (loc->address, loc->section);
+ const struct symbol *sym = loc->symbol;
+
+ if (sym == NULL)
+ sym = find_pc_sect_function (loc->address, loc->section);
+
if (sym)
{
uiout->text ("in ");
return print_address_bits;
}
-struct captured_breakpoint_query_args
- {
- int bnum;
- };
+/* See breakpoint.h. */
-static int
-do_captured_breakpoint_query (struct ui_out *uiout, void *data)
+void
+print_breakpoint (breakpoint *b)
{
- struct captured_breakpoint_query_args *args
- = (struct captured_breakpoint_query_args *) data;
- struct breakpoint *b;
struct bp_location *dummy_loc = NULL;
-
- ALL_BREAKPOINTS (b)
- {
- if (args->bnum == b->number)
- {
- print_one_breakpoint (b, &dummy_loc, 0);
- return GDB_RC_OK;
- }
- }
- return GDB_RC_NONE;
-}
-
-enum gdb_rc
-gdb_breakpoint_query (struct ui_out *uiout, int bnum,
- char **error_message)
-{
- struct captured_breakpoint_query_args args;
-
- args.bnum = bnum;
- /* For the moment we don't trust print_one_breakpoint() to not throw
- an error. */
- if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args,
- error_message, RETURN_MASK_ALL) < 0)
- return GDB_RC_FAIL;
- else
- return GDB_RC_OK;
+ print_one_breakpoint (b, &dummy_loc, 0);
}
/* Return true if this breakpoint was set by the user, false if it is
breakpoints listed. */
static int
-breakpoint_1 (char *args, int allflag,
+breakpoint_1 (const char *args, int allflag,
int (*filter) (const struct breakpoint *))
{
struct breakpoint *b;
}
static void
-maintenance_info_breakpoints (char *args, int from_tty)
+maintenance_info_breakpoints (const char *args, int from_tty)
{
breakpoint_1 (args, 1, NULL);
/* See breakpoint.h. */
int
-breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1,
- struct address_space *aspace2, CORE_ADDR addr2)
+breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1,
+ const address_space *aspace2, CORE_ADDR addr2)
{
return ((gdbarch_has_global_breakpoints (target_gdbarch ())
|| aspace1 == aspace2)
space doesn't really matter. */
static int
-breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1,
- int len1, struct address_space *aspace2,
+breakpoint_address_match_range (const address_space *aspace1,
+ CORE_ADDR addr1,
+ int len1, const address_space *aspace2,
CORE_ADDR addr2)
{
return ((gdbarch_has_global_breakpoints (target_gdbarch ())
static int
breakpoint_location_address_match (struct bp_location *bl,
- struct address_space *aspace,
+ const address_space *aspace,
CORE_ADDR addr)
{
return (breakpoint_address_match (bl->pspace->aspace, bl->address,
static int
breakpoint_location_address_range_overlap (struct bp_location *bl,
- struct address_space *aspace,
+ const address_space *aspace,
CORE_ADDR addr, int len)
{
if (gdbarch_has_global_breakpoints (target_gdbarch ())
static int
breakpoint_hit_catch_fork (const struct bp_location *bl,
- struct address_space *aspace, CORE_ADDR bp_addr,
+ const address_space *aspace, CORE_ADDR bp_addr,
const struct target_waitstatus *ws)
{
struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
static int
breakpoint_hit_catch_vfork (const struct bp_location *bl,
- struct address_space *aspace, CORE_ADDR bp_addr,
+ const address_space *aspace, CORE_ADDR bp_addr,
const struct target_waitstatus *ws)
{
struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner;
static int
breakpoint_hit_catch_solib (const struct bp_location *bl,
- struct address_space *aspace,
+ const address_space *aspace,
CORE_ADDR bp_addr,
const struct target_waitstatus *ws)
{
static int
breakpoint_hit_catch_exec (const struct bp_location *bl,
- struct address_space *aspace, CORE_ADDR bp_addr,
+ const address_space *aspace, CORE_ADDR bp_addr,
const struct target_waitstatus *ws)
{
struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner;
SAL. If FRAME_ID is valid, the breakpoint is restricted to that
frame. */
-struct breakpoint *
+breakpoint_up
set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal,
struct frame_id frame_id, enum bptype type)
{
update_global_location_list_nothrow (UGLL_MAY_INSERT);
- return b;
+ return breakpoint_up (b);
}
/* Make a momentary breakpoint based on the master breakpoint ORIG.
return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0);
}
-struct breakpoint *
+breakpoint_up
set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc,
enum bptype type)
{
loc->gdbarch = loc_gdbarch;
loc->line_number = sal->line;
loc->symtab = sal->symtab;
+ loc->symbol = sal->symbol;
set_breakpoint_location_function (loc,
sal->explicit_pc || sal->explicit_line);
decode_static_tracepoint_spec (const char **arg_p)
{
VEC(static_tracepoint_marker_p) *markers = NULL;
- struct cleanup *old_chain;
const char *p = &(*arg_p)[3];
const char *endp;
- char *marker_str;
int i;
p = skip_spaces (p);
endp = skip_to_space (p);
- marker_str = savestring (p, endp - p);
- old_chain = make_cleanup (xfree, marker_str);
+ std::string marker_str (p, endp - p);
- markers = target_static_tracepoint_markers_by_strid (marker_str);
+ markers = target_static_tracepoint_markers_by_strid (marker_str.c_str ());
if (VEC_empty(static_tracepoint_marker_p, markers))
- error (_("No known static tracepoint marker named %s"), marker_str);
+ error (_("No known static tracepoint marker named %s"),
+ marker_str.c_str ());
std::vector<symtab_and_line> sals;
sals.reserve (VEC_length(static_tracepoint_marker_p, markers));
release_static_tracepoint_marker (marker);
}
- do_cleanups (old_chain);
-
*arg_p = endp;
return sals;
}
and BP_TEMPFLAG. */
static void
-break_command_1 (char *arg, int flag, int from_tty)
+break_command_1 (const char *arg, int flag, int from_tty)
{
int tempflag = flag & BP_TEMPFLAG;
enum bptype type_wanted = (flag & BP_HARDWAREFLAG
}
static void
-stopin_command (char *arg, int from_tty)
+stopin_command (const char *arg, int from_tty)
{
int badInput = 0;
badInput = 1;
else if (*arg != '*')
{
- char *argptr = arg;
+ const char *argptr = arg;
int hasColon = 0;
/* Look for a ':'. If this is a line number specification, then
}
static void
-stopat_command (char *arg, int from_tty)
+stopat_command (const char *arg, int from_tty)
{
int badInput = 0;
badInput = 1;
else
{
- char *argptr = arg;
+ const char *argptr = arg;
int hasColon = 0;
/* Look for a ':'. If there is a '::' then get out, otherwise
line. */
static void
-dprintf_command (char *arg, int from_tty)
+dprintf_command (char *arg_in, int from_tty)
{
+ const char *arg = arg_in;
event_location_up location = string_to_event_location (&arg, current_language);
/* If non-NULL, ARG should have been advanced past the location;
static int
breakpoint_hit_ranged_breakpoint (const struct bp_location *bl,
- struct address_space *aspace,
+ const address_space *aspace,
CORE_ADDR bp_addr,
const struct target_waitstatus *ws)
{
/* Implement the "break-range" CLI command. */
static void
-break_range_command (char *arg, int from_tty)
+break_range_command (char *arg_in, int from_tty)
{
- char *arg_start, *addr_string_start;
+ const char *arg = arg_in;
+ const char *arg_start;
struct linespec_result canonical_start, canonical_end;
int bp_count, can_use_bp, length;
CORE_ADDR end;
struct breakpoint *b;
- struct cleanup *cleanup_bkpt;
/* We don't support software ranged breakpoints. */
if (target_ranged_break_num_registers () < 0)
error (_("Cannot create a ranged breakpoint with multiple locations."));
const symtab_and_line &sal_start = lsal_start.sals[0];
- addr_string_start = savestring (arg_start, arg - arg_start);
- cleanup_bkpt = make_cleanup (xfree, addr_string_start);
+ std::string addr_string_start (arg_start, arg - arg_start);
arg++; /* Skip the comma. */
arg = skip_spaces (arg);
{
/* This range is simple enough to be handled by
the `hbreak' command. */
- hbreak_command (addr_string_start, 1);
-
- do_cleanups (cleanup_bkpt);
+ hbreak_command (&addr_string_start[0], 1);
return;
}
b->location_range_end = std::move (end_location);
b->loc->length = length;
- do_cleanups (cleanup_bkpt);
-
mention (b);
observer_notify_breakpoint_created (b);
update_global_location_list (UGLL_MAY_INSERT);
case TERNOP_SLICE:
case OP_LONG:
- case OP_DOUBLE:
- case OP_DECFLOAT:
+ case OP_FLOAT:
case OP_LAST:
case OP_COMPLEX:
case OP_STRING:
static int
breakpoint_hit_watchpoint (const struct bp_location *bl,
- struct address_space *aspace, CORE_ADDR bp_addr,
+ const address_space *aspace, CORE_ADDR bp_addr,
const struct target_waitstatus *ws)
{
struct breakpoint *b = bl->owner;
the hardware watchpoint. */
int use_mask = 0;
CORE_ADDR mask = 0;
- char *expression;
- struct cleanup *back_to;
/* Make sure that we actually have parameters to parse. */
if (arg != NULL && arg[0] != '\0')
is in terms of a newly allocated string instead of the original
ARG. */
innermost_block = NULL;
- expression = savestring (arg, exp_end - arg);
- back_to = make_cleanup (xfree, expression);
- exp_start = arg = expression;
+ std::string expression (arg, exp_end - arg);
+ exp_start = arg = expression.c_str ();
expression_up exp = parse_exp_1 (&arg, 0, 0, 0);
exp_end = arg;
/* Remove trailing whitespace from the expression before saving it.
update_watchpoint (w.get (), 1);
install_breakpoint (internal, std::move (w), 1);
- do_cleanups (back_to);
}
/* Return count of debug registers needed to watch the given expression.
}
void
-watch_command_wrapper (char *arg, int from_tty, int internal)
+watch_command_wrapper (const char *arg, int from_tty, int internal)
{
watch_command_1 (arg, hw_write, from_tty, 0, internal);
}
}
void
-rwatch_command_wrapper (char *arg, int from_tty, int internal)
+rwatch_command_wrapper (const char *arg, int from_tty, int internal)
{
watch_command_1 (arg, hw_read, from_tty, 0, internal);
}
}
void
-awatch_command_wrapper (char *arg, int from_tty, int internal)
+awatch_command_wrapper (const char *arg, int from_tty, int internal)
{
watch_command_1 (arg, hw_access, from_tty, 0, internal);
}
static struct until_break_fsm *
new_until_break_fsm (struct interp *cmd_interp, int thread,
- struct breakpoint *location_breakpoint,
- struct breakpoint *caller_breakpoint)
+ breakpoint_up &&location_breakpoint,
+ breakpoint_up &&caller_breakpoint)
{
struct until_break_fsm *sm;
thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp);
sm->thread = thread;
- sm->location_breakpoint = location_breakpoint;
- sm->caller_breakpoint = caller_breakpoint;
+ sm->location_breakpoint = location_breakpoint.release ();
+ sm->caller_breakpoint = caller_breakpoint.release ();
return sm;
}
}
void
-until_break_command (char *arg, int from_tty, int anywhere)
+until_break_command (const char *arg, int from_tty, int anywhere)
{
struct frame_info *frame;
struct gdbarch *frame_gdbarch;
struct frame_id stack_frame_id;
struct frame_id caller_frame_id;
- struct breakpoint *location_breakpoint;
- struct breakpoint *caller_breakpoint = NULL;
struct cleanup *old_chain;
int thread;
struct thread_info *tp;
/* Keep within the current frame, or in frames called by the current
one. */
+ breakpoint_up caller_breakpoint;
if (frame_id_p (caller_frame_id))
{
struct symtab_and_line sal2;
sal2,
caller_frame_id,
bp_until);
- make_cleanup_delete_breakpoint (caller_breakpoint);
set_longjmp_breakpoint (tp, caller_frame_id);
make_cleanup (delete_longjmp_breakpoint_cleanup, &thread);
/* set_momentary_breakpoint could invalidate FRAME. */
frame = NULL;
+ breakpoint_up location_breakpoint;
if (anywhere)
/* If the user told us to continue until a specified location,
we don't specify a frame at which we need to stop. */
only at the very same frame. */
location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
stack_frame_id, bp_until);
- make_cleanup_delete_breakpoint (location_breakpoint);
sm = new_until_break_fsm (command_interp (), tp->global_num,
- location_breakpoint, caller_breakpoint);
+ std::move (location_breakpoint),
+ std::move (caller_breakpoint));
tp->thread_fsm = &sm->thread_fsm;
discard_cleanups (old_chain);
init_ada_exception_breakpoint (struct breakpoint *b,
struct gdbarch *gdbarch,
struct symtab_and_line sal,
- char *addr_string,
+ const char *addr_string,
const struct breakpoint_ops *ops,
int tempflag,
int enabled,
}
static void
-catch_command (char *arg, int from_tty)
+catch_command (const char *arg, int from_tty)
{
error (_("Catch requires an event name."));
}
\f
static void
-tcatch_command (char *arg, int from_tty)
+tcatch_command (const char *arg, int from_tty)
{
error (_("Catch requires an event name."));
}
-/* A qsort comparison function that sorts breakpoints in order. */
+/* Compare two breakpoints and return a strcmp-like result. */
static int
-compare_breakpoints (const void *a, const void *b)
+compare_breakpoints (const breakpoint *a, const breakpoint *b)
{
- const breakpoint_p *ba = (const breakpoint_p *) a;
- uintptr_t ua = (uintptr_t) *ba;
- const breakpoint_p *bb = (const breakpoint_p *) b;
- uintptr_t ub = (uintptr_t) *bb;
+ uintptr_t ua = (uintptr_t) a;
+ uintptr_t ub = (uintptr_t) b;
- if ((*ba)->number < (*bb)->number)
+ if (a->number < b->number)
return -1;
- else if ((*ba)->number > (*bb)->number)
+ else if (a->number > b->number)
return 1;
/* Now sort by address, in case we see, e..g, two breakpoints with
static void
clear_command (char *arg, int from_tty)
{
- struct breakpoint *b, *prev;
- VEC(breakpoint_p) *found = 0;
- int ix;
+ struct breakpoint *b;
int default_match;
int i;
- struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
std::vector<symtab_and_line> decoded_sals;
symtab_and_line last_sal;
from_tty is forced true if we delete more than one
breakpoint. */
- found = NULL;
- make_cleanup (VEC_cleanup (breakpoint_p), &found);
+ std::vector<struct breakpoint *> found;
for (const auto &sal : sals)
{
const char *sal_fullname;
}
if (match)
- VEC_safe_push(breakpoint_p, found, b);
+ found.push_back (b);
}
}
/* Now go thru the 'found' chain and delete them. */
- if (VEC_empty(breakpoint_p, found))
+ if (found.empty ())
{
if (arg)
error (_("No breakpoint at %s."), arg);
}
/* Remove duplicates from the vec. */
- qsort (VEC_address (breakpoint_p, found),
- VEC_length (breakpoint_p, found),
- sizeof (breakpoint_p),
- compare_breakpoints);
- prev = VEC_index (breakpoint_p, found, 0);
- for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix)
- {
- if (b == prev)
- {
- VEC_ordered_remove (breakpoint_p, found, ix);
- --ix;
- }
- }
+ std::sort (found.begin (), found.end (),
+ [] (const breakpoint *a, const breakpoint *b)
+ {
+ return compare_breakpoints (a, b) < 0;
+ });
+ found.erase (std::unique (found.begin (), found.end (),
+ [] (const breakpoint *a, const breakpoint *b)
+ {
+ return compare_breakpoints (a, b) == 0;
+ }),
+ found.end ());
- if (VEC_length(breakpoint_p, found) > 1)
+ if (found.size () > 1)
from_tty = 1; /* Always report if deleted more than one. */
if (from_tty)
{
- if (VEC_length(breakpoint_p, found) == 1)
+ if (found.size () == 1)
printf_unfiltered (_("Deleted breakpoint "));
else
printf_unfiltered (_("Deleted breakpoints "));
}
- for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++)
+ for (breakpoint *iter : found)
{
if (from_tty)
- printf_unfiltered ("%d ", b->number);
- delete_breakpoint (b);
+ printf_unfiltered ("%d ", iter->number);
+ delete_breakpoint (iter);
}
if (from_tty)
putchar_unfiltered ('\n');
-
- do_cleanups (cleanups);
}
\f
/* Delete breakpoint in BS if they are `delete' breakpoints and
{
struct breakpoint *b;
struct bp_location **locp, *loc;
- struct cleanup *cleanups;
/* Last breakpoint location address that was marked for update. */
CORE_ADDR last_addr = 0;
/* Last breakpoint location program space that was marked for update. */
/* Saved former bp_locations array which we compare against the newly
built bp_locations from the current state of ALL_BREAKPOINTS. */
- struct bp_location **old_locations, **old_locp;
+ struct bp_location **old_locp;
unsigned old_locations_count;
+ gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations);
- old_locations = bp_locations;
old_locations_count = bp_locations_count;
bp_locations = NULL;
bp_locations_count = 0;
- cleanups = make_cleanup (xfree, old_locations);
ALL_BREAKPOINTS (b)
for (loc = b->loc; loc; loc = loc->next)
and former bp_location array state respectively. */
locp = bp_locations;
- for (old_locp = old_locations;
- old_locp < old_locations + old_locations_count;
+ for (old_locp = old_locations.get ();
+ old_locp < old_locations.get () + old_locations_count;
old_locp++)
{
struct bp_location *old_loc = *old_locp;
if (insert_mode != UGLL_DONT_INSERT)
download_tracepoint_locations ();
-
- do_cleanups (cleanups);
}
void
static int
base_breakpoint_breakpoint_hit (const struct bp_location *bl,
- struct address_space *aspace,
+ const address_space *aspace,
CORE_ADDR bp_addr,
const struct target_waitstatus *ws)
{
static int
bkpt_breakpoint_hit (const struct bp_location *bl,
- struct address_space *aspace, CORE_ADDR bp_addr,
+ const address_space *aspace, CORE_ADDR bp_addr,
const struct target_waitstatus *ws)
{
if (ws->kind != TARGET_WAITKIND_STOPPED
static int
dprintf_breakpoint_hit (const struct bp_location *bl,
- struct address_space *aspace, CORE_ADDR bp_addr,
+ const address_space *aspace, CORE_ADDR bp_addr,
const struct target_waitstatus *ws)
{
if (dprintf_style == dprintf_style_agent
static int
tracepoint_breakpoint_hit (const struct bp_location *bl,
- struct address_space *aspace, CORE_ADDR bp_addr,
+ const address_space *aspace, CORE_ADDR bp_addr,
const struct target_waitstatus *ws)
{
/* By definition, the inferior does not report stops at
{
struct linespec_sals lsal;
const char *arg_start, *arg;
- char *str;
- struct cleanup *cleanup;
arg = arg_start = get_linespec_location (location);
lsal.sals = decode_static_tracepoint_spec (&arg);
- str = savestring (arg_start, arg - arg_start);
- cleanup = make_cleanup (xfree, str);
- canonical->location = new_linespec_location (&str);
- do_cleanups (cleanup);
+ std::string str (arg_start, arg - arg_start);
+ const char *ptr = str.c_str ();
+ canonical->location = new_linespec_location (&ptr);
lsal.canonical
= xstrdup (event_location_to_string (canonical->location.get ()));
delete bpt;
}
-static void
-do_delete_breakpoint_cleanup (void *b)
-{
- delete_breakpoint ((struct breakpoint *) b);
-}
-
-struct cleanup *
-make_cleanup_delete_breakpoint (struct breakpoint *b)
-{
- return make_cleanup (do_delete_breakpoint_cleanup, b);
-}
-
/* Iterator function to call a user-provided callback function once
for each of B and its related breakpoints. */
while (related != b);
}
-void
-delete_command (char *arg, int from_tty)
+static void
+delete_command (const char *arg, int from_tty)
{
struct breakpoint *b, *b_tmp;
return {};
}
-/* Prepare the global context for a re-set of breakpoint B. */
+/* Reset a breakpoint. */
-static struct cleanup *
-prepare_re_set_context (struct breakpoint *b)
+static void
+breakpoint_re_set_one (breakpoint *b)
{
input_radix = b->input_radix;
set_language (b->language);
- return make_cleanup (null_cleanup, NULL);
-}
-
-/* Reset a breakpoint given it's struct breakpoint * BINT.
- The value we return ends up being the return value from catch_errors.
- Unused in this case. */
-
-static int
-breakpoint_re_set_one (void *bint)
-{
- /* Get past catch_errs. */
- struct breakpoint *b = (struct breakpoint *) bint;
- struct cleanup *cleanups;
-
- cleanups = prepare_re_set_context (b);
b->ops->re_set (b);
- do_cleanups (cleanups);
- return 0;
}
/* Re-set breakpoint locations for the current program space.
breakpoint_re_set (void)
{
struct breakpoint *b, *b_tmp;
- enum language save_language;
- int save_input_radix;
-
- save_language = current_language->la_language;
- save_input_radix = input_radix;
{
+ scoped_restore_current_language save_language;
+ scoped_restore save_input_radix = make_scoped_restore (&input_radix);
scoped_restore_current_pspace_and_thread restore_pspace_thread;
/* Note: we must not try to insert locations until after all
ALL_BREAKPOINTS_SAFE (b, b_tmp)
{
- /* Format possible error msg. */
- char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
- b->number);
- struct cleanup *cleanups = make_cleanup (xfree, message);
- catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
- do_cleanups (cleanups);
+ TRY
+ {
+ breakpoint_re_set_one (b);
+ }
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ exception_fprintf (gdb_stderr, ex,
+ "Error in re-setting breakpoint %d: ",
+ b->number);
+ }
+ END_CATCH
}
- set_language (save_language);
- input_radix = save_input_radix;
jit_breakpoint_re_set ();
}
}
static void
-disable_command (char *args, int from_tty)
+disable_command (const char *args, int from_tty)
{
if (args == 0)
{
in stopping the inferior. */
static void
-enable_command (char *args, int from_tty)
+enable_command (const char *args, int from_tty)
{
if (args == 0)
{
}
static void
-enable_once_command (char *args, int from_tty)
+enable_once_command (const char *args, int from_tty)
{
map_breakpoint_numbers
(args, [&] (breakpoint *b)
}
static void
-enable_count_command (char *args, int from_tty)
+enable_count_command (const char *args, int from_tty)
{
int count;
}
static void
-enable_delete_command (char *args, int from_tty)
+enable_delete_command (const char *args, int from_tty)
{
map_breakpoint_numbers
(args, [&] (breakpoint *b)
}
\f
static void
-set_breakpoint_cmd (char *args, int from_tty)
+set_breakpoint_cmd (const char *args, int from_tty)
{
}
static void
-show_breakpoint_cmd (char *args, int from_tty)
+show_breakpoint_cmd (const char *args, int from_tty)
{
}
void
insert_single_step_breakpoint (struct gdbarch *gdbarch,
- struct address_space *aspace,
+ const address_space *aspace,
CORE_ADDR next_pc)
{
struct thread_info *tp = inferior_thread ();
if (!next_pcs.empty ())
{
struct frame_info *frame = get_current_frame ();
- struct address_space *aspace = get_frame_address_space (frame);
+ const address_space *aspace = get_frame_address_space (frame);
for (CORE_ADDR pc : next_pcs)
insert_single_step_breakpoint (gdbarch, aspace, pc);
int
breakpoint_has_location_inserted_here (struct breakpoint *bp,
- struct address_space *aspace,
+ const address_space *aspace,
CORE_ADDR pc)
{
struct bp_location *loc;
PC. */
int
-single_step_breakpoint_inserted_here_p (struct address_space *aspace,
+single_step_breakpoint_inserted_here_p (const address_space *aspace,
CORE_ADDR pc)
{
struct breakpoint *bpt;
}
static void
-trace_command (char *arg, int from_tty)
+trace_command (char *arg_in, int from_tty)
{
+ const char *arg = arg_in;
struct breakpoint_ops *ops;
event_location_up location = string_to_event_location (&arg,
}
static void
-ftrace_command (char *arg, int from_tty)
+ftrace_command (char *arg_in, int from_tty)
{
+ const char *arg = arg_in;
event_location_up location = string_to_event_location (&arg,
current_language);
create_breakpoint (get_current_arch (),
/* strace command implementation. Creates a static tracepoint. */
static void
-strace_command (char *arg, int from_tty)
+strace_command (char *arg_in, int from_tty)
{
+ const char *arg = arg_in;
struct breakpoint_ops *ops;
event_location_up location;
- struct cleanup *back_to;
/* Decide if we are dealing with a static tracepoint marker (`-m'),
or with a normal static tracepoint. */
struct tracepoint *
create_tracepoint_from_upload (struct uploaded_tp *utp)
{
- char *addr_str, small_buf[100];
+ const char *addr_str;
+ char small_buf[100];
struct tracepoint *tp;
if (utp->at_string)
/* Remove a tracepoint (or all if no argument). */
static void
-delete_trace_command (char *arg, int from_tty)
+delete_trace_command (const char *arg, int from_tty)
{
struct breakpoint *b, *b_tmp;
non-zero. */
static void
-save_breakpoints (char *filename, int from_tty,
+save_breakpoints (const char *filename, int from_tty,
int (*filter) (const struct breakpoint *))
{
struct breakpoint *tp;
/* The `save breakpoints' command. */
static void
-save_breakpoints_command (char *args, int from_tty)
+save_breakpoints_command (const char *args, int from_tty)
{
save_breakpoints (args, from_tty, NULL);
}
/* The `save tracepoints' command. */
static void
-save_tracepoints_command (char *args, int from_tty)
+save_tracepoints_command (const char *args, int from_tty)
{
save_breakpoints (args, from_tty, is_tracepoint);
}
}
static void
-save_command (char *arg, int from_tty)
+save_command (const char *arg, int from_tty)
{
printf_unfiltered (_("\"save\" must be followed by "
"the name of a save subcommand.\n"));
have been inlined. */
int
-pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc,
+pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc,
const struct target_waitstatus *ws)
{
struct breakpoint *b;
observer_attach_memory_changed (invalidate_bp_value_on_memory_change);
breakpoint_objfile_key
- = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes);
+ = register_objfile_data_with_cleanup (NULL, free_breakpoint_objfile_data);
breakpoint_chain = 0;
/* Don't bother to call set_breakpoint_count. $bpnum isn't useful