summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2017-12-06 12:30:12 +0100
committerMark Wielaard <mark@klomp.org>2018-05-15 11:25:43 +0200
commitcdf865b890c2480c14245e2dbcae33dea0a03cf7 (patch)
tree73cd9e8e7340948b5d188df7e6ed4189e5d75d3d /src
parent6ed8b94952ddf155960c799ef76f3048f033e873 (diff)
downloadelfutils-cdf865b890c2480c14245e2dbcae33dea0a03cf7.tar.gz
readelf, libdw: Handle DWARF5 .debug_macro.
Almost identical to GNU .debug_macro extension. Just accept and use DW_AT_macros where we accept or use DW_AT_GNU_macros. And be a little stricter in which FORMs we accept (this could have caused problems with the GNU variant too). Deals with DW_FORM_strx[1234], but not yet with imported macros through DW_MACRO_import_sup. Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog5
-rw-r--r--src/readelf.c70
2 files changed, 30 insertions, 45 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 3870508a..4e6887e1 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2018-05-11 Mark Wielaard <mark@klomp.org>
+
+ * readelf.c (print_debug_macro_section): Use libdw_valid_user_form.
+ Use print_form_data for strx and sup strings.
+
2018-05-09 Mark Wielaard <mark@klomp.org>
* readelf.c (dwarf_line_content_description_string): New function.
diff --git a/src/readelf.c b/src/readelf.c
index c3154cae..c1d89d39 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -8205,20 +8205,7 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
goto invalid_data;
unsigned int form = *readp++;
printf (" %s", dwarf_form_name (form));
- if (form != DW_FORM_data1
- && form != DW_FORM_data2
- && form != DW_FORM_data4
- && form != DW_FORM_data8
- && form != DW_FORM_sdata
- && form != DW_FORM_udata
- && form != DW_FORM_block
- && form != DW_FORM_block1
- && form != DW_FORM_block2
- && form != DW_FORM_block4
- && form != DW_FORM_flag
- && form != DW_FORM_string
- && form != DW_FORM_strp
- && form != DW_FORM_sec_offset)
+ if (! libdw_valid_user_form (form))
goto invalid_data;
args--;
if (args > 0)
@@ -8333,26 +8320,22 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
get_uleb128 (u128, readp, readendp);
if (readp + offset_len > readendp)
goto invalid_data;
- if (offset_len == 8)
- off = read_8ubyte_unaligned_inc (dbg, readp);
- else
- off = read_4ubyte_unaligned_inc (dbg, readp);
- // Needs support for reading from supplementary object file.
- printf ("%*s#define <str-at-0x%" PRIx64 ">, line %u (sup)\n",
- level, "", off, u128);
+ printf ("%*s#define ", level, "");
+ readp = print_form_data (dbg, DW_FORM_strp_sup,
+ readp, readendp, offset_len,
+ str_offsets_base);
+ printf (", line %u (sup)\n", u128);
break;
case DW_MACRO_undef_sup:
get_uleb128 (u128, readp, readendp);
if (readp + offset_len > readendp)
goto invalid_data;
- if (offset_len == 8)
- off = read_8ubyte_unaligned_inc (dbg, readp);
- else
- off = read_4ubyte_unaligned_inc (dbg, readp);
- // Needs support for reading from supplementary object file.
- printf ("%*s#undef <str-at-0x%" PRIx64 ">, line %u (sup)\n",
- level, "", off, u128);
+ printf ("%*s#undef ", level, "");
+ readp = print_form_data (dbg, DW_FORM_strp_sup,
+ readp, readendp, offset_len,
+ str_offsets_base);
+ printf (", line %u (sup)\n", u128);
break;
case DW_MACRO_import_sup:
@@ -8362,6 +8345,7 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
off = read_8ubyte_unaligned_inc (dbg, readp);
else
off = read_4ubyte_unaligned_inc (dbg, readp);
+ // XXX Needs support for reading from supplementary object file.
printf ("%*s#include offset 0x%" PRIx64 " (sup)\n",
level, "", off);
break;
@@ -8370,26 +8354,22 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
get_uleb128 (u128, readp, readendp);
if (readp + offset_len > readendp)
goto invalid_data;
- if (offset_len == 8)
- off = read_8ubyte_unaligned_inc (dbg, readp);
- else
- off = read_4ubyte_unaligned_inc (dbg, readp);
- // Needs support for reading indirect string offset table
- printf ("%*s#define <str-at-0x%" PRIx64 ">, line %u (strx)\n",
- level, "", off, u128);
+ printf ("%*s#define ", level, "");
+ readp = print_form_data (dbg, DW_FORM_strx,
+ readp, readendp, offset_len,
+ str_offsets_base);
+ printf (", line %u (strx)\n", u128);
break;
case DW_MACRO_undef_strx:
get_uleb128 (u128, readp, readendp);
if (readp + offset_len > readendp)
goto invalid_data;
- if (offset_len == 8)
- off = read_8ubyte_unaligned_inc (dbg, readp);
- else
- off = read_4ubyte_unaligned_inc (dbg, readp);
- // Needs support for reading indirect string offset table.
- printf ("%*s#undef <str-at-0x%" PRIx64 ">, line %u (strx)\n",
- level, "", off, u128);
+ printf ("%*s#undef ", level, "");
+ readp = print_form_data (dbg, DW_FORM_strx,
+ readp, readendp, offset_len,
+ str_offsets_base);
+ printf (", line %u (strx)\n", u128);
break;
default:
@@ -8405,11 +8385,11 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
// Just skip the arguments, we cannot really interpret them,
// but print as much as we can.
unsigned int args = *op_desc++;
- while (args > 0)
+ while (args > 0 && readp < readendp)
{
unsigned int form = *op_desc++;
- print_form_data (dbg, form, readp, readendp, offset_len,
- str_offsets_base);
+ readp = print_form_data (dbg, form, readp, readendp,
+ offset_len, str_offsets_base);
args--;
if (args > 0)
printf (", ");