Skip to content

Commit

Permalink
Print better error messages in parts of CompilationUnit
Browse files Browse the repository at this point in the history
Change CompilationUnit::SkipAttribute() and
CompilationUnit::ProcessOffsetBaseAttribute() to print the unknown form
types they encounter.

Along the way, fix various formatting issues, stray trailing spaces, and
update some NULLs to nullptrs.

Change-Id: I5b3e72c9c6c9cb31e8a930e54418adb74b02f6c2
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/5366242
Reviewed-by: Joshua Peraza <[email protected]>
  • Loading branch information
leizleiz committed Mar 12, 2024
1 parent 26666b8 commit 76788fa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
24 changes: 12 additions & 12 deletions src/common/dwarf/dwarf2reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ const uint8_t* CompilationUnit::SkipAttribute(const uint8_t* start,
case DW_FORM_sec_offset:
return start + reader_->OffsetSize();
}
fprintf(stderr,"Unhandled form type");
return NULL;
fprintf(stderr,"Unhandled form type 0x%x\n", form);
return nullptr;
}

// Read the abbreviation offset from a compilation unit header.
Expand Down Expand Up @@ -369,7 +369,7 @@ void CompilationUnit::ReadHeader() {
break;
case DW_UT_type:
case DW_UT_split_type:
is_type_unit_ = true;
is_type_unit_ = true;
headerptr += ReadTypeSignature(headerptr);
headerptr += ReadTypeOffset(headerptr);
break;
Expand Down Expand Up @@ -512,7 +512,7 @@ const uint8_t* CompilationUnit::ProcessOffsetBaseAttribute(
&len));
start += len;
return ProcessOffsetBaseAttribute(dieoffset, start, attr, form,
implicit_const);
implicit_const);

case DW_FORM_flag_present:
return start;
Expand Down Expand Up @@ -568,10 +568,10 @@ const uint8_t* CompilationUnit::ProcessOffsetBaseAttribute(
// offset size.
assert(header_.version >= 2);
if (header_.version == 2) {
reader_->ReadAddress(start);
reader_->ReadAddress(start);
return start + reader_->AddressSize();
} else if (header_.version >= 3) {
reader_->ReadOffset(start);
reader_->ReadOffset(start);
return start + reader_->OffsetSize();
}
break;
Expand Down Expand Up @@ -647,8 +647,8 @@ const uint8_t* CompilationUnit::ProcessOffsetBaseAttribute(
reader_->ReadUnsignedLEB128(start, &len);
return start + len;
}
fprintf(stderr, "Unhandled form type\n");
return NULL;
fprintf(stderr,"Unhandled form type 0x%x\n", form);
return nullptr;
}

// If one really wanted, you could merge SkipAttribute and
Expand Down Expand Up @@ -896,11 +896,11 @@ const uint8_t* CompilationUnit::ProcessDIE(uint64_t dieoffset,
uint64_t dieoffset_copy = dieoffset;
const uint8_t* start_copy = start;
for (AttributeList::const_iterator i = abbrev.attributes.begin();
i != abbrev.attributes.end();
i++) {
i != abbrev.attributes.end();
i++) {
start_copy = ProcessOffsetBaseAttribute(dieoffset_copy, start_copy,
i->attr_, i->form_,
i->value_);
i->attr_, i->form_,
i->value_);
}
}

Expand Down
36 changes: 18 additions & 18 deletions src/common/dwarf/dwarf2reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,10 @@ class CompilationUnit {
// Special version of ProcessAttribute, for finding str_offsets_base and
// DW_AT_addr_base in DW_TAG_compile_unit, for DWARF v5.
const uint8_t* ProcessOffsetBaseAttribute(uint64_t dieoffset,
const uint8_t* start,
enum DwarfAttribute attr,
enum DwarfForm form,
uint64_t implicit_const);
const uint8_t* start,
enum DwarfAttribute attr,
enum DwarfForm form,
uint64_t implicit_const);

// Called when we have an attribute with unsigned data to give to
// our handler. The attribute is for the DIE at OFFSET from the
Expand Down Expand Up @@ -909,11 +909,11 @@ class DwpReader {
//
// For example, here is a complete (uncompressed) table describing the
// function above:
//
//
// insn cfa r0 r1 ... ra
// =======================================
// func+0: sp cfa[0]
// func+1: sp+16 cfa[0]
// func+1: sp+16 cfa[0]
// func+2: sp+16 cfa[-4] cfa[0]
// func+11: sp+20 cfa[-4] cfa[0]
// func+21: sp+20 cfa[0]
Expand Down Expand Up @@ -947,7 +947,7 @@ class DwpReader {
// save them, caller-saves registers are probably dead in the caller
// anyway, so compilers usually don't generate CFA for caller-saves
// registers.)
//
//
// - Exactly where the CFA points is a matter of convention that
// depends on the architecture and ABI in use. In the example, the
// CFA is the value the stack pointer had upon entry to the
Expand All @@ -968,15 +968,15 @@ class DwpReader {
// reduces the size of the data by mentioning only the addresses and
// columns at which changes take place. So for the above, DWARF CFI
// data would only actually mention the following:
//
//
// insn cfa r0 r1 ... ra
// =======================================
// func+0: sp cfa[0]
// func+1: sp+16
// func+2: cfa[-4]
// func+11: sp+20
// func+21: r0
// func+22: sp
// func+22: sp
//
// In fact, this is the way the parser reports CFI to the consumer: as
// a series of statements of the form, "At address X, column Y changed
Expand Down Expand Up @@ -1094,7 +1094,7 @@ class CallFrameInfo {
// handling are described here, rather poorly:
// http://refspecs.linux-foundation.org/LSB_4.0.0/LSB-Core-generic/LSB-Core-generic/dwarfext.html
// http://refspecs.linux-foundation.org/LSB_4.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html
//
//
// The mechanics of C++ exception handling, personality routines,
// and language-specific data areas are described here, rather nicely:
// http://www.codesourcery.com/public/cxx-abi/abi-eh.html
Expand Down Expand Up @@ -1127,7 +1127,7 @@ class CallFrameInfo {

// The start of this entry in the buffer.
const uint8_t* start;

// Which kind of entry this is.
//
// We want to be able to use this for error reporting even while we're
Expand Down Expand Up @@ -1161,13 +1161,13 @@ class CallFrameInfo {
struct CIE: public Entry {
uint8_t version; // CFI data version number
string augmentation; // vendor format extension markers
uint64_t code_alignment_factor; // scale for code address adjustments
uint64_t code_alignment_factor; // scale for code address adjustments
int data_alignment_factor; // scale for stack pointer adjustments
unsigned return_address_register; // which register holds the return addr

// True if this CIE includes Linux C++ ABI 'z' augmentation data.
bool has_z_augmentation;

// Parsed 'z' augmentation data. These are meaningful only if
// has_z_augmentation is true.
bool has_z_lsda; // The 'z' augmentation included 'L'.
Expand Down Expand Up @@ -1221,7 +1221,7 @@ class CallFrameInfo {
class ValExpressionRule;
class RuleMap;
class State;

// Parse the initial length and id of a CFI entry, either a CIE, an FDE,
// or a .eh_frame end-of-data mark. CURSOR points to the beginning of the
// data to parse. On success, populate ENTRY as appropriate, and return
Expand Down Expand Up @@ -1308,7 +1308,7 @@ class CallFrameInfo::Handler {
// Immediately after a call to Entry, the handler should assume that
// the rule for each callee-saves register is "unchanged" --- that
// is, that the register still has the value it had in the caller.
//
//
// If a *Rule function returns true, we continue processing this entry's
// instructions. If a *Rule function returns false, we stop evaluating
// instructions, and skip to the next entry. Either way, we call End
Expand Down Expand Up @@ -1497,21 +1497,21 @@ class CallFrameInfo::Reporter {
// The instruction at INSN_OFFSET in the entry at OFFSET, of kind
// KIND, establishes a rule that cites the CFA, but we have not
// established a CFA rule yet.
virtual void NoCFARule(uint64_t offset, CallFrameInfo::EntryKind kind,
virtual void NoCFARule(uint64_t offset, CallFrameInfo::EntryKind kind,
uint64_t insn_offset);

// The instruction at INSN_OFFSET in the entry at OFFSET, of kind
// KIND, is a DW_CFA_restore_state instruction, but the stack of
// saved states is empty.
virtual void EmptyStateStack(uint64_t offset, CallFrameInfo::EntryKind kind,
virtual void EmptyStateStack(uint64_t offset, CallFrameInfo::EntryKind kind,
uint64_t insn_offset);

// The DW_CFA_remember_state instruction at INSN_OFFSET in the entry
// at OFFSET, of kind KIND, would restore a state that has no CFA
// rule, whereas the current state does have a CFA rule. This is
// bogus input, which the CallFrameInfo::Handler interface doesn't
// (and shouldn't) have any way to report.
virtual void ClearingCFARule(uint64_t offset, CallFrameInfo::EntryKind kind,
virtual void ClearingCFARule(uint64_t offset, CallFrameInfo::EntryKind kind,
uint64_t insn_offset);

protected:
Expand Down

0 comments on commit 76788fa

Please sign in to comment.