mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-24 04:00:07 +08:00
miscellaneous dwarf.c tidies
* dwarf.c: Leading and trailing whitespace fixes. (free_abbrev_list): New function. (free_all_abbrevs): Use the above. Free cu_abbrev_map here too. (process_abbrev_set): Print actual section name on error. (get_type_abbrev_from_form): Add overflow check. (free_debug_memory): Don't free cu_abbrev_map here.. (process_debug_info): ..or here. Warn on another case of not finding a neeeded abbrev.
This commit is contained in:
188
binutils/dwarf.c
188
binutils/dwarf.c
@ -901,38 +901,41 @@ record_abbrev_list_for_cu (dwarf_vma start, dwarf_vma end, abbrev_list * list)
|
|||||||
next_free_abbrev_map_entry ++;
|
next_free_abbrev_map_entry ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static abbrev_list *
|
||||||
|
free_abbrev_list (abbrev_list *list)
|
||||||
|
{
|
||||||
|
abbrev_entry *abbrv = list->first_abbrev;
|
||||||
|
|
||||||
|
while (abbrv)
|
||||||
|
{
|
||||||
|
abbrev_attr *attr = abbrv->first_attr;
|
||||||
|
|
||||||
|
while (attr)
|
||||||
|
{
|
||||||
|
abbrev_attr *next_attr = attr->next;
|
||||||
|
free (attr);
|
||||||
|
attr = next_attr;
|
||||||
|
}
|
||||||
|
|
||||||
|
abbrev_entry *next_abbrev = abbrv->next;
|
||||||
|
free (abbrv);
|
||||||
|
abbrv = next_abbrev;
|
||||||
|
}
|
||||||
|
|
||||||
|
abbrev_list *next = list->next;
|
||||||
|
free (list);
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_all_abbrevs (void)
|
free_all_abbrevs (void)
|
||||||
{
|
{
|
||||||
abbrev_list * list;
|
while (abbrev_lists)
|
||||||
|
abbrev_lists = free_abbrev_list (abbrev_lists);
|
||||||
|
|
||||||
for (list = abbrev_lists; list != NULL;)
|
free (cu_abbrev_map);
|
||||||
{
|
cu_abbrev_map = NULL;
|
||||||
abbrev_list * next = list->next;
|
next_free_abbrev_map_entry = 0;
|
||||||
abbrev_entry * abbrv;
|
|
||||||
|
|
||||||
for (abbrv = list->first_abbrev; abbrv != NULL;)
|
|
||||||
{
|
|
||||||
abbrev_entry * next_abbrev = abbrv->next;
|
|
||||||
abbrev_attr * attr;
|
|
||||||
|
|
||||||
for (attr = abbrv->first_attr; attr;)
|
|
||||||
{
|
|
||||||
abbrev_attr *next_attr = attr->next;
|
|
||||||
|
|
||||||
free (attr);
|
|
||||||
attr = next_attr;
|
|
||||||
}
|
|
||||||
|
|
||||||
free (abbrv);
|
|
||||||
abbrv = next_abbrev;
|
|
||||||
}
|
|
||||||
|
|
||||||
free (list);
|
|
||||||
list = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
abbrev_lists = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static abbrev_list *
|
static abbrev_list *
|
||||||
@ -1119,7 +1122,7 @@ process_abbrev_set (struct dwarf_section *section,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Report the missing single zero which ends the section. */
|
/* Report the missing single zero which ends the section. */
|
||||||
error (_(".debug_abbrev section not zero terminated\n"));
|
error (_("%s section not zero terminated\n"), section->name);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -2124,7 +2127,8 @@ get_type_abbrev_from_form (unsigned long form,
|
|||||||
case DW_FORM_ref4:
|
case DW_FORM_ref4:
|
||||||
case DW_FORM_ref8:
|
case DW_FORM_ref8:
|
||||||
case DW_FORM_ref_udata:
|
case DW_FORM_ref_udata:
|
||||||
if (uvalue + cu_offset > (size_t) (cu_end - section->start))
|
if (uvalue + cu_offset < uvalue
|
||||||
|
|| uvalue + cu_offset > (size_t) (cu_end - section->start))
|
||||||
{
|
{
|
||||||
warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > CU size %lx\n"),
|
warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > CU size %lx\n"),
|
||||||
uvalue, (long) cu_offset, (long) (cu_end - section->start));
|
uvalue, (long) cu_offset, (long) (cu_end - section->start));
|
||||||
@ -2750,10 +2754,10 @@ read_and_display_attr_value (unsigned long attribute,
|
|||||||
if (form == DW_FORM_loclistx)
|
if (form == DW_FORM_loclistx)
|
||||||
{
|
{
|
||||||
if (dwo)
|
if (dwo)
|
||||||
{
|
{
|
||||||
index = fetch_indexed_value (uvalue, loclists_dwo, 0);
|
index = fetch_indexed_value (uvalue, loclists_dwo, 0);
|
||||||
index += (offset_size == 8) ? 20 : 12;
|
index += (offset_size == 8) ? 20 : 12;
|
||||||
}
|
}
|
||||||
else if (debug_info_p == NULL)
|
else if (debug_info_p == NULL)
|
||||||
{
|
{
|
||||||
index = fetch_indexed_value (uvalue, loclists, 0);
|
index = fetch_indexed_value (uvalue, loclists, 0);
|
||||||
@ -2771,21 +2775,21 @@ read_and_display_attr_value (unsigned long attribute,
|
|||||||
else if (form == DW_FORM_rnglistx)
|
else if (form == DW_FORM_rnglistx)
|
||||||
{
|
{
|
||||||
if (dwo)
|
if (dwo)
|
||||||
{
|
{
|
||||||
index = fetch_indexed_value (uvalue, rnglists_dwo, 0);
|
index = fetch_indexed_value (uvalue, rnglists_dwo, 0);
|
||||||
index += (offset_size == 8) ? 20 : 12;
|
index += (offset_size == 8) ? 20 : 12;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (debug_info_p == NULL)
|
if (debug_info_p == NULL)
|
||||||
base = 0;
|
base = 0;
|
||||||
else
|
else
|
||||||
base = debug_info_p->rnglists_base;
|
base = debug_info_p->rnglists_base;
|
||||||
/* We do not have a cached value this time, so we perform the
|
/* We do not have a cached value this time, so we perform the
|
||||||
computation manually. */
|
computation manually. */
|
||||||
index = fetch_indexed_value (uvalue, rnglists, base);
|
index = fetch_indexed_value (uvalue, rnglists, base);
|
||||||
index += base;
|
index += base;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2836,9 +2840,9 @@ read_and_display_attr_value (unsigned long attribute,
|
|||||||
case DW_AT_rnglists_base:
|
case DW_AT_rnglists_base:
|
||||||
if (debug_info_p->rnglists_base)
|
if (debug_info_p->rnglists_base)
|
||||||
warn (_("CU @ 0x%s has multiple rnglists_base values (0x%s and 0x%s)"),
|
warn (_("CU @ 0x%s has multiple rnglists_base values (0x%s and 0x%s)"),
|
||||||
dwarf_vmatoa ("x", debug_info_p->cu_offset),
|
dwarf_vmatoa ("x", debug_info_p->cu_offset),
|
||||||
dwarf_vmatoa ("x", debug_info_p->rnglists_base),
|
dwarf_vmatoa ("x", debug_info_p->rnglists_base),
|
||||||
dwarf_vmatoa ("x", uvalue));
|
dwarf_vmatoa ("x", uvalue));
|
||||||
debug_info_p->rnglists_base = uvalue;
|
debug_info_p->rnglists_base = uvalue;
|
||||||
break;
|
break;
|
||||||
case DW_AT_str_offsets_base:
|
case DW_AT_str_offsets_base:
|
||||||
@ -2988,7 +2992,7 @@ read_and_display_attr_value (unsigned long attribute,
|
|||||||
case DW_FORM_strx3:
|
case DW_FORM_strx3:
|
||||||
case DW_FORM_strx4:
|
case DW_FORM_strx4:
|
||||||
add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, false,
|
add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, false,
|
||||||
debug_info_p->str_offsets_base),
|
debug_info_p->str_offsets_base),
|
||||||
cu_offset);
|
cu_offset);
|
||||||
break;
|
break;
|
||||||
case DW_FORM_string:
|
case DW_FORM_string:
|
||||||
@ -3022,7 +3026,7 @@ read_and_display_attr_value (unsigned long attribute,
|
|||||||
case DW_FORM_strx3:
|
case DW_FORM_strx3:
|
||||||
case DW_FORM_strx4:
|
case DW_FORM_strx4:
|
||||||
add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false,
|
add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false,
|
||||||
debug_info_p->str_offsets_base),
|
debug_info_p->str_offsets_base),
|
||||||
cu_offset);
|
cu_offset);
|
||||||
break;
|
break;
|
||||||
case DW_FORM_string:
|
case DW_FORM_string:
|
||||||
@ -3653,11 +3657,8 @@ process_debug_info (struct dwarf_section * section,
|
|||||||
introduce (section, false);
|
introduce (section, false);
|
||||||
|
|
||||||
free_all_abbrevs ();
|
free_all_abbrevs ();
|
||||||
free (cu_abbrev_map);
|
|
||||||
cu_abbrev_map = NULL;
|
|
||||||
next_free_abbrev_map_entry = 0;
|
|
||||||
|
|
||||||
/* In order to be able to resolve DW_FORM_ref_attr forms we need
|
/* In order to be able to resolve DW_FORM_ref_addr forms we need
|
||||||
to load *all* of the abbrevs for all CUs in this .debug_info
|
to load *all* of the abbrevs for all CUs in this .debug_info
|
||||||
section. This does effectively mean that we (partially) read
|
section. This does effectively mean that we (partially) read
|
||||||
every CU header twice. */
|
every CU header twice. */
|
||||||
@ -4028,12 +4029,11 @@ process_debug_info (struct dwarf_section * section,
|
|||||||
|
|
||||||
/* Scan through the abbreviation list until we reach the
|
/* Scan through the abbreviation list until we reach the
|
||||||
correct entry. */
|
correct entry. */
|
||||||
if (list == NULL)
|
entry = NULL;
|
||||||
continue;
|
if (list != NULL)
|
||||||
|
for (entry = list->first_abbrev; entry != NULL; entry = entry->next)
|
||||||
for (entry = list->first_abbrev; entry != NULL; entry = entry->next)
|
if (entry->number == abbrev_number)
|
||||||
if (entry->number == abbrev_number)
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
{
|
{
|
||||||
@ -6525,7 +6525,7 @@ display_loc_list (struct dwarf_section *section,
|
|||||||
|
|
||||||
/* Check base address specifiers. */
|
/* Check base address specifiers. */
|
||||||
if (is_max_address (begin, pointer_size)
|
if (is_max_address (begin, pointer_size)
|
||||||
&& !is_max_address (end, pointer_size))
|
&& !is_max_address (end, pointer_size))
|
||||||
{
|
{
|
||||||
base_address = end;
|
base_address = end;
|
||||||
print_dwarf_vma (begin, pointer_size);
|
print_dwarf_vma (begin, pointer_size);
|
||||||
@ -8335,12 +8335,12 @@ display_debug_ranges (struct dwarf_section *section,
|
|||||||
next = section_begin + offset + debug_info_p->rnglists_base;
|
next = section_begin + offset + debug_info_p->rnglists_base;
|
||||||
|
|
||||||
/* If multiple DWARF entities reference the same range then we will
|
/* If multiple DWARF entities reference the same range then we will
|
||||||
have multiple entries in the `range_entries' list for the same
|
have multiple entries in the `range_entries' list for the same
|
||||||
offset. Thanks to the sort above these will all be consecutive in
|
offset. Thanks to the sort above these will all be consecutive in
|
||||||
the `range_entries' list, so we can easily ignore duplicates
|
the `range_entries' list, so we can easily ignore duplicates
|
||||||
here. */
|
here. */
|
||||||
if (i > 0 && last_offset == offset)
|
if (i > 0 && last_offset == offset)
|
||||||
continue;
|
continue;
|
||||||
last_offset = offset;
|
last_offset = offset;
|
||||||
|
|
||||||
if (dwarf_check != 0 && i > 0)
|
if (dwarf_check != 0 && i > 0)
|
||||||
@ -10369,7 +10369,7 @@ display_debug_names (struct dwarf_section *section, void *file)
|
|||||||
break;
|
break;
|
||||||
if (tagno >= 0)
|
if (tagno >= 0)
|
||||||
printf ("%s<%lu>",
|
printf ("%s<%lu>",
|
||||||
(tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
|
(tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
|
||||||
(unsigned long) abbrev_tag);
|
(unsigned long) abbrev_tag);
|
||||||
|
|
||||||
for (entry = abbrev_lookup;
|
for (entry = abbrev_lookup;
|
||||||
@ -11410,8 +11410,8 @@ add_separate_debug_file (const char * filename, void * handle)
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
debuginfod_fetch_separate_debug_info (struct dwarf_section * section,
|
debuginfod_fetch_separate_debug_info (struct dwarf_section * section,
|
||||||
char ** filename,
|
char ** filename,
|
||||||
void * file)
|
void * file)
|
||||||
{
|
{
|
||||||
size_t build_id_len;
|
size_t build_id_len;
|
||||||
unsigned char * build_id;
|
unsigned char * build_id;
|
||||||
@ -11429,14 +11429,14 @@ debuginfod_fetch_separate_debug_info (struct dwarf_section * section,
|
|||||||
|
|
||||||
filelen = strnlen ((const char *)section->start, section->size);
|
filelen = strnlen ((const char *)section->start, section->size);
|
||||||
if (filelen == section->size)
|
if (filelen == section->size)
|
||||||
/* Corrupt debugaltlink. */
|
/* Corrupt debugaltlink. */
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
build_id = section->start + filelen + 1;
|
build_id = section->start + filelen + 1;
|
||||||
build_id_len = section->size - (filelen + 1);
|
build_id_len = section->size - (filelen + 1);
|
||||||
|
|
||||||
if (build_id_len == 0)
|
if (build_id_len == 0)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
@ -11448,25 +11448,25 @@ debuginfod_fetch_separate_debug_info (struct dwarf_section * section,
|
|||||||
|
|
||||||
client = debuginfod_begin ();
|
client = debuginfod_begin ();
|
||||||
if (client == NULL)
|
if (client == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Query debuginfod servers for the target file. If found its path
|
/* Query debuginfod servers for the target file. If found its path
|
||||||
will be stored in filename. */
|
will be stored in filename. */
|
||||||
fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename);
|
fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename);
|
||||||
debuginfod_end (client);
|
debuginfod_end (client);
|
||||||
|
|
||||||
/* Only free build_id if we allocated space for a hex string
|
/* Only free build_id if we allocated space for a hex string
|
||||||
in get_build_id (). */
|
in get_build_id (). */
|
||||||
if (build_id_len == 0)
|
if (build_id_len == 0)
|
||||||
free (build_id);
|
free (build_id);
|
||||||
|
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
{
|
{
|
||||||
/* File successfully retrieved. Close fd since we want to
|
/* File successfully retrieved. Close fd since we want to
|
||||||
use open_debug_file () on filename instead. */
|
use open_debug_file () on filename instead. */
|
||||||
close (fd);
|
close (fd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -11479,7 +11479,7 @@ load_separate_debug_info (const char * main_filename,
|
|||||||
parse_func_type parse_func,
|
parse_func_type parse_func,
|
||||||
check_func_type check_func,
|
check_func_type check_func,
|
||||||
void * func_data,
|
void * func_data,
|
||||||
void * file ATTRIBUTE_UNUSED)
|
void * file ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
const char * separate_filename;
|
const char * separate_filename;
|
||||||
char * debug_filename;
|
char * debug_filename;
|
||||||
@ -11595,11 +11595,11 @@ load_separate_debug_info (const char * main_filename,
|
|||||||
& tmp_filename,
|
& tmp_filename,
|
||||||
file))
|
file))
|
||||||
{
|
{
|
||||||
/* File successfully downloaded from server, replace
|
/* File successfully downloaded from server, replace
|
||||||
debug_filename with the file's path. */
|
debug_filename with the file's path. */
|
||||||
free (debug_filename);
|
free (debug_filename);
|
||||||
debug_filename = tmp_filename;
|
debug_filename = tmp_filename;
|
||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -11771,7 +11771,7 @@ load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED, void * ma
|
|||||||
NSize 0...3 4
|
NSize 0...3 4
|
||||||
DSize 4...7 8+
|
DSize 4...7 8+
|
||||||
Type 8..11 3 (NT_GNU_BUILD_ID)
|
Type 8..11 3 (NT_GNU_BUILD_ID)
|
||||||
Name 12.15 GNU\0
|
Name 12.15 GNU\0
|
||||||
Data 16.... */
|
Data 16.... */
|
||||||
|
|
||||||
/* FIXME: Check the name size, name and type fields. */
|
/* FIXME: Check the name size, name and type fields. */
|
||||||
@ -12079,10 +12079,6 @@ free_debug_memory (void)
|
|||||||
|
|
||||||
free_all_abbrevs ();
|
free_all_abbrevs ();
|
||||||
|
|
||||||
free (cu_abbrev_map);
|
|
||||||
cu_abbrev_map = NULL;
|
|
||||||
next_free_abbrev_map_entry = 0;
|
|
||||||
|
|
||||||
free (shndx_pool);
|
free (shndx_pool);
|
||||||
shndx_pool = NULL;
|
shndx_pool = NULL;
|
||||||
shndx_pool_size = 0;
|
shndx_pool_size = 0;
|
||||||
|
Reference in New Issue
Block a user