diff options
author | Tom Tromey <tom@tromey.com> | 2019-07-13 12:09:51 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2019-08-06 20:08:48 -0600 |
commit | efba19b06a6f2baacb3920599f970d1333ffc358 (patch) | |
tree | f8ab8d8f5a212c00950b8fc67a180e4373017f01 | |
parent | f25102f7b100337923d2c81ecc12a64d428e98fe (diff) | |
download | gdb-efba19b06a6f2baacb3920599f970d1333ffc358.zip gdb-efba19b06a6f2baacb3920599f970d1333ffc358.tar.gz gdb-efba19b06a6f2baacb3920599f970d1333ffc358.tar.bz2 |
Add obstack_strdup overload taking a std::string
This adds an obstack_strdup overload that takes a std::string, and
changes a few spots in gdb to use it.
gdb/ChangeLog
2019-08-06 Tom Tromey <tom@tromey.com>
* symfile.c (reread_symbols): Use obstack_strdup.
* stabsread.c (read_type): Use obstack_strdup.
* gdb_obstack.h (obstack_strdup): New overload.
* dwarf2read.c (dwarf2_compute_name, create_dwo_unit_in_dwp_v1)
(create_dwo_unit_in_dwp_v2, build_error_marker_type)
(dwarf2_canonicalize_name): Use obstack_strdup.
* dbxread.c (read_dbx_symtab): Use obstack_strdup.
* cp-support.c (inspect_type, replace_typedefs_qualified_name):
Use obstack_strdup.
-rw-r--r-- | gdb/ChangeLog | 12 | ||||
-rw-r--r-- | gdb/cp-support.c | 10 | ||||
-rw-r--r-- | gdb/dbxread.c | 5 | ||||
-rw-r--r-- | gdb/dwarf2read.c | 25 | ||||
-rw-r--r-- | gdb/gdb_obstack.h | 10 | ||||
-rw-r--r-- | gdb/stabsread.c | 8 | ||||
-rw-r--r-- | gdb/symfile.c | 4 |
7 files changed, 38 insertions, 36 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 29ffa1e..31cd69d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,17 @@ 2019-08-06 Tom Tromey <tom@tromey.com> + * symfile.c (reread_symbols): Use obstack_strdup. + * stabsread.c (read_type): Use obstack_strdup. + * gdb_obstack.h (obstack_strdup): New overload. + * dwarf2read.c (dwarf2_compute_name, create_dwo_unit_in_dwp_v1) + (create_dwo_unit_in_dwp_v2, build_error_marker_type) + (dwarf2_canonicalize_name): Use obstack_strdup. + * dbxread.c (read_dbx_symtab): Use obstack_strdup. + * cp-support.c (inspect_type, replace_typedefs_qualified_name): + Use obstack_strdup. + +2019-08-06 Tom Tromey <tom@tromey.com> + * gdb_obstack.h (obstack_strdup): Define. * gdb_obstack.c (obstack_strdup): Don't define. diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 562c6f1..b8b0fcc 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -244,7 +244,7 @@ inspect_type (struct demangle_parse_info *info, } len = buf.size (); - name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len); + name = obstack_strdup (&info->obstack, buf.string ()); /* Turn the result into a new tree. Note that this tree will contain pointers into NAME, so NAME cannot @@ -315,9 +315,7 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info, buf.write (d_left (comp)->u.s_name.s, d_left (comp)->u.s_name.len); newobj.type = DEMANGLE_COMPONENT_NAME; - newobj.u.s_name.s - = (char *) obstack_copy0 (&info->obstack, - buf.c_str (), buf.size ()); + newobj.u.s_name.s = obstack_strdup (&info->obstack, buf.string ()); newobj.u.s_name.len = buf.size (); if (inspect_type (info, &newobj, finder, data)) { @@ -379,9 +377,7 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info, with a DEMANGLE_COMPONENT_NAME node containing the whole name. */ ret_comp->type = DEMANGLE_COMPONENT_NAME; - ret_comp->u.s_name.s - = (char *) obstack_copy0 (&info->obstack, - buf.c_str (), buf.size ()); + ret_comp->u.s_name.s = obstack_strdup (&info->obstack, buf.string ()); ret_comp->u.s_name.len = buf.size (); inspect_type (info, ret_comp, finder, data); } diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 00eeb31..0b370cd 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -1440,9 +1440,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile) if (!new_name.empty ()) { sym_len = new_name.length (); - sym_name = (char *) obstack_copy0 (&objfile->objfile_obstack, - new_name.c_str (), - sym_len); + sym_name = obstack_strdup (&objfile->objfile_obstack, + new_name); } } diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index ab974a5..6d28924 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -10945,10 +10945,8 @@ dwarf2_compute_name (const char *name, INTERMEDIATE_NAME is already canonical, then we need to copy it to the appropriate obstack. */ if (canonical_name == NULL || canonical_name == intermediate_name.c_str ()) - name = ((const char *) - obstack_copy0 (&objfile->per_bfd->storage_obstack, - intermediate_name.c_str (), - intermediate_name.length ())); + name = obstack_strdup (&objfile->per_bfd->storage_obstack, + intermediate_name); else name = canonical_name; } @@ -12416,10 +12414,8 @@ create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile *dwarf2_per_objfile, virtual_dwo_name.c_str ()); } dwo_file = new struct dwo_file; - dwo_file->dwo_name - = (const char *) obstack_copy0 (&objfile->objfile_obstack, - virtual_dwo_name.c_str (), - virtual_dwo_name.size ()); + dwo_file->dwo_name = obstack_strdup (&objfile->objfile_obstack, + virtual_dwo_name); dwo_file->comp_dir = comp_dir; dwo_file->sections.abbrev = sections.abbrev; dwo_file->sections.line = sections.line; @@ -12614,10 +12610,8 @@ create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile *dwarf2_per_objfile, virtual_dwo_name.c_str ()); } dwo_file = new struct dwo_file; - dwo_file->dwo_name - = (const char *) obstack_copy0 (&objfile->objfile_obstack, - virtual_dwo_name.c_str (), - virtual_dwo_name.size ()); + dwo_file->dwo_name = obstack_strdup (&objfile->objfile_obstack, + virtual_dwo_name); dwo_file->comp_dir = comp_dir; dwo_file->sections.abbrev = create_dwp_v2_section (dwarf2_per_objfile, &dwp_file->sections.abbrev, @@ -22101,8 +22095,7 @@ build_error_marker_type (struct dwarf2_cu *cu, struct die_info *die) objfile_name (objfile), sect_offset_str (cu->header.sect_off), sect_offset_str (die->sect_off)); - saved = (char *) obstack_copy0 (&objfile->objfile_obstack, - message.c_str (), message.length ()); + saved = obstack_strdup (&objfile->objfile_obstack, message); return init_type (objfile, TYPE_CODE_ERROR, 0, saved); } @@ -22638,9 +22631,7 @@ dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu, if (!canon_name.empty ()) { if (canon_name != name) - name = (const char *) obstack_copy0 (obstack, - canon_name.c_str (), - canon_name.length ()); + name = obstack_strdup (obstack, canon_name); } } diff --git a/gdb/gdb_obstack.h b/gdb/gdb_obstack.h index 829e2f9..db849a0 100644 --- a/gdb/gdb_obstack.h +++ b/gdb/gdb_obstack.h @@ -95,6 +95,16 @@ 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 ()); +} + /* An obstack that frees itself on scope exit. */ struct auto_obstack : obstack { diff --git a/gdb/stabsread.c b/gdb/stabsread.c index b7524e7..23da5f9 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -1654,12 +1654,8 @@ again: std::string new_name = cp_canonicalize_string (name); if (!new_name.empty ()) - { - type_name - = (char *) obstack_copy0 (&objfile->objfile_obstack, - new_name.c_str (), - new_name.length ()); - } + type_name = obstack_strdup (&objfile->objfile_obstack, + new_name); } if (type_name == NULL) { diff --git a/gdb/symfile.c b/gdb/symfile.c index b927de5..8843781 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2596,9 +2596,7 @@ reread_symbols (void) set_objfile_per_bfd (objfile); objfile->original_name - = (char *) obstack_copy0 (&objfile->objfile_obstack, - original_name.c_str (), - original_name.size ()); + = obstack_strdup (&objfile->objfile_obstack, original_name); /* Reset the sym_fns pointer. The ELF reader can change it based on whether .gdb_index is present, and we need it to |