328 lines
7.9 KiB
Diff
328 lines
7.9 KiB
Diff
|
---
|
||
|
tools/debugedit.c | 137 +++++++++++++++++++++++++++---------------------------
|
||
|
1 file changed, 70 insertions(+), 67 deletions(-)
|
||
|
|
||
|
Index: b/tools/debugedit.c
|
||
|
===================================================================
|
||
|
--- tools/debugedit.c
|
||
|
+++ tools/debugedit.c
|
||
|
@@ -471,13 +471,13 @@ has_prefix (const char *str,
|
||
|
{
|
||
|
int str_len;
|
||
|
int prefix_len;
|
||
|
-
|
||
|
+
|
||
|
str_len = strlen (str);
|
||
|
prefix_len = strlen (prefix);
|
||
|
|
||
|
if (str_len < prefix_len)
|
||
|
return 0;
|
||
|
-
|
||
|
+
|
||
|
return strncmp (str, prefix, prefix_len) == 0;
|
||
|
}
|
||
|
|
||
|
@@ -485,7 +485,7 @@ static int
|
||
|
edit_dwarf2_line (DSO *dso, uint_32 off, char *comp_dir, int phase)
|
||
|
{
|
||
|
unsigned char *ptr = debug_sections[DEBUG_LINE].data, *dir;
|
||
|
- unsigned char **dirt;
|
||
|
+ char **dirt;
|
||
|
unsigned char *endsec = ptr + debug_sections[DEBUG_LINE].size;
|
||
|
unsigned char *endcu, *endprol;
|
||
|
unsigned char opcode_base;
|
||
|
@@ -496,9 +496,9 @@ edit_dwarf2_line (DSO *dso, uint_32 off,
|
||
|
|
||
|
if (phase != 0)
|
||
|
return 0;
|
||
|
-
|
||
|
+
|
||
|
ptr += off;
|
||
|
-
|
||
|
+
|
||
|
endcu = ptr + 4;
|
||
|
endcu += read_32 (ptr);
|
||
|
if (endcu == ptr + 0xffffffff)
|
||
|
@@ -521,7 +521,7 @@ edit_dwarf2_line (DSO *dso, uint_32 off,
|
||
|
value);
|
||
|
return 1;
|
||
|
}
|
||
|
-
|
||
|
+
|
||
|
endprol = ptr + 4;
|
||
|
endprol += read_32 (ptr);
|
||
|
if (endprol > endcu)
|
||
|
@@ -530,26 +530,26 @@ edit_dwarf2_line (DSO *dso, uint_32 off,
|
||
|
dso->filename);
|
||
|
return 1;
|
||
|
}
|
||
|
-
|
||
|
+
|
||
|
opcode_base = ptr[4];
|
||
|
ptr = dir = ptr + 4 + opcode_base;
|
||
|
-
|
||
|
+
|
||
|
/* dir table: */
|
||
|
value = 1;
|
||
|
while (*ptr != 0)
|
||
|
{
|
||
|
- ptr = strchr (ptr, 0) + 1;
|
||
|
+ ptr = (unsigned char *)strchr ((char *)ptr, 0) + 1;
|
||
|
++value;
|
||
|
}
|
||
|
|
||
|
- dirt = (unsigned char **) alloca (value * sizeof (unsigned char *));
|
||
|
+ dirt = (char **) alloca (value * sizeof (char *));
|
||
|
dirt[0] = ".";
|
||
|
dirt_cnt = 1;
|
||
|
ptr = dir;
|
||
|
while (*ptr != 0)
|
||
|
{
|
||
|
- dirt[dirt_cnt++] = ptr;
|
||
|
- ptr = strchr (ptr, 0) + 1;
|
||
|
+ dirt[dirt_cnt++] = (char *)ptr;
|
||
|
+ ptr = (unsigned char *)strchr ((char *)ptr, 0) + 1;
|
||
|
}
|
||
|
ptr++;
|
||
|
|
||
|
@@ -559,8 +559,8 @@ edit_dwarf2_line (DSO *dso, uint_32 off,
|
||
|
char *s, *file;
|
||
|
size_t file_len, dir_len;
|
||
|
|
||
|
- file = ptr;
|
||
|
- ptr = strchr (ptr, 0) + 1;
|
||
|
+ file = (char *)ptr;
|
||
|
+ ptr = (unsigned char *)strchr ((char *)ptr, 0) + 1;
|
||
|
value = read_uleb128 (ptr);
|
||
|
|
||
|
if (value >= dirt_cnt)
|
||
|
@@ -629,7 +629,7 @@ edit_dwarf2_line (DSO *dso, uint_32 off,
|
||
|
}
|
||
|
|
||
|
free (s);
|
||
|
-
|
||
|
+
|
||
|
read_uleb128 (ptr);
|
||
|
read_uleb128 (ptr);
|
||
|
}
|
||
|
@@ -661,7 +661,7 @@ edit_dwarf2_line (DSO *dso, uint_32 off,
|
||
|
|
||
|
if (dest_dir)
|
||
|
{
|
||
|
- unsigned char *srcptr, *buf = NULL;
|
||
|
+ char *srcptr, *srcstart, *buf = NULL;
|
||
|
size_t base_len = strlen (base_dir);
|
||
|
size_t dest_len = strlen (dest_dir);
|
||
|
size_t shrank = 0;
|
||
|
@@ -675,12 +675,16 @@ edit_dwarf2_line (DSO *dso, uint_32 off,
|
||
|
ptr = dir;
|
||
|
}
|
||
|
else
|
||
|
- ptr = srcptr = dir;
|
||
|
- unsigned char *srcstart=srcptr;
|
||
|
+ {
|
||
|
+ ptr = dir;
|
||
|
+ srcptr = (char *)dir;
|
||
|
+ }
|
||
|
+
|
||
|
+ srcstart = srcptr;
|
||
|
while (*srcptr != 0)
|
||
|
{
|
||
|
- size_t len = strlen (srcptr) + 1;
|
||
|
- const unsigned char *readptr = srcptr;
|
||
|
+ size_t len = strlen (srcptr);
|
||
|
+ const char *readptr = srcptr;
|
||
|
|
||
|
if (*srcptr == '/' && has_prefix (srcptr, base_dir))
|
||
|
{
|
||
|
@@ -689,24 +693,28 @@ edit_dwarf2_line (DSO *dso, uint_32 off,
|
||
|
memcpy (ptr, dest_dir, dest_len);
|
||
|
ptr += dest_len;
|
||
|
readptr += base_len;
|
||
|
- }
|
||
|
+ }
|
||
|
srcptr += len;
|
||
|
|
||
|
shrank += srcptr - readptr;
|
||
|
- canonicalize_path (readptr, ptr);
|
||
|
- len = strlen (ptr) + 1;
|
||
|
+ canonicalize_path (readptr, (char *)ptr);
|
||
|
+ len = strlen ((char *)ptr);
|
||
|
+
|
||
|
+ if ((srcptr - readptr) > len)
|
||
|
+ error(0, 0,"canonicalization unexpectedly shrank (%lu): \"%s\"\n",
|
||
|
+ (long unsigned int)(srcptr - readptr) - len, ptr);
|
||
|
+
|
||
|
shrank -= len;
|
||
|
ptr += len;
|
||
|
|
||
|
- elf_flagdata (debug_sections[DEBUG_STR].elf_data,
|
||
|
- ELF_C_SET, ELF_F_DIRTY);
|
||
|
- }
|
||
|
+ elf_flagdata (debug_sections[DEBUG_STR].elf_data,
|
||
|
+ ELF_C_SET, ELF_F_DIRTY);
|
||
|
+ ++ptr;
|
||
|
+ ++srcptr;
|
||
|
+ }
|
||
|
|
||
|
if (shrank > 0)
|
||
|
{
|
||
|
- if (--shrank == 0)
|
||
|
- error (EXIT_FAILURE, 0,
|
||
|
- "canonicalization unexpectedly shrank by one character");
|
||
|
memset (ptr, 'X', shrank);
|
||
|
ptr += shrank;
|
||
|
*ptr++ = '\0';
|
||
|
@@ -741,17 +749,17 @@ edit_dwarf2_line (DSO *dso, uint_32 off,
|
||
|
elf_flagdata (debug_sections[DEBUG_STR].elf_data,
|
||
|
ELF_C_SET, ELF_F_DIRTY);
|
||
|
}
|
||
|
- else if (ptr != srcptr)
|
||
|
+ else if ((char *)ptr != srcptr)
|
||
|
memmove (ptr, srcptr, len);
|
||
|
srcptr += len;
|
||
|
ptr += len;
|
||
|
- dir = srcptr;
|
||
|
+ dir = (unsigned char *)srcptr;
|
||
|
read_uleb128 (srcptr);
|
||
|
read_uleb128 (srcptr);
|
||
|
read_uleb128 (srcptr);
|
||
|
if (ptr != dir)
|
||
|
- memmove (ptr, dir, srcptr - dir);
|
||
|
- ptr += srcptr - dir;
|
||
|
+ memmove (ptr, dir, (unsigned char *)srcptr - dir);
|
||
|
+ ptr += (unsigned char *)srcptr - dir;
|
||
|
}
|
||
|
*ptr = '\0';
|
||
|
free (buf);
|
||
|
@@ -767,17 +775,13 @@ edit_attributes (DSO *dso, unsigned char
|
||
|
int i;
|
||
|
uint_32 list_offs;
|
||
|
int found_list_offs;
|
||
|
- unsigned char *comp_dir;
|
||
|
-
|
||
|
- comp_dir = NULL;
|
||
|
- list_offs = 0;
|
||
|
- found_list_offs = 0;
|
||
|
+ char *comp_dir;
|
||
|
+
|
||
|
for (i = 0; i < t->nattr; ++i)
|
||
|
{
|
||
|
uint_32 form = t->attr[i].form;
|
||
|
uint_32 len = 0;
|
||
|
int base_len, dest_len;
|
||
|
-
|
||
|
|
||
|
while (1)
|
||
|
{
|
||
|
@@ -791,56 +795,55 @@ edit_attributes (DSO *dso, unsigned char
|
||
|
}
|
||
|
|
||
|
if (t->attr[i].attr == DW_AT_comp_dir)
|
||
|
- {
|
||
|
+ {
|
||
|
if ( form == DW_FORM_string )
|
||
|
- {
|
||
|
+ {
|
||
|
free (comp_dir);
|
||
|
- comp_dir = strdup (ptr);
|
||
|
-
|
||
|
- if (phase == 1 && dest_dir && has_prefix (ptr, base_dir))
|
||
|
- {
|
||
|
+ comp_dir = strdup ((char *)ptr);
|
||
|
+
|
||
|
+ if (phase == 1 && dest_dir
|
||
|
+ && has_prefix ((char *)ptr, base_dir))
|
||
|
+ {
|
||
|
base_len = strlen (base_dir);
|
||
|
dest_len = strlen (dest_dir);
|
||
|
-
|
||
|
+
|
||
|
memcpy (ptr, dest_dir, dest_len);
|
||
|
if (dest_len < base_len)
|
||
|
- {
|
||
|
+ {
|
||
|
memset(ptr + dest_len, '/',
|
||
|
base_len - dest_len);
|
||
|
-
|
||
|
- }
|
||
|
+ }
|
||
|
elf_flagdata (debug_sections[DEBUG_INFO].elf_data,
|
||
|
ELF_C_SET, ELF_F_DIRTY);
|
||
|
- }
|
||
|
- }
|
||
|
-
|
||
|
+ }
|
||
|
+ }
|
||
|
else if (form == DW_FORM_strp &&
|
||
|
debug_sections[DEBUG_STR].data)
|
||
|
- {
|
||
|
+ {
|
||
|
char *dir;
|
||
|
|
||
|
- dir = debug_sections[DEBUG_STR].data
|
||
|
- + do_read_32_relocated (ptr);
|
||
|
+ dir = (char *)debug_sections[DEBUG_STR].data
|
||
|
+ + do_read_32_relocated (ptr);
|
||
|
|
||
|
free (comp_dir);
|
||
|
comp_dir = strdup (dir);
|
||
|
|
||
|
if (phase == 1 && dest_dir && has_prefix (dir, base_dir))
|
||
|
- {
|
||
|
+ {
|
||
|
base_len = strlen (base_dir);
|
||
|
dest_len = strlen (dest_dir);
|
||
|
-
|
||
|
+
|
||
|
memcpy (dir, dest_dir, dest_len);
|
||
|
if (dest_len < base_len)
|
||
|
- {
|
||
|
+ {
|
||
|
memmove (dir + dest_len, dir + base_len,
|
||
|
strlen (dir + base_len) + 1);
|
||
|
- }
|
||
|
+ }
|
||
|
elf_flagdata (debug_sections[DEBUG_STR].elf_data,
|
||
|
ELF_C_SET, ELF_F_DIRTY);
|
||
|
- }
|
||
|
- }
|
||
|
- }
|
||
|
+ }
|
||
|
+ }
|
||
|
+ }
|
||
|
else if ((t->tag == DW_TAG_compile_unit
|
||
|
|| t->tag == DW_TAG_partial_unit)
|
||
|
&& t->attr[i].attr == DW_AT_name
|
||
|
@@ -848,9 +851,9 @@ edit_attributes (DSO *dso, unsigned char
|
||
|
&& debug_sections[DEBUG_STR].data)
|
||
|
{
|
||
|
char *name;
|
||
|
-
|
||
|
- name = debug_sections[DEBUG_STR].data
|
||
|
- + do_read_32_relocated (ptr);
|
||
|
+
|
||
|
+ name = (char *)debug_sections[DEBUG_STR].data
|
||
|
+ + do_read_32_relocated (ptr);
|
||
|
if (*name == '/' && comp_dir == NULL)
|
||
|
{
|
||
|
char *enddir = strrchr (name, '/');
|
||
|
@@ -869,7 +872,7 @@ edit_attributes (DSO *dso, unsigned char
|
||
|
{
|
||
|
base_len = strlen (base_dir);
|
||
|
dest_len = strlen (dest_dir);
|
||
|
-
|
||
|
+
|
||
|
memcpy (name, dest_dir, dest_len);
|
||
|
if (dest_len < base_len)
|
||
|
{
|
||
|
@@ -913,7 +916,7 @@ edit_attributes (DSO *dso, unsigned char
|
||
|
ptr += 4;
|
||
|
break;
|
||
|
case DW_FORM_string:
|
||
|
- ptr = strchr (ptr, '\0') + 1;
|
||
|
+ ptr = (unsigned char *)strchr ((char *)ptr, '\0') + 1;
|
||
|
break;
|
||
|
case DW_FORM_indirect:
|
||
|
form = read_uleb128 (ptr);
|