Properly support DWARF5 debug information.

Resolves: rhbz#1920533
This commit is contained in:
Vít Ondruch 2021-03-03 11:25:14 +01:00
parent 2bc8b3d5d5
commit 9b149e59e4
2 changed files with 224 additions and 9 deletions

View File

@ -0,0 +1,217 @@
--- a/addr2line.c
+++ b/addr2line.c
@@ -159,11 +159,12 @@
struct dwarf_section debug_info;
struct dwarf_section debug_line;
struct dwarf_section debug_ranges;
+ struct dwarf_section debug_rnglists;
struct dwarf_section debug_str;
struct obj_info *next;
} obj_info_t;
-#define DWARF_SECTION_COUNT 5
+#define DWARF_SECTION_COUNT 6
static struct dwarf_section *
obj_dwarf_section_at(obj_info_t *obj, int n)
@@ -173,6 +174,7 @@
&obj->debug_info,
&obj->debug_line,
&obj->debug_ranges,
+ &obj->debug_rnglists,
&obj->debug_str
};
if (n < 0 || DWARF_SECTION_COUNT <= n) {
@@ -411,7 +413,7 @@
FILL_LINE();
break;
case DW_LNS_advance_pc:
- a = uleb128((char **)&p);
+ a = uleb128((char **)&p) * header.minimum_instruction_length;
addr += a;
break;
case DW_LNS_advance_line: {
@@ -450,7 +452,7 @@
/* isa = (unsigned int)*/(void)uleb128((char **)&p);
break;
case 0:
- a = *(unsigned char *)p++;
+ a = uleb128((char **)&p);
op = *p++;
switch (op) {
case DW_LNE_end_sequence:
@@ -807,6 +809,18 @@
DW_FORM_addrx4 = 0x2c
};
+/* Range list entry encodings */
+enum {
+ DW_RLE_end_of_list = 0x00,
+ DW_RLE_base_addressx = 0x01,
+ DW_RLE_startx_endx = 0x02,
+ DW_RLE_startx_length = 0x03,
+ DW_RLE_offset_pair = 0x04,
+ DW_RLE_base_address = 0x05,
+ DW_RLE_start_end = 0x06,
+ DW_RLE_start_length = 0x07
+};
+
enum {
VAL_none = 0,
VAL_cstr = 1,
@@ -961,6 +975,23 @@
}
static void
+di_skip_die_attributes(char **p)
+{
+ for (;;) {
+ uint64_t at = uleb128(p);
+ uint64_t form = uleb128(p);
+ if (!at && !form) break;
+ switch (form) {
+ default:
+ break;
+ case DW_FORM_implicit_const:
+ sleb128(p);
+ break;
+ }
+ }
+}
+
+static void
di_read_debug_abbrev_cu(DebugInfoReader *reader)
{
uint64_t prev = 0;
@@ -974,12 +1005,7 @@
prev = abbrev_number;
uleb128(&p); /* tag */
p++; /* has_children */
- /* skip content */
- for (;;) {
- uint64_t at = uleb128(&p);
- uint64_t form = uleb128(&p);
- if (!at && !form) break;
- }
+ di_skip_die_attributes(&p);
}
}
@@ -1243,12 +1269,7 @@
/* skip 255th record */
uleb128(&p); /* tag */
p++; /* has_children */
- /* skip content */
- for (;;) {
- uint64_t at = uleb128(&p);
- uint64_t form = uleb128(&p);
- if (!at && !form) break;
- }
+ di_skip_die_attributes(&p);
for (uint64_t n = uleb128(&p); abbrev_number != n; n = uleb128(&p)) {
if (n == 0) {
fprintf(stderr,"%d: Abbrev Number %"PRId64" not found\n",__LINE__, abbrev_number);
@@ -1256,12 +1277,7 @@
}
uleb128(&p); /* tag */
p++; /* has_children */
- /* skip content */
- for (;;) {
- uint64_t at = uleb128(&p);
- uint64_t form = uleb128(&p);
- if (!at && !form) break;
- }
+ di_skip_die_attributes(&p);
}
return p;
}
@@ -1389,6 +1405,21 @@
}
}
+static uint64_t
+read_dw_form_addr(DebugInfoReader *reader, char **ptr)
+{
+ char *p = *ptr;
+ *ptr = p + reader->format;
+ if (reader->format == 4) {
+ return read_uint32(&p);
+ } else if (reader->format == 8) {
+ return read_uint64(&p);
+ } else {
+ fprintf(stderr,"unknown address_size:%d", reader->address_size);
+ abort();
+ }
+}
+
static uintptr_t
ranges_include(DebugInfoReader *reader, ranges_t *ptr, uint64_t addr)
{
@@ -1402,8 +1433,50 @@
}
else if (ptr->ranges_set) {
/* TODO: support base address selection entry */
- char *p = reader->obj->debug_ranges.ptr + ptr->ranges;
+ char *p;
uint64_t base = ptr->low_pc_set ? ptr->low_pc : reader->current_low_pc;
+ if (reader->obj->debug_rnglists.ptr) {
+ p = reader->obj->debug_rnglists.ptr + ptr->ranges;
+ for (;;) {
+ uint8_t rle = read_uint8(&p);
+ uintptr_t base_address = 0;
+ uintptr_t from, to;
+ if (rle == DW_RLE_end_of_list) break;
+ switch (rle) {
+ case DW_RLE_base_addressx:
+ uleb128(&p);
+ break;
+ case DW_RLE_startx_endx:
+ uleb128(&p);
+ uleb128(&p);
+ break;
+ case DW_RLE_startx_length:
+ uleb128(&p);
+ uleb128(&p);
+ break;
+ case DW_RLE_offset_pair:
+ from = base_address + uleb128(&p);
+ to = base_address + uleb128(&p);
+ if (base + from <= addr && addr < base + to) {
+ return from;
+ }
+ break;
+ case DW_RLE_base_address:
+ base_address = read_dw_form_addr(reader, &p);
+ break;
+ case DW_RLE_start_end:
+ read_dw_form_addr(reader, &p);
+ read_dw_form_addr(reader, &p);
+ break;
+ case DW_RLE_start_length:
+ read_dw_form_addr(reader, &p);
+ uleb128(&p);
+ break;
+ }
+ }
+ return false;
+ }
+ p = reader->obj->debug_ranges.ptr + ptr->ranges;
for (;;) {
uintptr_t from = read_uintptr(&p);
uintptr_t to = read_uintptr(&p);
@@ -1747,6 +1820,7 @@
".debug_info",
".debug_line",
".debug_ranges",
+ ".debug_rnglists",
".debug_str"
};
@@ -2003,6 +2077,7 @@
"__debug_info",
"__debug_line",
"__debug_ranges",
+ "__debug_rnglists",
"__debug_str"
};
struct LP(segment_command) *scmd = (struct LP(segment_command) *)lcmd;

View File

@ -162,6 +162,10 @@ Patch13: ruby-3.0.0-va_list-args-in-rb_vrescue2-is-reused.patch
# Fix flaky excon test suite.
# https://bugs.ruby-lang.org/issues/17653
Patch14: ruby-3.0.0-Do-not-allocate-ractor-local-storage-in-dfree-function-during-GC.patch
# Fix DWARF5 support.
# https://bugzilla.redhat.com/show_bug.cgi?id=1920533
# https://bugs.ruby-lang.org/issues/17585
Patch15: ruby-dwarf5-avoid_crash-r1.patch
# Avoid possible timeout errors in TestBugReporter#test_bug_reporter_add.
# https://bugs.ruby-lang.org/issues/16492
Patch19: ruby-2.7.1-Timeout-the-test_bug_reporter_add-witout-raising-err.patch
@ -615,6 +619,7 @@ rm -rf ext/fiddle/libffi*
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch19 -p1
# Provide an example of usage of the tapset:
@ -887,15 +892,6 @@ make runruby TESTRUN_SCRIPT="--enable-gems %{SOURCE13}"
DISABLE_TESTS=""
MSPECOPTS=""
%ifarch armv7hl ppc64le
# Disable test which started to fail presumably after move to DWARF5:
# https://bugzilla.redhat.com/show_bug.cgi?id=1920533
# Unfortunately, these used to be problematic already before:
# https://bugs.ruby-lang.org/issues/13758
DISABLE_TESTS="$DISABLE_TESTS -n !/test_segv_\(setproctitle\|test\|loaded_features\)/"
DISABLE_TESTS="$DISABLE_TESTS -n !/test_bug_reporter_add/"
%endif
# Avoid `hostname' dependency.
%{!?with_hostname:MSPECOPTS="-P 'Socket.gethostname returns the host name'"}
@ -1381,6 +1377,8 @@ DISABLE_TESTS="$DISABLE_TESTS -n !/test_bug_reporter_add/"
%changelog
* Tue Mar 02 2021 Vít Ondruch <vondruch@redhat.com> - 3.0.0-146
- Fix flaky excon test suite.
- Properly support DWARF5 debug information.
Resolves: rhbz#1920533
* Mon Jan 25 2021 Vít Ondruch <vondruch@redhat.com> - 3.0.0-145
- Bundle OpenSSL into StdLib.