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
846 846
    const char *q;
847 847
    int format; // 4 or 8
848 848
    uint8_t address_size;
849
    uint64_t debug_abbrev_offset;
849 850
    int level;
850 851
    const char *abbrev_table[ABBREV_TABLE_SIZE];
851 852
} DebugInfoReader;
......
995 996
static void
996 997
di_read_debug_abbrev_cu(DebugInfoReader *reader)
997 998
{
998
    uint64_t prev = 0;
999 999
    const char *p = reader->q0;
1000
    size_t i;
1001
    for (i = 0; i < ABBREV_TABLE_SIZE; i++)
1002
        reader->abbrev_table[i] = NULL;
1000 1003
    for (;;) {
1001 1004
        uint64_t abbrev_number = uleb128(&p);
1002
        if (abbrev_number <= prev) break;
1005
        if (abbrev_number == 0) break;
1003 1006
        if (abbrev_number < ABBREV_TABLE_SIZE) {
1004 1007
            reader->abbrev_table[abbrev_number] = p;
1005 1008
        }
1006
        prev = abbrev_number;
1007 1009
        uleb128(&p); /* tag */
1008 1010
        p++; /* has_children */
1009 1011
        di_skip_die_attributes(&p);
......
1258 1260
    exit(1);
1259 1261
}
1260 1262

  
1263
static const char *
1264
di_abbrev_table(DebugInfoReader *reader, uint64_t abbrev_number)
1265
{
1266
    const char *p = reader->abbrev_table[abbrev_number];
1267
    if (!p) {
1268
        fprintf(stderr,"%d: Abbrev Number %"PRId64" not found\n",__LINE__, abbrev_number);
1269
        abort();
1270
    }
1271
    return p;
1272
}
1273

  
1261 1274
/* find abbrev in current compilation unit */
1262 1275
static const char *
1263 1276
di_find_abbrev(DebugInfoReader *reader, uint64_t abbrev_number)
1264 1277
{
1265 1278
    const char *p;
1266 1279
    if (abbrev_number < ABBREV_TABLE_SIZE) {
1267
        return reader->abbrev_table[abbrev_number];
1280
        return di_abbrev_table(reader, abbrev_number);
1268 1281
    }
1269
    p = reader->abbrev_table[ABBREV_TABLE_SIZE-1];
1270
    /* skip 255th record */
1271
    uleb128(&p); /* tag */
1272
    p++; /* has_children */
1273
    di_skip_die_attributes(&p);
1282
    p = reader->obj->debug_abbrev.ptr + reader->debug_abbrev_offset;
1274 1283
    for (uint64_t n = uleb128(&p); abbrev_number != n; n = uleb128(&p)) {
1275 1284
        if (n == 0) {
1276 1285
            fprintf(stderr,"%d: Abbrev Number %"PRId64" not found\n",__LINE__, abbrev_number);
......
1538 1547
{
1539 1548
    uint64_t unit_length;
1540 1549
    uint16_t version;
1541
    uint64_t debug_abbrev_offset;
1542 1550
    reader->format = 4;
1543 1551
    reader->current_cu = reader->p;
1544 1552
    unit_length = read_uint32(&reader->p);
......
1554 1562
    else if (version == 5) {
1555 1563
        /* unit_type = */ read_uint8(&reader->p);
1556 1564
        reader->address_size = read_uint8(&reader->p);
1557
        debug_abbrev_offset = read_uint(reader);
1565
        reader->debug_abbrev_offset = read_uint(reader);
1558 1566
    }
1559 1567
    else {
1560
        debug_abbrev_offset = read_uint(reader);
1568
        reader->debug_abbrev_offset = read_uint(reader);
1561 1569
        reader->address_size = read_uint8(&reader->p);
1562 1570
    }
1563
    reader->q0 = reader->obj->debug_abbrev.ptr + debug_abbrev_offset;
1571
    reader->q0 = reader->obj->debug_abbrev.ptr + reader->debug_abbrev_offset;
1564 1572

  
1565 1573
    reader->level = 0;
1566 1574
    di_read_debug_abbrev_cu(reader);