diff options
author | Tom Tromey <tom@tromey.com> | 2020-02-25 18:14:19 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-01-18 10:14:42 -0700 |
commit | 7904e9613e0a2fc38e9abc06a916dea6a009c7b4 (patch) | |
tree | 55c245504a0bb4dfce0eea29fc1e796789d0b0e5 /gdb | |
parent | 5947982f1dadfa72a6913f25cc4f56e137c7217e (diff) | |
download | gdb-7904e9613e0a2fc38e9abc06a916dea6a009c7b4.zip gdb-7904e9613e0a2fc38e9abc06a916dea6a009c7b4.tar.gz gdb-7904e9613e0a2fc38e9abc06a916dea6a009c7b4.tar.bz2 |
Move gdb_argv to gdbsupport
This moves the gdb_argv class to a new header in gdbsupport.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/cli/cli-decode.h | 1 | ||||
-rw-r--r-- | gdb/compile/compile.c | 1 | ||||
-rw-r--r-- | gdb/exec.c | 1 | ||||
-rw-r--r-- | gdb/guile/scm-string.c | 1 | ||||
-rw-r--r-- | gdb/inferior.c | 1 | ||||
-rw-r--r-- | gdb/infrun.c | 1 | ||||
-rw-r--r-- | gdb/interps.c | 1 | ||||
-rw-r--r-- | gdb/psymtab.c | 1 | ||||
-rw-r--r-- | gdb/skip.c | 1 | ||||
-rw-r--r-- | gdb/source.c | 1 | ||||
-rw-r--r-- | gdb/stack.c | 1 | ||||
-rw-r--r-- | gdb/symfile.c | 1 | ||||
-rw-r--r-- | gdb/symmisc.c | 1 | ||||
-rw-r--r-- | gdb/tracefile.c | 1 | ||||
-rw-r--r-- | gdb/tracepoint.c | 1 | ||||
-rw-r--r-- | gdb/utils.c | 12 | ||||
-rw-r--r-- | gdb/utils.h | 174 |
17 files changed, 16 insertions, 185 deletions
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h index 8f367bf..ed75d3d 100644 --- a/gdb/cli/cli-decode.h +++ b/gdb/cli/cli-decode.h @@ -27,6 +27,7 @@ #include "cli-script.h" #include "completer.h" #include "gdbsupport/intrusive_list.h" +#include "gdbsupport/buildargv.h" /* Not a set/show command. Note that some commands which begin with "set" or "show" might be in this category, if their syntax does diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 3b76e10..6794c93 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -44,6 +44,7 @@ #include "gdbsupport/gdb_unlinker.h" #include "gdbsupport/pathstuff.h" #include "gdbsupport/scoped_ignore_signal.h" +#include "gdbsupport/buildargv.h" @@ -49,6 +49,7 @@ #include <algorithm> #include "gdbsupport/pathstuff.h" #include "cli/cli-style.h" +#include "gdbsupport/buildargv.h" void (*deprecated_file_changed_hook) (const char *); diff --git a/gdb/guile/scm-string.c b/gdb/guile/scm-string.c index 184eaad..bf55892 100644 --- a/gdb/guile/scm-string.c +++ b/gdb/guile/scm-string.c @@ -23,6 +23,7 @@ #include "defs.h" #include "charset.h" #include "guile-internal.h" +#include "gdbsupport/buildargv.h" /* Convert STRING to an int. STRING must be a valid integer. */ diff --git a/gdb/inferior.c b/gdb/inferior.c index c7a6ae8..bebddb4 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -35,6 +35,7 @@ #include "target-descriptions.h" #include "readline/tilde.h" #include "progspace-and-thread.h" +#include "gdbsupport/buildargv.h" /* Keep a registry of per-inferior data-pointers required by other GDB modules. */ diff --git a/gdb/infrun.c b/gdb/infrun.c index 2335fc7..2e7ed15 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -72,6 +72,7 @@ #include "scoped-mock-context.h" #include "test-target.h" #include "gdbsupport/common-debug.h" +#include "gdbsupport/buildargv.h" /* Prototypes for local functions */ diff --git a/gdb/interps.c b/gdb/interps.c index d65698f..a475d87 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -38,6 +38,7 @@ #include "completer.h" #include "top.h" /* For command_loop. */ #include "main.h" +#include "gdbsupport/buildargv.h" /* Each UI has its own independent set of interpreters. */ diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 7e2da48..9db8a7a 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -36,6 +36,7 @@ #include "gdbcmd.h" #include <algorithm> #include <set> +#include "gdbsupport/buildargv.h" static struct partial_symbol *lookup_partial_symbol (struct objfile *, struct partial_symtab *, @@ -37,6 +37,7 @@ #include "gdbsupport/gdb_optional.h" #include <list> #include "cli/cli-style.h" +#include "gdbsupport/buildargv.h" /* True if we want to print debug printouts related to file/function skipping. */ diff --git a/gdb/source.c b/gdb/source.c index 6bf4a4e..ab5cfc5 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -50,6 +50,7 @@ #include "observable.h" #include "build-id.h" #include "debuginfod-support.h" +#include "gdbsupport/buildargv.h" #define OPEN_MODE (O_RDONLY | O_BINARY) #define FDOPEN_MODE FOPEN_RB diff --git a/gdb/stack.c b/gdb/stack.c index 8239c76..b81be29 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -55,6 +55,7 @@ #include "gdbsupport/def-vector.h" #include "cli/cli-option.h" #include "cli/cli-style.h" +#include "gdbsupport/buildargv.h" /* The possible choices of "set print frame-arguments", and the value of this setting. */ diff --git a/gdb/symfile.c b/gdb/symfile.c index 0449b91..37ce01b 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -61,6 +61,7 @@ #include "gdbsupport/selftest.h" #include "cli/cli-style.h" #include "gdbsupport/forward-scope-exit.h" +#include "gdbsupport/buildargv.h" #include <sys/types.h> #include <fcntl.h> diff --git a/gdb/symmisc.c b/gdb/symmisc.c index ca803fc..4cbe338 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -38,6 +38,7 @@ #include "source.h" #include "readline/tilde.h" #include <cli/cli-style.h> +#include "gdbsupport/buildargv.h" /* Prototypes for local functions */ diff --git a/gdb/tracefile.c b/gdb/tracefile.c index 50510af..f7d9331 100644 --- a/gdb/tracefile.c +++ b/gdb/tracefile.c @@ -24,6 +24,7 @@ #include "regcache.h" #include "gdbsupport/byte-vector.h" #include "gdbarch.h" +#include "gdbsupport/buildargv.h" /* Helper macros. */ diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index dc5e7f1..33f5c7f 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -58,6 +58,7 @@ #include <algorithm> #include "cli/cli-style.h" #include "expop.h" +#include "gdbsupport/buildargv.h" #include <unistd.h> diff --git a/gdb/utils.c b/gdb/utils.c index 3ee2b54..da60c1e 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -76,6 +76,7 @@ #include "cli-out.h" #include "gdbsupport/gdb-safe-ctype.h" #include "bt-utils.h" +#include "gdbsupport/buildargv.h" void (*deprecated_error_begin_hook) (void); @@ -2890,17 +2891,6 @@ ldirname (const char *filename) return dirname; } -/* See utils.h. */ - -void -gdb_argv::reset (const char *s) -{ - char **argv = buildargv (s); - - freeargv (m_argv); - m_argv = argv; -} - /* Return ARGS parsed as a valid pid, or throw an error. */ int diff --git a/gdb/utils.h b/gdb/utils.h index ac30fd5..5ac34eb 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -120,180 +120,6 @@ extern int parse_pid_to_attach (const char *args); extern int parse_escape (struct gdbarch *, const char **); -/* A wrapper for an array of char* that was allocated in the way that - 'buildargv' does, and should be freed with 'freeargv'. */ - -class gdb_argv -{ -public: - - /* A constructor that initializes to NULL. */ - - gdb_argv () - : m_argv (NULL) - { - } - - /* A constructor that calls buildargv on STR. STR may be NULL, in - which case this object is initialized with a NULL array. */ - - explicit gdb_argv (const char *str) - : m_argv (NULL) - { - reset (str); - } - - /* A constructor that takes ownership of an existing array. */ - - explicit gdb_argv (char **array) - : m_argv (array) - { - } - - gdb_argv (const gdb_argv &) = delete; - gdb_argv &operator= (const gdb_argv &) = delete; - - gdb_argv &operator= (gdb_argv &&other) - { - freeargv (m_argv); - m_argv = other.m_argv; - other.m_argv = nullptr; - return *this; - } - - gdb_argv (gdb_argv &&other) - { - m_argv = other.m_argv; - other.m_argv = nullptr; - } - - ~gdb_argv () - { - freeargv (m_argv); - } - - /* Call buildargv on STR, storing the result in this object. Any - previous state is freed. STR may be NULL, in which case this - object is reset with a NULL array. If buildargv fails due to - out-of-memory, call malloc_failure. Therefore, the value is - guaranteed to be non-NULL, unless the parameter itself is - NULL. */ - - void reset (const char *str); - - /* Return the underlying array. */ - - char **get () - { - return m_argv; - } - - const char * const * get () const - { - return m_argv; - } - - /* Return the underlying array, transferring ownership to the - caller. */ - - ATTRIBUTE_UNUSED_RESULT char **release () - { - char **result = m_argv; - m_argv = NULL; - return result; - } - - /* Return the number of items in the array. */ - - int count () const - { - return countargv (m_argv); - } - - /* Index into the array. */ - - char *operator[] (int arg) - { - gdb_assert (m_argv != NULL); - return m_argv[arg]; - } - - /* Return the arguments array as an array view. */ - - gdb::array_view<char *> as_array_view () - { - return gdb::array_view<char *> (this->get (), this->count ()); - } - - gdb::array_view<const char * const> as_array_view () const - { - return gdb::array_view<const char * const> (this->get (), this->count ()); - } - - /* Append arguments to this array. */ - void append (gdb_argv &&other) - { - int size = count (); - int argc = other.count (); - m_argv = XRESIZEVEC (char *, m_argv, (size + argc + 1)); - - for (int argi = 0; argi < argc; argi++) - { - /* Transfer ownership of the string. */ - m_argv[size++] = other.m_argv[argi]; - /* Ensure that destruction of OTHER works correctly. */ - other.m_argv[argi] = nullptr; - } - m_argv[size] = nullptr; - } - - /* Append arguments to this array. */ - void append (const gdb_argv &other) - { - int size = count (); - int argc = other.count (); - m_argv = XRESIZEVEC (char *, m_argv, (size + argc + 1)); - - for (int argi = 0; argi < argc; argi++) - m_argv[size++] = xstrdup (other.m_argv[argi]); - m_argv[size] = nullptr; - } - - /* The iterator type. */ - - typedef char **iterator; - - /* Return an iterator pointing to the start of the array. */ - - iterator begin () - { - return m_argv; - } - - /* Return an iterator pointing to the end of the array. */ - - iterator end () - { - return m_argv + count (); - } - - bool operator!= (std::nullptr_t) - { - return m_argv != NULL; - } - - bool operator== (std::nullptr_t) - { - return m_argv == NULL; - } - -private: - - /* The wrapped array. */ - - char **m_argv; -}; - /* Cleanup utilities. */ |