|
Mark Wielaard |
652537 |
From bab443ab4f756ef80f814af0353143f41e90e6a6 Mon Sep 17 00:00:00 2001
|
|
Mark Wielaard |
652537 |
From: Jan Kratochvil <jan.kratochvil@redhat.com>
|
|
Mark Wielaard |
652537 |
Date: Mon, 17 Aug 2020 21:58:19 +0200
|
|
Mark Wielaard |
652537 |
Subject: [PATCH 4/6] [NFC] debugedit: Move code to separate functions.
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
New functions edit_strp, skip_form and edit_attributes_str_comp_dir
|
|
Mark Wielaard |
652537 |
called by edit_attributes.
|
|
Mark Wielaard |
652537 |
Split part of read_dwarf2_line into a read_dwarf4_line function.
|
|
Mark Wielaard |
652537 |
New function edit_dwarf2_any_str called by edit_dwarf2 at the end of
|
|
Mark Wielaard |
652537 |
phase 0 to rebuild .debug_str.
|
|
Mark Wielaard |
652537 |
---
|
|
Mark Wielaard |
652537 |
tools/debugedit.c | 367 ++++++++++++++++++++++++++--------------------
|
|
Mark Wielaard |
652537 |
1 file changed, 212 insertions(+), 155 deletions(-)
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
diff --git a/tools/debugedit.c b/tools/debugedit.c
|
|
Mark Wielaard |
652537 |
index 87c1cd622..7464883c5 100644
|
|
Mark Wielaard |
652537 |
--- a/tools/debugedit.c
|
|
Mark Wielaard |
652537 |
+++ b/tools/debugedit.c
|
|
Mark Wielaard |
652537 |
@@ -1457,37 +1457,128 @@ edit_dwarf2_line (DSO *dso)
|
|
Mark Wielaard |
652537 |
}
|
|
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 |
- if line_table needs to be rewrite either the dir or file paths. */
|
|
Mark Wielaard |
652537 |
+/* Record or adjust (according to phase) DW_FORM_strp. */
|
|
Mark Wielaard |
652537 |
+static void
|
|
Mark Wielaard |
652537 |
+edit_strp (DSO *dso, unsigned char *ptr, int phase, bool handled_strp)
|
|
Mark Wielaard |
652537 |
+{
|
|
Mark Wielaard |
652537 |
+ unsigned char *ptr_orig = ptr;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* In the first pass we collect all strings, in the
|
|
Mark Wielaard |
652537 |
+ second we put the new references back (if there are
|
|
Mark Wielaard |
652537 |
+ any changes). */
|
|
Mark Wielaard |
652537 |
+ if (phase == 0)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ /* handled_strp is set for attributes referring to
|
|
Mark Wielaard |
652537 |
+ files. If it is set the string is already
|
|
Mark Wielaard |
652537 |
+ recorded. */
|
|
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 |
+ }
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+ else if (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 |
+ idx = do_read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
+ entry = string_find_entry (&dso->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 |
+
|
|
Mark Wielaard |
652537 |
+ assert (ptr == ptr_orig);
|
|
Mark Wielaard |
652537 |
+}
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+/* Adjust *PTRP after the current *FORMP, update *FORMP for FORM_INDIRECT. */
|
|
Mark Wielaard |
652537 |
+static enum { FORM_OK, FORM_ERROR, FORM_INDIRECT }
|
|
Mark Wielaard |
652537 |
+skip_form (DSO *dso, uint32_t *formp, unsigned char **ptrp)
|
|
Mark Wielaard |
652537 |
+{
|
|
Mark Wielaard |
652537 |
+ size_t len = 0;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ switch (*formp)
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_ref_addr:
|
|
Mark Wielaard |
652537 |
+ if (cu_version == 2)
|
|
Mark Wielaard |
652537 |
+ *ptrp += ptr_size;
|
|
Mark Wielaard |
652537 |
+ else
|
|
Mark Wielaard |
652537 |
+ *ptrp += 4;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_flag_present:
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_addr:
|
|
Mark Wielaard |
652537 |
+ *ptrp += ptr_size;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_ref1:
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_flag:
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_data1:
|
|
Mark Wielaard |
652537 |
+ ++*ptrp;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_ref2:
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_data2:
|
|
Mark Wielaard |
652537 |
+ *ptrp += 2;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_ref4:
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_data4:
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_sec_offset:
|
|
Mark Wielaard |
652537 |
+ *ptrp += 4;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_ref8:
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_data8:
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_ref_sig8:
|
|
Mark Wielaard |
652537 |
+ *ptrp += 8;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_sdata:
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_ref_udata:
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_udata:
|
|
Mark Wielaard |
652537 |
+ read_uleb128 (*ptrp);
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_strp:
|
|
Mark Wielaard |
652537 |
+ *ptrp += 4;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_string:
|
|
Mark Wielaard |
652537 |
+ *ptrp = (unsigned char *) strchr ((char *)*ptrp, '\0') + 1;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_indirect:
|
|
Mark Wielaard |
652537 |
+ *formp = read_uleb128 (*ptrp);
|
|
Mark Wielaard |
652537 |
+ return FORM_INDIRECT;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_block1:
|
|
Mark Wielaard |
652537 |
+ len = *(*ptrp)++;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_block2:
|
|
Mark Wielaard |
652537 |
+ len = read_16 (*ptrp);
|
|
Mark Wielaard |
652537 |
+ *formp = DW_FORM_block1;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_block4:
|
|
Mark Wielaard |
652537 |
+ len = read_32 (*ptrp);
|
|
Mark Wielaard |
652537 |
+ *formp = DW_FORM_block1;
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_block:
|
|
Mark Wielaard |
652537 |
+ case DW_FORM_exprloc:
|
|
Mark Wielaard |
652537 |
+ len = read_uleb128 (*ptrp);
|
|
Mark Wielaard |
652537 |
+ *formp = DW_FORM_block1;
|
|
Mark Wielaard |
652537 |
+ assert (len < UINT_MAX);
|
|
Mark Wielaard |
652537 |
+ break;
|
|
Mark Wielaard |
652537 |
+ default:
|
|
Mark Wielaard |
652537 |
+ error (0, 0, "%s: Unknown DWARF DW_FORM_%d", dso->filename, *formp);
|
|
Mark Wielaard |
652537 |
+ return FORM_ERROR;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ if (*formp == DW_FORM_block1)
|
|
Mark Wielaard |
652537 |
+ *ptrp += len;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ return FORM_OK;
|
|
Mark Wielaard |
652537 |
+}
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+/* Part of read_dwarf2_line processing DWARF-4. */
|
|
Mark Wielaard |
652537 |
static bool
|
|
Mark Wielaard |
652537 |
-read_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir)
|
|
Mark Wielaard |
652537 |
+read_dwarf4_line (DSO *dso, unsigned char *ptr, char *comp_dir,
|
|
Mark Wielaard |
652537 |
+ struct line_table *table)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- unsigned char *ptr, *dir;
|
|
Mark Wielaard |
652537 |
unsigned char **dirt;
|
|
Mark Wielaard |
652537 |
uint32_t value, dirt_cnt;
|
|
Mark Wielaard |
652537 |
size_t comp_dir_len = !comp_dir ? 0 : strlen (comp_dir);
|
|
Mark Wielaard |
652537 |
- struct line_table *table;
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- if (get_line_table (dso, off, &table) == false
|
|
Mark Wielaard |
652537 |
- || table == NULL)
|
|
Mark Wielaard |
652537 |
- return false;
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- /* Skip to the directory table. The rest of the header has already
|
|
Mark Wielaard |
652537 |
- been read and checked by get_line_table. */
|
|
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 |
- + 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 |
- dir = ptr;
|
|
Mark Wielaard |
652537 |
+ unsigned char *dir = ptr;
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
/* dir table: */
|
|
Mark Wielaard |
652537 |
value = 1;
|
|
Mark Wielaard |
652537 |
@@ -1620,6 +1711,40 @@ read_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir)
|
|
Mark Wielaard |
652537 |
read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
+ return true;
|
|
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 |
+ if line_table needs to be rewrite either the dir or file paths. */
|
|
Mark Wielaard |
652537 |
+static bool
|
|
Mark Wielaard |
652537 |
+read_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir)
|
|
Mark Wielaard |
652537 |
+{
|
|
Mark Wielaard |
652537 |
+ unsigned char *ptr;
|
|
Mark Wielaard |
652537 |
+ struct line_table *table;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ if (get_line_table (dso, off, &table) == false
|
|
Mark Wielaard |
652537 |
+ || table == NULL)
|
|
Mark Wielaard |
652537 |
+ return false;
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* Skip to the directory table. The rest of the header has already
|
|
Mark Wielaard |
652537 |
+ been read and checked by get_line_table. */
|
|
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 |
+ + 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 |
+ if (! read_dwarf4_line (dso, ptr, comp_dir, table))
|
|
Mark Wielaard |
652537 |
+ return false;
|
|
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 |
}
|
|
Mark Wielaard |
652537 |
@@ -1637,6 +1762,33 @@ 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 |
+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 |
+{
|
|
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 |
+
|
|
Mark Wielaard |
652537 |
+ free (*comp_dirp);
|
|
Mark Wielaard |
652537 |
+ *comp_dirp = strdup (dir);
|
|
Mark Wielaard |
652537 |
+ }
|
|
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 |
+ *handled_strpp = true;
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+}
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
/* This scans the attributes of one DIE described by the given abbrev_tag.
|
|
Mark Wielaard |
652537 |
PTR points to the data in the debug_info. It will be advanced till all
|
|
Mark Wielaard |
652537 |
abbrev data is consumed. In phase zero data is collected, in phase one
|
|
Mark Wielaard |
652537 |
@@ -1655,7 +1807,6 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
|
|
Mark Wielaard |
652537 |
for (i = 0; i < t->nattr; ++i)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
uint32_t form = t->attr[i].form;
|
|
Mark Wielaard |
652537 |
- size_t len = 0;
|
|
Mark Wielaard |
652537 |
while (1)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
/* Whether we already handled a string as file for this
|
|
Mark Wielaard |
652537 |
@@ -1743,29 +1894,8 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
else if (form == DW_FORM_strp &&
|
|
Mark Wielaard |
652537 |
debug_sections[DEBUG_STR].data)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- const char *dir;
|
|
Mark Wielaard |
652537 |
- size_t idx = do_read_32_relocated (ptr);
|
|
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,
|
|
Mark Wielaard |
652537 |
- "%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 |
-
|
|
Mark Wielaard |
652537 |
- free (comp_dir);
|
|
Mark Wielaard |
652537 |
- comp_dir = strdup (dir);
|
|
Mark Wielaard |
652537 |
- }
|
|
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 |
- handled_strp = true;
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
+ edit_attributes_str_comp_dir (dso, &ptr, phase, &comp_dir,
|
|
Mark Wielaard |
652537 |
+ &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 |
@@ -1815,99 +1945,21 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
switch (form)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
- case DW_FORM_ref_addr:
|
|
Mark Wielaard |
652537 |
- if (cu_version == 2)
|
|
Mark Wielaard |
652537 |
- ptr += ptr_size;
|
|
Mark Wielaard |
652537 |
- else
|
|
Mark Wielaard |
652537 |
- ptr += 4;
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_flag_present:
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_addr:
|
|
Mark Wielaard |
652537 |
- ptr += ptr_size;
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_ref1:
|
|
Mark Wielaard |
652537 |
- case DW_FORM_flag:
|
|
Mark Wielaard |
652537 |
- case DW_FORM_data1:
|
|
Mark Wielaard |
652537 |
- ++ptr;
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_ref2:
|
|
Mark Wielaard |
652537 |
- case DW_FORM_data2:
|
|
Mark Wielaard |
652537 |
- ptr += 2;
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_ref4:
|
|
Mark Wielaard |
652537 |
- case DW_FORM_data4:
|
|
Mark Wielaard |
652537 |
- case DW_FORM_sec_offset:
|
|
Mark Wielaard |
652537 |
- ptr += 4;
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_ref8:
|
|
Mark Wielaard |
652537 |
- case DW_FORM_data8:
|
|
Mark Wielaard |
652537 |
- case DW_FORM_ref_sig8:
|
|
Mark Wielaard |
652537 |
- ptr += 8;
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_sdata:
|
|
Mark Wielaard |
652537 |
- case DW_FORM_ref_udata:
|
|
Mark Wielaard |
652537 |
- case DW_FORM_udata:
|
|
Mark Wielaard |
652537 |
- read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
case DW_FORM_strp:
|
|
Mark Wielaard |
652537 |
- /* In the first pass we collect all strings, in the
|
|
Mark Wielaard |
652537 |
- second we put the new references back (if there are
|
|
Mark Wielaard |
652537 |
- any changes). */
|
|
Mark Wielaard |
652537 |
- if (phase == 0)
|
|
Mark Wielaard |
652537 |
- {
|
|
Mark Wielaard |
652537 |
- /* handled_strp is set for attributes referring to
|
|
Mark Wielaard |
652537 |
- files. If it is set the string is already
|
|
Mark Wielaard |
652537 |
- recorded. */
|
|
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 |
- }
|
|
Mark Wielaard |
652537 |
- }
|
|
Mark Wielaard |
652537 |
- else if (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 |
- idx = do_read_32_relocated (ptr);
|
|
Mark Wielaard |
652537 |
- entry = string_find_entry (&dso->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 |
- ptr += 4;
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_string:
|
|
Mark Wielaard |
652537 |
- ptr = (unsigned char *) strchr ((char *)ptr, '\0') + 1;
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_indirect:
|
|
Mark Wielaard |
652537 |
- form = read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
- continue;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_block1:
|
|
Mark Wielaard |
652537 |
- len = *ptr++;
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_block2:
|
|
Mark Wielaard |
652537 |
- len = read_16 (ptr);
|
|
Mark Wielaard |
652537 |
- form = DW_FORM_block1;
|
|
Mark Wielaard |
652537 |
+ edit_strp (dso, ptr, phase, handled_strp);
|
|
Mark Wielaard |
652537 |
break;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_block4:
|
|
Mark Wielaard |
652537 |
- len = read_32 (ptr);
|
|
Mark Wielaard |
652537 |
- form = DW_FORM_block1;
|
|
Mark Wielaard |
652537 |
- break;
|
|
Mark Wielaard |
652537 |
- case DW_FORM_block:
|
|
Mark Wielaard |
652537 |
- case DW_FORM_exprloc:
|
|
Mark Wielaard |
652537 |
- len = read_uleb128 (ptr);
|
|
Mark Wielaard |
652537 |
- form = DW_FORM_block1;
|
|
Mark Wielaard |
652537 |
- assert (len < UINT_MAX);
|
|
Mark Wielaard |
652537 |
+ }
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ switch (skip_form (dso, &form, &ptr))
|
|
Mark Wielaard |
652537 |
+ {
|
|
Mark Wielaard |
652537 |
+ case FORM_OK:
|
|
Mark Wielaard |
652537 |
break;
|
|
Mark Wielaard |
652537 |
- default:
|
|
Mark Wielaard |
652537 |
- error (0, 0, "%s: Unknown DWARF DW_FORM_%d", dso->filename,
|
|
Mark Wielaard |
652537 |
- form);
|
|
Mark Wielaard |
652537 |
+ case FORM_ERROR:
|
|
Mark Wielaard |
652537 |
return NULL;
|
|
Mark Wielaard |
652537 |
+ case FORM_INDIRECT:
|
|
Mark Wielaard |
652537 |
+ continue;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
- if (form == DW_FORM_block1)
|
|
Mark Wielaard |
652537 |
- ptr += len;
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
break;
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
@@ -2068,6 +2120,28 @@ edit_info (DSO *dso, int phase, struct debug_section *sec)
|
|
Mark Wielaard |
652537 |
return 0;
|
|
Mark Wielaard |
652537 |
}
|
|
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 |
+{
|
|
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 |
+ Elf_Scn *strscn = dso->scn[strndx];
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* Out with the old. */
|
|
Mark Wielaard |
652537 |
+ strdata->d_size = 0;
|
|
Mark Wielaard |
652537 |
+ /* In with the new. */
|
|
Mark Wielaard |
652537 |
+ strdata = elf_newdata (strscn);
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
+ /* We really should check whether we had enough memory,
|
|
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 |
+}
|
|
Mark Wielaard |
652537 |
+
|
|
Mark Wielaard |
652537 |
static int
|
|
Mark Wielaard |
652537 |
edit_dwarf2 (DSO *dso)
|
|
Mark Wielaard |
652537 |
{
|
|
Mark Wielaard |
652537 |
@@ -2466,24 +2540,7 @@ edit_dwarf2 (DSO *dso)
|
|
Mark Wielaard |
652537 |
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 |
- {
|
|
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 |
- Elf_Scn *strscn = dso->scn[strndx];
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- /* Out with the old. */
|
|
Mark Wielaard |
652537 |
- strdata->d_size = 0;
|
|
Mark Wielaard |
652537 |
- /* In with the new. */
|
|
Mark Wielaard |
652537 |
- strdata = elf_newdata (strscn);
|
|
Mark Wielaard |
652537 |
-
|
|
Mark Wielaard |
652537 |
- /* We really should check whether we had enough memory,
|
|
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 |
- }
|
|
Mark Wielaard |
652537 |
+ edit_dwarf2_any_str (dso);
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
}
|
|
Mark Wielaard |
652537 |
|
|
Mark Wielaard |
652537 |
--
|
|
Mark Wielaard |
652537 |
2.18.4
|
|
Mark Wielaard |
652537 |
|