Project

General

Profile

Bug #17052 » ruby-addr2line-abbrev_table-r1.patch

Correct `abbrev_table` entries (revised) - xtkoba (Tee KOBAYASHI), 08/17/2021 10:01 AM

View differences:

addr2line.c
const char *q;
int format; // 4 or 8
uint8_t address_size;
uint64_t debug_abbrev_offset;
int level;
const char *abbrev_table[ABBREV_TABLE_SIZE];
} DebugInfoReader;
......
static void
di_read_debug_abbrev_cu(DebugInfoReader *reader)
{
uint64_t prev = 0;
const char *p = reader->q0;
size_t i;
for (i = 0; i < ABBREV_TABLE_SIZE; i++)
reader->abbrev_table[i] = NULL;
for (;;) {
uint64_t abbrev_number = uleb128(&p);
if (abbrev_number <= prev) break;
if (abbrev_number == 0) break;
if (abbrev_number < ABBREV_TABLE_SIZE) {
reader->abbrev_table[abbrev_number] = p;
}
prev = abbrev_number;
uleb128(&p); /* tag */
p++; /* has_children */
di_skip_die_attributes(&p);
......
exit(1);
}
static const char *
di_abbrev_table(DebugInfoReader *reader, uint64_t abbrev_number)
{
const char *p = reader->abbrev_table[abbrev_number];
if (!p) {
fprintf(stderr,"%d: Abbrev Number %"PRId64" not found\n",__LINE__, abbrev_number);
abort();
}
return p;
}
/* find abbrev in current compilation unit */
static const char *
di_find_abbrev(DebugInfoReader *reader, uint64_t abbrev_number)
{
const char *p;
if (abbrev_number < ABBREV_TABLE_SIZE) {
return reader->abbrev_table[abbrev_number];
return di_abbrev_table(reader, abbrev_number);
}
p = reader->abbrev_table[ABBREV_TABLE_SIZE-1];
/* skip 255th record */
uleb128(&p); /* tag */
p++; /* has_children */
di_skip_die_attributes(&p);
p = reader->obj->debug_abbrev.ptr + reader->debug_abbrev_offset;
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);
......
{
uint64_t unit_length;
uint16_t version;
uint64_t debug_abbrev_offset;
reader->format = 4;
reader->current_cu = reader->p;
unit_length = read_uint32(&reader->p);
......
else if (version == 5) {
/* unit_type = */ read_uint8(&reader->p);
reader->address_size = read_uint8(&reader->p);
debug_abbrev_offset = read_uint(reader);
reader->debug_abbrev_offset = read_uint(reader);
}
else {
debug_abbrev_offset = read_uint(reader);
reader->debug_abbrev_offset = read_uint(reader);
reader->address_size = read_uint8(&reader->p);
}
reader->q0 = reader->obj->debug_abbrev.ptr + debug_abbrev_offset;
reader->q0 = reader->obj->debug_abbrev.ptr + reader->debug_abbrev_offset;
reader->level = 0;
di_read_debug_abbrev_cu(reader);
(4-4/5)