aboutsummaryrefslogtreecommitdiff
path: root/gdb/utils.h
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 /gdb/utils.h
parent5947982f1dadfa72a6913f25cc4f56e137c7217e (diff)
downloadfsf-binutils-gdb-7904e9613e0a2fc38e9abc06a916dea6a009c7b4.zip
fsf-binutils-gdb-7904e9613e0a2fc38e9abc06a916dea6a009c7b4.tar.gz
fsf-binutils-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/utils.h')
-rw-r--r--gdb/utils.h174
1 files changed, 0 insertions, 174 deletions
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. */