2010-06-09 00:52:24 +08:00
//===-- DWARFCallFrameInfo.cpp ----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// C Includes
// C++ Includes
# include <list>
2010-10-26 20:01:35 +08:00
# include "lldb/Core/Log.h"
2010-09-10 15:49:16 +08:00
# include "lldb/Core/Section.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Core/ArchSpec.h"
# include "lldb/Core/Module.h"
2012-01-05 11:57:59 +08:00
# include "lldb/Core/Section.h"
2013-03-21 05:57:42 +08:00
# include "lldb/Core/Timer.h"
2012-01-05 11:57:59 +08:00
# include "lldb/Host/Host.h"
# include "lldb/Symbol/DWARFCallFrameInfo.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Symbol/ObjectFile.h"
2012-01-05 11:57:59 +08:00
# include "lldb/Symbol/UnwindPlan.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Target/RegisterContext.h"
# include "lldb/Target/Thread.h"
using namespace lldb ;
using namespace lldb_private ;
2012-02-05 10:38:54 +08:00
DWARFCallFrameInfo : : DWARFCallFrameInfo ( ObjectFile & objfile , SectionSP & section_sp , lldb : : RegisterKind reg_kind , bool is_eh_frame ) :
2010-09-10 15:49:16 +08:00
m_objfile ( objfile ) ,
2012-02-05 10:38:54 +08:00
m_section_sp ( section_sp ) ,
2010-09-10 15:49:16 +08:00
m_reg_kind ( reg_kind ) , // The flavor of registers that the CFI data uses (enum RegisterKind)
2011-04-12 03:41:40 +08:00
m_flags ( ) ,
2010-09-10 15:49:16 +08:00
m_cie_map ( ) ,
m_cfi_data ( ) ,
m_cfi_data_initialized ( false ) ,
m_fde_index ( ) ,
m_fde_index_initialized ( false ) ,
2011-04-12 03:41:40 +08:00
m_is_eh_frame ( is_eh_frame )
2010-06-09 00:52:24 +08:00
{
}
2010-09-10 15:49:16 +08:00
DWARFCallFrameInfo : : ~ DWARFCallFrameInfo ( )
2010-06-09 00:52:24 +08:00
{
}
bool
2013-03-21 05:57:42 +08:00
DWARFCallFrameInfo : : GetUnwindPlan ( Address addr , UnwindPlan & unwind_plan )
2010-06-09 00:52:24 +08:00
{
2013-03-21 05:57:42 +08:00
FDEEntryMap : : Entry fde_entry ;
// Make sure that the Address we're searching for is the same object file
// as this DWARFCallFrameInfo, we only store File offsets in m_fde_index.
ModuleSP module_sp = addr . GetModule ( ) ;
2014-04-20 21:17:36 +08:00
if ( module_sp . get ( ) = = nullptr | | module_sp - > GetObjectFile ( ) = = nullptr | | module_sp - > GetObjectFile ( ) ! = & m_objfile )
2010-06-09 00:52:24 +08:00
return false ;
2013-03-21 05:57:42 +08:00
if ( GetFDEEntryByFileAddress ( addr . GetFileAddress ( ) , fde_entry ) = = false )
return false ;
return FDEToUnwindPlan ( fde_entry . data , addr , unwind_plan ) ;
2010-06-09 00:52:24 +08:00
}
2010-09-10 15:49:16 +08:00
bool
2013-03-21 05:57:42 +08:00
DWARFCallFrameInfo : : GetAddressRange ( Address addr , AddressRange & range )
2010-06-09 00:52:24 +08:00
{
2013-03-21 05:57:42 +08:00
// Make sure that the Address we're searching for is the same object file
// as this DWARFCallFrameInfo, we only store File offsets in m_fde_index.
ModuleSP module_sp = addr . GetModule ( ) ;
2014-04-20 21:17:36 +08:00
if ( module_sp . get ( ) = = nullptr | | module_sp - > GetObjectFile ( ) = = nullptr | | module_sp - > GetObjectFile ( ) ! = & m_objfile )
2013-03-21 05:57:42 +08:00
return false ;
2014-04-20 21:17:36 +08:00
if ( m_section_sp . get ( ) = = nullptr | | m_section_sp - > IsEncrypted ( ) )
2013-03-21 05:57:42 +08:00
return false ;
GetFDEIndex ( ) ;
FDEEntryMap : : Entry * fde_entry = m_fde_index . FindEntryThatContains ( addr . GetFileAddress ( ) ) ;
if ( ! fde_entry )
2010-09-10 15:49:16 +08:00
return false ;
2013-03-21 05:57:42 +08:00
range = AddressRange ( fde_entry - > base , fde_entry - > size , m_objfile . GetSectionList ( ) ) ;
return true ;
2010-06-09 00:52:24 +08:00
}
bool
2013-03-21 05:57:42 +08:00
DWARFCallFrameInfo : : GetFDEEntryByFileAddress ( addr_t file_addr , FDEEntryMap : : Entry & fde_entry )
2010-06-09 00:52:24 +08:00
{
2014-04-20 21:17:36 +08:00
if ( m_section_sp . get ( ) = = nullptr | | m_section_sp - > IsEncrypted ( ) )
2010-09-10 15:49:16 +08:00
return false ;
2010-06-09 00:52:24 +08:00
2013-03-21 05:57:42 +08:00
GetFDEIndex ( ) ;
2010-06-09 00:52:24 +08:00
2013-03-21 05:57:42 +08:00
if ( m_fde_index . IsEmpty ( ) )
2010-09-10 15:49:16 +08:00
return false ;
2010-06-09 00:52:24 +08:00
2013-03-21 05:57:42 +08:00
FDEEntryMap : : Entry * fde = m_fde_index . FindEntryThatContains ( file_addr ) ;
2010-06-09 00:52:24 +08:00
2014-04-20 21:17:36 +08:00
if ( fde = = nullptr )
2013-03-21 05:57:42 +08:00
return false ;
fde_entry = * fde ;
return true ;
2010-06-09 00:52:24 +08:00
}
2013-03-21 11:36:01 +08:00
void
DWARFCallFrameInfo : : GetFunctionAddressAndSizeVector ( FunctionAddressAndSizeVector & function_info )
{
GetFDEIndex ( ) ;
const size_t count = m_fde_index . GetSize ( ) ;
2013-03-23 06:43:14 +08:00
function_info . Clear ( ) ;
2013-03-23 07:42:09 +08:00
if ( count > 0 )
function_info . Reserve ( count ) ;
2013-03-21 11:36:01 +08:00
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 ) ;
}
}
}
2010-06-09 00:52:24 +08:00
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 ( ) )
{
// Parse and cache the CIE
2014-04-20 21:17:36 +08:00
if ( pos - > second . get ( ) = = nullptr )
2010-06-09 00:52:24 +08:00
pos - > second = ParseCIE ( cie_offset ) ;
return pos - > second . get ( ) ;
}
2014-04-20 21:17:36 +08:00
return nullptr ;
2010-06-09 00:52:24 +08:00
}
2010-09-10 15:49:16 +08:00
DWARFCallFrameInfo : : CIESP
2010-06-09 00:52:24 +08:00
DWARFCallFrameInfo : : ParseCIE ( const dw_offset_t cie_offset )
{
2010-09-10 15:49:16 +08:00
CIESP cie_sp ( new CIE ( cie_offset ) ) ;
2013-01-26 02:06:21 +08:00
lldb : : offset_t offset = cie_offset ;
2010-09-10 15:49:16 +08:00
if ( m_cfi_data_initialized = = false )
2011-12-29 08:05:26 +08:00
GetCFIData ( ) ;
2014-08-26 05:39:30 +08:00
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 ;
}
2013-01-26 02:06:21 +08:00
if ( length > 0 & & ( ( ! m_is_eh_frame & & cie_id = = UINT32_MAX ) | | ( m_is_eh_frame & & cie_id = = 0ul ) ) )
2010-06-09 00:52:24 +08:00
{
size_t i ;
// cie.offset = cie_offset;
// cie.length = length;
// cie.cieID = cieID;
2013-07-30 00:05:11 +08:00
cie_sp - > ptr_encoding = DW_EH_PE_absptr ; // default
2010-06-09 00:52:24 +08:00
cie_sp - > version = m_cfi_data . GetU8 ( & offset ) ;
for ( i = 0 ; i < CFI_AUG_MAX_SIZE ; + + i )
{
cie_sp - > augmentation [ i ] = m_cfi_data . GetU8 ( & offset ) ;
if ( cie_sp - > augmentation [ i ] = = ' \0 ' )
{
// Zero out remaining bytes in augmentation string
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 ' )
{
2012-01-05 11:57:59 +08:00
Host : : SystemLog ( Host : : eSystemLogError , " CIE parse error: CIE augmentation string was too large for the fixed sized buffer of %d bytes. \n " , CFI_AUG_MAX_SIZE ) ;
2010-06-09 00:52:24 +08:00
return cie_sp ;
}
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_cfi_data . GetU8 ( & offset ) ;
if ( cie_sp - > augmentation [ 0 ] )
{
// Get the length of the eh_frame augmentation data
// which starts with a ULEB128 length in bytes
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 ) ;
// A 'z' may be present as the first character of the string.
// If present, the Augmentation Data field shall be present.
2015-06-18 13:27:05 +08:00
// The contents of the Augmentation Data shall be interpreted
2010-06-09 00:52:24 +08:00
// according to other characters in the Augmentation String.
if ( cie_sp - > augmentation [ 0 ] = = ' z ' )
{
// Extract the Augmentation Data
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 ' :
// Indicates the presence of one argument in the
// Augmentation Data of the CIE, and a corresponding
// argument in the Augmentation Data of the FDE. The
// argument in the Augmentation Data of the CIE is
// 1-byte and represents the pointer encoding used
// for the argument in the Augmentation Data of the
// FDE, which is the address of a language-specific
// data area (LSDA). The size of the LSDA pointer is
// specified by the pointer encoding used.
2014-11-18 10:27:42 +08:00
cie_sp - > lsda_addr_encoding = m_cfi_data . GetU8 ( & offset ) ;
2010-06-09 00:52:24 +08:00
break ;
case ' P ' :
// Indicates the presence of two arguments in the
2014-11-18 10:27:42 +08:00
// Augmentation Data of the CIE. The first argument
2010-06-09 00:52:24 +08:00
// is 1-byte and represents the pointer encoding
// used for the second argument, which is the
// address of a personality routine handler. The
// size of the personality routine pointer is
// specified by the pointer encoding used.
2014-11-18 10:27:42 +08:00
//
// The address of the personality function will
// be stored at this location. Pre-execution, it
// will be all zero's so don't read it until we're
// trying to do an unwind & the reloc has been
// resolved.
2010-06-09 00:52:24 +08:00
{
uint8_t arg_ptr_encoding = m_cfi_data . GetU8 ( & offset ) ;
2014-11-18 10:27:42 +08:00
const lldb : : addr_t pc_rel_addr = m_section_sp - > GetFileAddress ( ) ;
cie_sp - > personality_loc = m_cfi_data . GetGNUEHPointer ( & offset , arg_ptr_encoding , pc_rel_addr , LLDB_INVALID_ADDRESS , LLDB_INVALID_ADDRESS ) ;
2010-06-09 00:52:24 +08:00
}
break ;
case ' R ' :
// A 'R' may be present at any position after the
// first character of the string. The Augmentation
// Data shall include a 1 byte argument that
// represents the pointer encoding for the address
// pointers used in the FDE.
2013-07-30 00:05:11 +08:00
// Example: 0x1B == DW_EH_PE_pcrel | DW_EH_PE_sdata4
2010-06-09 00:52:24 +08:00
cie_sp - > ptr_encoding = m_cfi_data . GetU8 ( & offset ) ;
break ;
}
}
}
else if ( strcmp ( cie_sp - > augmentation , " eh " ) = = 0 )
{
// If the Augmentation string has the value "eh", then
// the EH Data field shall be present
}
// Set the offset to be the end of the augmentation data just in case
// we didn't understand any of the data.
offset = ( uint32_t ) aug_data_end ;
}
if ( end_offset > offset )
{
cie_sp - > inst_offset = offset ;
cie_sp - > inst_length = end_offset - offset ;
}
2010-09-10 15:49:16 +08:00
while ( offset < end_offset )
{
uint8_t inst = m_cfi_data . GetU8 ( & offset ) ;
uint8_t primary_opcode = inst & 0xC0 ;
uint8_t extended_opcode = inst & 0x3F ;
2015-07-03 17:30:17 +08:00
if ( ! HandleCommonDwarfOpcode ( primary_opcode , extended_opcode , cie_sp - > data_align , offset , cie_sp - > initial_row ) )
break ; // Stop if we hit an unrecognized opcode
2010-09-10 15:49:16 +08:00
}
2010-06-09 00:52:24 +08:00
}
return cie_sp ;
}
2011-12-29 08:05:26 +08:00
void
DWARFCallFrameInfo : : GetCFIData ( )
{
if ( m_cfi_data_initialized = = false )
{
2013-03-28 07:08:40 +08:00
Log * log ( GetLogIfAllCategoriesSet ( LIBLLDB_LOG_UNWIND ) ) ;
2011-12-29 08:05:26 +08:00
if ( log )
2013-03-28 07:08:40 +08:00
m_objfile . GetModule ( ) - > LogMessage ( log , " Reading EH frame info " ) ;
2012-02-05 10:38:54 +08:00
m_objfile . ReadSectionData ( m_section_sp . get ( ) , m_cfi_data ) ;
2011-12-29 08:05:26 +08:00
m_cfi_data_initialized = true ;
}
}
2010-09-10 15:49:16 +08:00
// Scan through the eh_frame or debug_frame section looking for FDEs and noting the start/end addresses
// of the functions and a pointer back to the function's FDE for later expansion.
// Internalize CIEs as we come across them.
void
DWARFCallFrameInfo : : GetFDEIndex ( )
2010-06-09 00:52:24 +08:00
{
2014-04-20 21:17:36 +08:00
if ( m_section_sp . get ( ) = = nullptr | | m_section_sp - > IsEncrypted ( ) )
2010-09-10 15:49:16 +08:00
return ;
2012-07-12 09:11:40 +08:00
2010-09-10 15:49:16 +08:00
if ( m_fde_index_initialized )
return ;
2016-05-19 13:13:57 +08:00
std : : lock_guard < std : : mutex > guard ( m_fde_index_mutex ) ;
2012-07-12 09:11:40 +08:00
if ( m_fde_index_initialized ) // if two threads hit the locker
return ;
2010-10-26 20:01:35 +08:00
2013-03-21 05:57:42 +08:00
Timer scoped_timer ( __PRETTY_FUNCTION__ , " %s - %s " , __PRETTY_FUNCTION__ , m_objfile . GetFileSpec ( ) . GetFilename ( ) . AsCString ( " " ) ) ;
2013-01-26 02:06:21 +08:00
lldb : : offset_t offset = 0 ;
2010-09-10 15:49:16 +08:00
if ( m_cfi_data_initialized = = false )
2011-12-29 08:05:26 +08:00
GetCFIData ( ) ;
2010-09-10 15:49:16 +08:00
while ( m_cfi_data . ValidOffsetForDataOfSize ( offset , 8 ) )
{
2011-06-17 09:22:15 +08:00
const dw_offset_t current_entry = offset ;
2014-08-26 05:39:30 +08:00
dw_offset_t cie_id , next_entry , cie_offset ;
2010-09-10 15:49:16 +08:00
uint32_t len = m_cfi_data . GetU32 ( & offset ) ;
2014-08-26 05:39:30 +08:00
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 ;
}
2010-06-09 00:52:24 +08:00
2015-04-02 12:35:32 +08:00
if ( next_entry > m_cfi_data . GetByteSize ( ) + 1 )
{
Host : : SystemLog ( Host : : eSystemLogError ,
" error: Invalid fde/cie next entry offset of 0x%x found in cie/fde at 0x%x \n " ,
next_entry ,
current_entry ) ;
2015-07-22 08:16:02 +08:00
// Don't trust anything in this eh_frame section if we find blatantly
2015-04-02 12:35:32 +08:00
// invalid data.
m_fde_index . Clear ( ) ;
m_fde_index_initialized = true ;
return ;
}
if ( cie_offset > m_cfi_data . GetByteSize ( ) )
{
Host : : SystemLog ( Host : : eSystemLogError ,
" error: Invalid cie offset of 0x%x found in cie/fde at 0x%x \n " ,
cie_offset ,
current_entry ) ;
2015-07-22 08:16:02 +08:00
// Don't trust anything in this eh_frame section if we find blatantly
2015-04-02 12:35:32 +08:00
// invalid data.
m_fde_index . Clear ( ) ;
m_fde_index_initialized = true ;
return ;
}
2013-08-25 21:24:48 +08:00
if ( cie_id = = 0 | | cie_id = = UINT32_MAX | | len = = 0 )
2010-09-10 15:49:16 +08:00
{
m_cie_map [ current_entry ] = ParseCIE ( current_entry ) ;
offset = next_entry ;
continue ;
}
2011-06-17 09:22:15 +08:00
const CIE * cie = GetCIE ( cie_offset ) ;
if ( cie )
{
2012-02-05 10:38:54 +08:00
const lldb : : addr_t pc_rel_addr = m_section_sp - > GetFileAddress ( ) ;
2011-06-17 09:22:15 +08:00
const lldb : : addr_t text_addr = LLDB_INVALID_ADDRESS ;
const lldb : : addr_t data_addr = LLDB_INVALID_ADDRESS ;
lldb : : addr_t addr = m_cfi_data . GetGNUEHPointer ( & offset , cie - > ptr_encoding , pc_rel_addr , text_addr , data_addr ) ;
lldb : : addr_t length = m_cfi_data . GetGNUEHPointer ( & offset , cie - > ptr_encoding & DW_EH_PE_MASK_ENCODING , pc_rel_addr , text_addr , data_addr ) ;
2013-03-21 05:57:42 +08:00
FDEEntryMap : : Entry fde ( addr , length , current_entry ) ;
m_fde_index . Append ( fde ) ;
2011-06-17 09:22:15 +08:00
}
else
{
2012-01-05 11:57:59 +08:00
Host : : SystemLog ( Host : : eSystemLogError ,
" error: unable to find CIE at 0x%8.8x for cie_id = 0x%8.8x for entry at 0x%8.8x. \n " ,
cie_offset ,
cie_id ,
current_entry ) ;
2011-06-17 09:22:15 +08:00
}
2010-09-10 15:49:16 +08:00
offset = next_entry ;
2010-06-09 00:52:24 +08:00
}
2013-03-21 05:57:42 +08:00
m_fde_index . Sort ( ) ;
2010-09-10 15:49:16 +08:00
m_fde_index_initialized = true ;
2010-06-09 00:52:24 +08:00
}
2010-09-10 15:49:16 +08:00
bool
2013-01-26 02:06:21 +08:00
DWARFCallFrameInfo : : FDEToUnwindPlan ( dw_offset_t dwarf_offset , Address startaddr , UnwindPlan & unwind_plan )
2010-06-09 00:52:24 +08:00
{
2013-01-26 02:06:21 +08:00
lldb : : offset_t offset = dwarf_offset ;
lldb : : offset_t current_entry = offset ;
2010-06-09 00:52:24 +08:00
2014-04-20 21:17:36 +08:00
if ( m_section_sp . get ( ) = = nullptr | | m_section_sp - > IsEncrypted ( ) )
2010-09-10 15:49:16 +08:00
return false ;
2010-06-09 00:52:24 +08:00
2010-09-10 15:49:16 +08:00
if ( m_cfi_data_initialized = = false )
2011-12-29 08:05:26 +08:00
GetCFIData ( ) ;
2010-06-09 00:52:24 +08:00
2010-09-10 15:49:16 +08:00
uint32_t length = m_cfi_data . GetU32 ( & offset ) ;
2014-08-26 05:39:30 +08:00
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 ) ;
}
2010-06-09 00:52:24 +08:00
2010-09-10 15:49:16 +08:00
assert ( cie_offset ! = 0 & & cie_offset ! = UINT32_MAX ) ;
2010-06-09 00:52:24 +08:00
2010-09-10 15:49:16 +08:00
// Translate the CIE_id from the eh_frame format, which
// is relative to the FDE offset, into a __eh_frame section
// offset
if ( m_is_eh_frame )
2010-10-25 19:12:07 +08:00
{
unwind_plan . SetSourceName ( " eh_frame CFI " ) ;
2014-08-26 05:39:30 +08:00
cie_offset = current_entry + ( is_64bit ? 12 : 4 ) - cie_offset ;
2012-10-26 14:08:58 +08:00
unwind_plan . SetUnwindPlanValidAtAllInstructions ( eLazyBoolNo ) ;
2010-10-25 19:12:07 +08:00
}
else
{
unwind_plan . SetSourceName ( " DWARF CFI " ) ;
2012-10-26 14:08:58 +08:00
// In theory the debug_frame info should be valid at all call sites
// ("asynchronous unwind info" as it is sometimes called) but in practice
// gcc et al all emit call frame info for the prologue and call sites, but
// not for the epilogue or all the other locations during the function reliably.
unwind_plan . SetUnwindPlanValidAtAllInstructions ( eLazyBoolNo ) ;
2010-10-25 19:12:07 +08:00
}
2012-10-26 14:08:58 +08:00
unwind_plan . SetSourcedFromCompiler ( eLazyBoolYes ) ;
2010-06-09 00:52:24 +08:00
2010-09-10 15:49:16 +08:00
const CIE * cie = GetCIE ( cie_offset ) ;
2014-04-20 21:17:36 +08:00
assert ( cie ! = nullptr ) ;
2010-06-09 00:52:24 +08:00
2014-08-26 05:39:30 +08:00
const dw_offset_t end_offset = current_entry + length + ( is_64bit ? 12 : 4 ) ;
2010-06-09 00:52:24 +08:00
2012-02-05 10:38:54 +08:00
const lldb : : addr_t pc_rel_addr = m_section_sp - > GetFileAddress ( ) ;
2010-09-10 15:49:16 +08:00
const lldb : : addr_t text_addr = LLDB_INVALID_ADDRESS ;
const lldb : : addr_t data_addr = LLDB_INVALID_ADDRESS ;
lldb : : addr_t range_base = m_cfi_data . GetGNUEHPointer ( & offset , cie - > ptr_encoding , pc_rel_addr , text_addr , data_addr ) ;
lldb : : addr_t range_len = m_cfi_data . GetGNUEHPointer ( & 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 ) ;
2010-06-09 00:52:24 +08:00
2014-11-18 10:27:42 +08:00
addr_t lsda_data_file_address = LLDB_INVALID_ADDRESS ;
2010-09-10 15:49:16 +08:00
if ( cie - > augmentation [ 0 ] = = ' z ' )
{
uint32_t aug_data_len = ( uint32_t ) m_cfi_data . GetULEB128 ( & offset ) ;
2014-11-18 10:27:42 +08:00
if ( aug_data_len ! = 0 & & cie - > lsda_addr_encoding ! = DW_EH_PE_omit )
{
offset_t saved_offset = offset ;
lsda_data_file_address = m_cfi_data . GetGNUEHPointer ( & offset , cie - > lsda_addr_encoding , pc_rel_addr , text_addr , data_addr ) ;
if ( offset - saved_offset ! = aug_data_len )
{
// There is more in the augmentation region than we know how to process;
// don't read anything.
lsda_data_file_address = LLDB_INVALID_ADDRESS ;
}
offset = saved_offset ;
}
2010-09-10 15:49:16 +08:00
offset + = aug_data_len ;
2010-06-09 00:52:24 +08:00
}
2014-11-18 10:27:42 +08:00
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 ) ;
}
2010-06-09 00:52:24 +08:00
uint32_t code_align = cie - > code_align ;
int32_t data_align = cie - > data_align ;
2010-09-10 15:49:16 +08:00
unwind_plan . SetPlanValidAddressRange ( range ) ;
2012-07-14 12:52:53 +08:00
UnwindPlan : : Row * cie_initial_row = new UnwindPlan : : Row ;
* cie_initial_row = cie - > initial_row ;
UnwindPlan : : RowSP row ( cie_initial_row ) ;
2010-09-10 15:49:16 +08:00
unwind_plan . SetRegisterKind ( m_reg_kind ) ;
2012-08-18 14:53:34 +08:00
unwind_plan . SetReturnAddressRegister ( cie - > return_addr_reg_num ) ;
2010-06-09 00:52:24 +08:00
2013-09-13 07:38:30 +08:00
std : : vector < UnwindPlan : : RowSP > stack ;
2010-09-10 15:49:16 +08:00
UnwindPlan : : Row : : RegisterLocation reg_location ;
2010-06-09 00:52:24 +08:00
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 ;
2015-07-03 17:30:17 +08:00
if ( ! HandleCommonDwarfOpcode ( primary_opcode , extended_opcode , data_align , offset , * row ) )
2010-06-09 00:52:24 +08:00
{
2015-07-03 17:30:17 +08:00
if ( primary_opcode )
2010-06-09 00:52:24 +08:00
{
2015-07-03 17:30:17 +08:00
switch ( primary_opcode )
{
case DW_CFA_advance_loc : // (Row Creation Instruction)
2010-06-09 00:52:24 +08:00
{ // 0x40 - high 2 bits are 0x1, lower 6 bits are delta
// takes a single argument that represents a constant delta. The
// required action is to create a new table row with a location
// value that is computed by taking the current entry's location
// value and adding (delta * code_align). All other
// values in the new row are initially identical to the current row.
2010-09-10 15:49:16 +08:00
unwind_plan . AppendRow ( row ) ;
2012-08-01 06:42:30 +08:00
UnwindPlan : : Row * newrow = new UnwindPlan : : Row ;
* newrow = * row . get ( ) ;
row . reset ( newrow ) ;
2012-07-14 12:52:53 +08:00
row - > SlideOffset ( extended_opcode * code_align ) ;
2015-07-03 17:30:17 +08:00
break ;
2010-06-09 00:52:24 +08:00
}
2015-07-03 17:30:17 +08:00
case DW_CFA_restore :
2010-06-09 00:52:24 +08:00
{ // 0xC0 - high 2 bits are 0x3, lower 6 bits are register
// takes a single argument that represents a register number. The
// required action is to change the rule for the indicated register
// to the rule assigned it by the initial_instructions in the CIE.
2015-07-03 17:30:17 +08:00
uint32_t reg_num = extended_opcode ;
2010-06-09 00:52:24 +08:00
// We only keep enough register locations around to
// unwind what is in our thread, and these are organized
// by the register index in that state, so we need to convert our
Clean up register naming conventions inside lldb.
"gcc" register numbers are now correctly referred to as "ehframe"
register numbers. In almost all cases, ehframe and dwarf register
numbers are identical (the one exception is i386 darwin where ehframe
regnums were incorrect).
The old "gdb" register numbers, which I incorrectly thought were
stabs register numbers, are now referred to as "Process Plugin"
register numbers. This is the register numbering scheme that the
remote process controller stub (lldb-server, gdbserver, core file
support, kdp server, remote jtag devices, etc) uses to refer to the
registers. The process plugin register numbers may not be contiguous
- there are remote jtag devices that have gaps in their register
numbering schemes.
I removed all of the enums for "gdb" register numbers that we had
in lldb - these were meaningless - and I put LLDB_INVALID_REGNUM
in all of the register tables for the Process Plugin regnum slot.
This change is almost entirely mechnical; the one actual change in
here is to ProcessGDBRemote.cpp's ParseRegisters() which parses the
qXfer:features:read:target.xml response. As it parses register
definitions from the xml, it will assign sequential numbers as the
eRegisterKindLLDB numbers (the lldb register numberings must be
sequential, without any gaps) and if the xml file specifies register
numbers, those will be used as the eRegisterKindProcessPlugin
register numbers (and those may have gaps). A J-Link jtag device's
target.xml does contain a gap in register numbers, and it only
specifies the register numbers for the registers after that gap.
The device supports many different ARM boards and probably selects
different part of its register file as appropriate.
http://reviews.llvm.org/D12791
<rdar://problem/22623262>
llvm-svn: 247741
2015-09-16 07:20:34 +08:00
// eh_frame register number from the EH frame info, to a register index
2010-06-09 00:52:24 +08:00
2012-07-14 12:52:53 +08:00
if ( unwind_plan . IsValidRowIndex ( 0 ) & & unwind_plan . GetRowAtIndex ( 0 ) - > GetRegisterInfo ( reg_num , reg_location ) )
row - > SetRegisterInfo ( reg_num , reg_location ) ;
2015-07-03 17:30:17 +08:00
break ;
2010-06-09 00:52:24 +08:00
}
2015-07-03 17:30:17 +08:00
}
2010-06-09 00:52:24 +08:00
}
2015-07-03 17:30:17 +08:00
else
2010-06-09 00:52:24 +08:00
{
2015-07-03 17:30:17 +08:00
switch ( extended_opcode )
{
case DW_CFA_set_loc : // 0x1 (Row Creation Instruction)
2010-06-09 00:52:24 +08:00
{
// DW_CFA_set_loc takes a single argument that represents an address.
// The required action is to create a new table row using the
// specified address as the location. All other values in the new row
// are initially identical to the current row. The new location value
// should always be greater than the current one.
2010-09-10 15:49:16 +08:00
unwind_plan . AppendRow ( row ) ;
2012-08-01 06:42:30 +08:00
UnwindPlan : : Row * newrow = new UnwindPlan : : Row ;
* newrow = * row . get ( ) ;
row . reset ( newrow ) ;
2012-07-14 12:52:53 +08:00
row - > SetOffset ( m_cfi_data . GetPointer ( & offset ) - startaddr . GetFileAddress ( ) ) ;
2015-07-03 17:30:17 +08:00
break ;
2010-06-09 00:52:24 +08:00
}
2015-07-03 17:30:17 +08:00
case DW_CFA_advance_loc1 : // 0x2 (Row Creation Instruction)
2010-06-09 00:52:24 +08:00
{
// takes a single uword argument that represents a constant delta.
// This instruction is identical to DW_CFA_advance_loc except for the
// encoding and size of the delta argument.
2010-09-10 15:49:16 +08:00
unwind_plan . AppendRow ( row ) ;
2012-08-01 06:42:30 +08:00
UnwindPlan : : Row * newrow = new UnwindPlan : : Row ;
* newrow = * row . get ( ) ;
row . reset ( newrow ) ;
2012-07-14 12:52:53 +08:00
row - > SlideOffset ( m_cfi_data . GetU8 ( & offset ) * code_align ) ;
2015-07-03 17:30:17 +08:00
break ;
2010-06-09 00:52:24 +08:00
}
2015-07-03 17:30:17 +08:00
case DW_CFA_advance_loc2 : // 0x3 (Row Creation Instruction)
2010-06-09 00:52:24 +08:00
{
// takes a single uword argument that represents a constant delta.
// This instruction is identical to DW_CFA_advance_loc except for the
// encoding and size of the delta argument.
2010-09-10 15:49:16 +08:00
unwind_plan . AppendRow ( row ) ;
2012-08-01 06:42:30 +08:00
UnwindPlan : : Row * newrow = new UnwindPlan : : Row ;
* newrow = * row . get ( ) ;
row . reset ( newrow ) ;
2012-07-14 12:52:53 +08:00
row - > SlideOffset ( m_cfi_data . GetU16 ( & offset ) * code_align ) ;
2015-07-03 17:30:17 +08:00
break ;
2010-06-09 00:52:24 +08:00
}
2015-07-03 17:30:17 +08:00
case DW_CFA_advance_loc4 : // 0x4 (Row Creation Instruction)
2010-06-09 00:52:24 +08:00
{
// takes a single uword argument that represents a constant delta.
// This instruction is identical to DW_CFA_advance_loc except for the
// encoding and size of the delta argument.
2010-09-10 15:49:16 +08:00
unwind_plan . AppendRow ( row ) ;
2012-08-01 06:42:30 +08:00
UnwindPlan : : Row * newrow = new UnwindPlan : : Row ;
* newrow = * row . get ( ) ;
row . reset ( newrow ) ;
2012-07-14 12:52:53 +08:00
row - > SlideOffset ( m_cfi_data . GetU32 ( & offset ) * code_align ) ;
2015-07-03 17:30:17 +08:00
break ;
2010-06-09 00:52:24 +08:00
}
2015-07-03 17:30:17 +08:00
case DW_CFA_restore_extended : // 0x6
2010-06-09 00:52:24 +08:00
{
// takes a single unsigned LEB128 argument that represents a register
// number. This instruction is identical to DW_CFA_restore except for
// the encoding and size of the register argument.
2015-07-03 17:30:17 +08:00
uint32_t reg_num = ( uint32_t ) m_cfi_data . GetULEB128 ( & offset ) ;
2012-07-14 12:52:53 +08:00
if ( unwind_plan . IsValidRowIndex ( 0 ) & & unwind_plan . GetRowAtIndex ( 0 ) - > GetRegisterInfo ( reg_num , reg_location ) )
row - > SetRegisterInfo ( reg_num , reg_location ) ;
2015-07-03 17:30:17 +08:00
break ;
2010-06-09 00:52:24 +08:00
}
2015-07-03 17:30:17 +08:00
case DW_CFA_remember_state : // 0xA
2012-08-01 06:42:30 +08:00
{
// These instructions define a stack of information. Encountering the
// DW_CFA_remember_state instruction means to save the rules for every
// register on the current row on the stack. Encountering the
// DW_CFA_restore_state instruction means to pop the set of rules off
// the stack and place them in the current row. (This operation is
// useful for compilers that move epilogue code into the body of a
// function.)
2013-09-13 07:38:30 +08:00
stack . push_back ( row ) ;
2012-08-01 06:42:30 +08:00
UnwindPlan : : Row * newrow = new UnwindPlan : : Row ;
* newrow = * row . get ( ) ;
row . reset ( newrow ) ;
2015-07-03 17:30:17 +08:00
break ;
2012-08-01 06:42:30 +08:00
}
2015-07-03 17:30:17 +08:00
case DW_CFA_restore_state : // 0xB
2010-06-09 00:52:24 +08:00
{
2015-07-03 17:30:17 +08:00
// These instructions define a stack of information. Encountering the
// DW_CFA_remember_state instruction means to save the rules for every
// register on the current row on the stack. Encountering the
// DW_CFA_restore_state instruction means to pop the set of rules off
// the stack and place them in the current row. (This operation is
// useful for compilers that move epilogue code into the body of a
// function.)
2015-07-03 17:30:14 +08:00
lldb : : addr_t offset = row - > GetOffset ( ) ;
2013-09-13 07:38:30 +08:00
row = stack . back ( ) ;
stack . pop_back ( ) ;
2015-07-03 17:30:14 +08:00
row - > SetOffset ( offset ) ;
2015-07-03 17:30:17 +08:00
break ;
2010-06-09 00:52:24 +08:00
}
2015-07-03 17:30:17 +08:00
case DW_CFA_val_offset : // 0x14
case DW_CFA_val_offset_sf : // 0x15
default :
break ;
}
}
}
}
unwind_plan . AppendRow ( row ) ;
2010-06-09 00:52:24 +08:00
2015-07-03 17:30:17 +08:00
return true ;
}
2010-06-09 00:52:24 +08:00
2015-07-03 17:30:17 +08:00
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 ;
2010-06-09 00:52:24 +08:00
2015-07-03 17:30:17 +08:00
if ( primary_opcode )
{
switch ( primary_opcode )
{
case DW_CFA_offset :
{ // 0x80 - high 2 bits are 0x2, lower 6 bits are register
// takes two arguments: an unsigned LEB128 constant representing a
// factored offset and a register number. The required action is to
// change the rule for the register indicated by the register number
// to be an offset(N) rule with a value of
// (N = factored offset * data_align).
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 : // 0x0
return true ;
2010-06-09 00:52:24 +08:00
2015-07-03 17:30:17 +08:00
case DW_CFA_offset_extended : // 0x5
{
// takes two unsigned LEB128 arguments representing a register number
// and a factored offset. This instruction is identical to DW_CFA_offset
// except for the encoding and size of the register argument.
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 ;
}
2010-06-09 00:52:24 +08:00
2015-07-03 17:30:17 +08:00
case DW_CFA_undefined : // 0x7
{
// takes a single unsigned LEB128 argument that represents a register
// number. The required action is to set the rule for the specified
// register to 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 ;
}
2010-06-09 00:52:24 +08:00
2015-07-03 17:30:17 +08:00
case DW_CFA_same_value : // 0x8
{
// takes a single unsigned LEB128 argument that represents a register
// number. The required action is to set the rule for the specified
// register to 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 ;
}
2010-06-09 00:52:24 +08:00
2015-07-03 17:30:17 +08:00
case DW_CFA_register : // 0x9
{
// takes two unsigned LEB128 arguments representing register numbers.
// The required action is to set the rule for the first register to be
// the second 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 ;
}
2010-06-09 00:52:24 +08:00
2015-07-03 17:30:17 +08:00
case DW_CFA_def_cfa : // 0xC (CFA Definition Instruction)
{
// Takes two unsigned LEB128 operands representing a register
// number and a (non-factored) offset. The required action
// is to define the current CFA rule to use the provided
// register and offset.
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 : // 0xD (CFA Definition Instruction)
{
// takes a single unsigned LEB128 argument representing a register
// number. The required action is to define the current CFA rule to
// use the provided register (but to keep the old offset).
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 : // 0xE (CFA Definition Instruction)
{
// Takes a single unsigned LEB128 operand representing a
// (non-factored) offset. The required action is to define
// the current CFA rule to use the provided offset (but
// to keep the old register).
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 : // 0xF (CFA Definition Instruction)
{
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 : // 0x10
{
// Takes two operands: an unsigned LEB128 value representing
// a register number, and a DW_FORM_block value representing a DWARF
// expression. The required action is to change the rule for the
// register indicated by the register number to be an expression(E)
// rule where E is the DWARF expression. That is, the DWARF
// expression computes the address. The value of the CFA is
// pushed on the DWARF evaluation stack prior to execution of
// the DWARF 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 : // 0x11
{
// takes two operands: an unsigned LEB128 value representing a
// register number and a signed LEB128 factored offset. This
// instruction is identical to DW_CFA_offset_extended except
//that the second operand is signed and factored.
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 : // 0x12 (CFA Definition Instruction)
{
// Takes two operands: an unsigned LEB128 value representing
// a register number and a signed LEB128 factored offset.
// This instruction is identical to DW_CFA_def_cfa except
// that the second operand is signed and factored.
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 : // 0x13 (CFA Definition Instruction)
{
// takes a signed LEB128 operand representing a factored
// offset. This instruction is identical to DW_CFA_def_cfa_offset
// except that the operand is signed and factored.
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 : // 0x16
{
// takes two operands: an unsigned LEB128 value representing a register
// number, and a DW_FORM_block value representing a DWARF expression.
// The required action is to change the rule for the register indicated
// by the register number to be a val_expression(E) rule where E is the
// DWARF expression. That is, the DWARF expression computes the value of
// the given register. The value of the CFA is pushed on the DWARF
// evaluation stack prior to execution of the DWARF 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 ) ;
2010-06-09 00:52:24 +08:00
//#if defined(__i386__) || defined(__x86_64__)
2015-07-03 17:30:17 +08:00
// // The EH frame info for EIP and RIP contains code that looks for traps to
// // be a specific type and increments the PC.
// // For i386:
// // DW_CFA_val_expression where:
// // eip = DW_OP_breg6(+28), DW_OP_deref, DW_OP_dup, DW_OP_plus_uconst(0x34),
// // DW_OP_deref, DW_OP_swap, DW_OP_plus_uconst(0), DW_OP_deref,
// // DW_OP_dup, DW_OP_lit3, DW_OP_ne, DW_OP_swap, DW_OP_lit4, DW_OP_ne,
// // DW_OP_and, DW_OP_plus
// // This basically does a:
// // eip = ucontenxt.mcontext32->gpr.eip;
// // if (ucontenxt.mcontext32->exc.trapno != 3 && ucontenxt.mcontext32->exc.trapno != 4)
// // eip++;
// //
// // For x86_64:
// // DW_CFA_val_expression where:
// // rip = DW_OP_breg3(+48), DW_OP_deref, DW_OP_dup, DW_OP_plus_uconst(0x90), DW_OP_deref,
// // DW_OP_swap, DW_OP_plus_uconst(0), DW_OP_deref_size(4), DW_OP_dup, DW_OP_lit3,
// // DW_OP_ne, DW_OP_swap, DW_OP_lit4, DW_OP_ne, DW_OP_and, DW_OP_plus
// // This basically does a:
// // rip = ucontenxt.mcontext64->gpr.rip;
// // if (ucontenxt.mcontext64->exc.trapno != 3 && ucontenxt.mcontext64->exc.trapno != 4)
// // rip++;
// // The trap comparisons and increments are not needed as it hoses up the unwound PC which
// // is expected to point at least past the instruction that causes the fault/trap. So we
// // take it out by trimming the expression right at the first "DW_OP_swap" opcodes
// if (block_data != NULL && thread->GetPCRegNum(Thread::GCC) == reg_num)
// {
// if (thread->Is64Bit())
// {
// if (block_len > 9 && block_data[8] == DW_OP_swap && block_data[9] == DW_OP_plus_uconst)
// block_len = 8;
// }
// else
// {
// if (block_len > 8 && block_data[7] == DW_OP_swap && block_data[8] == DW_OP_plus_uconst)
// block_len = 7;
// }
// }
2010-06-09 00:52:24 +08:00
//#endif
2015-07-03 17:30:17 +08:00
reg_location . SetIsDWARFExpression ( block_data , block_len ) ;
row . SetRegisterInfo ( reg_num , reg_location ) ;
return true ;
2010-06-09 00:52:24 +08:00
}
}
}
2015-07-03 17:30:17 +08:00
return false ;
2010-06-09 00:52:24 +08:00
}
2016-02-18 19:12:18 +08:00
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 ;
}
}