{
if (*exp == 0)
{
- xfree (b->cond_string);
- b->cond_string = nullptr;
+ b->cond_string.reset ();
if (is_watchpoint (b))
static_cast<watchpoint *> (b)->cond_exp.reset ();
/* We know that the new condition parsed successfully. The
condition string of the breakpoint can be safely updated. */
- xfree (b->cond_string);
- b->cond_string = xstrdup (exp);
+ b->cond_string = make_unique_xstrdup (exp);
b->condition_not_parsed = 0;
}
mark_breakpoint_modified (b);
{
b->cond_exp.reset ();
- s = b->cond_string;
+ s = b->cond_string.get ();
b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0);
}
}
need to parse the command to bytecodes again. */
loc->cmd_bytecode
= parse_cmd_to_aexpr (bl->address,
- loc->owner->extra_string);
+ loc->owner->extra_string.get ());
}
/* If we have a NULL bytecode expression, it means something
uiout->text (",");
else
uiout->text (" ");
- uiout->text (b->extra_string);
+ uiout->text (b->extra_string.get ());
}
}
uiout->text ("\ttrace only if ");
else
uiout->text ("\tstop only if ");
- uiout->field_string ("cond", b->cond_string);
+ uiout->field_string ("cond", b->cond_string.get ());
/* Print whether the target is doing the breakpoint's condition
evaluation. If GDB is doing the evaluation, don't print anything. */
init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops);
- b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string);
+ if (cond_string == nullptr)
+ b->cond_string.reset ();
+ else
+ b->cond_string = make_unique_xstrdup (cond_string);
b->disposition = temp ? disp_del : disp_donttouch;
}
static void
update_dprintf_command_list (struct breakpoint *b)
{
- char *dprintf_args = b->extra_string;
+ const char *dprintf_args = b->extra_string.get ();
char *printf_line = NULL;
if (!dprintf_args)
b->thread = thread;
b->task = task;
- b->cond_string = cond_string.release ();
- b->extra_string = extra_string.release ();
+ b->cond_string = std::move (cond_string);
+ b->extra_string = std::move (extra_string);
b->ignore_count = ignore_count;
b->enable_state = enabled ? bp_enabled : bp_disabled;
b->disposition = disposition;
error (_("Format string required"));
}
else if (b->extra_string)
- error (_("Garbage '%s' at end of command"), b->extra_string);
+ error (_("Garbage '%s' at end of command"), b->extra_string.get ());
}
for (bp_location *loc : b->locations ())
{
if (b->cond_string != nullptr)
- set_breakpoint_location_condition (b->cond_string, loc, b->number,
- loc_num);
+ set_breakpoint_location_condition (b->cond_string.get (), loc,
+ b->number, loc_num);
++loc_num;
}
static void
find_condition_and_thread (const char *tok, CORE_ADDR pc,
- char **cond_string, int *thread, int *task,
- char **rest)
+ gdb::unique_xmalloc_ptr<char> *cond_string,
+ int *thread, int *task,
+ gdb::unique_xmalloc_ptr<char> *rest)
{
- *cond_string = NULL;
+ cond_string->reset ();
*thread = -1;
*task = 0;
- *rest = NULL;
+ rest->reset ();
bool force = false;
while (tok && *tok)
if ((*tok == '"' || *tok == ',') && rest)
{
- *rest = savestring (tok, strlen (tok));
+ rest->reset (savestring (tok, strlen (tok)));
return;
}
tok = tok + strlen (tok);
}
cond_end = tok;
- *cond_string = savestring (cond_start, cond_end - cond_start);
+ cond_string->reset (savestring (cond_start, cond_end - cond_start));
}
else if (toklen >= 1 && strncmp (tok, "-force-condition", toklen) == 0)
{
}
else if (rest)
{
- *rest = savestring (tok, strlen (tok));
+ rest->reset (savestring (tok, strlen (tok)));
return;
}
else
static void
find_condition_and_thread_for_sals (const std::vector<symtab_and_line> &sals,
- const char *input, char **cond_string,
- int *thread, int *task, char **rest)
+ const char *input,
+ gdb::unique_xmalloc_ptr<char> *cond_string,
+ int *thread, int *task,
+ gdb::unique_xmalloc_ptr<char> *rest)
{
int num_failures = 0;
for (auto &sal : sals)
{
- char *cond = nullptr;
+ gdb::unique_xmalloc_ptr<char> cond;
int thread_id = 0;
int task_id = 0;
- char *remaining = nullptr;
+ gdb::unique_xmalloc_ptr<char> remaining;
/* Here we want to parse 'arg' to separate condition from thread
number. But because parsing happens in a context and the
{
find_condition_and_thread (input, sal.pc, &cond, &thread_id,
&task_id, &remaining);
- *cond_string = cond;
+ *cond_string = std::move (cond);
*thread = thread_id;
*task = task_id;
- *rest = remaining;
+ *rest = std::move (remaining);
break;
}
catch (const gdb_exception_error &e)
if (parse_extra)
{
- char *rest;
- char *cond;
+ gdb::unique_xmalloc_ptr<char> rest;
+ gdb::unique_xmalloc_ptr<char> cond;
const linespec_sals &lsal = canonical.lsals[0];
find_condition_and_thread_for_sals (lsal.sals, extra_string,
&cond, &thread, &task, &rest);
- cond_string_copy.reset (cond);
- extra_string_copy.reset (rest);
+ cond_string_copy = std::move (cond);
+ extra_string_copy = std::move (rest);
}
else
{
else
{
/* Create a private copy of condition string. */
- b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL;
+ b->cond_string.reset (cond_string != NULL
+ ? xstrdup (cond_string)
+ : NULL);
b->thread = thread;
}
/* Create a private copy of any extra string. */
- b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL;
+ b->extra_string.reset (extra_string != NULL
+ ? xstrdup (extra_string)
+ : NULL);
b->ignore_count = ignore_count;
b->disposition = tempflag ? disp_del : disp_donttouch;
b->condition_not_parsed = 1;
}
if (cond_start)
- w->cond_string = savestring (cond_start, cond_end - cond_start);
+ w->cond_string.reset (savestring (cond_start, cond_end - cond_start));
else
w->cond_string = 0;
{
printf_filtered (_(" (%s,%s) pending."),
event_location_to_string (b->location.get ()),
- b->extra_string);
+ b->extra_string.get ());
}
else
{
printf_filtered (_(" (%s %s) pending."),
event_location_to_string (b->location.get ()),
- b->extra_string);
+ b->extra_string.get ());
}
}
else
}
}
-/* Destructor for the breakpoint base class. */
-
-breakpoint::~breakpoint ()
-{
- xfree (this->cond_string);
- xfree (this->extra_string);
-}
-
/* See breakpoint.h. */
bp_location_range breakpoint::locations ()
/* Print out extra_string if this breakpoint is pending. It might
contain, for example, conditions that were set by the user. */
if (tp->loc == NULL && tp->extra_string != NULL)
- fprintf_unfiltered (fp, " %s", tp->extra_string);
+ fprintf_unfiltered (fp, " %s", tp->extra_string.get ());
print_recreate_thread (tp, fp);
}
{
fprintf_unfiltered (fp, "dprintf %s,%s",
event_location_to_string (tp->location.get ()),
- tp->extra_string);
+ tp->extra_string.get ());
print_recreate_thread (tp, fp);
}
{
const char *s;
- s = b->cond_string;
+ s = b->cond_string.get ();
try
{
new_loc->cond = parse_exp_1 (&s, sal.pc,
resolve_sal_pc (&sal);
if (b->condition_not_parsed && b->extra_string != NULL)
{
- char *cond_string, *extra_string;
+ gdb::unique_xmalloc_ptr<char> cond_string, extra_string;
int thread, task;
- find_condition_and_thread_for_sals (sals, b->extra_string,
+ find_condition_and_thread_for_sals (sals, b->extra_string.get (),
&cond_string, &thread,
&task, &extra_string);
gdb_assert (b->cond_string == NULL);
if (cond_string)
- b->cond_string = cond_string;
+ b->cond_string = std::move (cond_string);
b->thread = thread;
b->task = task;
if (extra_string)
- {
- xfree (b->extra_string);
- b->extra_string = extra_string;
- }
+ b->extra_string = std::move (extra_string);
b->condition_not_parsed = 0;
}
instead. */
if (tp->cond_string)
- fp.printf (" condition $bpnum %s\n", tp->cond_string);
+ fp.printf (" condition $bpnum %s\n", tp->cond_string.get ());
if (tp->ignore_count)
fp.printf (" ignore $bpnum %d\n", tp->ignore_count);