Move gdb obstack code to gdbsupport
authorTom Tromey <tom@tromey.com>
Tue, 21 Dec 2021 23:38:32 +0000 (16:38 -0700)
committerTom Tromey <tom@tromey.com>
Tue, 18 Jan 2022 17:14:42 +0000 (10:14 -0700)
This moves the gdb-specific obstack code -- both extensions like
obconcat and obstack_strdup, and things like auto_obstack -- to
gdbsupport.

65 files changed:
gdb/Makefile.in
gdb/ada-lang.c
gdb/addrmap.c
gdb/bcache.c
gdb/block.c
gdb/break-catch-throw.c
gdb/bsd-uthread.c
gdb/buildsym.c
gdb/buildsym.h
gdb/c-lang.c
gdb/c-typeprint.c
gdb/charset.c
gdb/coffread.c
gdb/cp-namespace.c
gdb/cp-support.h
gdb/cp-valprint.c
gdb/d-namespace.c
gdb/dbxread.c
gdb/dictionary.c
gdb/dwarf2/read.h
gdb/eval.c
gdb/f-typeprint.c
gdb/frame-base.c
gdb/frame-unwind.c
gdb/frame.c
gdb/gdb_obstack.c [deleted file]
gdb/gdb_obstack.h [deleted file]
gdb/gdbarch.h
gdb/gdbtypes.h
gdb/gnu-nat.c
gdb/go-lang.c
gdb/i386-windows-tdep.c
gdb/linux-tdep.c
gdb/m2-typeprint.c
gdb/macroexp.c
gdb/macrotab.c
gdb/mdebugread.c
gdb/mi/mi-cmd-break.c
gdb/namespace.h
gdb/objfiles.c
gdb/objfiles.h
gdb/p-typeprint.c
gdb/p-valprint.c
gdb/psymtab.h
gdb/python/py-unwind.c
gdb/reggroups.c
gdb/rust-parse.c
gdb/stabsread.c
gdb/symfile.c
gdb/symmisc.c
gdb/symtab.c
gdb/symtab.h
gdb/target-descriptions.c
gdb/typeprint.c
gdb/typeprint.h
gdb/ui-file.c
gdb/utils.c
gdb/valprint.c
gdb/windows-nat.c
gdb/windows-tdep.c
gdb/xml-support.h
gdbsupport/Makefile.am
gdbsupport/Makefile.in
gdbsupport/gdb_obstack.cc [new file with mode: 0644]
gdbsupport/gdb_obstack.h [new file with mode: 0644]

index d0db5fbdee19eab70d8621587e9a27562cca0d35..ce9f1ad441c080104064ac9eeed159678640c9b3 100644 (file)
@@ -1074,7 +1074,6 @@ COMMON_SFILES = \
        gcore.c \
        gdb-demangle.c \
        gdb_bfd.c \
-       gdb_obstack.c \
        gdb_regex.c \
        gdbtypes.c \
        gmp-utils.c \
@@ -1316,7 +1315,6 @@ HFILES_NO_SRCDIR = \
        gdb_bfd.h \
        gdb_curses.h \
        gdb_expat.h \
-       gdb_obstack.h \
        gdb_proc_service.h \
        gdb_regex.h \
        gdb_select.h \
index f2f8617cc1ef2839cc49c2b5f733353889a3348d..b88b27b55b1260123f3cd97458af7daac7247223 100644 (file)
@@ -35,7 +35,7 @@
 #include "breakpoint.h"
 #include "gdbcore.h"
 #include "hashtab.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "ada-lang.h"
 #include "completer.h"
 #include "ui-out.h"
index a35eeed100e7ae2b20800c485d041db2b28658c2..bf30faab66b3cfd60a7b18f574eb88bfb0ec6e3e 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "defs.h"
 #include "splay-tree.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "addrmap.h"
 #include "gdbsupport/selftest.h"
 
index c8a5b011598d4041f7a15632f6c449a3f12f0420..6d0741b59d0f1a8c7ba3600deb0941823cda951d 100644 (file)
@@ -20,7 +20,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "bcache.h"
 
 #include <algorithm>
index b590697a491bb9e81950ece6206e401a079570b5..2b6196c09aa41479ba0597169611257297d72c5d 100644 (file)
@@ -21,7 +21,7 @@
 #include "block.h"
 #include "symtab.h"
 #include "symfile.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "cp-support.h"
 #include "addrmap.h"
 #include "gdbtypes.h"
index 15c290b0ad1bbad0ba1236b194ae6ca20e3d67d9..5d17854d9afa23fedbc933a13740a2d61992f819 100644 (file)
@@ -27,7 +27,7 @@
 #include "valprint.h"
 #include "cli/cli-utils.h"
 #include "completer.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "mi/mi-common.h"
 #include "linespec.h"
 #include "probe.h"
index 5d5978d66ac0008124159bd2ad6680dcadab9f60..d0d9e89e93c18601451d55b46b8c09ca758a0390 100644 (file)
@@ -29,7 +29,7 @@
 #include "symfile.h"
 #include "target.h"
 
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 
 #include "bsd-uthread.h"
 
index 8827ddf1a110b475a28b38e7742ddbe30a0f45e0..1754f5ffe6ede39105ed5d74b3f582fd8705ab44 100644 (file)
@@ -19,7 +19,7 @@
 #include "defs.h"
 #include "buildsym-legacy.h"
 #include "bfd.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "symtab.h"
 #include "symfile.h"
 #include "objfiles.h"
index 4ca8e0528f44bca81b6b041d2c1804f381b61c0a..003d8a597193842a0a18b13d71031e3fd2199fe0 100644 (file)
@@ -19,7 +19,7 @@
 #if !defined (BUILDSYM_H)
 #define BUILDSYM_H 1
 
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 
 struct objfile;
 struct symbol;
index 4c9f8a741dfb4f523398fa4c9fbe141c68c28caa..ed7554fadea831f6cc87fbbc5459ebae3a0ac7e1 100644 (file)
@@ -32,7 +32,7 @@
 #include "demangle.h"
 #include "cp-abi.h"
 #include "cp-support.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include <ctype.h>
 #include "gdbcore.h"
 #include "gdbarch.h"
index 71d8797e84cc3ce90cd922b5654cc0803444a513..81fc82ec2637a60c957378f4b12996b5483cb9e6 100644 (file)
@@ -17,7 +17,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "bfd.h"               /* Binary File Description.  */
 #include "symtab.h"
 #include "gdbtypes.h"
index 0b3ef26f1d674cd31083f31a80e6efcadd41474c..9b1de08a93a4acbb12cdc4dbe7a4559210da5414 100644 (file)
@@ -20,7 +20,7 @@
 #include "defs.h"
 #include "charset.h"
 #include "gdbcmd.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gdbsupport/gdb_wait.h"
 #include "charset-list.h"
 #include "gdbsupport/environ.h"
index e264918fb3a6c3b6a3f5c7672ce605183730e084..921cfce1053a494c85376d7a5f67d0411abb9ddb 100644 (file)
@@ -24,7 +24,7 @@
 #include "breakpoint.h"
 
 #include "bfd.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include <ctype.h>
 
 #include "coff/internal.h"     /* Internal format of COFF symbols in BFD */
index e61767196779d294fb7ecb316ed1943511b8d6ec..6130381fdd6680a0760b61d8b41fb806957b61a2 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "defs.h"
 #include "cp-support.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "symtab.h"
 #include "symfile.h"
 #include "block.h"
index 832155bff427ee293b239312e6ee2d867206eecc..cd473a2c553a6e239843ecf0c1e9865266981768 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "symtab.h"
 #include "gdbsupport/gdb_vecs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gdbsupport/array-view.h"
 #include <vector>
 
index 98ac636a21cf78ac32110d9b6e6a0e7e9bf7e49d..1d98eb58214d30313eefe44ac12028ae6756cdbc 100644 (file)
@@ -18,7 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "expression.h"
index 39097e8055c75387e93aa8625b803c044d8a8d54..eab99cec672058b39a13bd7c233008bcdd170ee8 100644 (file)
@@ -23,7 +23,7 @@
 #include "language.h"
 #include "namespace.h"
 #include "d-lang.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gdbarch.h"
 
 /* This returns the length of first component of NAME, which should be
index 849ae0133f7ecae452f0d78c83a12a53dbdbe30e..911d518b7e9413bd33914158d7b4296785bbf01b 100644 (file)
@@ -32,7 +32,7 @@
 
 #include "defs.h"
 
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include <sys/stat.h>
 #include "symtab.h"
 #include "breakpoint.h"
index 7a686281475c4182800f2447e74e419612fa34c5..849d07469cfe1eb7acae39827e85eeb49750add7 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "defs.h"
 #include <ctype.h>
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "symtab.h"
 #include "buildsym.h"
 #include "dictionary.h"
index 0071c385bfa4242565ff7e473ff67a637bd9f957..effeaabc4af7fc6c61c445e233b43a3599af0658 100644 (file)
@@ -27,7 +27,7 @@
 #include "dwarf2/index-cache.h"
 #include "dwarf2/section.h"
 #include "filename-seen-cache.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gdbsupport/hash_enum.h"
 #include "gdbsupport/function-view.h"
 #include "psympriv.h"
index acac28e5c2d68fc72d317e3235cbfad65b8193ba..713f977bc77d550ff4677349cd1878673d6d016b 100644 (file)
@@ -36,7 +36,7 @@
 #include "regcache.h"
 #include "user-regs.h"
 #include "valprint.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "objfiles.h"
 #include "typeprint.h"
 #include <ctype.h>
index a633e47b2d3a6783a5f4a1eb95b273c1b030fc9f..0a338c11cbcdb1a8caf0d0a1bbdce396f6dc2e35 100644 (file)
@@ -21,7 +21,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "bfd.h"
 #include "symtab.h"
 #include "gdbtypes.h"
index 7f018122d374469023e1c47435ba51f9353f2cfb..91af24b4f74eb0cf58aaf3303a3ba583e2440e35 100644 (file)
@@ -20,7 +20,7 @@
 #include "defs.h"
 #include "frame-base.h"
 #include "frame.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gdbarch.h"
 
 /* A default frame base implementations.  If it wasn't for the old
index fdfe44cb10a75d4fa607c58c94ad07a81a2aa6ed..302ce1efb99892339879e9b34f3d793ffc5ee83a 100644 (file)
@@ -24,7 +24,7 @@
 #include "inline-frame.h"
 #include "value.h"
 #include "regcache.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "target.h"
 #include "gdbarch.h"
 #include "dwarf2/frame-tailcall.h"
index cee6b08a49ac61f45cff4bf30a27701527e1bf3a..6e2f6b245a255f71605a7a2caacb072c99bae406 100644 (file)
@@ -24,7 +24,7 @@
 #include "inferior.h"  /* for inferior_ptid */
 #include "regcache.h"
 #include "user-regs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "dummy-frame.h"
 #include "sentinel-frame.h"
 #include "gdbcore.h"
diff --git a/gdb/gdb_obstack.c b/gdb/gdb_obstack.c
deleted file mode 100644 (file)
index 3f8d82a..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/* Obstack wrapper for GDB.
-
-   Copyright (C) 2013-2022 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/>.  */
-
-#include "defs.h"
-#include "gdb_obstack.h"
-
-/* Concatenate NULL terminated variable argument list of `const char *'
-   strings; return the new string.  Space is found in the OBSTACKP.
-   Argument list must be terminated by a sentinel expression `(char *)
-   NULL'.  */
-
-char *
-obconcat (struct obstack *obstackp, ...)
-{
-  va_list ap;
-
-  va_start (ap, obstackp);
-  for (;;)
-    {
-      const char *s = va_arg (ap, const char *);
-
-      if (s == NULL)
-       break;
-
-      obstack_grow_str (obstackp, s);
-    }
-  va_end (ap);
-  obstack_1grow (obstackp, 0);
-
-  return (char *) obstack_finish (obstackp);
-}
diff --git a/gdb/gdb_obstack.h b/gdb/gdb_obstack.h
deleted file mode 100644 (file)
index 5e870cb..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-/* Obstack wrapper for GDB.
-
-   Copyright (C) 2002-2022 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/>.  */
-
-#if !defined (GDB_OBSTACK_H)
-#define GDB_OBSTACK_H 1
-
-#include "obstack.h"
-
-/* Utility macros - wrap obstack alloc into something more robust.  */
-
-template <typename T>
-static inline T*
-obstack_zalloc (struct obstack *ob)
-{
-  static_assert (IsMallocable<T>::value, "Trying to use OBSTACK_ZALLOC with a \
-non-POD data type.  Use obstack_new instead.");
-  return ((T *) memset (obstack_alloc (ob, sizeof (T)), 0, sizeof (T)));
-}
-
-#define OBSTACK_ZALLOC(OBSTACK,TYPE) obstack_zalloc<TYPE> ((OBSTACK))
-
-template <typename T>
-static inline T *
-obstack_calloc (struct obstack *ob, size_t number)
-{
-  static_assert (IsMallocable<T>::value, "Trying to use OBSTACK_CALLOC with a \
-non-POD data type.  Use obstack_new instead.");
-  return ((T *) memset (obstack_alloc (ob, number * sizeof (T)), 0,
-                       number * sizeof (T)));
-}
-
-#define OBSTACK_CALLOC(OBSTACK,NUMBER,TYPE) \
-  obstack_calloc<TYPE> ((OBSTACK), (NUMBER))
-
-/* Allocate an object on OB and call its constructor.  */
-
-template <typename T, typename... Args>
-static inline T*
-obstack_new (struct obstack *ob, Args&&... args)
-{
-  T* object = (T *) obstack_alloc (ob, sizeof (T));
-  object = new (object) T (std::forward<Args> (args)...);
-  return object;
-}
-
-/* Unless explicitly specified, GDB obstacks always use xmalloc() and
-   xfree().  */
-/* Note: ezannoni 2004-02-09: One could also specify the allocation
-   functions using a special init function for each obstack,
-   obstack_specify_allocation.  However we just use obstack_init and
-   let these defines here do the job.  While one could argue the
-   superiority of one approach over the other, we just chose one
-   throughout.  */
-
-#define obstack_chunk_alloc xmalloc
-#define obstack_chunk_free xfree
-
-#define obstack_grow_str(OBSTACK,STRING) \
-  obstack_grow (OBSTACK, STRING, strlen (STRING))
-#define obstack_grow_str0(OBSTACK,STRING) \
-  obstack_grow0 (OBSTACK, STRING, strlen (STRING))
-
-#define obstack_grow_wstr(OBSTACK, WSTRING) \
-  obstack_grow (OBSTACK, WSTRING, sizeof (gdb_wchar_t) * gdb_wcslen (WSTRING))
-
-/* Concatenate NULL terminated variable argument list of `const char
-   *' strings; return the new string.  Space is found in the OBSTACKP.
-   Argument list must be terminated by a sentinel expression `(char *)
-   NULL'.  */
-
-extern char *obconcat (struct obstack *obstackp, ...) ATTRIBUTE_SENTINEL;
-
-/* Duplicate STRING, returning an equivalent string that's allocated on the
-   obstack OBSTACKP.  */
-
-static inline char *
-obstack_strdup (struct obstack *obstackp, const char *string)
-{
-  return (char *) obstack_copy0 (obstackp, string, strlen (string));
-}
-
-/* Duplicate STRING, returning an equivalent string that's allocated on the
-   obstack OBSTACKP.  */
-
-static inline char *
-obstack_strdup (struct obstack *obstackp, const std::string &string)
-{
-  return (char *) obstack_copy0 (obstackp, string.c_str (),
-                                string.size ());
-}
-
-/* Duplicate the first N characters of STRING, returning a
-   \0-terminated string that's allocated on the obstack OBSTACKP.
-   Note that exactly N characters are copied, even if STRING is
-   shorter.  */
-
-static inline char *
-obstack_strndup (struct obstack *obstackp, const char *string, size_t n)
-{
-  return (char *) obstack_copy0 (obstackp, string, n);
-}
-
-/* An obstack that frees itself on scope exit.  */
-struct auto_obstack : obstack
-{
-  auto_obstack ()
-  { obstack_init (this); }
-
-  ~auto_obstack ()
-  { obstack_free (this, NULL); }
-
-  DISABLE_COPY_AND_ASSIGN (auto_obstack);
-
-  /* Free all memory in the obstack but leave it valid for further
-     allocation.  */
-  void clear ()
-  { obstack_free (this, obstack_base (this)); }
-};
-
-/* Objects are allocated on obstack instead of heap.  */
-
-struct allocate_on_obstack
-{
-  allocate_on_obstack () = default;
-
-  void* operator new (size_t size, struct obstack *obstack)
-  {
-    return obstack_alloc (obstack, size);
-  }
-
-  void* operator new[] (size_t size, struct obstack *obstack)
-  {
-    return obstack_alloc (obstack, size);
-  }
-
-  void operator delete (void *memory) {}
-  void operator delete[] (void *memory) {}
-};
-
-#endif
index fc1582449ed4fffdd10dbdb65ec01cf67ecd1012..6404dc1cb438b09e2179ff90c29d6b582f3ee63c 100644 (file)
@@ -24,7 +24,7 @@
 #include <vector>
 #include "frame.h"
 #include "dis-asm.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "infrun.h"
 #include "osabi.h"
 #include "displaced-stepping.h"
index 42878dba933d9101fe8713749d5a082b3795f4d7..467f60975e1a93990c39091eb5e860b078df0652 100644 (file)
@@ -52,7 +52,7 @@
 #include "gdbsupport/underlying.h"
 #include "gdbsupport/print-utils.h"
 #include "dwarf2.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gmp-utils.h"
 
 /* Forward declarations for prototypes.  */
index 1586a738dee240c7ad365e7c8c7862b9b23570b0..e0219b1a3fff6003f8cf9ec17fe0b7d5d0bcebb4 100644 (file)
@@ -69,7 +69,7 @@ extern "C"
 #include "gdbcmd.h"
 #include "gdbcore.h"
 #include "gdbthread.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "tid-parse.h"
 #include "nat/fork-inferior.h"
 
index d0c6188cb0bcdbb7d7b986cd73202363bbb73fd2..74b8b214abbedc308e222d224ffbf68b011c4cd8 100644 (file)
@@ -32,7 +32,7 @@
 */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "block.h"
 #include "symtab.h"
 #include "language.h"
index d50d6edb385caa5794151b700adfeb5ab9ecc488..8e1cc17b91c85436a9563b24c569ba51ccd583e5 100644 (file)
@@ -23,7 +23,7 @@
 #include "i386-tdep.h"
 #include "windows-tdep.h"
 #include "regset.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "xml-support.h"
 #include "gdbcore.h"
 #include "inferior.h"
index b0056358cf9205e9af70657fa6ba9fc841893995..4b69121e4d09a4507c41a13edc3e9e6b96af9f75 100644 (file)
@@ -31,7 +31,7 @@
 #include "inferior.h"
 #include "cli/cli-utils.h"
 #include "arch-utils.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "observable.h"
 #include "objfiles.h"
 #include "infcall.h"
index 9fd86f5f0d29b0d67eef4c297739292457a1dc89..f929ab4df3ce90dfdb2f9694b6139e6ec99789d7 100644 (file)
@@ -17,7 +17,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "bfd.h"               /* Binary File Description */
 #include "symtab.h"
 #include "gdbtypes.h"
index 97adb6e31a2649ff9564f70d9965c64e4b8700c1..be5723fe600f23836c907371359f1cdd32459fce 100644 (file)
@@ -18,7 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "macrotab.h"
 #include "macroexp.h"
 #include "macroscope.h"
index 479d08f13c64352c00b8f9909b46965fad26e35e..92d68e78e71dacc6bf056818f46b7baca7a5fc38 100644 (file)
@@ -18,7 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "splay-tree.h"
 #include "filenames.h"
 #include "symtab.h"
index b8c8ccb5e970fa371408f4d0cd5c4c272be73ea7..1b327ad61153b167601f9cb2aaa5d8d91c80425f 100644 (file)
@@ -45,7 +45,7 @@
 #include "gdbcore.h"
 #include "filenames.h"
 #include "objfiles.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "buildsym-legacy.h"
 #include "stabsread.h"
 #include "complaints.h"
index 7be4c3cb3b8c8adb3e3e00b520af59f597a9384b..05eac3553aee12832cd6679c8c3b4343be3817eb 100644 (file)
@@ -30,7 +30,7 @@
 #include "language.h"
 #include "location.h"
 #include "linespec.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include <ctype.h>
 #include "tracepoint.h"
 
index e3bac97727ed55b260a6bd18b7c84e95196e9529..dc052a44e4207f6dce7aff6e80621571bda26c69 100644 (file)
@@ -20,7 +20,7 @@
 #define NAMESPACE_H
 
 #include "gdbsupport/gdb_vecs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 
 /* This struct is designed to store data from using directives.  It
    says that names from namespace IMPORT_SRC should be visible within
index 262009eeda345d3716f41207f8fac44a5eedab5e..219dd0175cbcbada84e7708712004cb1dccadc9e 100644 (file)
@@ -36,7 +36,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "hashtab.h"
 
 #include "breakpoint.h"
index 27737dc99ca2ddeff272efee7ce051ef7c534fdc..8bd76705688a20ff98a2c5309509a8f3ffd7f9e6 100644 (file)
@@ -21,7 +21,7 @@
 #define OBJFILES_H
 
 #include "hashtab.h"
-#include "gdb_obstack.h"       /* For obstack internals.  */
+#include "gdbsupport/gdb_obstack.h"    /* For obstack internals.  */
 #include "objfile-flags.h"
 #include "symfile.h"
 #include "progspace.h"
index 468f0fdece1a4f101026a82809acf563a9303ea5..3450836996dc796a7ddd0a7fe30319ffae734f23 100644 (file)
@@ -19,7 +19,7 @@
 /* This file is derived from p-typeprint.c */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "bfd.h"               /* Binary File Description */
 #include "symtab.h"
 #include "gdbtypes.h"
index d4a3971103c5cc9f535bc219a27acc7f67007858..e0c3868991b9c1a82206bdcc32c65a7fece1e405 100644 (file)
@@ -20,7 +20,7 @@
 /* This file is derived from c-valprint.c */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "expression.h"
index 7ad9a534af1394a30ff536eaebfe8dd140f84510..70eb3e246bac8a1b70363afd19485c633339c8a5 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef PSYMTAB_H
 #define PSYMTAB_H
 
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "symfile.h"
 #include "gdbsupport/next-iterator.h"
 #include "bcache.h"
index a884c83ec26985e38499ef8b490ec802c7c7c262..4fea9068aad75d2f159e760f691739505268a2b7 100644 (file)
@@ -20,7 +20,7 @@
 #include "defs.h"
 #include "arch-utils.h"
 #include "frame-unwind.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gdbcmd.h"
 #include "language.h"
 #include "observable.h"
index 2b612fbd0402ad5530c44cb160a9c26a96b5eba9..1ad2a9c40f85dac18d9d0139d4b40a1ce7e35785 100644 (file)
@@ -26,7 +26,7 @@
 #include "regcache.h"
 #include "command.h"
 #include "gdbcmd.h"            /* For maintenanceprintlist.  */
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 
 /* Individual register groups.  */
 
index 6628a86f575028724b0121ba692d70ec3e9e70d7..a3969fe4fa91eeb842c2cbfda7a7c0d9e7f5361f 100644 (file)
@@ -22,7 +22,7 @@
 #include "block.h"
 #include "charset.h"
 #include "cp-support.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gdb_regex.h"
 #include "rust-lang.h"
 #include "parser-defs.h"
index f6b211ec29e7194741fa5ab519b4b19067f555e3..20cba381cc55892d4129f3c63b2d3b37cb5bb008 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "defs.h"
 #include "bfd.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "expression.h"
index 37ce01bb0e6da332068bbdab10ccf994bae69fb4..a60892b08db1bfb508826b214e054aad1f0ef4d9 100644 (file)
@@ -40,7 +40,7 @@
 #include "regcache.h"
 #include "filenames.h"         /* for DOSish file names */
 #include "gdb-stabs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "completer.h"
 #include "bcache.h"
 #include "hashtab.h"
index 4cbe338cb842a58bbcde802c0a59af5127ba2ace..3b5c3a07fc7742d7e88fc8b0257735ff132cd7d4 100644 (file)
@@ -26,7 +26,7 @@
 #include "objfiles.h"
 #include "breakpoint.h"
 #include "command.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "language.h"
 #include "bcache.h"
 #include "block.h"
index ba8e34df6510cbdc4ec378962b6e1c5269c4c9bd..cf9f6cec34f86cb09ff254458f159440dc29fe7c 100644 (file)
@@ -47,7 +47,7 @@
 #include "hashtab.h"
 #include "typeprint.h"
 
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "block.h"
 #include "dictionary.h"
 
index a17ee02163adb02b5e7073fa9a0ed9f729cd39b1..740c7ed8c747f766b3e123a97a8a16da1104b806 100644 (file)
@@ -26,7 +26,7 @@
 #include <set>
 #include "gdbsupport/gdb_vecs.h"
 #include "gdbtypes.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gdb_regex.h"
 #include "gdbsupport/enum-flags.h"
 #include "gdbsupport/function-view.h"
index 282729df9e6919adbe161147aec56e81d918f17d..7c380cdb60ff9b0095e17751165d18123f8801ee 100644 (file)
@@ -30,7 +30,7 @@
 #include "xml-tdesc.h"
 #include "osabi.h"
 
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "hashtab.h"
 #include "inferior.h"
 #include <algorithm>
index 2428aa2244fd3bf5231adc570b585243c7e19a1a..0430df82012ecfc8fecd473d2bafccc2b9567d43 100644 (file)
@@ -18,7 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "bfd.h"               /* Binary File Description */
 #include "symtab.h"
 #include "gdbtypes.h"
index 97620a4caf266c6e90a174085c96d5e2e6f84f9a..29687234c7f5c75548b5147ea09de24318282efc 100644 (file)
@@ -19,7 +19,7 @@
 #ifndef TYPEPRINT_H
 #define TYPEPRINT_H
 
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 
 enum language;
 struct ui_file;
index c6a4888ed48eb1d0f48cd1cb370b16bb4af9f4aa..d30ec04a68fc03f8811d4831e2770a5fd2ce3b3e 100644 (file)
@@ -21,7 +21,7 @@
 
 #include "defs.h"
 #include "ui-file.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gdbsupport/gdb_select.h"
 #include "gdbsupport/filestuff.h"
 #include "cli/cli-style.h"
index da60c1e4144493aa51996f34479594a15bc11b8c..0be49a6d4f841c847669714cf71b68016ef74552 100644 (file)
@@ -48,7 +48,7 @@
 #include "annotate.h"
 #include "filenames.h"
 #include "symfile.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gdbcore.h"
 #include "top.h"
 #include "main.h"
index 0bc739cf2e293857a787b646b76714e8ce48c532..f80c1698ad690efd9df5c2dc3abe1fffcdedd3d8 100644 (file)
@@ -30,7 +30,7 @@
 #include "target-float.h"
 #include "extension.h"
 #include "ada-lang.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "charset.h"
 #include "typeprint.h"
 #include <ctype.h>
index bdf6ac93c49ebb955c6026f2ad065435805ca35f..81e26fe4759fc40fcc826a2804a2db809b1fb7f3 100644 (file)
@@ -48,7 +48,7 @@
 #include "symfile.h"
 #include "objfiles.h"
 #include "gdb_bfd.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gdbthread.h"
 #include "gdbcmd.h"
 #include <unistd.h>
index 78984d65fd62f202600425407b257a14344aa75f..13be3e4e461d8e309910118351f1cd8901482f2b 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "defs.h"
 #include "windows-tdep.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "xml-support.h"
 #include "gdbarch.h"
 #include "target.h"
index 1be77f8eaaec2b12ba121d17819ff48c112487b9..13edeaec9104a01996899f44daeb796d45d030e0 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef XML_SUPPORT_H
 #define XML_SUPPORT_H
 
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
 #include "gdbsupport/xml-utils.h"
 #include "gdbsupport/byte-vector.h"
 #include "gdbsupport/gdb_optional.h"
index d8f204b824aeebe76ff1bbc6b7bcc24b5bb6b4f4..73d4149f294605cee5e3406b1b59d486c218c5b2 100644 (file)
@@ -52,6 +52,7 @@ libgdbsupport_a_SOURCES = \
     filestuff.cc \
     format.cc \
     gdb-dlfcn.cc \
+    gdb_obstack.cc \
     gdb_tilde_expand.cc \
     gdb_wait.cc \
     gdb_vecs.cc \
index c74e26aacd3f6c719e66c87042de15cc8d712414..88d3dd153d69d3643c24fa000499855c045dd472 100644 (file)
@@ -151,14 +151,15 @@ am_libgdbsupport_a_OBJECTS = agent.$(OBJEXT) btrace-common.$(OBJEXT) \
        common-regcache.$(OBJEXT) common-utils.$(OBJEXT) \
        environ.$(OBJEXT) errors.$(OBJEXT) event-loop.$(OBJEXT) \
        fileio.$(OBJEXT) filestuff.$(OBJEXT) format.$(OBJEXT) \
-       gdb-dlfcn.$(OBJEXT) gdb_tilde_expand.$(OBJEXT) \
-       gdb_wait.$(OBJEXT) gdb_vecs.$(OBJEXT) job-control.$(OBJEXT) \
-       netstuff.$(OBJEXT) new-op.$(OBJEXT) pathstuff.$(OBJEXT) \
-       print-utils.$(OBJEXT) ptid.$(OBJEXT) rsp-low.$(OBJEXT) \
-       run-time-clock.$(OBJEXT) safe-strerror.$(OBJEXT) \
-       scoped_mmap.$(OBJEXT) search.$(OBJEXT) signals.$(OBJEXT) \
-       signals-state-save-restore.$(OBJEXT) tdesc.$(OBJEXT) \
-       thread-pool.$(OBJEXT) xml-utils.$(OBJEXT) $(am__objects_1)
+       gdb-dlfcn.$(OBJEXT) gdb_obstack.$(OBJEXT) \
+       gdb_tilde_expand.$(OBJEXT) gdb_wait.$(OBJEXT) \
+       gdb_vecs.$(OBJEXT) job-control.$(OBJEXT) netstuff.$(OBJEXT) \
+       new-op.$(OBJEXT) pathstuff.$(OBJEXT) print-utils.$(OBJEXT) \
+       ptid.$(OBJEXT) rsp-low.$(OBJEXT) run-time-clock.$(OBJEXT) \
+       safe-strerror.$(OBJEXT) scoped_mmap.$(OBJEXT) search.$(OBJEXT) \
+       signals.$(OBJEXT) signals-state-save-restore.$(OBJEXT) \
+       tdesc.$(OBJEXT) thread-pool.$(OBJEXT) xml-utils.$(OBJEXT) \
+       $(am__objects_1)
 libgdbsupport_a_OBJECTS = $(am_libgdbsupport_a_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -336,6 +337,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -375,6 +377,7 @@ libgdbsupport_a_SOURCES = \
     filestuff.cc \
     format.cc \
     gdb-dlfcn.cc \
+    gdb_obstack.cc \
     gdb_tilde_expand.cc \
     gdb_wait.cc \
     gdb_vecs.cc \
@@ -480,6 +483,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filestuff.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/format.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdb-dlfcn.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdb_obstack.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdb_tilde_expand.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdb_vecs.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gdb_wait.Po@am__quote@
diff --git a/gdbsupport/gdb_obstack.cc b/gdbsupport/gdb_obstack.cc
new file mode 100644 (file)
index 0000000..571f34a
--- /dev/null
@@ -0,0 +1,47 @@
+/* Obstack wrapper for GDB.
+
+   Copyright (C) 2013-2022 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/>.  */
+
+#include "common-defs.h"
+#include "gdb_obstack.h"
+
+/* Concatenate NULL terminated variable argument list of `const char *'
+   strings; return the new string.  Space is found in the OBSTACKP.
+   Argument list must be terminated by a sentinel expression `(char *)
+   NULL'.  */
+
+char *
+obconcat (struct obstack *obstackp, ...)
+{
+  va_list ap;
+
+  va_start (ap, obstackp);
+  for (;;)
+    {
+      const char *s = va_arg (ap, const char *);
+
+      if (s == NULL)
+       break;
+
+      obstack_grow_str (obstackp, s);
+    }
+  va_end (ap);
+  obstack_1grow (obstackp, 0);
+
+  return (char *) obstack_finish (obstackp);
+}
diff --git a/gdbsupport/gdb_obstack.h b/gdbsupport/gdb_obstack.h
new file mode 100644 (file)
index 0000000..5e870cb
--- /dev/null
@@ -0,0 +1,156 @@
+/* Obstack wrapper for GDB.
+
+   Copyright (C) 2002-2022 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/>.  */
+
+#if !defined (GDB_OBSTACK_H)
+#define GDB_OBSTACK_H 1
+
+#include "obstack.h"
+
+/* Utility macros - wrap obstack alloc into something more robust.  */
+
+template <typename T>
+static inline T*
+obstack_zalloc (struct obstack *ob)
+{
+  static_assert (IsMallocable<T>::value, "Trying to use OBSTACK_ZALLOC with a \
+non-POD data type.  Use obstack_new instead.");
+  return ((T *) memset (obstack_alloc (ob, sizeof (T)), 0, sizeof (T)));
+}
+
+#define OBSTACK_ZALLOC(OBSTACK,TYPE) obstack_zalloc<TYPE> ((OBSTACK))
+
+template <typename T>
+static inline T *
+obstack_calloc (struct obstack *ob, size_t number)
+{
+  static_assert (IsMallocable<T>::value, "Trying to use OBSTACK_CALLOC with a \
+non-POD data type.  Use obstack_new instead.");
+  return ((T *) memset (obstack_alloc (ob, number * sizeof (T)), 0,
+                       number * sizeof (T)));
+}
+
+#define OBSTACK_CALLOC(OBSTACK,NUMBER,TYPE) \
+  obstack_calloc<TYPE> ((OBSTACK), (NUMBER))
+
+/* Allocate an object on OB and call its constructor.  */
+
+template <typename T, typename... Args>
+static inline T*
+obstack_new (struct obstack *ob, Args&&... args)
+{
+  T* object = (T *) obstack_alloc (ob, sizeof (T));
+  object = new (object) T (std::forward<Args> (args)...);
+  return object;
+}
+
+/* Unless explicitly specified, GDB obstacks always use xmalloc() and
+   xfree().  */
+/* Note: ezannoni 2004-02-09: One could also specify the allocation
+   functions using a special init function for each obstack,
+   obstack_specify_allocation.  However we just use obstack_init and
+   let these defines here do the job.  While one could argue the
+   superiority of one approach over the other, we just chose one
+   throughout.  */
+
+#define obstack_chunk_alloc xmalloc
+#define obstack_chunk_free xfree
+
+#define obstack_grow_str(OBSTACK,STRING) \
+  obstack_grow (OBSTACK, STRING, strlen (STRING))
+#define obstack_grow_str0(OBSTACK,STRING) \
+  obstack_grow0 (OBSTACK, STRING, strlen (STRING))
+
+#define obstack_grow_wstr(OBSTACK, WSTRING) \
+  obstack_grow (OBSTACK, WSTRING, sizeof (gdb_wchar_t) * gdb_wcslen (WSTRING))
+
+/* Concatenate NULL terminated variable argument list of `const char
+   *' strings; return the new string.  Space is found in the OBSTACKP.
+   Argument list must be terminated by a sentinel expression `(char *)
+   NULL'.  */
+
+extern char *obconcat (struct obstack *obstackp, ...) ATTRIBUTE_SENTINEL;
+
+/* Duplicate STRING, returning an equivalent string that's allocated on the
+   obstack OBSTACKP.  */
+
+static inline char *
+obstack_strdup (struct obstack *obstackp, const char *string)
+{
+  return (char *) obstack_copy0 (obstackp, string, strlen (string));
+}
+
+/* Duplicate STRING, returning an equivalent string that's allocated on the
+   obstack OBSTACKP.  */
+
+static inline char *
+obstack_strdup (struct obstack *obstackp, const std::string &string)
+{
+  return (char *) obstack_copy0 (obstackp, string.c_str (),
+                                string.size ());
+}
+
+/* Duplicate the first N characters of STRING, returning a
+   \0-terminated string that's allocated on the obstack OBSTACKP.
+   Note that exactly N characters are copied, even if STRING is
+   shorter.  */
+
+static inline char *
+obstack_strndup (struct obstack *obstackp, const char *string, size_t n)
+{
+  return (char *) obstack_copy0 (obstackp, string, n);
+}
+
+/* An obstack that frees itself on scope exit.  */
+struct auto_obstack : obstack
+{
+  auto_obstack ()
+  { obstack_init (this); }
+
+  ~auto_obstack ()
+  { obstack_free (this, NULL); }
+
+  DISABLE_COPY_AND_ASSIGN (auto_obstack);
+
+  /* Free all memory in the obstack but leave it valid for further
+     allocation.  */
+  void clear ()
+  { obstack_free (this, obstack_base (this)); }
+};
+
+/* Objects are allocated on obstack instead of heap.  */
+
+struct allocate_on_obstack
+{
+  allocate_on_obstack () = default;
+
+  void* operator new (size_t size, struct obstack *obstack)
+  {
+    return obstack_alloc (obstack, size);
+  }
+
+  void* operator new[] (size_t size, struct obstack *obstack)
+  {
+    return obstack_alloc (obstack, size);
+  }
+
+  void operator delete (void *memory) {}
+  void operator delete[] (void *memory) {}
+};
+
+#endif