2017-03-01 12:09:17 +01:00
|
|
|
Index: tools/debugedit.c
|
|
|
|
===================================================================
|
|
|
|
--- tools/debugedit.c.orig 2017-02-27 13:35:18.727800856 +0100
|
|
|
|
+++ tools/debugedit.c 2017-02-27 14:22:33.975985617 +0100
|
2011-07-19 15:04:21 +02:00
|
|
|
@@ -162,7 +162,7 @@ strptr (DSO *dso, int sec, off_t offset)
|
2008-11-01 23:16:01 +01:00
|
|
|
{
|
|
|
|
if (data->d_buf
|
|
|
|
&& offset >= data->d_off
|
|
|
|
- && offset < data->d_off + data->d_size)
|
|
|
|
+ && offset < data->d_off + (off_t)data->d_size)
|
|
|
|
return (const char *) data->d_buf + (offset - data->d_off);
|
|
|
|
}
|
|
|
|
}
|
2017-01-19 16:41:55 +01:00
|
|
|
@@ -505,9 +505,10 @@ static int
|
2009-08-28 15:54:03 +02:00
|
|
|
edit_dwarf2_line (DSO *dso, uint32_t off, char *comp_dir, int phase)
|
2008-10-06 16:13:13 +02:00
|
|
|
{
|
|
|
|
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;
|
2008-10-23 22:18:30 +02:00
|
|
|
+ char line_base;
|
2008-10-06 16:13:13 +02:00
|
|
|
unsigned char opcode_base;
|
2009-08-28 15:54:03 +02:00
|
|
|
uint32_t value, dirt_cnt;
|
2017-01-19 16:41:55 +01:00
|
|
|
size_t comp_dir_len = !comp_dir ? 0 : strlen (comp_dir);
|
|
|
|
@@ -555,6 +556,7 @@ edit_dwarf2_line (DSO *dso, uint32_t off
|
2008-10-06 16:13:13 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2011-05-16 18:07:44 +02:00
|
|
|
|
2011-07-19 15:04:21 +02:00
|
|
|
+ line_base = (char) (ptr[2 + (value >= 4)] & 0xff);
|
|
|
|
opcode_base = ptr[4 + (value >= 4)];
|
|
|
|
ptr = dir = ptr + 4 + (value >= 4) + opcode_base;
|
2011-05-16 18:07:44 +02:00
|
|
|
|
2017-01-19 16:41:55 +01:00
|
|
|
@@ -566,13 +568,13 @@ edit_dwarf2_line (DSO *dso, uint32_t off
|
2008-10-06 16:13:13 +02:00
|
|
|
++value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- dirt = (unsigned char **) alloca (value * sizeof (unsigned char *));
|
2009-08-28 15:54:03 +02:00
|
|
|
+ dirt = (char **) alloca (value * sizeof (unsigned char *));
|
|
|
|
dirt[0] = (unsigned char *) ".";
|
2008-10-06 16:13:13 +02:00
|
|
|
dirt_cnt = 1;
|
|
|
|
ptr = dir;
|
|
|
|
while (*ptr != 0)
|
|
|
|
{
|
|
|
|
- dirt[dirt_cnt++] = ptr;
|
|
|
|
+ dirt[dirt_cnt++] = (char *)ptr;
|
2009-08-28 15:54:03 +02:00
|
|
|
ptr = (unsigned char *) strchr ((char *)ptr, 0) + 1;
|
2008-10-06 16:13:13 +02:00
|
|
|
}
|
|
|
|
ptr++;
|
2017-01-19 16:41:55 +01:00
|
|
|
@@ -685,7 +687,7 @@ edit_dwarf2_line (DSO *dso, uint32_t off
|
2008-10-06 16:13:13 +02:00
|
|
|
|
|
|
|
if (dest_dir)
|
|
|
|
{
|
|
|
|
- unsigned char *srcptr, *buf = NULL;
|
2009-08-28 15:54:03 +02:00
|
|
|
+ char *srcptr, *buf = NULL;
|
2008-10-06 16:13:13 +02:00
|
|
|
size_t base_len = strlen (base_dir);
|
|
|
|
size_t dest_len = strlen (dest_dir);
|
|
|
|
size_t shrank = 0;
|
2017-01-19 16:41:55 +01:00
|
|
|
@@ -699,11 +701,14 @@ edit_dwarf2_line (DSO *dso, uint32_t off
|
2008-10-06 16:13:13 +02:00
|
|
|
ptr = dir;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
- ptr = srcptr = dir;
|
|
|
|
+ {
|
|
|
|
+ ptr = dir;
|
|
|
|
+ srcptr = (char *)dir;
|
|
|
|
+ }
|
|
|
|
while (*srcptr != 0)
|
|
|
|
{
|
2011-05-16 18:07:44 +02:00
|
|
|
size_t len = strlen ((char *)srcptr) + 1;
|
2008-10-06 16:13:13 +02:00
|
|
|
- const unsigned char *readptr = srcptr;
|
|
|
|
+ const char *readptr = srcptr;
|
|
|
|
|
2011-05-16 18:07:44 +02:00
|
|
|
char *orig = strdup ((const char *) srcptr);
|
2008-10-23 22:18:30 +02:00
|
|
|
|
2017-03-01 12:09:17 +01:00
|
|
|
@@ -730,11 +735,18 @@ edit_dwarf2_line (DSO *dso, uint32_t off
|
2011-05-20 13:31:31 +02:00
|
|
|
|
|
|
|
if (shrank > 0)
|
|
|
|
{
|
|
|
|
- if (--shrank == 0)
|
2017-03-01 12:09:17 +01:00
|
|
|
- error (EXIT_FAILURE, 0,
|
|
|
|
- "canonicalization unexpectedly shrank by one character");
|
|
|
|
+ if (shrank == 1)
|
|
|
|
+ {
|
|
|
|
+ /* For size 1 we can't append a dummy entry as a '\0' tells
|
|
|
|
+ it the directory table ends prematurely and thus the file
|
|
|
|
+ table will end up empty. Simply append a / to the last
|
|
|
|
+ directory entry in this case. */
|
|
|
|
+ *(ptr - 1) = '/';
|
|
|
|
+ *ptr++ = '\0';
|
|
|
|
+ }
|
2011-05-20 13:31:31 +02:00
|
|
|
else
|
|
|
|
{
|
2017-03-01 12:09:17 +01:00
|
|
|
+ --shrank;
|
2011-05-20 13:31:31 +02:00
|
|
|
memset (ptr, 'X', shrank);
|
|
|
|
ptr += shrank;
|
2017-03-01 12:09:17 +01:00
|
|
|
*ptr++ = '\0';
|
|
|
|
@@ -769,21 +781,26 @@ edit_dwarf2_line (DSO *dso, uint32_t off
|
2011-05-16 18:07:44 +02:00
|
|
|
}
|
|
|
|
dirty_section (DEBUG_STR);
|
2008-10-06 16:13:13 +02:00
|
|
|
}
|
|
|
|
- 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);
|
2008-10-23 22:18:30 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ ptr++;
|
2008-11-01 23:16:01 +01:00
|
|
|
+ /* fill the rest until the line number program starts with NOP opcode */
|
|
|
|
+ memset(ptr, opcode_base - line_base, endprol - ptr);
|
|
|
|
+ /* don't touch the line number program */
|
2008-10-23 22:18:30 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|