aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-02-25 18:14:19 -0700
committerTom Tromey <tom@tromey.com>2022-01-18 10:14:42 -0700
commit7904e9613e0a2fc38e9abc06a916dea6a009c7b4 (patch)
tree55c245504a0bb4dfce0eea29fc1e796789d0b0e5
parent5947982f1dadfa72a6913f25cc4f56e137c7217e (diff)
downloadgdb-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.
-rw-r--r--gdb/cli/cli-decode.h1
-rw-r--r--gdb/compile/compile.c1
-rw-r--r--gdb/exec.c1
-rw-r--r--gdb/guile/scm-string.c1
-rw-r--r--gdb/inferior.c1
-rw-r--r--gdb/infrun.c1
-rw-r--r--gdb/interps.c1
-rw-r--r--gdb/psymtab.c1
-rw-r--r--gdb/skip.c1
-rw-r--r--gdb/source.c1
-rw-r--r--gdb/stack.c1
-rw-r--r--gdb/symfile.c1
-rw-r--r--gdb/symmisc.c1
-rw-r--r--gdb/tracefile.c1
-rw-r--r--gdb/tracepoint.c1
-rw-r--r--gdb/utils.c12
-rw-r--r--gdb/utils.h174
-rw-r--r--gdbsupport/buildargv.h204
18 files changed, 220 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"
diff --git a/gdb/exec.c b/gdb/exec.c
index f42862b..d9854d5 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -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 *,
diff --git a/gdb/skip.c b/gdb/skip.c
index 2525b8b..3308252 100644
--- a/gdb/skip.c
+++ b/gdb/skip.c
@@ -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. */
diff --git a/gdbsupport/buildargv.h b/gdbsupport/buildargv.h
new file mode 100644
index 0000000..7a34d9b
--- /dev/null
+++ b/gdbsupport/buildargv.h
@@ -0,0 +1,204 @@
+/* RAII wrapper for buildargv
+
+ Copyright (C) 2021 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef GDBSUPPORT_BUILDARGV_H
+#define GDBSUPPORT_BUILDARGV_H
+
+#include "libiberty.h"
+
+/* 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)
+ {
+ char **argv = buildargv (str);
+ freeargv (m_argv);
+ m_argv = argv;
+ }
+
+ /* 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;
+};
+
+#endif /* GDBSUPPORT_BUILDARGV_H */