#include "lldb/Symbol/DWARFCallFrameInfo.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/Section.h"
#include "lldb/Core/dwarf.h"
#include "lldb/Host/Host.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/UnwindPlan.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Timer.h"
#include <cstring>
#include <list>
#include <optional>
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::dwarf;
static uint64_t
GetGNUEHPointer(const DataExtractor &DE, offset_t *offset_ptr,
uint32_t eh_ptr_enc, addr_t pc_rel_addr, addr_t text_addr,
addr_t data_addr)
{
if (eh_ptr_enc == DW_EH_PE_omit)
return ULLONG_MAX;
uint64_t baseAddress = 0;
uint64_t addressValue = 0;
const uint32_t addr_size = DE.GetAddressByteSize();
assert(addr_size == 4 || addr_size == 8);
bool signExtendValue = false;
switch (eh_ptr_enc & 0x70) {
case DW_EH_PE_pcrel:
signExtendValue = true;
baseAddress = *offset_ptr;
if (pc_rel_addr != LLDB_INVALID_ADDRESS)
baseAddress += pc_rel_addr;
break;
case DW_EH_PE_textrel:
signExtendValue = true;
if (text_addr != LLDB_INVALID_ADDRESS)
baseAddress = text_addr;
break;
case DW_EH_PE_datarel:
signExtendValue = true;
if (data_addr != LLDB_INVALID_ADDRESS)
baseAddress = data_addr;
break;
case DW_EH_PE_funcrel:
signExtendValue = true;
break;
case DW_EH_PE_aligned: {
assert(addr_size != 0);
if (addr_size) {
uint32_t alignOffset = *offset_ptr % addr_size;
if (alignOffset)
offset_ptr += addr_size - alignOffset;
}
} break;
default:
break;
}
switch (eh_ptr_enc & DW_EH_PE_MASK_ENCODING) {
case DW_EH_PE_absptr: {
addressValue = DE.GetAddress(offset_ptr);
} break;
case DW_EH_PE_uleb128:
addressValue = DE.GetULEB128(offset_ptr);
break;
case DW_EH_PE_udata2:
addressValue = DE.GetU16(offset_ptr);
break;
case DW_EH_PE_udata4:
addressValue = DE.GetU32(offset_ptr);
break;
case DW_EH_PE_udata8:
addressValue = DE.GetU64(offset_ptr);
break;
case DW_EH_PE_sleb128:
addressValue = DE.GetSLEB128(offset_ptr);
break;
case DW_EH_PE_sdata2:
addressValue = (int16_t)DE.GetU16(offset_ptr);
break;
case DW_EH_PE_sdata4:
addressValue = (int32_t)DE.GetU32(offset_ptr);
break;
case DW_EH_PE_sdata8:
addressValue = (int64_t)DE.GetU64(offset_ptr);
break;
default:
assert(eh_ptr_enc);
break;
}
if (signExtendValue && addr_size < sizeof(baseAddress)) {
uint64_t sign_bit = 1ull << ((addr_size * 8ull) - 1ull);
if (sign_bit & addressValue) {
uint64_t mask = ~sign_bit + 1;
addressValue |= mask;
}
}
return baseAddress + addressValue;
}
DWARFCallFrameInfo::DWARFCallFrameInfo(ObjectFile &objfile,
SectionSP §ion_sp, Type type)
: m_objfile(objfile), m_section_sp(section_sp), m_type(type) {}
bool DWARFCallFrameInfo::GetUnwindPlan(const Address &addr,
UnwindPlan &unwind_plan) {
return GetUnwindPlan(AddressRange(addr, 1), unwind_plan);
}
bool DWARFCallFrameInfo::GetUnwindPlan(const AddressRange &range,
UnwindPlan &unwind_plan) {
FDEEntryMap::Entry fde_entry;
Address addr = range.GetBaseAddress();
ModuleSP module_sp = addr.GetModule();
if (module_sp.get() == nullptr || module_sp->GetObjectFile() == nullptr ||
module_sp->GetObjectFile() != &m_objfile)
return false;
if (std::optional<FDEEntryMap::Entry> entry = GetFirstFDEEntryInRange(range))
return FDEToUnwindPlan(entry->data, addr, unwind_plan);
return false;
}
bool DWARFCallFrameInfo::GetAddressRange(Address addr, AddressRange &range) {
ModuleSP module_sp = addr.GetModule();
if (module_sp.get() == nullptr || module_sp->GetObjectFile() == nullptr ||
module_sp->GetObjectFile() != &m_objfile)
return false;
if (m_section_sp.get() == nullptr || m_section_sp->IsEncrypted())
return false;
GetFDEIndex();
FDEEntryMap::Entry *fde_entry =
m_fde_index.FindEntryThatContains(addr.GetFileAddress());
if (!fde_entry)
return false;
range = AddressRange(fde_entry->base, fde_entry->size,
m_objfile.GetSectionList());
return true;
}
std::optional<DWARFCallFrameInfo::FDEEntryMap::Entry>
DWARFCallFrameInfo::GetFirstFDEEntryInRange(const AddressRange &range) {
if (!m_section_sp || m_section_sp->IsEncrypted())
return std::nullopt;
GetFDEIndex();
addr_t start_file_addr = range.GetBaseAddress().GetFileAddress();
const FDEEntryMap::Entry *fde =
m_fde_index.FindEntryThatContainsOrFollows(start_file_addr);
if (fde && fde->DoesIntersect(
FDEEntryMap::Range(start_file_addr, range.GetByteSize())))
return *fde;
return std::nullopt;
}
void DWARFCallFrameInfo::GetFunctionAddressAndSizeVector(
FunctionAddressAndSizeVector &function_info) {
GetFDEIndex();
const size_t count = m_fde_index.GetSize();
function_info.Clear();
if (count > 0)
function_info.Reserve(count);
for (size_t i = 0; i < count; ++i) {
const FDEEntryMap::Entry *func_offset_data_entry =
m_fde_index.GetEntryAtIndex(i);
if (func_offset_data_entry) {
FunctionAddressAndSizeVector::Entry function_offset_entry(
func_offset_data_entry->base, func_offset_data_entry->size);
function_info.Append(function_offset_entry);
}
}
}
const DWARFCallFrameInfo::CIE *
DWARFCallFrameInfo::GetCIE(dw_offset_t cie_offset) {
cie_map_t::iterator pos = m_cie_map.find(cie_offset);
if (pos != m_cie_map.end()) {
if (pos->second == nullptr)
pos->second = ParseCIE(cie_offset);
return pos->second.get();
}
return nullptr;
}
DWARFCallFrameInfo::CIESP
DWARFCallFrameInfo::ParseCIE(const dw_offset_t cie_offset) {
CIESP cie_sp(new CIE(cie_offset));
lldb::offset_t offset = cie_offset;
if (!m_cfi_data_initialized)
GetCFIData();
uint32_t length = m_cfi_data.GetU32(&offset);
dw_offset_t cie_id, end_offset;
bool is_64bit = (length == UINT32_MAX);
if (is_64bit) {
length = m_cfi_data.GetU64(&offset);
cie_id = m_cfi_data.GetU64(&offset);
end_offset = cie_offset + length + 12;
} else {
cie_id = m_cfi_data.GetU32(&offset);
end_offset = cie_offset + length + 4;
}
if (length > 0 && ((m_type == DWARF && cie_id == UINT32_MAX) ||
(m_type == EH && cie_id == 0ul))) {
size_t i;
cie_sp->ptr_encoding = DW_EH_PE_absptr;
cie_sp->version = m_cfi_data.GetU8(&offset);
if (cie_sp->version > CFI_VERSION4) {
Debugger::ReportError(
llvm::formatv("CIE parse error: CFI version {0} is not supported",
cie_sp->version));
return nullptr;
}
for (i = 0; i < CFI_AUG_MAX_SIZE; ++i) {
cie_sp->augmentation[i] = m_cfi_data.GetU8(&offset);
if (cie_sp->augmentation[i] == '\0') {
for (size_t j = i + 1; j < CFI_AUG_MAX_SIZE; ++j)
cie_sp->augmentation[j] = '\0';
break;
}
}
if (i == CFI_AUG_MAX_SIZE &&
cie_sp->augmentation[CFI_AUG_MAX_SIZE - 1] != '\0') {
Debugger::ReportError(llvm::formatv(
"CIE parse error: CIE augmentation string was too large "
"for the fixed sized buffer of {0} bytes.",
CFI_AUG_MAX_SIZE));
return nullptr;
}
if (m_type == DWARF && cie_sp->version >= CFI_VERSION4) {
cie_sp->address_size = m_cfi_data.GetU8(&offset);
cie_sp->segment_size = m_cfi_data.GetU8(&offset);
}
cie_sp->code_align = (uint32_t)m_cfi_data.GetULEB128(&offset);
cie_sp->data_align = (int32_t)m_cfi_data.GetSLEB128(&offset);
cie_sp->return_addr_reg_num =
m_type == DWARF && cie_sp->version >= CFI_VERSION3
? static_cast<uint32_t>(m_cfi_data.GetULEB128(&offset))
: m_cfi_data.GetU8(&offset);
if (cie_sp->augmentation[0]) {
const size_t aug_data_len = (size_t)m_cfi_data.GetULEB128(&offset);
const size_t aug_data_end = offset + aug_data_len;
const size_t aug_str_len = strlen(cie_sp->augmentation);
if (cie_sp->augmentation[0] == 'z') {
size_t aug_str_idx = 0;
for (aug_str_idx = 1; aug_str_idx < aug_str_len; aug_str_idx++) {
char aug = cie_sp->augmentation[aug_str_idx];
switch (aug) {
case 'L':
cie_sp->lsda_addr_encoding = m_cfi_data.GetU8(&offset);
break;
case 'P':
{
uint8_t arg_ptr_encoding = m_cfi_data.GetU8(&offset);
const lldb::addr_t pc_rel_addr = m_section_sp->GetFileAddress();
cie_sp->personality_loc = GetGNUEHPointer(
m_cfi_data, &offset, arg_ptr_encoding, pc_rel_addr,
LLDB_INVALID_ADDRESS, LLDB_INVALID_ADDRESS);
}
break;
case 'R':
cie_sp->ptr_encoding = m_cfi_data.GetU8(&offset);
break;
}
}
} else if (strcmp(cie_sp->augmentation, "eh") == 0) {
}
offset = (uint32_t)aug_data_end;
}
if (end_offset > offset) {
cie_sp->inst_offset = offset;
cie_sp->inst_length = end_offset - offset;
}
while (offset < end_offset) {
uint8_t inst = m_cfi_data.GetU8(&offset);
uint8_t primary_opcode = inst & 0xC0;
uint8_t extended_opcode = inst & 0x3F;
if (!HandleCommonDwarfOpcode(primary_opcode, extended_opcode,
cie_sp->data_align, offset,
cie_sp->initial_row))
break;
}
}
return cie_sp;
}
void DWARFCallFrameInfo::GetCFIData() {
if (!m_cfi_data_initialized) {
Log *log = GetLog(LLDBLog::Unwind);
if (log)
m_objfile.GetModule()->LogMessage(log, "Reading EH frame info");
m_objfile.ReadSectionData(m_section_sp.get(), m_cfi_data);
m_cfi_data_initialized = true;
}
}
void DWARFCallFrameInfo::GetFDEIndex() {
if (m_section_sp.get() == nullptr || m_section_sp->IsEncrypted())
return;
if (m_fde_index_initialized)
return;
std::lock_guard<std::mutex> guard(m_fde_index_mutex);
if (m_fde_index_initialized)
return;
LLDB_SCOPED_TIMERF("%s", m_objfile.GetFileSpec().GetFilename().AsCString(""));
bool clear_address_zeroth_bit = false;
if (ArchSpec arch = m_objfile.GetArchitecture()) {
if (arch.GetTriple().getArch() == llvm::Triple::arm ||
arch.GetTriple().getArch() == llvm::Triple::thumb)
clear_address_zeroth_bit = true;
}
lldb::offset_t offset = 0;
if (!m_cfi_data_initialized)
GetCFIData();
while (m_cfi_data.ValidOffsetForDataOfSize(offset, 8)) {
const dw_offset_t current_entry = offset;
dw_offset_t cie_id, next_entry, cie_offset;
uint32_t len = m_cfi_data.GetU32(&offset);
bool is_64bit = (len == UINT32_MAX);
if (is_64bit) {
len = m_cfi_data.GetU64(&offset);
cie_id = m_cfi_data.GetU64(&offset);
next_entry = current_entry + len + 12;
cie_offset = current_entry + 12 - cie_id;
} else {
cie_id = m_cfi_data.GetU32(&offset);
next_entry = current_entry + len + 4;
cie_offset = current_entry + 4 - cie_id;
}
if (next_entry > m_cfi_data.GetByteSize() + 1) {
Debugger::ReportError(llvm::formatv("Invalid fde/cie next entry offset "
"of {0:x} found in cie/fde at {1:x}",
next_entry, current_entry));
m_fde_index.Clear();
m_fde_index_initialized = true;
return;
}
if ((cie_id == 0 && m_type == EH) || cie_id == UINT32_MAX || len == 0) {
auto cie_sp = ParseCIE(current_entry);
if (!cie_sp) {
m_fde_index.Clear();
m_fde_index_initialized = true;
return;
}
m_cie_map[current_entry] = std::move(cie_sp);
offset = next_entry;
continue;
}
if (m_type == DWARF)
cie_offset = cie_id;
if (cie_offset > m_cfi_data.GetByteSize()) {
Debugger::ReportError(llvm::formatv("Invalid cie offset of {0:x} "
"found in cie/fde at {1:x}",
cie_offset, current_entry));
m_fde_index.Clear();
m_fde_index_initialized = true;
return;
}
const CIE *cie = GetCIE(cie_offset);
if (cie) {
const lldb::addr_t pc_rel_addr = m_section_sp->GetFileAddress();
const lldb::addr_t text_addr = LLDB_INVALID_ADDRESS;
const lldb::addr_t data_addr = LLDB_INVALID_ADDRESS;
lldb::addr_t addr =
GetGNUEHPointer(m_cfi_data, &offset, cie->ptr_encoding, pc_rel_addr,
text_addr, data_addr);
if (clear_address_zeroth_bit)
addr &= ~1ull;
lldb::addr_t length = GetGNUEHPointer(
m_cfi_data, &offset, cie->ptr_encoding & DW_EH_PE_MASK_ENCODING,
pc_rel_addr, text_addr, data_addr);
FDEEntryMap::Entry fde(addr, length, current_entry);
m_fde_index.Append(fde);
} else {
Debugger::ReportError(llvm::formatv(
"unable to find CIE at {0:x} for cie_id = {1:x} for entry at {2:x}.",
cie_offset, cie_id, current_entry));
}
offset = next_entry;
}
m_fde_index.Sort();
m_fde_index_initialized = true;
}
bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t dwarf_offset,
Address startaddr,
UnwindPlan &unwind_plan) {
Log *log = GetLog(LLDBLog::Unwind);
lldb::offset_t offset = dwarf_offset;
lldb::offset_t current_entry = offset;
if (m_section_sp.get() == nullptr || m_section_sp->IsEncrypted())
return false;
if (!m_cfi_data_initialized)
GetCFIData();
uint32_t length = m_cfi_data.GetU32(&offset);
dw_offset_t cie_offset;
bool is_64bit = (length == UINT32_MAX);
if (is_64bit) {
length = m_cfi_data.GetU64(&offset);
cie_offset = m_cfi_data.GetU64(&offset);
} else {
cie_offset = m_cfi_data.GetU32(&offset);
}
assert(!(m_type == EH && 0 == cie_offset) && cie_offset != UINT32_MAX);
if (m_type == EH) {
unwind_plan.SetSourceName("eh_frame CFI");
cie_offset = current_entry + (is_64bit ? 12 : 4) - cie_offset;
unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
} else {
unwind_plan.SetSourceName("DWARF CFI");
unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
}
unwind_plan.SetSourcedFromCompiler(eLazyBoolYes);
const CIE *cie = GetCIE(cie_offset);
assert(cie != nullptr);
const dw_offset_t end_offset = current_entry + length + (is_64bit ? 12 : 4);
const lldb::addr_t pc_rel_addr = m_section_sp->GetFileAddress();
const lldb::addr_t text_addr = LLDB_INVALID_ADDRESS;
const lldb::addr_t data_addr = LLDB_INVALID_ADDRESS;
lldb::addr_t range_base =
GetGNUEHPointer(m_cfi_data, &offset, cie->ptr_encoding, pc_rel_addr,
text_addr, data_addr);
lldb::addr_t range_len = GetGNUEHPointer(
m_cfi_data, &offset, cie->ptr_encoding & DW_EH_PE_MASK_ENCODING,
pc_rel_addr, text_addr, data_addr);
AddressRange range(range_base, m_objfile.GetAddressByteSize(),
m_objfile.GetSectionList());
range.SetByteSize(range_len);
addr_t lsda_data_file_address = LLDB_INVALID_ADDRESS;
if (cie->augmentation[0] == 'z') {
uint32_t aug_data_len = (uint32_t)m_cfi_data.GetULEB128(&offset);
if (aug_data_len != 0 && cie->lsda_addr_encoding != DW_EH_PE_omit) {
offset_t saved_offset = offset;
lsda_data_file_address =
GetGNUEHPointer(m_cfi_data, &offset, cie->lsda_addr_encoding,
pc_rel_addr, text_addr, data_addr);
if (offset - saved_offset != aug_data_len) {
lsda_data_file_address = LLDB_INVALID_ADDRESS;
}
offset = saved_offset;
}
offset += aug_data_len;
}
unwind_plan.SetUnwindPlanForSignalTrap(
strchr(cie->augmentation, 'S') ? eLazyBoolYes : eLazyBoolNo);
Address lsda_data;
Address personality_function_ptr;
if (lsda_data_file_address != LLDB_INVALID_ADDRESS &&
cie->personality_loc != LLDB_INVALID_ADDRESS) {
m_objfile.GetModule()->ResolveFileAddress(lsda_data_file_address,
lsda_data);
m_objfile.GetModule()->ResolveFileAddress(cie->personality_loc,
personality_function_ptr);
}
if (lsda_data.IsValid() && personality_function_ptr.IsValid()) {
unwind_plan.SetLSDAAddress(lsda_data);
unwind_plan.SetPersonalityFunctionPtr(personality_function_ptr);
}
uint32_t code_align = cie->code_align;
int32_t data_align = cie->data_align;
unwind_plan.SetPlanValidAddressRange(range);
UnwindPlan::Row *cie_initial_row = new UnwindPlan::Row;
*cie_initial_row = cie->initial_row;
UnwindPlan::RowSP row(cie_initial_row);
unwind_plan.SetRegisterKind(GetRegisterKind());
unwind_plan.SetReturnAddressRegister(cie->return_addr_reg_num);
std::vector<UnwindPlan::RowSP> stack;
UnwindPlan::Row::RegisterLocation reg_location;
while (m_cfi_data.ValidOffset(offset) && offset < end_offset) {
uint8_t inst = m_cfi_data.GetU8(&offset);
uint8_t primary_opcode = inst & 0xC0;
uint8_t extended_opcode = inst & 0x3F;
if (!HandleCommonDwarfOpcode(primary_opcode, extended_opcode, data_align,
offset, *row)) {
if (primary_opcode) {
switch (primary_opcode) {
case DW_CFA_advance_loc:
{
unwind_plan.AppendRow(row);
UnwindPlan::Row *newrow = new UnwindPlan::Row;
*newrow = *row.get();
row.reset(newrow);
row->SlideOffset(extended_opcode * code_align);
break;
}
case DW_CFA_restore: {
uint32_t reg_num = extended_opcode;
if (unwind_plan.IsValidRowIndex(0) &&
unwind_plan.GetRowAtIndex(0)->GetRegisterInfo(reg_num,
reg_location))
row->SetRegisterInfo(reg_num, reg_location);
else {
row->RemoveRegisterInfo(reg_num);
}
break;
}
}
} else {
switch (extended_opcode) {
case DW_CFA_set_loc:
{
unwind_plan.AppendRow(row);
UnwindPlan::Row *newrow = new UnwindPlan::Row;
*newrow = *row.get();
row.reset(newrow);
row->SetOffset(m_cfi_data.GetAddress(&offset) -
startaddr.GetFileAddress());
break;
}
case DW_CFA_advance_loc1:
{
unwind_plan.AppendRow(row);
UnwindPlan::Row *newrow = new UnwindPlan::Row;
*newrow = *row.get();
row.reset(newrow);
row->SlideOffset(m_cfi_data.GetU8(&offset) * code_align);
break;
}
case DW_CFA_advance_loc2:
{
unwind_plan.AppendRow(row);
UnwindPlan::Row *newrow = new UnwindPlan::Row;
*newrow = *row.get();
row.reset(newrow);
row->SlideOffset(m_cfi_data.GetU16(&offset) * code_align);
break;
}
case DW_CFA_advance_loc4:
{
unwind_plan.AppendRow(row);
UnwindPlan::Row *newrow = new UnwindPlan::Row;
*newrow = *row.get();
row.reset(newrow);
row->SlideOffset(m_cfi_data.GetU32(&offset) * code_align);
break;
}
case DW_CFA_restore_extended:
{
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
if (unwind_plan.IsValidRowIndex(0) &&
unwind_plan.GetRowAtIndex(0)->GetRegisterInfo(reg_num,
reg_location))
row->SetRegisterInfo(reg_num, reg_location);
break;
}
case DW_CFA_remember_state:
{
stack.push_back(row);
UnwindPlan::Row *newrow = new UnwindPlan::Row;
*newrow = *row.get();
row.reset(newrow);
break;
}
case DW_CFA_restore_state:
{
if (stack.empty()) {
LLDB_LOG(log,
"DWARFCallFrameInfo::{0}(dwarf_offset: "
"{1:x16}, startaddr: [{2:x16}] encountered "
"DW_CFA_restore_state but state stack "
"is empty. Corrupt unwind info?",
__FUNCTION__, dwarf_offset, startaddr.GetFileAddress());
break;
}
lldb::addr_t offset = row->GetOffset();
row = stack.back();
stack.pop_back();
row->SetOffset(offset);
break;
}
case DW_CFA_GNU_args_size:
{
m_cfi_data.GetULEB128(&offset);
break;
}
case DW_CFA_val_offset:
case DW_CFA_val_offset_sf:
default:
break;
}
}
}
}
unwind_plan.AppendRow(row);
return true;
}
bool DWARFCallFrameInfo::HandleCommonDwarfOpcode(uint8_t primary_opcode,
uint8_t extended_opcode,
int32_t data_align,
lldb::offset_t &offset,
UnwindPlan::Row &row) {
UnwindPlan::Row::RegisterLocation reg_location;
if (primary_opcode) {
switch (primary_opcode) {
case DW_CFA_offset: {
uint8_t reg_num = extended_opcode;
int32_t op_offset = (int32_t)m_cfi_data.GetULEB128(&offset) * data_align;
reg_location.SetAtCFAPlusOffset(op_offset);
row.SetRegisterInfo(reg_num, reg_location);
return true;
}
}
} else {
switch (extended_opcode) {
case DW_CFA_nop:
return true;
case DW_CFA_offset_extended:
{
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
int32_t op_offset = (int32_t)m_cfi_data.GetULEB128(&offset) * data_align;
UnwindPlan::Row::RegisterLocation reg_location;
reg_location.SetAtCFAPlusOffset(op_offset);
row.SetRegisterInfo(reg_num, reg_location);
return true;
}
case DW_CFA_undefined:
{
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
UnwindPlan::Row::RegisterLocation reg_location;
reg_location.SetUndefined();
row.SetRegisterInfo(reg_num, reg_location);
return true;
}
case DW_CFA_same_value:
{
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
UnwindPlan::Row::RegisterLocation reg_location;
reg_location.SetSame();
row.SetRegisterInfo(reg_num, reg_location);
return true;
}
case DW_CFA_register:
{
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
uint32_t other_reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
UnwindPlan::Row::RegisterLocation reg_location;
reg_location.SetInRegister(other_reg_num);
row.SetRegisterInfo(reg_num, reg_location);
return true;
}
case DW_CFA_def_cfa:
{
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
int32_t op_offset = (int32_t)m_cfi_data.GetULEB128(&offset);
row.GetCFAValue().SetIsRegisterPlusOffset(reg_num, op_offset);
return true;
}
case DW_CFA_def_cfa_register:
{
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
row.GetCFAValue().SetIsRegisterPlusOffset(reg_num,
row.GetCFAValue().GetOffset());
return true;
}
case DW_CFA_def_cfa_offset:
{
int32_t op_offset = (int32_t)m_cfi_data.GetULEB128(&offset);
row.GetCFAValue().SetIsRegisterPlusOffset(
row.GetCFAValue().GetRegisterNumber(), op_offset);
return true;
}
case DW_CFA_def_cfa_expression:
{
size_t block_len = (size_t)m_cfi_data.GetULEB128(&offset);
const uint8_t *block_data =
static_cast<const uint8_t *>(m_cfi_data.GetData(&offset, block_len));
row.GetCFAValue().SetIsDWARFExpression(block_data, block_len);
return true;
}
case DW_CFA_expression:
{
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
uint32_t block_len = (uint32_t)m_cfi_data.GetULEB128(&offset);
const uint8_t *block_data =
static_cast<const uint8_t *>(m_cfi_data.GetData(&offset, block_len));
UnwindPlan::Row::RegisterLocation reg_location;
reg_location.SetAtDWARFExpression(block_data, block_len);
row.SetRegisterInfo(reg_num, reg_location);
return true;
}
case DW_CFA_offset_extended_sf:
{
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
int32_t op_offset = (int32_t)m_cfi_data.GetSLEB128(&offset) * data_align;
UnwindPlan::Row::RegisterLocation reg_location;
reg_location.SetAtCFAPlusOffset(op_offset);
row.SetRegisterInfo(reg_num, reg_location);
return true;
}
case DW_CFA_def_cfa_sf:
{
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
int32_t op_offset = (int32_t)m_cfi_data.GetSLEB128(&offset) * data_align;
row.GetCFAValue().SetIsRegisterPlusOffset(reg_num, op_offset);
return true;
}
case DW_CFA_def_cfa_offset_sf:
{
int32_t op_offset = (int32_t)m_cfi_data.GetSLEB128(&offset) * data_align;
uint32_t cfa_regnum = row.GetCFAValue().GetRegisterNumber();
row.GetCFAValue().SetIsRegisterPlusOffset(cfa_regnum, op_offset);
return true;
}
case DW_CFA_val_expression:
{
uint32_t reg_num = (uint32_t)m_cfi_data.GetULEB128(&offset);
uint32_t block_len = (uint32_t)m_cfi_data.GetULEB128(&offset);
const uint8_t *block_data =
(const uint8_t *)m_cfi_data.GetData(&offset, block_len);
reg_location.SetIsDWARFExpression(block_data, block_len);
row.SetRegisterInfo(reg_num, reg_location);
return true;
}
}
}
return false;
}
void DWARFCallFrameInfo::ForEachFDEEntries(
const std::function<bool(lldb::addr_t, uint32_t, dw_offset_t)> &callback) {
GetFDEIndex();
for (size_t i = 0, c = m_fde_index.GetSize(); i < c; ++i) {
const FDEEntryMap::Entry &entry = m_fde_index.GetEntryRef(i);
if (!callback(entry.base, entry.size, entry.data))
break;
}
}