aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2/macro.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/dwarf2/macro.c')
-rw-r--r--gdb/dwarf2/macro.c64
1 files changed, 20 insertions, 44 deletions
diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c
index bc781c2..1dc3a9e 100644
--- a/gdb/dwarf2/macro.c
+++ b/gdb/dwarf2/macro.c
@@ -1,6 +1,6 @@
/* Read DWARF macro information
- Copyright (C) 1994-2024 Free Software Foundation, Inc.
+ Copyright (C) 1994-2025 Free Software Foundation, Inc.
Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
Inc. with support from Florida State University (under contract
@@ -35,6 +35,7 @@
#include "macrotab.h"
#include "complaints.h"
#include "objfiles.h"
+#include "gdbsupport/unordered_set.h"
static void
dwarf2_macro_malformed_definition_complaint (const char *arg1)
@@ -160,9 +161,7 @@ parse_macro_definition (struct macro_source_file *file, int line,
/* It's a function-like macro. */
gdb_assert (*p == '(');
std::string name (body, p - body);
- int argc = 0;
- int argv_size = 1;
- char **argv = XNEWVEC (char *, argv_size);
+ std::vector<std::string> argv;
p++;
@@ -178,18 +177,12 @@ parse_macro_definition (struct macro_source_file *file, int line,
p++;
if (! *p || p == arg_start)
- dwarf2_macro_malformed_definition_complaint (body);
- else
{
- /* Make sure argv has room for the new argument. */
- if (argc >= argv_size)
- {
- argv_size *= 2;
- argv = XRESIZEVEC (char *, argv, argv_size);
- }
-
- argv[argc++] = savestring (arg_start, p - arg_start);
+ dwarf2_macro_malformed_definition_complaint (body);
+ return;
}
+ else
+ argv.emplace_back (arg_start, p);
p = consume_improper_spaces (p, body);
@@ -208,16 +201,12 @@ parse_macro_definition (struct macro_source_file *file, int line,
if (*p == ' ')
/* Perfectly formed definition, no complaints. */
- macro_define_function (file, line, name.c_str (),
- argc, (const char **) argv,
- p + 1);
+ macro_define_function (file, line, name.c_str (), argv, p + 1);
else if (*p == '\0')
{
/* Complain, but do define it. */
dwarf2_macro_malformed_definition_complaint (body);
- macro_define_function (file, line, name.c_str (),
- argc, (const char **) argv,
- p);
+ macro_define_function (file, line, name.c_str (), argv, p);
}
else
/* Just complain. */
@@ -226,11 +215,6 @@ parse_macro_definition (struct macro_source_file *file, int line,
else
/* Just complain. */
dwarf2_macro_malformed_definition_complaint (body);
-
- for (int i = 0; i < argc; i++)
- xfree (argv[i]);
-
- xfree (argv);
}
/* Skip some bytes from BYTES according to the form given in FORM.
@@ -275,6 +259,7 @@ skip_form_bytes (bfd *abfd, const gdb_byte *bytes, const gdb_byte *buffer_end,
case DW_FORM_sec_offset:
case DW_FORM_strp:
case DW_FORM_GNU_strp_alt:
+ case DW_FORM_strp_sup:
bytes += offset_size;
break;
@@ -439,7 +424,8 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
struct dwarf2_section_info *str_section,
struct dwarf2_section_info *str_offsets_section,
std::optional<ULONGEST> str_offsets_base,
- htab_t include_hash, struct dwarf2_cu *cu)
+ gdb::unordered_set<const gdb_byte *> &include_hash,
+ struct dwarf2_cu *cu)
{
struct objfile *objfile = per_objfile->objfile;
enum dwarf_macro_record_type macinfo_type;
@@ -518,8 +504,7 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
|| macinfo_type == DW_MACRO_undef_sup
|| section_is_dwz)
{
- dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd,
- true);
+ dwz_file *dwz = per_objfile->per_bfd->get_dwz_file (true);
body = dwz->read_string (objfile, str_offset);
}
@@ -667,7 +652,7 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
complaint (_("macro debug info has an unmatched "
"`close_file' directive"));
else if (current_file->included_by == nullptr
- && producer_is_clang (cu))
+ && cu->producer_is_clang ())
{
/* Clang, until the current version, misplaces some macro
definitions - such as ones defined in the command line,
@@ -714,7 +699,6 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
case DW_MACRO_import_sup:
{
LONGEST offset;
- void **slot;
bfd *include_bfd = abfd;
const struct dwarf2_section_info *include_section = section;
const gdb_byte *include_mac_end = mac_end;
@@ -726,8 +710,7 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
if (macinfo_type == DW_MACRO_import_sup)
{
- dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd,
- true);
+ dwz_file *dwz = per_objfile->per_bfd->get_dwz_file (true);
include_section = &dwz->macro;
include_bfd = include_section->get_bfd_owner ();
@@ -736,9 +719,8 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
}
new_mac_ptr = include_section->buffer + offset;
- slot = htab_find_slot (include_hash, new_mac_ptr, INSERT);
- if (*slot != NULL)
+ if (!include_hash.insert (new_mac_ptr).second)
{
/* This has actually happened; see
http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
@@ -747,8 +729,6 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
}
else
{
- *slot = (void *) new_mac_ptr;
-
dwarf_decode_macro_bytes (per_objfile, builder, include_bfd,
new_mac_ptr, include_mac_end,
current_file, lh, section,
@@ -756,7 +736,7 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
str_section, str_offsets_section,
str_offsets_base, include_hash, cu);
- htab_remove_elt (include_hash, (void *) new_mac_ptr);
+ include_hash.erase (new_mac_ptr);
}
}
break;
@@ -805,7 +785,6 @@ dwarf_decode_macros (dwarf2_per_objfile *per_objfile,
struct macro_source_file *current_file = 0;
enum dwarf_macro_record_type macinfo_type;
const gdb_byte *opcode_definitions[256];
- void **slot;
abfd = section->get_bfd_owner ();
@@ -950,14 +929,11 @@ dwarf_decode_macros (dwarf2_per_objfile *per_objfile,
command-line macro definitions/undefinitions. This flag is unset when we
reach the first DW_MACINFO_start_file entry. */
- htab_up include_hash (htab_create_alloc (1, htab_hash_pointer,
- htab_eq_pointer,
- NULL, xcalloc, xfree));
+ gdb::unordered_set<const gdb_byte *> include_hash;
mac_ptr = section->buffer + offset;
- slot = htab_find_slot (include_hash.get (), mac_ptr, INSERT);
- *slot = (void *) mac_ptr;
+ include_hash.insert (mac_ptr);
dwarf_decode_macro_bytes (per_objfile, builder, abfd, mac_ptr, mac_end,
current_file, lh, section, section_is_gnu, 0,
offset_size, str_section, str_offsets_section,
- str_offsets_base, include_hash.get (), cu);
+ str_offsets_base, include_hash, cu);
}