Project

General

Profile

Bug #17052 ยป ruby-addr2line-abbrev_table.patch

addr2line.c: Correct `abbrev_table` entries - xtkoba (Tee KOBAYASHI), 08/17/2021 07:42 AM

View differences:

addr2line.c
995 995
static void
996 996
di_read_debug_abbrev_cu(DebugInfoReader *reader)
997 997
{
998
    uint64_t prev = 0;
999 998
    const char *p = reader->q0;
999
    size_t i;
1000
    for (i = 0; i < ABBREV_TABLE_SIZE; i++)
1001
        reader->abbrev_table[i] = NULL;
1000 1002
    for (;;) {
1001 1003
        uint64_t abbrev_number = uleb128(&p);
1002
        if (abbrev_number <= prev) break;
1004
        if (abbrev_number == 0) break;
1003 1005
        if (abbrev_number < ABBREV_TABLE_SIZE) {
1004 1006
            reader->abbrev_table[abbrev_number] = p;
1005 1007
        }
1006
        prev = abbrev_number;
1007 1008
        uleb128(&p); /* tag */
1008 1009
        p++; /* has_children */
1009 1010
        di_skip_die_attributes(&p);
......
1258 1259
    exit(1);
1259 1260
}
1260 1261

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

  
1261 1273
/* find abbrev in current compilation unit */
1262 1274
static const char *
1263 1275
di_find_abbrev(DebugInfoReader *reader, uint64_t abbrev_number)
1264 1276
{
1265 1277
    const char *p;
1266 1278
    if (abbrev_number < ABBREV_TABLE_SIZE) {
1267
        return reader->abbrev_table[abbrev_number];
1279
        return di_abbrev_table(reader, abbrev_number);
1268 1280
    }
1269
    p = reader->abbrev_table[ABBREV_TABLE_SIZE-1];
1281
    p = di_abbrev_table(reader, ABBREV_TABLE_SIZE-1);
1270 1282
    /* skip 255th record */
1271 1283
    uleb128(&p); /* tag */
1272 1284
    p++; /* has_children */