From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA v2 17/17] Remove last cleanup from captured_main_1
Date: Thu, 13 Oct 2016 21:18:00 -0000 [thread overview]
Message-ID: <1476393012-29987-18-git-send-email-tom@tromey.com> (raw)
In-Reply-To: <1476393012-29987-1-git-send-email-tom@tromey.com>
An earlier patch split captured_main into two parts. This patch
removes the last remaining cleanup from captured_main_1, and also
replaces a second hand-rolled VEC-like array with a std::vector.
2016-10-11 Tom Tromey <tom@tromey.com>
* main.c: Include <vector>.
(cmdarg_s): Remove typedef. Don't define VEC.
(captured_main_1): Use vector, not VEC. Remove cleanups.
---
gdb/ChangeLog | 6 ++++
gdb/main.c | 93 +++++++++++++++++++++++++----------------------------------
2 files changed, 46 insertions(+), 53 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 849adbb..5e23f32 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2016-10-11 Tom Tromey <tom@tromey.com>
+
+ * main.c: Include <vector>.
+ (cmdarg_s): Remove typedef. Don't define VEC.
+ (captured_main_1): Use vector, not VEC. Remove cleanups.
+
2016-09-26 Tom Tromey <tom@tromey.com>
* dwarf2loc.c (struct dwarf_expr_context_funcs): Don't declare.
diff --git a/gdb/main.c b/gdb/main.c
index 420b4d3..280b7c5 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -45,6 +45,7 @@
#include "event-top.h"
#include "infrun.h"
#include "signals-state-save-restore.h"
+#include <vector>
/* The selected interpreter. This will be used as a set command
variable, so it should always be malloc'ed - since
@@ -429,17 +430,14 @@ enum cmdarg_kind
};
/* Arguments of --command option and its counterpart. */
-typedef struct cmdarg {
+struct cmdarg {
/* Type of this option. */
enum cmdarg_kind type;
/* Value of this option - filename or the GDB command itself. String memory
is not owned by this structure despite it is 'const'. */
char *string;
-} cmdarg_s;
-
-/* Define type VEC (cmdarg_s). */
-DEF_VEC_O (cmdarg_s);
+};
static void
captured_main_1 (struct captured_main_args *context)
@@ -467,15 +465,10 @@ captured_main_1 (struct captured_main_args *context)
static int print_configuration;
/* Pointers to all arguments of --command option. */
- VEC (cmdarg_s) *cmdarg_vec = NULL;
- struct cmdarg *cmdarg_p;
+ std::vector<struct cmdarg> cmdarg_vec;
- /* Indices of all arguments of --directory option. */
- char **dirarg;
- /* Allocated size. */
- int dirsize;
- /* Number of elements used. */
- int ndir;
+ /* All arguments of --directory option. */
+ std::vector<char *> dirarg;
/* gdb init files. */
const char *system_gdbinit;
@@ -510,11 +503,6 @@ captured_main_1 (struct captured_main_args *context)
notice_open_fds ();
save_original_signals_state ();
- chain = make_cleanup (VEC_cleanup (cmdarg_s), &cmdarg_vec);
- dirsize = 1;
- dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg));
- ndir = 0;
-
saved_command_line = (char *) xstrdup ("");
#ifdef __MINGW32__
@@ -746,28 +734,28 @@ captured_main_1 (struct captured_main_args *context)
{
struct cmdarg cmdarg = { CMDARG_FILE, optarg };
- VEC_safe_push (cmdarg_s, cmdarg_vec, &cmdarg);
+ cmdarg_vec.push_back (cmdarg);
}
break;
case 'X':
{
struct cmdarg cmdarg = { CMDARG_COMMAND, optarg };
- VEC_safe_push (cmdarg_s, cmdarg_vec, &cmdarg);
+ cmdarg_vec.push_back (cmdarg);
}
break;
case OPT_IX:
{
struct cmdarg cmdarg = { CMDARG_INIT_FILE, optarg };
- VEC_safe_push (cmdarg_s, cmdarg_vec, &cmdarg);
+ cmdarg_vec.push_back (cmdarg);
}
break;
case OPT_IEX:
{
struct cmdarg cmdarg = { CMDARG_INIT_COMMAND, optarg };
- VEC_safe_push (cmdarg_s, cmdarg_vec, &cmdarg);
+ cmdarg_vec.push_back (cmdarg);
}
break;
case 'B':
@@ -809,13 +797,7 @@ captured_main_1 (struct captured_main_args *context)
interpreter_p = xstrdup (optarg);
break;
case 'd':
- dirarg[ndir++] = optarg;
- if (ndir >= dirsize)
- {
- dirsize *= 2;
- dirarg = (char **) xrealloc ((char *) dirarg,
- dirsize * sizeof (*dirarg));
- }
+ dirarg.push_back (optarg);
break;
case 't':
ttyarg = optarg;
@@ -1006,17 +988,21 @@ captured_main_1 (struct captured_main_args *context)
catch_command_errors_const (source_script, home_gdbinit, 0);
/* Process '-ix' and '-iex' options early. */
- for (i = 0; VEC_iterate (cmdarg_s, cmdarg_vec, i, cmdarg_p); i++)
- switch (cmdarg_p->type)
+ for (i = 0; i < cmdarg_vec.size (); i++)
{
- case CMDARG_INIT_FILE:
- catch_command_errors_const (source_script, cmdarg_p->string,
- !batch_flag);
- break;
- case CMDARG_INIT_COMMAND:
- catch_command_errors (execute_command, cmdarg_p->string,
- !batch_flag);
- break;
+ const struct cmdarg &cmdarg_p = cmdarg_vec[i];
+
+ switch (cmdarg_p.type)
+ {
+ case CMDARG_INIT_FILE:
+ catch_command_errors_const (source_script, cmdarg_p.string,
+ !batch_flag);
+ break;
+ case CMDARG_INIT_COMMAND:
+ catch_command_errors (execute_command, cmdarg_p.string,
+ !batch_flag);
+ break;
+ }
}
/* Now perform all the actions indicated by the arguments. */
@@ -1025,9 +1011,8 @@ captured_main_1 (struct captured_main_args *context)
catch_command_errors (cd_command, cdarg, 0);
}
- for (i = 0; i < ndir; i++)
+ for (i = 0; i < dirarg.size (); i++)
catch_command_errors (directory_switch, dirarg[i], 0);
- xfree (dirarg);
/* Skip auto-loading section-specified scripts until we've sourced
local_gdbinit (which is often used to augment the source search
@@ -1116,17 +1101,21 @@ captured_main_1 (struct captured_main_args *context)
load_auto_scripts_for_objfile (objfile);
/* Process '-x' and '-ex' options. */
- for (i = 0; VEC_iterate (cmdarg_s, cmdarg_vec, i, cmdarg_p); i++)
- switch (cmdarg_p->type)
+ for (i = 0; i < cmdarg_vec.size (); i++)
{
- case CMDARG_FILE:
- catch_command_errors_const (source_script, cmdarg_p->string,
- !batch_flag);
- break;
- case CMDARG_COMMAND:
- catch_command_errors (execute_command, cmdarg_p->string,
- !batch_flag);
- break;
+ const struct cmdarg &cmdarg_p = cmdarg_vec[i];
+
+ switch (cmdarg_p.type)
+ {
+ case CMDARG_FILE:
+ catch_command_errors_const (source_script, cmdarg_p.string,
+ !batch_flag);
+ break;
+ case CMDARG_COMMAND:
+ catch_command_errors (execute_command, cmdarg_p.string,
+ !batch_flag);
+ break;
+ }
}
/* Read in the old history after all the command files have been
@@ -1138,8 +1127,6 @@ captured_main_1 (struct captured_main_args *context)
/* We have hit the end of the batch file. */
quit_force (NULL, 0);
}
-
- do_cleanups (chain);
}
static void
--
2.7.4
next prev parent reply other threads:[~2016-10-13 21:18 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-13 21:11 [RFA v2 00/17] more C++ Tom Tromey
2016-10-13 21:11 ` [RFA v2 15/17] Convert DWARF expr functions to methods Tom Tromey
2016-10-13 23:01 ` Pedro Alves
2016-10-20 21:47 ` Tom Tromey
2016-10-20 22:01 ` Pedro Alves
2016-10-13 21:11 ` [RFA v2 08/17] Remove some cleanups in MI Tom Tromey
2016-10-13 22:38 ` Pedro Alves
2016-10-13 21:11 ` [RFA v2 12/17] Remove make_cleanup_restore_current_uiout Tom Tromey
2016-10-13 22:49 ` Pedro Alves
2016-10-14 21:30 ` Tom Tromey
2016-10-20 21:46 ` Tom Tromey
2016-10-20 21:57 ` Pedro Alves
2016-10-13 21:11 ` [RFA v2 04/17] Introduce minimal_symbol_reader Tom Tromey
2016-10-13 22:20 ` Pedro Alves
2016-10-13 21:11 ` [RFA v2 05/17] Change minimal_symbol_reader to store objfile Tom Tromey
2016-10-13 22:21 ` Pedro Alves
2016-10-13 21:11 ` [RFA v2 03/17] Use scoped_restore for current_ui Tom Tromey
2016-10-13 22:16 ` Pedro Alves
2016-10-13 21:11 ` [RFA v2 02/17] Use scoped_restore for ui_file Tom Tromey
2016-10-13 22:07 ` Pedro Alves
2016-10-14 21:33 ` Tom Tromey
2016-10-13 21:11 ` [RFA v2 10/17] Replace two xmallocs with unique_ptr Tom Tromey
2016-10-13 22:44 ` Pedro Alves
2016-10-13 21:11 ` [RFA v2 16/17] Convert dwarf_expr_context_funcs to methods Tom Tromey
2016-10-13 23:05 ` Pedro Alves
2016-10-18 2:50 ` Tom Tromey
2016-10-18 10:51 ` Pedro Alves
2016-10-18 14:55 ` Tom Tromey
2016-10-18 17:38 ` Pedro Alves
2016-10-19 22:29 ` Tom Tromey
2016-10-20 21:48 ` Tom Tromey
2016-10-20 21:56 ` Pedro Alves
2016-10-28 13:36 ` Pedro Alves
2016-10-31 2:48 ` Tom Tromey
2016-11-01 22:07 ` Tom Tromey
2016-11-02 16:12 ` Pedro Alves
2016-10-13 21:11 ` [RFA v2 06/17] Record minimal symbols directly in reader Tom Tromey
2016-10-13 22:34 ` Pedro Alves
2016-10-14 21:22 ` Tom Tromey
2016-10-20 21:47 ` Tom Tromey
2016-10-20 22:13 ` Pedro Alves
2016-10-13 21:11 ` [RFA v2 11/17] Use gdb::unique_ptr in elf_read_minimal_symbols Tom Tromey
2016-10-13 22:44 ` Pedro Alves
2016-10-13 21:11 ` [RFA v2 07/17] Remove make_cleanup_restore_current_ui Tom Tromey
2016-10-13 22:37 ` Pedro Alves
2016-10-13 21:11 ` [RFA v2 01/17] Use RAII to save and restore scalars Tom Tromey
2016-10-13 22:03 ` Pedro Alves
2016-10-13 21:11 ` [RFA v2 14/17] Initial conversion of dwarf_expr_ctx Tom Tromey
2016-10-13 22:54 ` Pedro Alves
2016-10-13 21:13 ` [RFA v2 13/17] Some cleanup removal in dwarf2loc.c Tom Tromey
2016-10-13 22:52 ` Pedro Alves
2016-10-13 21:14 ` [RFA v2 09/17] Change command stats reporting to use class Tom Tromey
2016-10-13 22:43 ` Pedro Alves
2016-10-13 21:18 ` Tom Tromey [this message]
2016-10-13 23:13 ` [RFA v2 17/17] Remove last cleanup from captured_main_1 Pedro Alves
2016-10-13 21:39 ` [RFA v2 00/17] more C++ Pedro Alves
2016-10-14 16:26 ` Pedro Alves
2016-10-20 21:49 ` Tom Tromey
2016-10-20 22:27 ` Pedro Alves
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=1476393012-29987-18-git-send-email-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).