summaryrefslogtreecommitdiffstats
path: root/libdw
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2017-07-26 23:02:18 +0200
committerMark Wielaard <[email protected]>2017-08-02 13:51:52 +0200
commitf9d791a92bce59cd68a909d77b94e5ece3c66c01 (patch)
treeb9543b782a92ff790100370fbac3f7f6ebc3ead0 /libdw
parent274f28ce24955b2e6a17e9ff2eb0c7c2e5751f97 (diff)
libdw: Add DW_MACRO constants and DW_MACRO_GNU compatibility defines.
Accept version 5 .debug_macro format, which is identical to the GNU version 4 format. No real support yet for the new supplementary object file (sup) and indirect string references (strx). GCC doesn't generate them yet. readelf does recognize them, but doesn't try to decode them. dwarf_getmacros currently rejects the new formats. Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'libdw')
-rw-r--r--libdw/ChangeLog7
-rw-r--r--libdw/dwarf.h38
-rw-r--r--libdw/dwarf_getmacros.c27
3 files changed, 50 insertions, 22 deletions
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index d0b3f4ca..6533eb50 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,12 @@
2017-07-26 Mark Wielaard <[email protected]>
+ * dwarf.h: Add DW_MACRO_* and compat defines for DW_MACRO_GNU_*.
+ * dwarf_getmacros.c (get_table_for_offset): Accept either version
+ 4 or 5. Use DW_MACRO names instead of DW_MACRO_GNU names.
+ (read_macros): Use table version for fake_cu.
+
+2017-07-26 Mark Wielaard <[email protected]>
+
* dwarf_peel_type.c (dwarf_peel_type): Handle DW_TAG_immutable_type,
DW_TAG_packed_type and DW_TAG_shared_type.
* libdw.h (dwarf_peel_type): Extend documentation.
diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index 82a68f26..902d2617 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -780,20 +780,38 @@ enum
};
-/* DWARF debug_macro type encodings. GNU/DWARF5 extension. */
+/* DWARF debug_macro type encodings. */
enum
{
- DW_MACRO_GNU_define = 0x01,
- DW_MACRO_GNU_undef = 0x02,
- DW_MACRO_GNU_start_file = 0x03,
- DW_MACRO_GNU_end_file = 0x04,
- DW_MACRO_GNU_define_indirect = 0x05,
- DW_MACRO_GNU_undef_indirect = 0x06,
- DW_MACRO_GNU_transparent_include = 0x07,
- DW_MACRO_GNU_lo_user = 0xe0,
- DW_MACRO_GNU_hi_user = 0xff
+ DW_MACRO_define = 0x01,
+ DW_MACRO_undef = 0x02,
+ DW_MACRO_start_file = 0x03,
+ DW_MACRO_end_file = 0x04,
+ DW_MACRO_define_strp = 0x05,
+ DW_MACRO_undef_strp = 0x06,
+ DW_MACRO_import = 0x07,
+ DW_MACRO_define_sup = 0x08,
+ DW_MACRO_undef_sup = 0x09,
+ DW_MACRO_import_sup = 0x0a,
+ DW_MACRO_define_strx = 0x0b,
+ DW_MACRO_undef_strx = 0x0c,
+ DW_MACRO_lo_user = 0xe0,
+ DW_MACRO_hi_user = 0xff
};
+/* Old GNU extension names for DWARF5 debug_macro type encodings.
+ There are no equivalents for the supplementary object file (sup)
+ and indirect string references (strx). */
+#define DW_MACRO_GNU_define DW_MACRO_define
+#define DW_MACRO_GNU_undef DW_MACRO_undef
+#define DW_MACRO_GNU_start_file DW_MACRO_start_file
+#define DW_MACRO_GNU_end_file DW_MACRO_end_file
+#define DW_MACRO_GNU_define_indirect DW_MACRO_define_strp
+#define DW_MACRO_GNU_undef_indirect DW_MACRO_undef_strp
+#define DW_MACRO_GNU_transparent_include DW_MACRO_import
+#define DW_MACRO_GNU_lo_user DW_MACRO_lo_user
+#define DW_MACRO_GNU_hi_user DW_MACRO_hi_user
+
/* DWARF call frame instruction encodings. */
enum
diff --git a/libdw/dwarf_getmacros.c b/libdw/dwarf_getmacros.c
index eb505085..db6582b6 100644
--- a/libdw/dwarf_getmacros.c
+++ b/libdw/dwarf_getmacros.c
@@ -158,7 +158,7 @@ get_table_for_offset (Dwarf *dbg, Dwarf_Word macoff,
}
uint16_t version = read_2ubyte_unaligned_inc (dbg, readp);
- if (version != 4)
+ if (version != 4 && version != 5)
{
__libdw_seterrno (DWARF_E_INVALID_VERSION);
return NULL;
@@ -198,15 +198,17 @@ get_table_for_offset (Dwarf *dbg, Dwarf_Word macoff,
Dwarf_Macro_Op_Proto op_protos[255] =
{
- [DW_MACRO_GNU_define - 1] = p_udata_str,
- [DW_MACRO_GNU_undef - 1] = p_udata_str,
- [DW_MACRO_GNU_define_indirect - 1] = p_udata_strp,
- [DW_MACRO_GNU_undef_indirect - 1] = p_udata_strp,
- [DW_MACRO_GNU_start_file - 1] = p_udata_udata,
- [DW_MACRO_GNU_end_file - 1] = p_none,
- [DW_MACRO_GNU_transparent_include - 1] = p_secoffset,
- /* N.B. DW_MACRO_undef_indirectx, DW_MACRO_define_indirectx
- should be added when 130313.1 is supported. */
+ [DW_MACRO_define - 1] = p_udata_str,
+ [DW_MACRO_undef - 1] = p_udata_str,
+ [DW_MACRO_define_strp - 1] = p_udata_strp,
+ [DW_MACRO_undef_strp - 1] = p_udata_strp,
+ [DW_MACRO_start_file - 1] = p_udata_udata,
+ [DW_MACRO_end_file - 1] = p_none,
+ [DW_MACRO_import - 1] = p_secoffset,
+ /* When adding support for DWARF5 supplementary object files and
+ indirect string tables also add support for DW_MACRO_define_sup,
+ DW_MACRO_undef_sup, DW_MACRO_import_sup, DW_MACRO_define_strx
+ and DW_MACRO_undef_strx. */
};
if ((flags & 0x4) != 0)
@@ -354,10 +356,11 @@ read_macros (Dwarf *dbg, int sec_index,
/* A fake CU with bare minimum data to fool dwarf_formX into
doing the right thing with the attributes that we put out.
- We arbitrarily pretend it's version 4. */
+ We pretend it is the same version as the actual table.
+ Version 4 for the old GNU extension, version 5 for DWARF5. */
Dwarf_CU fake_cu = {
.dbg = dbg,
- .version = 4,
+ .version = table->version,
.offset_size = table->is_64bit ? 8 : 4,
.startp = (void *) startp + offset,
.endp = (void *) endp,