Cleanup.
- Rename _ParseCIEAugmentation to _ParseCIEHeader since that more accurately reflects what it does. - Refactor a bit to avoid having to parse the header twice, and simplify various places as a result.
This commit is contained in:
@@ -1527,22 +1527,17 @@ DwarfFile::_UnwindCallFrame(bool usingEHFrameSection, CompilationUnit* unit,
|
|||||||
// when using .eh_frame format, we need to parse the CIE's
|
// when using .eh_frame format, we need to parse the CIE's
|
||||||
// augmentation up front in order to know how the FDE's addresses
|
// augmentation up front in order to know how the FDE's addresses
|
||||||
// will be represented
|
// will be represented
|
||||||
if (usingEHFrameSection) {
|
DataReader cieReader;
|
||||||
// TODO: this isn't so ideal since it means we parse
|
off_t cieRemaining;
|
||||||
// the CIE twice, once here in order to get the augmentation
|
status_t error = _ParseCIEHeader(currentFrameSection,
|
||||||
// data for address parsing, and again later when we perform
|
usingEHFrameSection, unit, addressSize, context, cieID,
|
||||||
// the full CIE parse to get its initial Cfa ruleset. In the
|
cieAugmentation, cieReader, cieRemaining);
|
||||||
// long term, we should probably
|
if (error != B_OK)
|
||||||
// shift to parsing the CIEs as we hit them and caching
|
return error;
|
||||||
// their information so it can simply be retrieved directly
|
if (cieReader.HasOverflow())
|
||||||
// later.
|
return B_BAD_DATA;
|
||||||
DataReader cieReader;
|
if (cieRemaining < 0)
|
||||||
status_t error = _ParseCIEAugmentation(currentFrameSection,
|
return B_BAD_DATA;
|
||||||
usingEHFrameSection, unit, addressSize, context, cieID,
|
|
||||||
cieAugmentation, cieReader);
|
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
target_addr_t initialLocation = cieAugmentation.ReadEncodedAddress(
|
target_addr_t initialLocation = cieAugmentation.ReadEncodedAddress(
|
||||||
dataReader, fElfFile);
|
dataReader, fElfFile);
|
||||||
@@ -1593,7 +1588,7 @@ DwarfFile::_UnwindCallFrame(bool usingEHFrameSection, CompilationUnit* unit,
|
|||||||
|
|
||||||
context.SetLocation(location, initialLocation);
|
context.SetLocation(location, initialLocation);
|
||||||
uint32 registerCount = outputInterface->CountRegisters();
|
uint32 registerCount = outputInterface->CountRegisters();
|
||||||
status_t error = context.Init(registerCount);
|
error = context.Init(registerCount);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
@@ -1601,9 +1596,10 @@ DwarfFile::_UnwindCallFrame(bool usingEHFrameSection, CompilationUnit* unit,
|
|||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
// process the CIE
|
// process the CIE's frame info instructions
|
||||||
error = _ParseCIE(currentFrameSection, usingEHFrameSection,
|
cieReader = cieReader.RestrictedReader(cieRemaining);
|
||||||
unit, addressSize, context, cieID, cieAugmentation);
|
error = _ParseFrameInfoInstructions(unit, context,
|
||||||
|
cieReader);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
@@ -1772,10 +1768,10 @@ DwarfFile::_UnwindCallFrame(bool usingEHFrameSection, CompilationUnit* unit,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
DwarfFile::_ParseCIEAugmentation(ElfSection* debugFrameSection,
|
DwarfFile::_ParseCIEHeader(ElfSection* debugFrameSection,
|
||||||
bool usingEHFrameSection, CompilationUnit* unit, uint8 addressSize,
|
bool usingEHFrameSection, CompilationUnit* unit, uint8 addressSize,
|
||||||
CfaContext& context, off_t cieOffset, CIEAugmentation& cieAugmentation,
|
CfaContext& context, off_t cieOffset, CIEAugmentation& cieAugmentation,
|
||||||
DataReader& dataReader, off_t* _length, off_t* _lengthOffset)
|
DataReader& dataReader, off_t& _cieRemaining)
|
||||||
{
|
{
|
||||||
if (cieOffset < 0 || cieOffset >= debugFrameSection->Size())
|
if (cieOffset < 0 || cieOffset >= debugFrameSection->Size())
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
@@ -1786,15 +1782,11 @@ DwarfFile::_ParseCIEAugmentation(ElfSection* debugFrameSection,
|
|||||||
|
|
||||||
// length
|
// length
|
||||||
bool dwarf64;
|
bool dwarf64;
|
||||||
uint64 length = dataReader.ReadInitialLength(dwarf64);
|
off_t length = dataReader.ReadInitialLength(dwarf64);
|
||||||
if (length > (uint64)dataReader.BytesRemaining())
|
if (length > (uint64)dataReader.BytesRemaining())
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
|
|
||||||
if (_length != NULL)
|
off_t lengthOffset = dataReader.Offset();
|
||||||
*_length = length;
|
|
||||||
|
|
||||||
if (_lengthOffset != NULL)
|
|
||||||
*_lengthOffset = dataReader.Offset();
|
|
||||||
|
|
||||||
// CIE ID/CIE pointer
|
// CIE ID/CIE pointer
|
||||||
uint64 cieID = dwarf64
|
uint64 cieID = dwarf64
|
||||||
@@ -1842,32 +1834,14 @@ DwarfFile::_ParseCIEAugmentation(ElfSection* debugFrameSection,
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
DwarfFile::_ParseCIE(ElfSection* debugFrameSection, bool usingEHFrameSection,
|
|
||||||
CompilationUnit* unit, uint8 addressSize, CfaContext& context,
|
|
||||||
off_t cieOffset, CIEAugmentation& cieAugmentation)
|
|
||||||
{
|
|
||||||
DataReader dataReader;
|
|
||||||
off_t length;
|
|
||||||
off_t lengthOffset;
|
|
||||||
status_t result = _ParseCIEAugmentation(debugFrameSection,
|
|
||||||
usingEHFrameSection, unit, addressSize, context, cieOffset,
|
|
||||||
cieAugmentation, dataReader, &length, &lengthOffset);
|
|
||||||
if (result != B_OK)
|
|
||||||
return result;
|
|
||||||
if (dataReader.HasOverflow())
|
if (dataReader.HasOverflow())
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
off_t remaining = (off_t)length
|
|
||||||
- (dataReader.Offset() - lengthOffset);
|
_cieRemaining = length -(dataReader.Offset() - lengthOffset);
|
||||||
if (remaining < 0)
|
if (_cieRemaining < 0)
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
|
|
||||||
DataReader restrictedReader = dataReader.RestrictedReader(remaining);
|
return B_OK;
|
||||||
return _ParseFrameInfoInstructions(unit, context, restrictedReader);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -123,22 +123,14 @@ private:
|
|||||||
DwarfTargetInterface* outputInterface,
|
DwarfTargetInterface* outputInterface,
|
||||||
target_addr_t& _framePointer);
|
target_addr_t& _framePointer);
|
||||||
|
|
||||||
status_t _ParseCIEAugmentation(
|
status_t _ParseCIEHeader(ElfSection* debugFrameSection,
|
||||||
ElfSection* debugFrameSection,
|
|
||||||
bool usingEHFrameSection,
|
bool usingEHFrameSection,
|
||||||
CompilationUnit* unit,
|
CompilationUnit* unit,
|
||||||
uint8 addressSize,
|
uint8 addressSize,
|
||||||
CfaContext& context, off_t cieOffset,
|
CfaContext& context, off_t cieOffset,
|
||||||
CIEAugmentation& cieAugmentation,
|
CIEAugmentation& cieAugmentation,
|
||||||
DataReader& reader,
|
DataReader& reader,
|
||||||
off_t* length = NULL,
|
off_t& _cieRemaining);
|
||||||
off_t* lengthOffset = NULL);
|
|
||||||
status_t _ParseCIE(ElfSection* debugFrameSection,
|
|
||||||
bool usingEHFrameSection,
|
|
||||||
CompilationUnit* unit,
|
|
||||||
uint8 addressSize,
|
|
||||||
CfaContext& context, off_t cieOffset,
|
|
||||||
CIEAugmentation& cieAugmentation);
|
|
||||||
status_t _ParseFrameInfoInstructions(
|
status_t _ParseFrameInfoInstructions(
|
||||||
CompilationUnit* unit, CfaContext& context,
|
CompilationUnit* unit, CfaContext& context,
|
||||||
DataReader& dataReader);
|
DataReader& dataReader);
|
||||||
|
|||||||
Reference in New Issue
Block a user