|
Mark Wielaard |
652537 |
From d9947f2dc0c2cd812f8e64380d5f6f53705a5280 Mon Sep 17 00:00:00 2001
|
|
Mark Wielaard |
652537 |
From: Mark Wielaard <mark@klomp.org>
|
|
Mark Wielaard |
652537 |
Date: Tue, 19 Jan 2021 04:12:33 +0100
|
|
Mark Wielaard |
652537 |
Subject: [PATCH 6/6] debugedit: Handle DWARF-5 debug_line and debug_line_str.
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
Handle the new DWARF5 .debug_line tables and the new DW_FORM_line_strp.
|
|
Mark Wielaard |
652537 |
DWARF5 tables are handled separately from the earlier tables. They
|
|
Mark Wielaard |
652537 |
will never change size, but they do need updates to the .debug_str
|
|
Mark Wielaard |
652537 |
or .debug_line_str references.
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
Based on a patch from Jan Kratochvil <jan.kratochvil@redhat.com>
|
|
Mark Wielaard |
652537 |
---
|
|
Mark Wielaard |
652537 |
tools/debugedit.c | 471 ++++++++++++++++++++++++++++++++++++++++------
|
|
Mark Wielaard |
652537 |
1 file changed, 410 insertions(+), 61 deletions(-)
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
diff --git a/tools/debugedit.c b/tools/debugedit.c
|
|
Mark Wielaard |
652537 |
index be5fee85b..d6a0058e9 100644
|
|
Mark Wielaard |
652537 |
--- a/tools/debugedit.c
|
|
Mark Wielaard |
652537 |
+++ b/tools/debugedit.c
|
|
Mark Wielaard |
652537 |
@@ -103,6 +103,8 @@ static bool need_string_replacement = false;
|
|
Mark Wielaard |
652537 |
/* Whether we need to do any updates of the string indexes (DW_FORM_strp)
|
|
Mark Wielaard |
652537 |
in debug_info for string indexes. */
|
|
Mark Wielaard |
652537 |
static bool need_strp_update = false;
|
|
Mark Wielaard |
652537 |
+/* Likewise for DW_FORM_line_strp. */
|
|
Mark Wielaard |
652537 |
+static bool need_line_strp_update = false;
|
|
Mark Wielaard |
652537 |
/* If the debug_line changes size we will need to update the
|
|
Mark Wielaard |
652537 |
DW_AT_stmt_list attributes indexes in the debug_info. */
|
|
Mark Wielaard |
652537 |
static bool need_stmt_update = false;
|
|
Mark Wielaard |
652537 |
@@ -192,7 +194,7 @@ typedef struct
|
|
Mark Wielaard |
652537 |
const char *filename;
|
|
Mark Wielaard |
652537 |
int lastscn;
|
|
Mark Wielaard |
652537 |
size_t phnum;
|
|
Mark Wielaard |
652537 |
- struct strings strings;
|
|
Mark Wielaard |
652537 |
+ struct strings debug_str, debug_line_str;
|
|
Mark Wielaard |
652537 |
struct debug_lines lines;
|
|
Mark Wielaard |
652537 |
GElf_Shdr shdr[0];
|
|
Mark Wielaard |
652537 |
} DSO;
|
|
Mark Wielaard |
652537 |
@@ -553,10 +555,11 @@ setup_relbuf (DSO *dso, debug_section *sec, int *reltype)
|
|
Mark Wielaard |
652537 |
/* Relocations against section symbols are uninteresting in REL. */
|
|
Mark Wielaard |
652537 |
if (dso->shdr[i].sh_type == SHT_REL && sym.st_value == 0)
|
|
Mark Wielaard |
652537 |
continue;
|
|
Mark Wielaard |
652537 |
- /* Only consider relocations against .debug_str, .debug_line
|
|
Mark Wielaard |
652537 |
- and .debug_abbrev. */
|
|
Mark Wielaard |
652537 |
+ /* Only consider relocations against .debug_str, .debug_line,
|
|
Mark Wielaard |
652537 |
+ .debug_line_str, and .debug_abbrev. */
|
|
Mark Wielaard |
652537 |
if (sym.st_shndx != debug_sections[DEBUG_STR].sec
|
|
Mark Wielaard |
652537 |
&& sym.st_shndx != debug_sections[DEBUG_LINE].sec
|
|
Mark Wielaard |
652537 |
+ && sym.st_shndx != debug_sections[DEBUG_LINE_STR].sec
|
|
Mark Wielaard |
652537 |
&& sym.st_shndx != debug_sections[DEBUG_ABBREV].sec)
|
|
Mark Wielaard |
652537 |
continue;
|
|
Mark Wielaard |
652537 |
rela.r_addend += sym.st_value;
|
|
Mark Wielaard |
652537 |
@@ -768,6 +771,7 @@ no_memory:
|
|
Mark Wielaard |
652537 |
|| (form > DW_FORM_flag_present
|
|
Mark Wielaard |
652537 |
&& !(form == DW_FORM_ref_sig8
|
|
Mark Wielaard |
652537 |
|| form == DW_FORM_data16
|
|
Mark Wielaard |
652537 |
+ || form == DW_FORM_line_strp
|
|
Mark Wielaard |
652537 |
|| form == DW_FORM_implicit_const
|
|
Mark Wielaard |
652537 |
|| form == DW_FORM_addrx
|
|
Mark Wielaard |
652537 |
|| form == DW_FORM_loclistx
|
|
Mark Wielaard |
652537 |
@@ -1049,17 +1053,20 @@ string_find_entry (struct strings *strings, size_t old_idx)
|
|
Mark Wielaard |
652537 |
a replacement file string has been recorded for it, otherwise
|
|
Mark Wielaard |
652537 |
returns false. */
|
|
Mark Wielaard |
652537 |
static bool
|
|
Mark Wielaard |
652537 |
-record_file_string_entry_idx (struct strings *strings, size_t old_idx)
|
|
Mark Wielaard |
652537 |
+record_file_string_entry_idx (bool line_strp, DSO *dso, size_t old_idx)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
+ struct strings *strings = line_strp ? &dso->debug_line_str : &dso->debug_str;
|
|
Mark Wielaard |
652537 |
bool ret = false;
|
|
Mark Wielaard |
652537 |
struct stridxentry *entry = string_find_new_entry (strings, old_idx);
|
|
Mark Wielaard |
652537 |
if (entry != NULL)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- if (old_idx >= debug_sections[DEBUG_STR].size)
|
|
Mark Wielaard |
652537 |
- error (1, 0, "Bad string pointer index %zd", old_idx);
|
|
Mark Wielaard |
652537 |
+ debug_section *sec = &debug_sections[line_strp
|
|
Mark Wielaard |
652537 |
+ ? DEBUG_LINE_STR : DEBUG_STR];
|
|
Mark Wielaard |
652537 |
+ if (old_idx >= sec->size)
|
|
Mark Wielaard |
652537 |
+ error (1, 0, "Bad string pointer index %zd (%s)", old_idx, sec->name);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
Strent *strent;
|
|
Mark Wielaard |
652537 |
- const char *old_str = (char *)debug_sections[DEBUG_STR].data + old_idx;
|
|
Mark Wielaard |
652537 |
+ const char *old_str = (char *)sec->data + old_idx;
|
|
Mark Wielaard |
652537 |
const char *file = skip_dir_prefix (old_str, base_dir);
|
|
Mark Wielaard |
652537 |
if (file == NULL)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
@@ -1103,15 +1110,18 @@ record_file_string_entry_idx (struct strings *strings, size_t old_idx)
|
|
Mark Wielaard |
652537 |
base_dir with dest_dir, just records the existing string associated
|
|
Mark Wielaard |
652537 |
with the index. */
|
|
Mark Wielaard |
652537 |
static void
|
|
Mark Wielaard |
652537 |
-record_existing_string_entry_idx (struct strings *strings, size_t old_idx)
|
|
Mark Wielaard |
652537 |
+record_existing_string_entry_idx (bool line_strp, DSO *dso, size_t old_idx)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
+ struct strings *strings = line_strp ? &dso->debug_line_str : &dso->debug_str;
|
|
Mark Wielaard |
652537 |
struct stridxentry *entry = string_find_new_entry (strings, old_idx);
|
|
Mark Wielaard |
652537 |
if (entry != NULL)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- if (old_idx >= debug_sections[DEBUG_STR].size)
|
|
Mark Wielaard |
652537 |
- error (1, 0, "Bad string pointer index %zd", old_idx);
|
|
Mark Wielaard |
652537 |
+ debug_section *sec = &debug_sections[line_strp
|
|
Mark Wielaard |
652537 |
+ ? DEBUG_LINE_STR : DEBUG_STR];
|
|
Mark Wielaard |
652537 |
+ if (old_idx >= sec->size)
|
|
Mark Wielaard |
652537 |
+ error (1, 0, "Bad string pointer index %zd (%s)", old_idx, sec->name);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- const char *str = (char *)debug_sections[DEBUG_STR].data + old_idx;
|
|
Mark Wielaard |
652537 |
+ const char *str = (char *)sec->data + old_idx;
|
|
Mark Wielaard |
652537 |
Strent *strent = strtab_add_len (strings->str_tab,
|
|
Mark Wielaard |
652537 |
str, strlen (str) + 1);
|
|
Mark Wielaard |
652537 |
if (strent == NULL)
|
|
Mark Wielaard |
652537 |
@@ -1244,13 +1254,28 @@ get_line_table (DSO *dso, size_t off, struct line_table **table)
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
/* version */
|
|
Mark Wielaard |
652537 |
t->version = read_16 (ptr);
|
|
Mark Wielaard |
652537 |
- if (t->version != 2 && t->version != 3 && t->version != 4)
|
|
Mark Wielaard |
652537 |
+ if (t->version != 2 && t->version != 3 && t->version != 4 && t->version != 5)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
error (0, 0, "%s: DWARF version %d unhandled", dso->filename,
|
|
Mark Wielaard |
652537 |
t->version);
|
|
Mark Wielaard |
652537 |
return false;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
+ if (t->version >= 5)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ /* address_size */
|
|
Mark Wielaard |
652537 |
+ assert (ptr_size != 0);
|
|
Mark Wielaard |
652537 |
+ if (ptr_size != read_8 (ptr))
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: .debug_line address size differs from .debug_info",
|
|
Mark Wielaard |
652537 |
+ dso->filename);
|
|
Mark Wielaard |
652537 |
+ return false;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* segment_selector_size */
|
|
Mark Wielaard |
652537 |
+ (void) read_8 (ptr);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
/* header_length */
|
|
Mark Wielaard |
652537 |
unsigned char *endprol = ptr + 4;
|
|
Mark Wielaard |
652537 |
t->header_length = read_32 (ptr);
|
|
Mark Wielaard |
652537 |
@@ -1343,7 +1368,9 @@ edit_dwarf2_line (DSO *dso)
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
linedata->d_size = dso->lines.debug_lines_len;
|
|
Mark Wielaard |
652537 |
linedata->d_buf = dso->lines.line_buf;
|
|
Mark Wielaard |
652537 |
+ debug_sections[DEBUG_LINE].data = linedata->d_buf;
|
|
Mark Wielaard |
652537 |
debug_sections[DEBUG_LINE].size = linedata->d_size;
|
|
Mark Wielaard |
652537 |
+ debug_sections[DEBUG_LINE].elf_data = linedata;
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
/* Make sure the line tables are sorted on the old index. */
|
|
Mark Wielaard |
652537 |
qsort (dso->lines.table, dso->lines.used, sizeof (struct line_table),
|
|
Mark Wielaard |
652537 |
@@ -1483,9 +1510,10 @@ edit_dwarf2_line (DSO *dso)
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
-/* Record or adjust (according to phase) DW_FORM_strp. */
|
|
Mark Wielaard |
652537 |
+/* Record or adjust (according to phase) DW_FORM_strp or DW_FORM_line_strp. */
|
|
Mark Wielaard |
652537 |
static void
|
|
Mark Wielaard |
652537 |
-edit_strp (DSO *dso, unsigned char *ptr, int phase, bool handled_strp)
|
|
Mark Wielaard |
652537 |
+edit_strp (DSO *dso, bool line_strp, unsigned char *ptr, int phase,
|
|
Mark Wielaard |
652537 |
+ bool handled_strp)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
unsigned char *ptr_orig = ptr;
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
@@ -1500,15 +1528,18 @@ edit_strp (DSO *dso, unsigned char *ptr, int phase, bool handled_strp)
|
|
Mark Wielaard |
652537 |
if (! handled_strp)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
size_t idx = do_read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
- record_existing_string_entry_idx (&dso->strings, idx);
|
|
Mark Wielaard |
652537 |
+ record_existing_string_entry_idx (line_strp, dso, idx);
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
- else if (need_strp_update) /* && phase == 1 */
|
|
Mark Wielaard |
652537 |
+ else if (line_strp
|
|
Mark Wielaard |
652537 |
+ ? need_line_strp_update : need_strp_update) /* && phase == 1 */
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
struct stridxentry *entry;
|
|
Mark Wielaard |
652537 |
size_t idx, new_idx;
|
|
Mark Wielaard |
652537 |
+ struct strings *strings = (line_strp
|
|
Mark Wielaard |
652537 |
+ ? &dso->debug_line_str : &dso->debug_str);
|
|
Mark Wielaard |
652537 |
idx = do_read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
- entry = string_find_entry (&dso->strings, idx);
|
|
Mark Wielaard |
652537 |
+ entry = string_find_entry (strings, idx);
|
|
Mark Wielaard |
652537 |
new_idx = strent_offset (entry->entry);
|
|
Mark Wielaard |
652537 |
do_write_32_relocated (ptr, new_idx);
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
@@ -1759,6 +1790,254 @@ read_dwarf4_line (DSO *dso, unsigned char *ptr, char *comp_dir,
|
|
Mark Wielaard |
652537 |
return true;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
+/* Called by read_dwarf5_line first for directories and then file
|
|
Mark Wielaard |
652537 |
+ names as they both have the same format. */
|
|
Mark Wielaard |
652537 |
+static bool
|
|
Mark Wielaard |
652537 |
+read_dwarf5_line_entries (DSO *dso, unsigned char **ptrp,
|
|
Mark Wielaard |
652537 |
+ struct line_table *table, int phase,
|
|
Mark Wielaard |
652537 |
+ char ***dirs, int *ndir,
|
|
Mark Wielaard |
652537 |
+ const char *entry_name)
|
|
Mark Wielaard |
652537 |
+{
|
|
Mark Wielaard |
652537 |
+ /* directory_entry_format_count */
|
|
Mark Wielaard |
652537 |
+ /* file_name_entry_format_count */
|
|
Mark Wielaard |
652537 |
+ unsigned format_count = read_8 (*ptrp);
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ unsigned char *formats = *ptrp;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* directory_entry_format */
|
|
Mark Wielaard |
652537 |
+ /* file_name_entry_format */
|
|
Mark Wielaard |
652537 |
+ for (unsigned formati = 0; formati < format_count; ++formati)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ read_uleb128 (*ptrp);
|
|
Mark Wielaard |
652537 |
+ read_uleb128 (*ptrp);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* directories_count */
|
|
Mark Wielaard |
652537 |
+ /* file_names_count */
|
|
Mark Wielaard |
652537 |
+ unsigned entry_count = read_uleb128 (*ptrp);
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ bool collecting_dirs = dest_dir && phase == 0 && *dirs == NULL;
|
|
Mark Wielaard |
652537 |
+ bool writing_files = dest_dir && phase == 0 && *dirs != NULL;
|
|
Mark Wielaard |
652537 |
+ if (collecting_dirs)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ *ndir = entry_count;
|
|
Mark Wielaard |
652537 |
+ *dirs = malloc (entry_count * sizeof (char *));
|
|
Mark Wielaard |
652537 |
+ if (*dirs == NULL)
|
|
Mark Wielaard |
652537 |
+ error (1, errno, "%s: Could not allocate debug_line dirs",
|
|
Mark Wielaard |
652537 |
+ dso->filename);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* directories */
|
|
Mark Wielaard |
652537 |
+ /* file_names */
|
|
Mark Wielaard |
652537 |
+ for (unsigned entryi = 0; entryi < entry_count; ++entryi)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ char *dir = NULL;
|
|
Mark Wielaard |
652537 |
+ char *file = NULL;;
|
|
Mark Wielaard |
652537 |
+ unsigned char *format_ptr = formats;
|
|
Mark Wielaard |
652537 |
+ for (unsigned formati = 0; formati < format_count; ++formati)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ unsigned lnct = read_uleb128 (format_ptr);
|
|
Mark Wielaard |
652537 |
+ unsigned form = read_uleb128 (format_ptr);
|
|
Mark Wielaard |
652537 |
+ bool handled_form = false;
|
|
Mark Wielaard |
652537 |
+ bool handled_strp = false;
|
|
Mark Wielaard |
652537 |
+ bool line_strp = form == DW_FORM_line_strp;
|
|
Mark Wielaard |
652537 |
+ if (lnct == DW_LNCT_path)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ switch (form)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_strp:
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_line_strp:
|
|
Mark Wielaard |
652537 |
+ if (dest_dir && phase == 0)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ size_t idx = do_read_32_relocated (*ptrp);
|
|
Mark Wielaard |
652537 |
+ if (record_file_string_entry_idx (line_strp, dso, idx))
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ if (line_strp)
|
|
Mark Wielaard |
652537 |
+ need_line_strp_update = true;
|
|
Mark Wielaard |
652537 |
+ else
|
|
Mark Wielaard |
652537 |
+ need_strp_update = true;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ handled_strp = true;
|
|
Mark Wielaard |
652537 |
+ if (collecting_dirs || writing_files)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ debug_section *sec = &debug_sections[line_strp
|
|
Mark Wielaard |
652537 |
+ ? DEBUG_LINE_STR : DEBUG_STR];
|
|
Mark Wielaard |
652537 |
+ if (collecting_dirs)
|
|
Mark Wielaard |
652537 |
+ dir = (char *)sec->data + idx;
|
|
Mark Wielaard |
652537 |
+ if (writing_files)
|
|
Mark Wielaard |
652537 |
+ file = (char *)sec->data + idx;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ default:
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: Unsupported "
|
|
Mark Wielaard |
652537 |
+ ".debug_line %s %u path DW_FORM_0x%x",
|
|
Mark Wielaard |
652537 |
+ dso->filename, entry_name, entryi, form);
|
|
Mark Wielaard |
652537 |
+ return false;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ if (writing_files && lnct == DW_LNCT_directory_index)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ int dirndx;
|
|
Mark Wielaard |
652537 |
+ switch (form)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_udata:
|
|
Mark Wielaard |
652537 |
+ handled_form = true;
|
|
Mark Wielaard |
652537 |
+ dirndx = read_uleb128 (*ptrp);
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_data1:
|
|
Mark Wielaard |
652537 |
+ dirndx = **ptrp;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_data2:
|
|
Mark Wielaard |
652537 |
+ dirndx = do_read_16 (*ptrp);
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_data4:
|
|
Mark Wielaard |
652537 |
+ dirndx = do_read_32 (*ptrp);
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ default:
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: Unsupported "
|
|
Mark Wielaard |
652537 |
+ ".debug_line %s %u dirndx DW_FORM_0x%x",
|
|
Mark Wielaard |
652537 |
+ dso->filename, entry_name, entryi, form);
|
|
Mark Wielaard |
652537 |
+ return false;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ if (dirndx > *ndir)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: Bad dir number %u in .debug_line %s",
|
|
Mark Wielaard |
652537 |
+ dso->filename, entryi, entry_name);
|
|
Mark Wielaard |
652537 |
+ return false;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ dir = (*dirs)[dirndx];
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ switch (form)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_strp:
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_line_strp:
|
|
Mark Wielaard |
652537 |
+ edit_strp (dso, line_strp, *ptrp, phase, handled_strp);
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ if (!handled_form)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ switch (skip_form (dso, &form, ptrp))
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ case FORM_OK:
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case FORM_ERROR:
|
|
Mark Wielaard |
652537 |
+ return false;
|
|
Mark Wielaard |
652537 |
+ case FORM_INDIRECT:
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: Unsupported "
|
|
Mark Wielaard |
652537 |
+ ".debug_line %s %u DW_FORM_indirect",
|
|
Mark Wielaard |
652537 |
+ dso->filename, entry_name, entryi);
|
|
Mark Wielaard |
652537 |
+ return false;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ if (collecting_dirs)
|
|
Mark Wielaard |
652537 |
+ (*dirs)[entryi] = dir;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ if (writing_files)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ char *comp_dir = (*dirs)[0];
|
|
Mark Wielaard |
652537 |
+ size_t comp_dir_len = strlen(comp_dir);
|
|
Mark Wielaard |
652537 |
+ size_t file_len = strlen (file);
|
|
Mark Wielaard |
652537 |
+ size_t dir_len = strlen (dir);
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ char *s = malloc (comp_dir_len + 1 + file_len + 1 + dir_len + 1);
|
|
Mark Wielaard |
652537 |
+ if (s == NULL)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ error (0, ENOMEM, "%s: Reading file table", dso->filename);
|
|
Mark Wielaard |
652537 |
+ return false;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ if (file[0] == '/')
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ memcpy (s, file, file_len + 1);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ else if (dir[0] == '/')
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ memcpy (s, dir, dir_len);
|
|
Mark Wielaard |
652537 |
+ s[dir_len] = '/';
|
|
Mark Wielaard |
652537 |
+ memcpy (s + dir_len + 1, file, file_len + 1);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ else
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ char *p = s;
|
|
Mark Wielaard |
652537 |
+ if (comp_dir_len != 0)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ memcpy (s, comp_dir, comp_dir_len);
|
|
Mark Wielaard |
652537 |
+ s[comp_dir_len] = '/';
|
|
Mark Wielaard |
652537 |
+ p += comp_dir_len + 1;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ memcpy (p, dir, dir_len);
|
|
Mark Wielaard |
652537 |
+ p[dir_len] = '/';
|
|
Mark Wielaard |
652537 |
+ memcpy (p + dir_len + 1, file, file_len + 1);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ canonicalize_path (s, s);
|
|
Mark Wielaard |
652537 |
+ if (list_file_fd != -1)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ const char *p = NULL;
|
|
Mark Wielaard |
652537 |
+ if (base_dir == NULL)
|
|
Mark Wielaard |
652537 |
+ p = s;
|
|
Mark Wielaard |
652537 |
+ else
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ p = skip_dir_prefix (s, base_dir);
|
|
Mark Wielaard |
652537 |
+ if (p == NULL && dest_dir != NULL)
|
|
Mark Wielaard |
652537 |
+ p = skip_dir_prefix (s, dest_dir);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ if (p)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ size_t size = strlen (p) + 1;
|
|
Mark Wielaard |
652537 |
+ while (size > 0)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ ssize_t ret = write (list_file_fd, p, size);
|
|
Mark Wielaard |
652537 |
+ if (ret == -1)
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ size -= ret;
|
|
Mark Wielaard |
652537 |
+ p += ret;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ free (s);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ return true;
|
|
Mark Wielaard |
652537 |
+}
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+/* Part of read_dwarf2_line processing DWARF-5. */
|
|
Mark Wielaard |
652537 |
+static bool
|
|
Mark Wielaard |
652537 |
+read_dwarf5_line (DSO *dso, unsigned char *ptr, struct line_table *table,
|
|
Mark Wielaard |
652537 |
+ int phase)
|
|
Mark Wielaard |
652537 |
+{
|
|
Mark Wielaard |
652537 |
+ char **dirs = NULL;
|
|
Mark Wielaard |
652537 |
+ int ndir;
|
|
Mark Wielaard |
652537 |
+ /* Skip header. */
|
|
Mark Wielaard |
652537 |
+ ptr += (4 /* unit len */
|
|
Mark Wielaard |
652537 |
+ + 2 /* version */
|
|
Mark Wielaard |
652537 |
+ + (table->version < 5 ? 0 : 0
|
|
Mark Wielaard |
652537 |
+ + 1 /* address_size */
|
|
Mark Wielaard |
652537 |
+ + 1 /* segment_selector*/)
|
|
Mark Wielaard |
652537 |
+ + 4 /* header len */
|
|
Mark Wielaard |
652537 |
+ + 1 /* min instr len */
|
|
Mark Wielaard |
652537 |
+ + (table->version >= 4) /* max op per instr, if version >= 4 */
|
|
Mark Wielaard |
652537 |
+ + 1 /* default is stmt */
|
|
Mark Wielaard |
652537 |
+ + 1 /* line base */
|
|
Mark Wielaard |
652537 |
+ + 1 /* line range */
|
|
Mark Wielaard |
652537 |
+ + 1 /* opcode base */
|
|
Mark Wielaard |
652537 |
+ + table->opcode_base - 1); /* opcode len table */
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ bool retval = (read_dwarf5_line_entries (dso, &ptr, table, phase,
|
|
Mark Wielaard |
652537 |
+ &dirs, &ndir, "directory")
|
|
Mark Wielaard |
652537 |
+ && read_dwarf5_line_entries (dso, &ptr, table, phase,
|
|
Mark Wielaard |
652537 |
+ &dirs, &ndir, "file name"));
|
|
Mark Wielaard |
652537 |
+ free (dirs);
|
|
Mark Wielaard |
652537 |
+ return retval;
|
|
Mark Wielaard |
652537 |
+}
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
/* Called during phase zero for each debug_line table referenced from
|
|
Mark Wielaard |
652537 |
.debug_info. Outputs all source files seen and records any
|
|
Mark Wielaard |
652537 |
adjustments needed in the debug_list data structures. Returns true
|
|
Mark Wielaard |
652537 |
@@ -1778,6 +2057,9 @@ read_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir)
|
|
Mark Wielaard |
652537 |
ptr = debug_sections[DEBUG_LINE].data + off;
|
|
Mark Wielaard |
652537 |
ptr += (4 /* unit len */
|
|
Mark Wielaard |
652537 |
+ 2 /* version */
|
|
Mark Wielaard |
652537 |
+ + (table->version < 5 ? 0 : 0
|
|
Mark Wielaard |
652537 |
+ + 1 /* address_size */
|
|
Mark Wielaard |
652537 |
+ + 1 /* segment_selector*/)
|
|
Mark Wielaard |
652537 |
+ 4 /* header len */
|
|
Mark Wielaard |
652537 |
+ 1 /* min instr len */
|
|
Mark Wielaard |
652537 |
+ (table->version >= 4) /* max op per instr, if version >= 4 */
|
|
Mark Wielaard |
652537 |
@@ -1787,8 +2069,13 @@ read_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir)
|
|
Mark Wielaard |
652537 |
+ 1 /* opcode base */
|
|
Mark Wielaard |
652537 |
+ table->opcode_base - 1); /* opcode len table */
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- if (! read_dwarf4_line (dso, ptr, comp_dir, table))
|
|
Mark Wielaard |
652537 |
- return false;
|
|
Mark Wielaard |
652537 |
+ /* DWARF version 5 line tables won't change size. But they might need
|
|
Mark Wielaard |
652537 |
+ [line]strp recording/updates. Handle that part later. */
|
|
Mark Wielaard |
652537 |
+ if (table->version < 5)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ if (! read_dwarf4_line (dso, ptr, comp_dir, table))
|
|
Mark Wielaard |
652537 |
+ return false;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
dso->lines.debug_lines_len += 4 + table->unit_length + table->size_diff;
|
|
Mark Wielaard |
652537 |
return table->replace_dirs || table->replace_files;
|
|
Mark Wielaard |
652537 |
@@ -1807,20 +2094,22 @@ find_new_list_offs (struct debug_lines *lines, size_t idx)
|
|
Mark Wielaard |
652537 |
return table->new_idx;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
-/* Read DW_FORM_strp collecting compilation directory. */
|
|
Mark Wielaard |
652537 |
+/* Read DW_FORM_strp or DW_FORM_line_strp collecting compilation directory. */
|
|
Mark Wielaard |
652537 |
static void
|
|
Mark Wielaard |
652537 |
-edit_attributes_str_comp_dir (DSO *dso, unsigned char **ptrp, int phase,
|
|
Mark Wielaard |
652537 |
- char **comp_dirp, bool *handled_strpp)
|
|
Mark Wielaard |
652537 |
+edit_attributes_str_comp_dir (bool line_strp, DSO *dso, unsigned char **ptrp,
|
|
Mark Wielaard |
652537 |
+ int phase, char **comp_dirp, bool *handled_strpp)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
const char *dir;
|
|
Mark Wielaard |
652537 |
size_t idx = do_read_32_relocated (*ptrp);
|
|
Mark Wielaard |
652537 |
/* In phase zero we collect the comp_dir. */
|
|
Mark Wielaard |
652537 |
if (phase == 0)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- if (idx >= debug_sections[DEBUG_STR].size)
|
|
Mark Wielaard |
652537 |
- error (1, 0, "%s: Bad string pointer index %zd for comp_dir",
|
|
Mark Wielaard |
652537 |
- dso->filename, idx);
|
|
Mark Wielaard |
652537 |
- dir = (char *) debug_sections[DEBUG_STR].data + idx;
|
|
Mark Wielaard |
652537 |
+ debug_section *sec = &debug_sections[line_strp
|
|
Mark Wielaard |
652537 |
+ ? DEBUG_LINE_STR : DEBUG_STR];
|
|
Mark Wielaard |
652537 |
+ if (sec->data == NULL || idx >= debug_sections[DEBUG_STR].size)
|
|
Mark Wielaard |
652537 |
+ error (1, 0, "%s: Bad string pointer index %zd for comp_dir (%s)",
|
|
Mark Wielaard |
652537 |
+ dso->filename, idx, sec->name);
|
|
Mark Wielaard |
652537 |
+ dir = (char *) sec->data + idx;
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
free (*comp_dirp);
|
|
Mark Wielaard |
652537 |
*comp_dirp = strdup (dir);
|
|
Mark Wielaard |
652537 |
@@ -1828,8 +2117,13 @@ edit_attributes_str_comp_dir (DSO *dso, unsigned char **ptrp, int phase,
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
if (dest_dir != NULL && phase == 0)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- if (record_file_string_entry_idx (&dso->strings, idx))
|
|
Mark Wielaard |
652537 |
- need_strp_update = true;
|
|
Mark Wielaard |
652537 |
+ if (record_file_string_entry_idx (line_strp, dso, idx))
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ if (line_strp)
|
|
Mark Wielaard |
652537 |
+ need_line_strp_update = true;
|
|
Mark Wielaard |
652537 |
+ else
|
|
Mark Wielaard |
652537 |
+ need_strp_update = true;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
*handled_strpp = true;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
@@ -1937,17 +2231,24 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
- else if (form == DW_FORM_strp &&
|
|
Mark Wielaard |
652537 |
- debug_sections[DEBUG_STR].data)
|
|
Mark Wielaard |
652537 |
- edit_attributes_str_comp_dir (dso, &ptr, phase, &comp_dir,
|
|
Mark Wielaard |
652537 |
+ else if (form == DW_FORM_strp)
|
|
Mark Wielaard |
652537 |
+ edit_attributes_str_comp_dir (false /* line_strp */, dso,
|
|
Mark Wielaard |
652537 |
+ &ptr, phase, &comp_dir,
|
|
Mark Wielaard |
652537 |
&handled_strp);
|
|
Mark Wielaard |
652537 |
+ else if (form == DW_FORM_line_strp)
|
|
Mark Wielaard |
652537 |
+ edit_attributes_str_comp_dir (true /* line_strp */, dso, &ptr,
|
|
Mark Wielaard |
652537 |
+ phase, &comp_dir, &handled_strp);
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
else if ((t->tag == DW_TAG_compile_unit
|
|
Mark Wielaard |
652537 |
|| t->tag == DW_TAG_partial_unit)
|
|
Mark Wielaard |
652537 |
- && t->attr[i].attr == DW_AT_name
|
|
Mark Wielaard |
652537 |
- && form == DW_FORM_strp
|
|
Mark Wielaard |
652537 |
- && debug_sections[DEBUG_STR].data)
|
|
Mark Wielaard |
652537 |
+ && ((form == DW_FORM_strp
|
|
Mark Wielaard |
652537 |
+ && debug_sections[DEBUG_STR].data)
|
|
Mark Wielaard |
652537 |
+ || (form == DW_FORM_line_strp
|
|
Mark Wielaard |
652537 |
+ && debug_sections[DEBUG_LINE_STR].data))
|
|
Mark Wielaard |
652537 |
+ && t->attr[i].attr == DW_AT_name)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
+ bool line_strp = form == DW_FORM_line_strp;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
/* DW_AT_name is the primary file for this compile
|
|
Mark Wielaard |
652537 |
unit. If starting with / it is a full path name.
|
|
Mark Wielaard |
652537 |
Note that we don't handle DW_FORM_string in this
|
|
Mark Wielaard |
652537 |
@@ -1957,11 +2258,14 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
|
|
Mark Wielaard |
652537 |
/* In phase zero we will look for a comp_dir to use. */
|
|
Mark Wielaard |
652537 |
if (phase == 0)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- if (idx >= debug_sections[DEBUG_STR].size)
|
|
Mark Wielaard |
652537 |
+ debug_section *sec = &debug_sections[line_strp
|
|
Mark Wielaard |
652537 |
+ ? DEBUG_LINE_STR
|
|
Mark Wielaard |
652537 |
+ : DEBUG_STR];
|
|
Mark Wielaard |
652537 |
+ if (idx >= sec->size)
|
|
Mark Wielaard |
652537 |
error (1, 0,
|
|
Mark Wielaard |
652537 |
- "%s: Bad string pointer index %zd for unit name",
|
|
Mark Wielaard |
652537 |
- dso->filename, idx);
|
|
Mark Wielaard |
652537 |
- char *name = (char *) debug_sections[DEBUG_STR].data + idx;
|
|
Mark Wielaard |
652537 |
+ "%s: Bad string pointer index %zd for unit name (%s)",
|
|
Mark Wielaard |
652537 |
+ dso->filename, idx, sec->name);
|
|
Mark Wielaard |
652537 |
+ char *name = (char *) sec->data + idx;
|
|
Mark Wielaard |
652537 |
if (*name == '/' && comp_dir == NULL)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
char *enddir = strrchr (name, '/');
|
|
Mark Wielaard |
652537 |
@@ -1982,8 +2286,13 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
|
|
Mark Wielaard |
652537 |
pass (1) stores it (the new index). */
|
|
Mark Wielaard |
652537 |
if (dest_dir && phase == 0)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- if (record_file_string_entry_idx (&dso->strings, idx))
|
|
Mark Wielaard |
652537 |
- need_strp_update = true;
|
|
Mark Wielaard |
652537 |
+ if (record_file_string_entry_idx (line_strp, dso, idx))
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ if (line_strp)
|
|
Mark Wielaard |
652537 |
+ need_line_strp_update = true;
|
|
Mark Wielaard |
652537 |
+ else
|
|
Mark Wielaard |
652537 |
+ need_strp_update = true;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
handled_strp = true;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
@@ -1991,7 +2300,10 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
|
|
Mark Wielaard |
652537 |
switch (form)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
case DW_FORM_strp:
|
|
Mark Wielaard |
652537 |
- edit_strp (dso, ptr, phase, handled_strp);
|
|
Mark Wielaard |
652537 |
+ edit_strp (dso, false /* line_strp */, ptr, phase, handled_strp);
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_line_strp:
|
|
Mark Wielaard |
652537 |
+ edit_strp (dso, true /* line_strp */, ptr, phase, handled_strp);
|
|
Mark Wielaard |
652537 |
break;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
@@ -2196,11 +2508,11 @@ edit_info (DSO *dso, int phase, struct debug_section *sec)
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
/* Rebuild .debug_str. */
|
|
Mark Wielaard |
652537 |
static void
|
|
Mark Wielaard |
652537 |
-edit_dwarf2_any_str (DSO *dso)
|
|
Mark Wielaard |
652537 |
+edit_dwarf2_any_str (DSO *dso, struct strings *strings, debug_section *secp)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- Strtab *strtab = dso->strings.str_tab;
|
|
Mark Wielaard |
652537 |
- Elf_Data *strdata = debug_sections[DEBUG_STR].elf_data;
|
|
Mark Wielaard |
652537 |
- int strndx = debug_sections[DEBUG_STR].sec;
|
|
Mark Wielaard |
652537 |
+ Strtab *strtab = strings->str_tab;
|
|
Mark Wielaard |
652537 |
+ Elf_Data *strdata = secp->elf_data;
|
|
Mark Wielaard |
652537 |
+ int strndx = secp->sec;
|
|
Mark Wielaard |
652537 |
Elf_Scn *strscn = dso->scn[strndx];
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
/* Out with the old. */
|
|
Mark Wielaard |
652537 |
@@ -2212,8 +2524,8 @@ edit_dwarf2_any_str (DSO *dso)
|
|
Mark Wielaard |
652537 |
but the old ebl version will just abort on out of
|
|
Mark Wielaard |
652537 |
memory... */
|
|
Mark Wielaard |
652537 |
strtab_finalize (strtab, strdata);
|
|
Mark Wielaard |
652537 |
- debug_sections[DEBUG_STR].size = strdata->d_size;
|
|
Mark Wielaard |
652537 |
- dso->strings.str_buf = strdata->d_buf;
|
|
Mark Wielaard |
652537 |
+ secp->size = strdata->d_size;
|
|
Mark Wielaard |
652537 |
+ strings->str_buf = strdata->d_buf;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
static int
|
|
Mark Wielaard |
652537 |
@@ -2359,12 +2671,14 @@ edit_dwarf2 (DSO *dso)
|
|
Mark Wielaard |
652537 |
bool info_rel_updated = false;
|
|
Mark Wielaard |
652537 |
bool types_rel_updated = false;
|
|
Mark Wielaard |
652537 |
bool macro_rel_updated = false;
|
|
Mark Wielaard |
652537 |
+ bool line_rel_updated = false;
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
for (phase = 0; phase < 2; phase++)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
/* If we don't need to update anyhing, skip phase 1. */
|
|
Mark Wielaard |
652537 |
if (phase == 1
|
|
Mark Wielaard |
652537 |
&& !need_strp_update
|
|
Mark Wielaard |
652537 |
+ && !need_line_strp_update
|
|
Mark Wielaard |
652537 |
&& !need_string_replacement
|
|
Mark Wielaard |
652537 |
&& !need_stmt_update)
|
|
Mark Wielaard |
652537 |
break;
|
|
Mark Wielaard |
652537 |
@@ -2582,15 +2896,14 @@ edit_dwarf2 (DSO *dso)
|
|
Mark Wielaard |
652537 |
if (phase == 0)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
size_t idx = read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
- record_existing_string_entry_idx (&dso->strings,
|
|
Mark Wielaard |
652537 |
- idx);
|
|
Mark Wielaard |
652537 |
+ record_existing_string_entry_idx (false, dso, idx);
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
else
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
struct stridxentry *entry;
|
|
Mark Wielaard |
652537 |
size_t idx, new_idx;
|
|
Mark Wielaard |
652537 |
idx = do_read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
- entry = string_find_entry (&dso->strings, idx);
|
|
Mark Wielaard |
652537 |
+ entry = string_find_entry (&dso->debug_str, idx);
|
|
Mark Wielaard |
652537 |
new_idx = strent_offset (entry->entry);
|
|
Mark Wielaard |
652537 |
write_32_relocated (ptr, new_idx);
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
@@ -2610,24 +2923,50 @@ edit_dwarf2 (DSO *dso)
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- /* Same for the debug_str section. Make sure everything is
|
|
Mark Wielaard |
652537 |
- in place for phase 1 updating of debug_info
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* Now handle all the DWARF5 line tables, they contain strp
|
|
Mark Wielaard |
652537 |
+ and/or line_strp entries that need to be registered/rewritten. */
|
|
Mark Wielaard |
652537 |
+ setup_relbuf(dso, &debug_sections[DEBUG_LINE], &reltype);
|
|
Mark Wielaard |
652537 |
+ rel_updated = false;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* edit_dwarf2_line will have set this up, unless there are no
|
|
Mark Wielaard |
652537 |
+ moved/resized (DWARF4) lines. In which case we can just use
|
|
Mark Wielaard |
652537 |
+ the original section data. new_idx will have been setup
|
|
Mark Wielaard |
652537 |
+ correctly, even if it is the same as old_idx. */
|
|
Mark Wielaard |
652537 |
+ unsigned char *line_buf = (unsigned char *)dso->lines.line_buf;
|
|
Mark Wielaard |
652537 |
+ if (line_buf == NULL)
|
|
Mark Wielaard |
652537 |
+ line_buf = debug_sections[DEBUG_LINE].data;
|
|
Mark Wielaard |
652537 |
+ for (int ldx = 0; ldx < dso->lines.used; ldx++)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ struct line_table *t = &dso->lines.table[ldx];
|
|
Mark Wielaard |
652537 |
+ if (t->version >= 5)
|
|
Mark Wielaard |
652537 |
+ read_dwarf5_line (dso, line_buf + t->new_idx, t, phase);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ if (rel_updated)
|
|
Mark Wielaard |
652537 |
+ line_rel_updated = true;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* Same for the debug_str and debug_line_str sections.
|
|
Mark Wielaard |
652537 |
+ Make sure everything is in place for phase 1 updating of debug_info
|
|
Mark Wielaard |
652537 |
references. */
|
|
Mark Wielaard |
652537 |
if (phase == 0 && need_strp_update)
|
|
Mark Wielaard |
652537 |
- edit_dwarf2_any_str (dso);
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
+ edit_dwarf2_any_str (dso, &dso->debug_str,
|
|
Mark Wielaard |
652537 |
+ &debug_sections[DEBUG_STR]);
|
|
Mark Wielaard |
652537 |
+ if (phase == 0 && need_line_strp_update)
|
|
Mark Wielaard |
652537 |
+ edit_dwarf2_any_str (dso, &dso->debug_line_str,
|
|
Mark Wielaard |
652537 |
+ &debug_sections[DEBUG_LINE_STR]);
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
/* After phase 1 we might have rewritten the debug_info with
|
|
Mark Wielaard |
652537 |
new strp, strings and/or linep offsets. */
|
|
Mark Wielaard |
652537 |
- if (need_strp_update || need_string_replacement || need_stmt_update) {
|
|
Mark Wielaard |
652537 |
+ if (need_strp_update || need_line_strp_update
|
|
Mark Wielaard |
652537 |
+ || need_string_replacement || need_stmt_update) {
|
|
Mark Wielaard |
652537 |
dirty_section (DEBUG_INFO);
|
|
Mark Wielaard |
652537 |
if (debug_sections[DEBUG_TYPES].data != NULL)
|
|
Mark Wielaard |
652537 |
dirty_section (DEBUG_TYPES);
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
if (need_strp_update || need_stmt_update)
|
|
Mark Wielaard |
652537 |
dirty_section (DEBUG_MACRO);
|
|
Mark Wielaard |
652537 |
- if (need_stmt_update)
|
|
Mark Wielaard |
652537 |
+ if (need_stmt_update || need_line_strp_update)
|
|
Mark Wielaard |
652537 |
dirty_section (DEBUG_LINE);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
/* Update any relocations addends we might have touched. */
|
|
Mark Wielaard |
652537 |
@@ -2653,6 +2992,9 @@ edit_dwarf2 (DSO *dso)
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
+ if (line_rel_updated)
|
|
Mark Wielaard |
652537 |
+ update_rela_data (dso, &debug_sections[DEBUG_LINE]);
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
return 0;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
@@ -2745,7 +3087,8 @@ fdopen_dso (int fd, const char *name)
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
dso->filename = (const char *) strdup (name);
|
|
Mark Wielaard |
652537 |
- setup_strings (&dso->strings);
|
|
Mark Wielaard |
652537 |
+ setup_strings (&dso->debug_str);
|
|
Mark Wielaard |
652537 |
+ setup_strings (&dso->debug_line_str);
|
|
Mark Wielaard |
652537 |
setup_lines (&dso->lines);
|
|
Mark Wielaard |
652537 |
return dso;
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
@@ -2753,7 +3096,8 @@ error_out:
|
|
Mark Wielaard |
652537 |
if (dso)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
free ((char *) dso->filename);
|
|
Mark Wielaard |
652537 |
- destroy_strings (&dso->strings);
|
|
Mark Wielaard |
652537 |
+ destroy_strings (&dso->debug_str);
|
|
Mark Wielaard |
652537 |
+ destroy_strings (&dso->debug_line_str);
|
|
Mark Wielaard |
652537 |
destroy_lines (&dso->lines);
|
|
Mark Wielaard |
652537 |
free (dso);
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
@@ -3034,7 +3378,9 @@ main (int argc, char *argv[])
|
|
Mark Wielaard |
652537 |
in elfutils before 0.169 we will have to update and write out all
|
|
Mark Wielaard |
652537 |
section data if any data has changed (when ELF_F_LAYOUT was
|
|
Mark Wielaard |
652537 |
set). https://sourceware.org/bugzilla/show_bug.cgi?id=21199 */
|
|
Mark Wielaard |
652537 |
- bool need_update = need_strp_update || need_stmt_update;
|
|
Mark Wielaard |
652537 |
+ bool need_update = (need_strp_update
|
|
Mark Wielaard |
652537 |
+ || need_line_strp_update
|
|
Mark Wielaard |
652537 |
+ || need_stmt_update);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
#if !_ELFUTILS_PREREQ (0, 169)
|
|
Mark Wielaard |
652537 |
/* string replacements or build_id updates don't change section size. */
|
|
Mark Wielaard |
652537 |
@@ -3106,10 +3452,12 @@ main (int argc, char *argv[])
|
|
Mark Wielaard |
652537 |
GElf_Xword sec_size = shdr->sh_size;
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
/* We might have changed the size (and content) of the
|
|
Mark Wielaard |
652537 |
- debug_str or debug_line section. */
|
|
Mark Wielaard |
652537 |
+ debug_str, debug_line_str or debug_line section. */
|
|
Mark Wielaard |
652537 |
size_t secnum = elf_ndxscn (scn);
|
|
Mark Wielaard |
652537 |
if (secnum == debug_sections[DEBUG_STR].sec)
|
|
Mark Wielaard |
652537 |
sec_size = debug_sections[DEBUG_STR].size;
|
|
Mark Wielaard |
652537 |
+ if (secnum == debug_sections[DEBUG_LINE_STR].sec)
|
|
Mark Wielaard |
652537 |
+ sec_size = debug_sections[DEBUG_LINE_STR].size;
|
|
Mark Wielaard |
652537 |
if (secnum == debug_sections[DEBUG_LINE].sec)
|
|
Mark Wielaard |
652537 |
sec_size = debug_sections[DEBUG_LINE].size;
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
@@ -3179,7 +3527,8 @@ main (int argc, char *argv[])
|
|
Mark Wielaard |
652537 |
chmod (file, stat_buf.st_mode);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
free ((char *) dso->filename);
|
|
Mark Wielaard |
652537 |
- destroy_strings (&dso->strings);
|
|
Mark Wielaard |
652537 |
+ destroy_strings (&dso->debug_str);
|
|
Mark Wielaard |
652537 |
+ destroy_strings (&dso->debug_line_str);
|
|
Mark Wielaard |
652537 |
destroy_lines (&dso->lines);
|
|
Mark Wielaard |
652537 |
free (dso);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
--
|
|
Mark Wielaard |
652537 |
2.18.4
|
|
Mark Wielaard |
652537 |
|