[2/2] Use gdbarch obstack to allocate the TYPE_NAME string in arch_type
Commit Message
[ The earlier committed version of this patch was reverted. ]
Since the type whose name is being set is now being allocated on the
gdbarch obstack, we should allocate its TYPE_NAME on the obstack too.
This reduces the number of individual valgrind warnings for the command
"gdb gdb" from ~300 to ~150.
Tested on x86_64-unknown-linux-gnu.
gdb/ChangeLog:
* gdb_obstack.h (obstack_strdup): Declare.
* gdb_obstack.c (obstack_strdup): Declare.
* gdbarch.sh (gdbarch_obstack_strdup): Declare and define.
* gdbarch.c: Regenerate.
* gdbarch.h: Regenerate.
* gdbtypes.c (arch_type): Use gdbarch_obstack_strdup.
---
gdb/gdb_obstack.c | 10 ++++++++++
gdb/gdb_obstack.h | 5 +++++
gdb/gdbarch.c | 8 ++++++++
gdb/gdbarch.h | 5 +++++
gdb/gdbarch.sh | 13 +++++++++++++
gdb/gdbtypes.c | 2 +-
6 files changed, 42 insertions(+), 1 deletion(-)
Comments
Patrick Palka <patrick@parcs.ath.cx> writes:
> [ The earlier committed version of this patch was reverted. ]
>
> Since the type whose name is being set is now being allocated on the
> gdbarch obstack, we should allocate its TYPE_NAME on the obstack too.
> This reduces the number of individual valgrind warnings for the command
> "gdb gdb" from ~300 to ~150.
>
> Tested on x86_64-unknown-linux-gnu.
>
> gdb/ChangeLog:
>
> * gdb_obstack.h (obstack_strdup): Declare.
> * gdb_obstack.c (obstack_strdup): Declare.
> * gdbarch.sh (gdbarch_obstack_strdup): Declare and define.
> * gdbarch.c: Regenerate.
> * gdbarch.h: Regenerate.
> * gdbtypes.c (arch_type): Use gdbarch_obstack_strdup.
LGTM.
Thanks!
@@ -45,3 +45,13 @@ obconcat (struct obstack *obstackp, ...)
return obstack_finish (obstackp);
}
+
+/* See gdb_obstack.h. */
+
+char *
+obstack_strdup (struct obstack *obstackp, const char *string)
+{
+ char *obstring = obstack_alloc (obstackp, strlen (string) + 1);
+ strcpy (obstring, string);
+ return obstring;
+}
@@ -58,4 +58,9 @@
extern char *obconcat (struct obstack *obstackp, ...) ATTRIBUTE_SENTINEL;
+/* Duplicate STRING, returning an equivalent string that's allocated on the
+ obstack OBSTACKP. */
+
+extern char *obstack_strdup (struct obstack *obstackp, const char *string);
+
#endif
@@ -449,6 +449,14 @@ gdbarch_obstack_zalloc (struct gdbarch *arch, long size)
return data;
}
+/* See gdbarch.h. */
+
+char *
+gdbarch_obstack_strdup (struct gdbarch *arch, const char *string)
+{
+ return obstack_strdup (arch->obstack, string);
+}
+
/* Free a gdbarch struct. This should never happen in normal
operation --- once you've created a gdbarch, you keep it around.
@@ -1618,6 +1618,11 @@ extern void *gdbarch_obstack_zalloc (struct gdbarch *gdbarch, long size);
#define GDBARCH_OBSTACK_CALLOC(GDBARCH, NR, TYPE) ((TYPE *) gdbarch_obstack_zalloc ((GDBARCH), (NR) * sizeof (TYPE)))
#define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE) ((TYPE *) gdbarch_obstack_zalloc ((GDBARCH), sizeof (TYPE)))
+/* Duplicate STRING, returning an equivalent string that's allocated on the
+ obstack associated with GDBARCH. The string is freed when the corresponding
+ architecture is also freed. */
+
+extern char *gdbarch_obstack_strdup (struct gdbarch *arch, const char *string);
/* Helper function. Force an update of the current architecture.
@@ -1486,6 +1486,11 @@ extern void *gdbarch_obstack_zalloc (struct gdbarch *gdbarch, long size);
#define GDBARCH_OBSTACK_CALLOC(GDBARCH, NR, TYPE) ((TYPE *) gdbarch_obstack_zalloc ((GDBARCH), (NR) * sizeof (TYPE)))
#define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE) ((TYPE *) gdbarch_obstack_zalloc ((GDBARCH), sizeof (TYPE)))
+/* Duplicate STRING, returning an equivalent string that's allocated on the
+ obstack associated with GDBARCH. The string is freed when the corresponding
+ architecture is also freed. */
+
+extern char *gdbarch_obstack_strdup (struct gdbarch *arch, const char *string);
/* Helper function. Force an update of the current architecture.
@@ -1791,6 +1796,14 @@ gdbarch_obstack_zalloc (struct gdbarch *arch, long size)
return data;
}
+/* See gdbarch.h. */
+
+char *
+gdbarch_obstack_strdup (struct gdbarch *arch, const char *string)
+{
+ return obstack_strdup (arch->obstack, string);
+}
+
/* Free a gdbarch struct. This should never happen in normal
operation --- once you've created a gdbarch, you keep it around.
@@ -4549,7 +4549,7 @@ arch_type (struct gdbarch *gdbarch,
TYPE_LENGTH (type) = length;
if (name)
- TYPE_NAME (type) = xstrdup (name);
+ TYPE_NAME (type) = gdbarch_obstack_strdup (gdbarch, name);
return type;
}