bombela / backward-cpp

A beautiful stack trace pretty printer for C++
MIT License
3.74k stars 474 forks source link

DW_AT_call_file is an unsigned value #181

Closed pedronavf closed 3 years ago

pedronavf commented 4 years ago

According to the DWARF spec, DW_AT_call_file is an unsigned value and we were treating it like a signed integer. Some old gcc compilers for ARM create, probably because of a bug, very high file index numbers which were being interpreted as a negative number, causing a crash.

pedronavf commented 4 years ago

By the way, this problem also happens in the DW implementation of die_call_file, but as I can't test with that I didn't add it to my pull request.

static const char *die_call_file(Dwarf_Die *die) {
    Dwarf_Attribute attr_mem;
    Dwarf_Sword file_idx = 0;

    dwarf_formsdata(dwarf_attr(die, DW_AT_call_file, &attr_mem), &file_idx);

It should be:

    Dwarf_Word file_idx = 0;

    dwarf_formudata(dwarf_attr(die, DW_AT_call_file, &attr_mem), &file_idx);