Use std::vector in syscall_catchpoint

This changes syscall_catchpoint to use a std::vector rather than a VEC
for "syscalls_to_be_caught".  This simplifies the code a bit.

ChangeLog
2017-07-22  Tom Tromey  <tom@tromey.com>

	* break-catch-syscall.c (syscall_catchpoint)
	<syscalls_to_be_caught>: Now a std::vector<int>
	(~syscall_catchpoint): Remove.
	(insert_catch_syscall, remove_catch_syscall)
	(breakpoint_hit_catch_syscall, print_one_catch_syscall)
	(print_mention_catch_syscall, print_recreate_catch_syscall):
	Update.
	(create_syscall_event_catchpoint): Change type of "filter"
	parameter.
	(catch_syscall_split_args): Return a std::vector.
	(catch_syscall_command_1, catching_syscall_number_1): Update.
This commit is contained in:
Tom Tromey 2017-07-17 16:58:22 -06:00
parent 4fa8aeac19
commit e12c9b7a0c
2 changed files with 50 additions and 79 deletions

View File

@ -1,3 +1,17 @@
2017-07-22 Tom Tromey <tom@tromey.com>
* break-catch-syscall.c (syscall_catchpoint)
<syscalls_to_be_caught>: Now a std::vector<int>
(~syscall_catchpoint): Remove.
(insert_catch_syscall, remove_catch_syscall)
(breakpoint_hit_catch_syscall, print_one_catch_syscall)
(print_mention_catch_syscall, print_recreate_catch_syscall):
Update.
(create_syscall_event_catchpoint): Change type of "filter"
parameter.
(catch_syscall_split_args): Return a std::vector.
(catch_syscall_command_1, catching_syscall_number_1): Update.
2017-07-22 Tom Tromey <tom@tromey.com> 2017-07-22 Tom Tromey <tom@tromey.com>
* break-catch-throw.c (struct exception_catchpoint) * break-catch-throw.c (struct exception_catchpoint)

View File

@ -36,22 +36,12 @@
struct syscall_catchpoint : public breakpoint struct syscall_catchpoint : public breakpoint
{ {
~syscall_catchpoint () override;
/* Syscall numbers used for the 'catch syscall' feature. If no /* Syscall numbers used for the 'catch syscall' feature. If no
syscall has been specified for filtering, its value is NULL. syscall has been specified for filtering, it is empty.
Otherwise, it holds a list of all syscalls to be caught. The Otherwise, it holds a list of all syscalls to be caught. */
list elements are allocated with xmalloc. */ std::vector<int> syscalls_to_be_caught;
VEC(int) *syscalls_to_be_caught;
}; };
/* catch_syscall destructor. */
syscall_catchpoint::~syscall_catchpoint ()
{
VEC_free (int, this->syscalls_to_be_caught);
}
static const struct inferior_data *catch_syscall_inferior_data = NULL; static const struct inferior_data *catch_syscall_inferior_data = NULL;
struct catch_syscall_inferior_data struct catch_syscall_inferior_data
@ -106,15 +96,11 @@ insert_catch_syscall (struct bp_location *bl)
= get_catch_syscall_inferior_data (inf); = get_catch_syscall_inferior_data (inf);
++inf_data->total_syscalls_count; ++inf_data->total_syscalls_count;
if (!c->syscalls_to_be_caught) if (c->syscalls_to_be_caught.empty ())
++inf_data->any_syscall_count; ++inf_data->any_syscall_count;
else else
{ {
int i, iter; for (int iter : c->syscalls_to_be_caught)
for (i = 0;
VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
i++)
{ {
int elem; int elem;
@ -157,15 +143,11 @@ remove_catch_syscall (struct bp_location *bl, enum remove_bp_reason reason)
= get_catch_syscall_inferior_data (inf); = get_catch_syscall_inferior_data (inf);
--inf_data->total_syscalls_count; --inf_data->total_syscalls_count;
if (!c->syscalls_to_be_caught) if (c->syscalls_to_be_caught.empty ())
--inf_data->any_syscall_count; --inf_data->any_syscall_count;
else else
{ {
int i, iter; for (int iter : c->syscalls_to_be_caught)
for (i = 0;
VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
i++)
{ {
int elem; int elem;
if (iter >= VEC_length (int, inf_data->syscalls_counts)) if (iter >= VEC_length (int, inf_data->syscalls_counts))
@ -207,13 +189,9 @@ breakpoint_hit_catch_syscall (const struct bp_location *bl,
syscall_number = ws->value.syscall_number; syscall_number = ws->value.syscall_number;
/* Now, checking if the syscall is the same. */ /* Now, checking if the syscall is the same. */
if (c->syscalls_to_be_caught) if (!c->syscalls_to_be_caught.empty ())
{ {
int i, iter; for (int iter : c->syscalls_to_be_caught)
for (i = 0;
VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
i++)
if (syscall_number == iter) if (syscall_number == iter)
return 1; return 1;
@ -296,20 +274,16 @@ print_one_catch_syscall (struct breakpoint *b,
uiout->field_skip ("addr"); uiout->field_skip ("addr");
annotate_field (5); annotate_field (5);
if (c->syscalls_to_be_caught if (c->syscalls_to_be_caught.size () > 1)
&& VEC_length (int, c->syscalls_to_be_caught) > 1)
uiout->text ("syscalls \""); uiout->text ("syscalls \"");
else else
uiout->text ("syscall \""); uiout->text ("syscall \"");
if (c->syscalls_to_be_caught) if (!c->syscalls_to_be_caught.empty ())
{ {
int i, iter;
char *text = xstrprintf ("%s", ""); char *text = xstrprintf ("%s", "");
for (i = 0; for (int iter : c->syscalls_to_be_caught)
VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
i++)
{ {
char *x = text; char *x = text;
struct syscall s; struct syscall s;
@ -346,23 +320,19 @@ print_mention_catch_syscall (struct breakpoint *b)
struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
struct gdbarch *gdbarch = b->loc->gdbarch; struct gdbarch *gdbarch = b->loc->gdbarch;
if (c->syscalls_to_be_caught) if (!c->syscalls_to_be_caught.empty ())
{ {
int i, iter; if (c->syscalls_to_be_caught.size () > 1)
if (VEC_length (int, c->syscalls_to_be_caught) > 1)
printf_filtered (_("Catchpoint %d (syscalls"), b->number); printf_filtered (_("Catchpoint %d (syscalls"), b->number);
else else
printf_filtered (_("Catchpoint %d (syscall"), b->number); printf_filtered (_("Catchpoint %d (syscall"), b->number);
for (i = 0; for (int iter : c->syscalls_to_be_caught)
VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
i++)
{ {
struct syscall s; struct syscall s;
get_syscall_by_number (gdbarch, iter, &s); get_syscall_by_number (gdbarch, iter, &s);
if (s.name) if (s.name != NULL)
printf_filtered (" '%s' [%d]", s.name, s.number); printf_filtered (" '%s' [%d]", s.name, s.number);
else else
printf_filtered (" %d", s.number); printf_filtered (" %d", s.number);
@ -385,23 +355,17 @@ print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp)
fprintf_unfiltered (fp, "catch syscall"); fprintf_unfiltered (fp, "catch syscall");
if (c->syscalls_to_be_caught) for (int iter : c->syscalls_to_be_caught)
{
int i, iter;
for (i = 0;
VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
i++)
{ {
struct syscall s; struct syscall s;
get_syscall_by_number (gdbarch, iter, &s); get_syscall_by_number (gdbarch, iter, &s);
if (s.name) if (s.name != NULL)
fprintf_unfiltered (fp, " %s", s.name); fprintf_unfiltered (fp, " %s", s.name);
else else
fprintf_unfiltered (fp, " %d", s.number); fprintf_unfiltered (fp, " %d", s.number);
} }
}
print_recreate_thread (b, fp); print_recreate_thread (b, fp);
} }
@ -418,7 +382,7 @@ syscall_catchpoint_p (struct breakpoint *b)
} }
static void static void
create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, create_syscall_event_catchpoint (int tempflag, std::vector<int> &&filter,
const struct breakpoint_ops *ops) const struct breakpoint_ops *ops)
{ {
struct syscall_catchpoint *c; struct syscall_catchpoint *c;
@ -431,13 +395,12 @@ create_syscall_event_catchpoint (int tempflag, VEC(int) *filter,
install_breakpoint (0, c, 1); install_breakpoint (0, c, 1);
} }
/* Splits the argument using space as delimiter. Returns an xmalloc'd /* Splits the argument using space as delimiter. */
filter list, or NULL if no filtering is required. */
static VEC(int) * static std::vector<int>
catch_syscall_split_args (char *arg) catch_syscall_split_args (char *arg)
{ {
VEC(int) *result = NULL; std::vector<int> result;
struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result);
struct gdbarch *gdbarch = target_gdbarch (); struct gdbarch *gdbarch = target_gdbarch ();
while (*arg != '\0') while (*arg != '\0')
@ -460,7 +423,7 @@ catch_syscall_split_args (char *arg)
if (*endptr == '\0') if (*endptr == '\0')
{ {
get_syscall_by_number (gdbarch, syscall_number, &s); get_syscall_by_number (gdbarch, syscall_number, &s);
VEC_safe_push (int, result, s.number); result.push_back (s.number);
} }
else if (startswith (cur_name, "g:") else if (startswith (cur_name, "g:")
|| startswith (cur_name, "group:")) || startswith (cur_name, "group:"))
@ -482,7 +445,7 @@ catch_syscall_split_args (char *arg)
{ {
/* Insert each syscall that are part of the group. No /* Insert each syscall that are part of the group. No
need to check if it is valid. */ need to check if it is valid. */
VEC_safe_push (int, result, syscall_list[i].number); result.push_back (syscall_list[i].number);
} }
xfree (syscall_list); xfree (syscall_list);
@ -500,11 +463,10 @@ catch_syscall_split_args (char *arg)
error (_("Unknown syscall name '%s'."), cur_name); error (_("Unknown syscall name '%s'."), cur_name);
/* Ok, it's valid. */ /* Ok, it's valid. */
VEC_safe_push (int, result, s.number); result.push_back (s.number);
} }
} }
discard_cleanups (cleanup);
return result; return result;
} }
@ -515,7 +477,7 @@ catch_syscall_command_1 (char *arg, int from_tty,
struct cmd_list_element *command) struct cmd_list_element *command)
{ {
int tempflag; int tempflag;
VEC(int) *filter; std::vector<int> filter;
struct syscall s; struct syscall s;
struct gdbarch *gdbarch = get_current_arch (); struct gdbarch *gdbarch = get_current_arch ();
@ -542,10 +504,8 @@ this architecture yet."));
if (arg != NULL) if (arg != NULL)
filter = catch_syscall_split_args (arg); filter = catch_syscall_split_args (arg);
else
filter = NULL;
create_syscall_event_catchpoint (tempflag, filter, create_syscall_event_catchpoint (tempflag, std::move (filter),
&catch_syscall_breakpoint_ops); &catch_syscall_breakpoint_ops);
} }
@ -586,12 +546,9 @@ catching_syscall_number_1 (struct breakpoint *b,
{ {
struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; struct syscall_catchpoint *c = (struct syscall_catchpoint *) b;
if (c->syscalls_to_be_caught) if (!c->syscalls_to_be_caught.empty ())
{ {
int i, iter; for (int iter : c->syscalls_to_be_caught)
for (i = 0;
VEC_iterate (int, c->syscalls_to_be_caught, i, iter);
i++)
if (syscall_number == iter) if (syscall_number == iter)
return 1; return 1;
} }