From: Tom Tromey Date: Tue, 21 Dec 2021 23:38:32 +0000 (-0700) Subject: Move gdb obstack code to gdbsupport X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bf31fd38f02ca9b1a7d75e2d00ee0af665fd3efd;p=binutils-gdb.git Move gdb obstack code to gdbsupport This moves the gdb-specific obstack code -- both extensions like obconcat and obstack_strdup, and things like auto_obstack -- to gdbsupport. --- diff --git a/gdb/Makefile.in b/gdb/Makefile.in index d0db5fbdee1..ce9f1ad441c 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -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 \ diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index f2f8617cc1e..b88b27b55b1 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -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" diff --git a/gdb/addrmap.c b/gdb/addrmap.c index a35eeed100e..bf30faab66b 100644 --- a/gdb/addrmap.c +++ b/gdb/addrmap.c @@ -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" diff --git a/gdb/bcache.c b/gdb/bcache.c index c8a5b011598..6d0741b59d0 100644 --- a/gdb/bcache.c +++ b/gdb/bcache.c @@ -20,7 +20,7 @@ along with this program. If not, see . */ #include "defs.h" -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include "bcache.h" #include diff --git a/gdb/block.c b/gdb/block.c index b590697a491..2b6196c09aa 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -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" diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c index 15c290b0ad1..5d17854d9af 100644 --- a/gdb/break-catch-throw.c +++ b/gdb/break-catch-throw.c @@ -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" diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c index 5d5978d66ac..d0d9e89e93c 100644 --- a/gdb/bsd-uthread.c +++ b/gdb/bsd-uthread.c @@ -29,7 +29,7 @@ #include "symfile.h" #include "target.h" -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include "bsd-uthread.h" diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 8827ddf1a11..1754f5ffe6e 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -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" diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 4ca8e0528f4..003d8a59719 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -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; diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 4c9f8a741df..ed7554fadea 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -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 #include "gdbcore.h" #include "gdbarch.h" diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 71d8797e84c..81fc82ec263 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -17,7 +17,7 @@ along with this program. If not, see . */ #include "defs.h" -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include "bfd.h" /* Binary File Description. */ #include "symtab.h" #include "gdbtypes.h" diff --git a/gdb/charset.c b/gdb/charset.c index 0b3ef26f1d6..9b1de08a93a 100644 --- a/gdb/charset.c +++ b/gdb/charset.c @@ -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" diff --git a/gdb/coffread.c b/gdb/coffread.c index e264918fb3a..921cfce1053 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -24,7 +24,7 @@ #include "breakpoint.h" #include "bfd.h" -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include #include "coff/internal.h" /* Internal format of COFF symbols in BFD */ diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index e6176719677..6130381fdd6 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -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" diff --git a/gdb/cp-support.h b/gdb/cp-support.h index 832155bff42..cd473a2c553 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -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 diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index 98ac636a21c..1d98eb58214 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -18,7 +18,7 @@ along with this program. If not, see . */ #include "defs.h" -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include "symtab.h" #include "gdbtypes.h" #include "expression.h" diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c index 39097e8055c..eab99cec672 100644 --- a/gdb/d-namespace.c +++ b/gdb/d-namespace.c @@ -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 diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 849ae0133f7..911d518b7e9 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -32,7 +32,7 @@ #include "defs.h" -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include #include "symtab.h" #include "breakpoint.h" diff --git a/gdb/dictionary.c b/gdb/dictionary.c index 7a686281475..849d07469cf 100644 --- a/gdb/dictionary.c +++ b/gdb/dictionary.c @@ -22,7 +22,7 @@ #include "defs.h" #include -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include "symtab.h" #include "buildsym.h" #include "dictionary.h" diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 0071c385bfa..effeaabc4af 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -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" diff --git a/gdb/eval.c b/gdb/eval.c index acac28e5c2d..713f977bc77 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -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 diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c index a633e47b2d3..0a338c11cbc 100644 --- a/gdb/f-typeprint.c +++ b/gdb/f-typeprint.c @@ -21,7 +21,7 @@ along with this program. If not, see . */ #include "defs.h" -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include "bfd.h" #include "symtab.h" #include "gdbtypes.h" diff --git a/gdb/frame-base.c b/gdb/frame-base.c index 7f018122d37..91af24b4f74 100644 --- a/gdb/frame-base.c +++ b/gdb/frame-base.c @@ -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 diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c index fdfe44cb10a..302ce1efb99 100644 --- a/gdb/frame-unwind.c +++ b/gdb/frame-unwind.c @@ -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" diff --git a/gdb/frame.c b/gdb/frame.c index cee6b08a49a..6e2f6b245a2 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -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 index 3f8d82a245e..00000000000 --- a/gdb/gdb_obstack.c +++ /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 . */ - -#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 index 5e870cb7981..00000000000 --- a/gdb/gdb_obstack.h +++ /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 . */ - -#if !defined (GDB_OBSTACK_H) -#define GDB_OBSTACK_H 1 - -#include "obstack.h" - -/* Utility macros - wrap obstack alloc into something more robust. */ - -template -static inline T* -obstack_zalloc (struct obstack *ob) -{ - static_assert (IsMallocable::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 ((OBSTACK)) - -template -static inline T * -obstack_calloc (struct obstack *ob, size_t number) -{ - static_assert (IsMallocable::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 ((OBSTACK), (NUMBER)) - -/* Allocate an object on OB and call its constructor. */ - -template -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)...); - 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 diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index fc1582449ed..6404dc1cb43 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -24,7 +24,7 @@ #include #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" diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 42878dba933..467f60975e1 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -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. */ diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c index 1586a738dee..e0219b1a3ff 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -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" diff --git a/gdb/go-lang.c b/gdb/go-lang.c index d0c6188cb0b..74b8b214abb 100644 --- a/gdb/go-lang.c +++ b/gdb/go-lang.c @@ -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" diff --git a/gdb/i386-windows-tdep.c b/gdb/i386-windows-tdep.c index d50d6edb385..8e1cc17b91c 100644 --- a/gdb/i386-windows-tdep.c +++ b/gdb/i386-windows-tdep.c @@ -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" diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index b0056358cf9..4b69121e4d0 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -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" diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c index 9fd86f5f0d2..f929ab4df3c 100644 --- a/gdb/m2-typeprint.c +++ b/gdb/m2-typeprint.c @@ -17,7 +17,7 @@ along with this program. If not, see . */ #include "defs.h" -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include "bfd.h" /* Binary File Description */ #include "symtab.h" #include "gdbtypes.h" diff --git a/gdb/macroexp.c b/gdb/macroexp.c index 97adb6e31a2..be5723fe600 100644 --- a/gdb/macroexp.c +++ b/gdb/macroexp.c @@ -18,7 +18,7 @@ along with this program. If not, see . */ #include "defs.h" -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include "macrotab.h" #include "macroexp.h" #include "macroscope.h" diff --git a/gdb/macrotab.c b/gdb/macrotab.c index 479d08f13c6..92d68e78e71 100644 --- a/gdb/macrotab.c +++ b/gdb/macrotab.c @@ -18,7 +18,7 @@ along with this program. If not, see . */ #include "defs.h" -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include "splay-tree.h" #include "filenames.h" #include "symtab.h" diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index b8c8ccb5e97..1b327ad6115 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -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" diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c index 7be4c3cb3b8..05eac3553ae 100644 --- a/gdb/mi/mi-cmd-break.c +++ b/gdb/mi/mi-cmd-break.c @@ -30,7 +30,7 @@ #include "language.h" #include "location.h" #include "linespec.h" -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include #include "tracepoint.h" diff --git a/gdb/namespace.h b/gdb/namespace.h index e3bac97727e..dc052a44e42 100644 --- a/gdb/namespace.h +++ b/gdb/namespace.h @@ -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 diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 262009eeda3..219dd0175cb 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -36,7 +36,7 @@ #include #include #include -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include "hashtab.h" #include "breakpoint.h" diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 27737dc99ca..8bd76705688 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -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" diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c index 468f0fdece1..3450836996d 100644 --- a/gdb/p-typeprint.c +++ b/gdb/p-typeprint.c @@ -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" diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c index d4a3971103c..e0c3868991b 100644 --- a/gdb/p-valprint.c +++ b/gdb/p-valprint.c @@ -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" diff --git a/gdb/psymtab.h b/gdb/psymtab.h index 7ad9a534af1..70eb3e246ba 100644 --- a/gdb/psymtab.h +++ b/gdb/psymtab.h @@ -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" diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index a884c83ec26..4fea9068aad 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -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" diff --git a/gdb/reggroups.c b/gdb/reggroups.c index 2b612fbd040..1ad2a9c40f8 100644 --- a/gdb/reggroups.c +++ b/gdb/reggroups.c @@ -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. */ diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index 6628a86f575..a3969fe4fa9 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -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" diff --git a/gdb/stabsread.c b/gdb/stabsread.c index f6b211ec29e..20cba381cc5 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -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" diff --git a/gdb/symfile.c b/gdb/symfile.c index 37ce01bb0e6..a60892b08db 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -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" diff --git a/gdb/symmisc.c b/gdb/symmisc.c index 4cbe338cb84..3b5c3a07fc7 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -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" diff --git a/gdb/symtab.c b/gdb/symtab.c index ba8e34df651..cf9f6cec34f 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -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" diff --git a/gdb/symtab.h b/gdb/symtab.h index a17ee02163a..740c7ed8c74 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -26,7 +26,7 @@ #include #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" diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index 282729df9e6..7c380cdb60f 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -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 diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 2428aa2244f..0430df82012 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -18,7 +18,7 @@ along with this program. If not, see . */ #include "defs.h" -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" #include "bfd.h" /* Binary File Description */ #include "symtab.h" #include "gdbtypes.h" diff --git a/gdb/typeprint.h b/gdb/typeprint.h index 97620a4caf2..29687234c7f 100644 --- a/gdb/typeprint.h +++ b/gdb/typeprint.h @@ -19,7 +19,7 @@ #ifndef TYPEPRINT_H #define TYPEPRINT_H -#include "gdb_obstack.h" +#include "gdbsupport/gdb_obstack.h" enum language; struct ui_file; diff --git a/gdb/ui-file.c b/gdb/ui-file.c index c6a4888ed48..d30ec04a68f 100644 --- a/gdb/ui-file.c +++ b/gdb/ui-file.c @@ -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" diff --git a/gdb/utils.c b/gdb/utils.c index da60c1e4144..0be49a6d4f8 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -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" diff --git a/gdb/valprint.c b/gdb/valprint.c index 0bc739cf2e2..f80c1698ad6 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -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 diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index bdf6ac93c49..81e26fe4759 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -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 diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c index 78984d65fd6..13be3e4e461 100644 --- a/gdb/windows-tdep.c +++ b/gdb/windows-tdep.c @@ -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" diff --git a/gdb/xml-support.h b/gdb/xml-support.h index 1be77f8eaae..13edeaec910 100644 --- a/gdb/xml-support.h +++ b/gdb/xml-support.h @@ -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" diff --git a/gdbsupport/Makefile.am b/gdbsupport/Makefile.am index d8f204b824a..73d4149f294 100644 --- a/gdbsupport/Makefile.am +++ b/gdbsupport/Makefile.am @@ -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 \ diff --git a/gdbsupport/Makefile.in b/gdbsupport/Makefile.in index c74e26aacd3..88d3dd153d6 100644 --- a/gdbsupport/Makefile.in +++ b/gdbsupport/Makefile.in @@ -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 index 00000000000..571f34a7add --- /dev/null +++ b/gdbsupport/gdb_obstack.cc @@ -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 . */ + +#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 index 00000000000..5e870cb7981 --- /dev/null +++ b/gdbsupport/gdb_obstack.h @@ -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 . */ + +#if !defined (GDB_OBSTACK_H) +#define GDB_OBSTACK_H 1 + +#include "obstack.h" + +/* Utility macros - wrap obstack alloc into something more robust. */ + +template +static inline T* +obstack_zalloc (struct obstack *ob) +{ + static_assert (IsMallocable::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 ((OBSTACK)) + +template +static inline T * +obstack_calloc (struct obstack *ob, size_t number) +{ + static_assert (IsMallocable::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 ((OBSTACK), (NUMBER)) + +/* Allocate an object on OB and call its constructor. */ + +template +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)...); + 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