From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 10/11] Use a std::vector for ada_exceptions_list
Date: Tue, 12 Sep 2017 18:57:00 -0000 [thread overview]
Message-ID: <20170912185736.20436-11-tom@tromey.com> (raw)
In-Reply-To: <20170912185736.20436-1-tom@tromey.com>
Change ada_exceptions_list to return a std::vector and fix up the
users. This allows removing a cleanup in MI.
ChangeLog
2017-09-12 Tom Tromey <tom@tromey.com>
* mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions): Update.
* ada-lang.h (struct ada_exc_info): Remove typedef. Declare
operator< and operator==.
(ada_exceptions_list): Return a std::vector.
* ada-lang.c (ada_exc_info::operator<): Rename from
compare_ada_exception_info.
(ada_exc_info::operator==): New.
(sort_remove_dups_ada_exceptions_list): Change type of
"exceptions".
(ada_add_standard_exceptions, ada_add_exceptions_from_frame)
(ada_add_global_exceptions): Likewise.
(ada_exceptions_list_1): Return a std::vector.
(ada_exceptions_list): Likewise.
---
gdb/ChangeLog | 16 ++++++++++
gdb/ada-lang.c | 88 ++++++++++++++++++++--------------------------------
gdb/ada-lang.h | 9 +++---
gdb/mi/mi-cmd-info.c | 17 +++-------
4 files changed, 60 insertions(+), 70 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 54928fc..ee965c4 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,21 @@
2017-09-12 Tom Tromey <tom@tromey.com>
+ * mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions): Update.
+ * ada-lang.h (struct ada_exc_info): Remove typedef. Declare
+ operator< and operator==.
+ (ada_exceptions_list): Return a std::vector.
+ * ada-lang.c (ada_exc_info::operator<): Rename from
+ compare_ada_exception_info.
+ (ada_exc_info::operator==): New.
+ (sort_remove_dups_ada_exceptions_list): Change type of
+ "exceptions".
+ (ada_add_standard_exceptions, ada_add_exceptions_from_frame)
+ (ada_add_global_exceptions): Likewise.
+ (ada_exceptions_list_1): Return a std::vector.
+ (ada_exceptions_list): Likewise.
+
+2017-09-12 Tom Tromey <tom@tromey.com>
+
* mi/mi-main.c (struct print_one_inferior_data) <inferiors>: Now a
'std::set *'.
(print_one_inferior): Update.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 64f1a33..cafba2d 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -62,6 +62,7 @@
#include "cli/cli-utils.h"
#include "common/function-view.h"
#include "common/byte-vector.h"
+#include <algorithm>
/* Define whether or not the C operator '/' truncates towards zero for
differently signed operands (truncation direction is undefined in C).
@@ -13121,23 +13122,23 @@ ada_is_non_standard_exception_sym (struct symbol *sym)
The comparison is determined first by exception name, and then
by exception address. */
-static int
-compare_ada_exception_info (const void *a, const void *b)
+bool
+ada_exc_info::operator< (const ada_exc_info &other)
{
- const struct ada_exc_info *exc_a = (struct ada_exc_info *) a;
- const struct ada_exc_info *exc_b = (struct ada_exc_info *) b;
int result;
- result = strcmp (exc_a->name, exc_b->name);
- if (result != 0)
- return result;
-
- if (exc_a->addr < exc_b->addr)
- return -1;
- if (exc_a->addr > exc_b->addr)
- return 1;
+ result = strcmp (name, other.name);
+ if (result < 0)
+ return true;
+ if (result == 0 && addr < other.addr)
+ return true;
+ return false;
+}
- return 0;
+bool
+ada_exc_info::operator== (const ada_exc_info &other)
+{
+ return strcmp (name, other.name) == 0 && addr == other.addr;
}
/* Sort EXCEPTIONS using compare_ada_exception_info as the comparison
@@ -13146,23 +13147,12 @@ compare_ada_exception_info (const void *a, const void *b)
All duplicates are also removed. */
static void
-sort_remove_dups_ada_exceptions_list (VEC(ada_exc_info) **exceptions,
+sort_remove_dups_ada_exceptions_list (std::vector<ada_exc_info> *exceptions,
int skip)
{
- struct ada_exc_info *to_sort
- = VEC_address (ada_exc_info, *exceptions) + skip;
- int to_sort_len
- = VEC_length (ada_exc_info, *exceptions) - skip;
- int i, j;
-
- qsort (to_sort, to_sort_len, sizeof (struct ada_exc_info),
- compare_ada_exception_info);
-
- for (i = 1, j = 1; i < to_sort_len; i++)
- if (compare_ada_exception_info (&to_sort[i], &to_sort[j - 1]) != 0)
- to_sort[j++] = to_sort[i];
- to_sort_len = j;
- VEC_truncate(ada_exc_info, *exceptions, skip + to_sort_len);
+ std::sort (exceptions->begin () + skip, exceptions->end ());
+ exceptions->erase (std::unique (exceptions->begin () + skip, exceptions->end ()),
+ exceptions->end ());
}
/* Add all exceptions defined by the Ada standard whose name match
@@ -13177,7 +13167,7 @@ sort_remove_dups_ada_exceptions_list (VEC(ada_exc_info) **exceptions,
static void
ada_add_standard_exceptions (compiled_regex *preg,
- VEC(ada_exc_info) **exceptions)
+ std::vector<ada_exc_info> *exceptions)
{
int i;
@@ -13194,7 +13184,7 @@ ada_add_standard_exceptions (compiled_regex *preg,
struct ada_exc_info info
= {standard_exc[i], BMSYMBOL_VALUE_ADDRESS (msymbol)};
- VEC_safe_push (ada_exc_info, *exceptions, &info);
+ exceptions->push_back (info);
}
}
}
@@ -13213,7 +13203,7 @@ ada_add_standard_exceptions (compiled_regex *preg,
static void
ada_add_exceptions_from_frame (compiled_regex *preg,
struct frame_info *frame,
- VEC(ada_exc_info) **exceptions)
+ std::vector<ada_exc_info> *exceptions)
{
const struct block *block = get_frame_block (frame, 0);
@@ -13236,7 +13226,7 @@ ada_add_exceptions_from_frame (compiled_regex *preg,
struct ada_exc_info info = {SYMBOL_PRINT_NAME (sym),
SYMBOL_VALUE_ADDRESS (sym)};
- VEC_safe_push (ada_exc_info, *exceptions, &info);
+ exceptions->push_back (info);
}
}
}
@@ -13276,7 +13266,7 @@ name_matches_regex (const char *name, compiled_regex *preg)
static void
ada_add_global_exceptions (compiled_regex *preg,
- VEC(ada_exc_info) **exceptions)
+ std::vector<ada_exc_info> *exceptions)
{
struct objfile *objfile;
struct compunit_symtab *s;
@@ -13311,7 +13301,7 @@ ada_add_global_exceptions (compiled_regex *preg,
struct ada_exc_info info
= {SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE_ADDRESS (sym)};
- VEC_safe_push (ada_exc_info, *exceptions, &info);
+ exceptions->push_back (info);
}
}
}
@@ -13323,12 +13313,10 @@ ada_add_global_exceptions (compiled_regex *preg,
If not NULL, PREG is used to filter out exceptions whose names
do not match. Otherwise, all exceptions are listed. */
-static VEC(ada_exc_info) *
+static std::vector<ada_exc_info>
ada_exceptions_list_1 (compiled_regex *preg)
{
- VEC(ada_exc_info) *result = NULL;
- struct cleanup *old_chain
- = make_cleanup (VEC_cleanup (ada_exc_info), &result);
+ std::vector<ada_exc_info> result;
int prev_len;
/* First, list the known standard exceptions. These exceptions
@@ -13342,21 +13330,20 @@ ada_exceptions_list_1 (compiled_regex *preg)
if (has_stack_frames ())
{
- prev_len = VEC_length (ada_exc_info, result);
+ prev_len = result.size ();
ada_add_exceptions_from_frame (preg, get_selected_frame (NULL),
&result);
- if (VEC_length (ada_exc_info, result) > prev_len)
+ if (result.size () > prev_len)
sort_remove_dups_ada_exceptions_list (&result, prev_len);
}
/* Add all exceptions whose scope is global. */
- prev_len = VEC_length (ada_exc_info, result);
+ prev_len = result.size ();
ada_add_global_exceptions (preg, &result);
- if (VEC_length (ada_exc_info, result) > prev_len)
+ if (result.size () > prev_len)
sort_remove_dups_ada_exceptions_list (&result, prev_len);
- discard_cleanups (old_chain);
return result;
}
@@ -13374,7 +13361,7 @@ ada_exceptions_list_1 (compiled_regex *preg)
alphabetical order;
- Exceptions whose scope is global, in alphabetical order. */
-VEC(ada_exc_info) *
+std::vector<ada_exc_info>
ada_exceptions_list (const char *regexp)
{
if (regexp == NULL)
@@ -13389,14 +13376,9 @@ ada_exceptions_list (const char *regexp)
static void
info_exceptions_command (char *regexp, int from_tty)
{
- VEC(ada_exc_info) *exceptions;
- struct cleanup *cleanup;
struct gdbarch *gdbarch = get_current_arch ();
- int ix;
- struct ada_exc_info *info;
- exceptions = ada_exceptions_list (regexp);
- cleanup = make_cleanup (VEC_cleanup (ada_exc_info), &exceptions);
+ std::vector<ada_exc_info> exceptions = ada_exceptions_list (regexp);
if (regexp != NULL)
printf_filtered
@@ -13404,10 +13386,8 @@ info_exceptions_command (char *regexp, int from_tty)
else
printf_filtered (_("All defined Ada exceptions:\n"));
- for (ix = 0; VEC_iterate(ada_exc_info, exceptions, ix, info); ix++)
- printf_filtered ("%s: %s\n", info->name, paddress (gdbarch, info->addr));
-
- do_cleanups (cleanup);
+ for (ada_exc_info &info : exceptions)
+ printf_filtered ("%s: %s\n", info.name, paddress (gdbarch, info.addr));
}
/* Operators */
diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index f5b3bca..f92b88d 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -379,18 +379,19 @@ extern void create_ada_exception_catchpoint
/* Some information about a given Ada exception. */
-typedef struct ada_exc_info
+struct ada_exc_info
{
/* The name of the exception. */
const char *name;
/* The address of the symbol corresponding to that exception. */
CORE_ADDR addr;
-} ada_exc_info;
-DEF_VEC_O(ada_exc_info);
+ bool operator< (const ada_exc_info &);
+ bool operator== (const ada_exc_info &);
+};
-extern VEC(ada_exc_info) *ada_exceptions_list (const char *regexp);
+extern std::vector<ada_exc_info> ada_exceptions_list (const char *regexp);
/* Tasking-related: ada-tasks.c */
diff --git a/gdb/mi/mi-cmd-info.c b/gdb/mi/mi-cmd-info.c
index fa0d16e..33c64f0 100644
--- a/gdb/mi/mi-cmd-info.c
+++ b/gdb/mi/mi-cmd-info.c
@@ -30,10 +30,6 @@ mi_cmd_info_ada_exceptions (const char *command, char **argv, int argc)
struct ui_out *uiout = current_uiout;
struct gdbarch *gdbarch = get_current_arch ();
char *regexp;
- struct cleanup *old_chain;
- VEC(ada_exc_info) *exceptions;
- int ix;
- struct ada_exc_info *info;
switch (argc)
{
@@ -48,24 +44,21 @@ mi_cmd_info_ada_exceptions (const char *command, char **argv, int argc)
break;
}
- exceptions = ada_exceptions_list (regexp);
- old_chain = make_cleanup (VEC_cleanup (ada_exc_info), &exceptions);
+ std::vector<ada_exc_info> exceptions = ada_exceptions_list (regexp);
ui_out_emit_table table_emitter (uiout, 2,
- VEC_length (ada_exc_info, exceptions),
+ exceptions.size (),
"ada-exceptions");
uiout->table_header (1, ui_left, "name", "Name");
uiout->table_header (1, ui_left, "address", "Address");
uiout->table_body ();
- for (ix = 0; VEC_iterate(ada_exc_info, exceptions, ix, info); ix++)
+ for (ada_exc_info &info : exceptions)
{
ui_out_emit_tuple tuple_emitter (uiout, NULL);
- uiout->field_string ("name", info->name);
- uiout->field_core_addr ("address", gdbarch, info->addr);
+ uiout->field_string ("name", info.name);
+ uiout->field_core_addr ("address", gdbarch, info.addr);
}
-
- do_cleanups (old_chain);
}
/* Implement the "-info-gdb-mi-command" GDB/MI command. */
--
2.9.4
next prev parent reply other threads:[~2017-09-12 18:57 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-12 18:57 more cleanup removal, particularly in MI Tom Tromey
2017-09-12 18:57 ` [RFA 11/11] Change captured_mi_execute_command to use scoped_restore Tom Tromey
2017-09-28 10:35 ` Pedro Alves
2017-09-12 18:57 ` [RFA 07/11] Use gdb::byte_vector in mi_cmd_data_write_memory_bytes Tom Tromey
2017-09-28 9:46 ` Pedro Alves
2017-09-12 18:57 ` [RFA 08/11] Use string and unique_xmalloc_ptr in mi-main.c Tom Tromey
2017-09-28 9:57 ` Pedro Alves
2017-09-29 1:42 ` Tom Tromey
2017-09-29 10:23 ` Pedro Alves
2017-09-12 18:57 ` [RFA 06/11] Change some gdb_* functions to use a std::string out parameter Tom Tromey
2017-09-28 9:42 ` Pedro Alves
2017-09-28 19:58 ` Tom Tromey
2017-09-12 18:57 ` [RFA 09/11] Use std::set in mi-main.c Tom Tromey
2017-09-28 10:10 ` Pedro Alves
2017-10-02 13:05 ` Simon Marchi
2017-10-03 11:21 ` Simon Marchi
2017-10-03 11:39 ` Tom Tromey
2017-09-12 18:57 ` Tom Tromey [this message]
2017-09-28 10:20 ` [RFA 10/11] Use a std::vector for ada_exceptions_list Pedro Alves
2017-09-12 18:57 ` [RFA 05/11] Remove unused declaration Tom Tromey
2017-09-28 9:40 ` Pedro Alves
2017-09-12 18:57 ` [RFA 04/11] Don't copy a string in mi_cmd_disassemble Tom Tromey
2017-09-28 9:40 ` Pedro Alves
2017-09-12 18:57 ` [RFA 02/11] Remove cleanups from mi_cmd_break_insert_1 Tom Tromey
2017-09-28 9:24 ` Pedro Alves
2017-09-28 19:57 ` Tom Tromey
2017-09-29 1:40 ` Tom Tromey
2017-09-29 10:21 ` Pedro Alves
2017-09-12 18:59 ` [RFA 01/11] Remove make_cleanup_defer_target_commit_resume Tom Tromey
2017-09-28 9:17 ` Pedro Alves
2017-09-12 19:03 ` [RFA 03/11] Remove cleanups from mi-cmd-var.c Tom Tromey
2017-09-28 9:36 ` Pedro Alves
2017-09-29 1:40 ` Tom Tromey
2017-09-29 10:22 ` Pedro Alves
2017-09-23 16:15 ` more cleanup removal, particularly in MI Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170912185736.20436-11-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox