Index: stable/11/contrib/llvm/projects/libunwind/include/__libunwind_config.h =================================================================== --- stable/11/contrib/llvm/projects/libunwind/include/__libunwind_config.h (revision 303317) +++ stable/11/contrib/llvm/projects/libunwind/include/__libunwind_config.h (revision 303318) @@ -1,63 +1,71 @@ //===------------------------- __libunwind_config.h -----------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef ____LIBUNWIND_CONFIG_H__ #define ____LIBUNWIND_CONFIG_H__ #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \ !defined(__ARM_DWARF_EH__) #define _LIBUNWIND_ARM_EHABI 1 #else #define _LIBUNWIND_ARM_EHABI 0 #endif #if defined(_LIBUNWIND_IS_NATIVE_ONLY) # if defined(__i386__) # define _LIBUNWIND_TARGET_I386 1 # define _LIBUNWIND_CONTEXT_SIZE 8 # define _LIBUNWIND_CURSOR_SIZE 19 +# define _LIBUNWIND_MAX_REGISTER 9 # elif defined(__x86_64__) # define _LIBUNWIND_TARGET_X86_64 1 # define _LIBUNWIND_CONTEXT_SIZE 21 # define _LIBUNWIND_CURSOR_SIZE 33 +# define _LIBUNWIND_MAX_REGISTER 17 # elif defined(__ppc__) # define _LIBUNWIND_TARGET_PPC 1 # define _LIBUNWIND_CONTEXT_SIZE 117 # define _LIBUNWIND_CURSOR_SIZE 128 +# define _LIBUNWIND_MAX_REGISTER 113 # elif defined(__aarch64__) # define _LIBUNWIND_TARGET_AARCH64 1 # define _LIBUNWIND_CONTEXT_SIZE 66 # define _LIBUNWIND_CURSOR_SIZE 78 +# define _LIBUNWIND_MAX_REGISTER 96 # elif defined(__arm__) # define _LIBUNWIND_TARGET_ARM 1 # define _LIBUNWIND_CONTEXT_SIZE 60 # define _LIBUNWIND_CURSOR_SIZE 67 +# define _LIBUNWIND_MAX_REGISTER 96 # elif defined(__or1k__) # define _LIBUNWIND_TARGET_OR1K 1 # define _LIBUNWIND_CONTEXT_SIZE 16 # define _LIBUNWIND_CURSOR_SIZE 28 +# define _LIBUNWIND_MAX_REGISTER 32 # elif defined(__riscv__) # define _LIBUNWIND_TARGET_RISCV 1 # define _LIBUNWIND_CONTEXT_SIZE 128 /* XXX */ # define _LIBUNWIND_CURSOR_SIZE 140 /* XXX */ +# define _LIBUNWIND_MAX_REGISTER 96 # else # error "Unsupported architecture." # endif #else // !_LIBUNWIND_IS_NATIVE_ONLY # define _LIBUNWIND_TARGET_I386 1 # define _LIBUNWIND_TARGET_X86_64 1 # define _LIBUNWIND_TARGET_PPC 1 # define _LIBUNWIND_TARGET_AARCH64 1 # define _LIBUNWIND_TARGET_ARM 1 # define _LIBUNWIND_TARGET_OR1K 1 # define _LIBUNWIND_CONTEXT_SIZE 128 # define _LIBUNWIND_CURSOR_SIZE 140 +# define _LIBUNWIND_MAX_REGISTER 120 #endif // _LIBUNWIND_IS_NATIVE_ONLY #endif // ____LIBUNWIND_CONFIG_H__ Index: stable/11/contrib/llvm/projects/libunwind/include/unwind.h =================================================================== --- stable/11/contrib/llvm/projects/libunwind/include/unwind.h (revision 303317) +++ stable/11/contrib/llvm/projects/libunwind/include/unwind.h (revision 303318) @@ -1,372 +1,372 @@ //===------------------------------- unwind.h -----------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // // // C++ ABI Level 1 ABI documented at: // http://mentorembedded.github.io/cxx-abi/abi-eh.html // //===----------------------------------------------------------------------===// #ifndef __UNWIND_H__ #define __UNWIND_H__ #include <__libunwind_config.h> #include #include #if defined(__APPLE__) #define LIBUNWIND_UNAVAIL __attribute__ (( unavailable )) #else #define LIBUNWIND_UNAVAIL #endif typedef enum { _URC_NO_REASON = 0, _URC_OK = 0, _URC_FOREIGN_EXCEPTION_CAUGHT = 1, _URC_FATAL_PHASE2_ERROR = 2, _URC_FATAL_PHASE1_ERROR = 3, _URC_NORMAL_STOP = 4, _URC_END_OF_STACK = 5, _URC_HANDLER_FOUND = 6, _URC_INSTALL_CONTEXT = 7, _URC_CONTINUE_UNWIND = 8, #if _LIBUNWIND_ARM_EHABI _URC_FAILURE = 9 #endif } _Unwind_Reason_Code; typedef enum { _UA_SEARCH_PHASE = 1, _UA_CLEANUP_PHASE = 2, _UA_HANDLER_FRAME = 4, _UA_FORCE_UNWIND = 8, _UA_END_OF_STACK = 16 // gcc extension to C++ ABI } _Unwind_Action; typedef struct _Unwind_Context _Unwind_Context; // opaque #if _LIBUNWIND_ARM_EHABI typedef uint32_t _Unwind_State; static const _Unwind_State _US_VIRTUAL_UNWIND_FRAME = 0; static const _Unwind_State _US_UNWIND_FRAME_STARTING = 1; static const _Unwind_State _US_UNWIND_FRAME_RESUME = 2; /* Undocumented flag for force unwinding. */ static const _Unwind_State _US_FORCE_UNWIND = 8; typedef uint32_t _Unwind_EHT_Header; struct _Unwind_Control_Block; typedef struct _Unwind_Control_Block _Unwind_Control_Block; typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */ struct _Unwind_Control_Block { uint64_t exception_class; void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block*); /* Unwinder cache, private fields for the unwinder's use */ struct { uint32_t reserved1; /* init reserved1 to 0, then don't touch */ uint32_t reserved2; uint32_t reserved3; uint32_t reserved4; uint32_t reserved5; } unwinder_cache; /* Propagation barrier cache (valid after phase 1): */ struct { uint32_t sp; uint32_t bitpattern[5]; } barrier_cache; /* Cleanup cache (preserved over cleanup): */ struct { uint32_t bitpattern[4]; } cleanup_cache; /* Pr cache (for pr's benefit): */ struct { uint32_t fnstart; /* function start address */ _Unwind_EHT_Header* ehtp; /* pointer to EHT entry header word */ uint32_t additional; uint32_t reserved1; } pr_cache; long long int :0; /* Enforce the 8-byte alignment */ }; typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (_Unwind_State state, _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); typedef _Unwind_Reason_Code (*__personality_routine) (_Unwind_State state, _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); #else struct _Unwind_Context; // opaque struct _Unwind_Exception; // forward declaration typedef struct _Unwind_Exception _Unwind_Exception; struct _Unwind_Exception { uint64_t exception_class; void (*exception_cleanup)(_Unwind_Reason_Code reason, _Unwind_Exception *exc); uintptr_t private_1; // non-zero means forced unwind uintptr_t private_2; // holds sp that phase1 found for phase2 to use #ifndef __LP64__ // The gcc implementation of _Unwind_Exception used attribute mode on the // above fields which had the side effect of causing this whole struct to // round up to 32 bytes in size. To be more explicit, we add pad fields // added for binary compatibility. uint32_t reserved[3]; #endif -}; +} __attribute__((__aligned__)); typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int version, _Unwind_Action actions, uint64_t exceptionClass, _Unwind_Exception* exceptionObject, struct _Unwind_Context* context, void* stop_parameter ); typedef _Unwind_Reason_Code (*__personality_routine) (int version, _Unwind_Action actions, uint64_t exceptionClass, _Unwind_Exception* exceptionObject, struct _Unwind_Context* context); #endif #ifdef __cplusplus extern "C" { #endif // // The following are the base functions documented by the C++ ABI // #ifdef __USING_SJLJ_EXCEPTIONS__ extern _Unwind_Reason_Code _Unwind_SjLj_RaiseException(_Unwind_Exception *exception_object); extern void _Unwind_SjLj_Resume(_Unwind_Exception *exception_object); #else extern _Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception *exception_object); extern void _Unwind_Resume(_Unwind_Exception *exception_object); #endif extern void _Unwind_DeleteException(_Unwind_Exception *exception_object); #if _LIBUNWIND_ARM_EHABI typedef enum { _UVRSC_CORE = 0, /* integer register */ _UVRSC_VFP = 1, /* vfp */ _UVRSC_WMMXD = 3, /* Intel WMMX data register */ _UVRSC_WMMXC = 4 /* Intel WMMX control register */ } _Unwind_VRS_RegClass; typedef enum { _UVRSD_UINT32 = 0, _UVRSD_VFPX = 1, _UVRSD_UINT64 = 3, _UVRSD_FLOAT = 4, _UVRSD_DOUBLE = 5 } _Unwind_VRS_DataRepresentation; typedef enum { _UVRSR_OK = 0, _UVRSR_NOT_IMPLEMENTED = 1, _UVRSR_FAILED = 2 } _Unwind_VRS_Result; extern void _Unwind_Complete(_Unwind_Exception* exception_object); extern _Unwind_VRS_Result _Unwind_VRS_Get(_Unwind_Context *context, _Unwind_VRS_RegClass regclass, uint32_t regno, _Unwind_VRS_DataRepresentation representation, void *valuep); extern _Unwind_VRS_Result _Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass, uint32_t regno, _Unwind_VRS_DataRepresentation representation, void *valuep); extern _Unwind_VRS_Result _Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass, uint32_t discriminator, _Unwind_VRS_DataRepresentation representation); #endif #if !_LIBUNWIND_ARM_EHABI extern uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index); extern void _Unwind_SetGR(struct _Unwind_Context *context, int index, uintptr_t new_value); extern uintptr_t _Unwind_GetIP(struct _Unwind_Context *context); extern void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t new_value); #else // _LIBUNWIND_ARM_EHABI #if defined(_LIBUNWIND_UNWIND_LEVEL1_EXTERNAL_LINKAGE) #define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 extern #else #define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 static __inline__ #endif // These are de facto helper functions for ARM, which delegate the function // calls to _Unwind_VRS_Get/Set(). These are not a part of ARM EHABI // specification, thus these function MUST be inlined. Please don't replace // these with the "extern" function declaration; otherwise, the program // including this header won't be ABI compatible and will result in // link error when we are linking the program with libgcc. _LIBUNWIND_EXPORT_UNWIND_LEVEL1 uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index) { uintptr_t value = 0; _Unwind_VRS_Get(context, _UVRSC_CORE, (uint32_t)index, _UVRSD_UINT32, &value); return value; } _LIBUNWIND_EXPORT_UNWIND_LEVEL1 void _Unwind_SetGR(struct _Unwind_Context *context, int index, uintptr_t value) { _Unwind_VRS_Set(context, _UVRSC_CORE, (uint32_t)index, _UVRSD_UINT32, &value); } _LIBUNWIND_EXPORT_UNWIND_LEVEL1 uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) { // remove the thumb-bit before returning return _Unwind_GetGR(context, 15) & (~(uintptr_t)0x1); } _LIBUNWIND_EXPORT_UNWIND_LEVEL1 void _Unwind_SetIP(struct _Unwind_Context *context, uintptr_t value) { uintptr_t thumb_bit = _Unwind_GetGR(context, 15) & ((uintptr_t)0x1); _Unwind_SetGR(context, 15, value | thumb_bit); } #endif // _LIBUNWIND_ARM_EHABI extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *context); extern uintptr_t _Unwind_GetLanguageSpecificData(struct _Unwind_Context *context); #ifdef __USING_SJLJ_EXCEPTIONS__ extern _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind(_Unwind_Exception *exception_object, _Unwind_Stop_Fn stop, void *stop_parameter); #else extern _Unwind_Reason_Code _Unwind_ForcedUnwind(_Unwind_Exception *exception_object, _Unwind_Stop_Fn stop, void *stop_parameter); #endif #ifdef __USING_SJLJ_EXCEPTIONS__ typedef struct _Unwind_FunctionContext *_Unwind_FunctionContext_t; extern void _Unwind_SjLj_Register(_Unwind_FunctionContext_t fc); extern void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t fc); #endif // // The following are semi-suppoted extensions to the C++ ABI // // // called by __cxa_rethrow(). // #ifdef __USING_SJLJ_EXCEPTIONS__ extern _Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow(_Unwind_Exception *exception_object); #else extern _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object); #endif // _Unwind_Backtrace() is a gcc extension that walks the stack and calls the // _Unwind_Trace_Fn once per frame until it reaches the bottom of the stack // or the _Unwind_Trace_Fn function returns something other than _URC_NO_REASON. typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *, void *); extern _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *); // _Unwind_GetCFA is a gcc extension that can be called from within a // personality handler to get the CFA (stack pointer before call) of // current frame. extern uintptr_t _Unwind_GetCFA(struct _Unwind_Context *); // _Unwind_GetIPInfo is a gcc extension that can be called from within a // personality handler. Similar to _Unwind_GetIP() but also returns in // *ipBefore a non-zero value if the instruction pointer is at or before the // instruction causing the unwind. Normally, in a function call, the IP returned // is the return address which is after the call instruction and may be past the // end of the function containing the call instruction. extern uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context, int *ipBefore); // __register_frame() is used with dynamically generated code to register the // FDE for a generated (JIT) code. The FDE must use pc-rel addressing to point // to its function and optional LSDA. // __register_frame() has existed in all versions of Mac OS X, but in 10.4 and // 10.5 it was buggy and did not actually register the FDE with the unwinder. // In 10.6 and later it does register properly. extern void __register_frame(const void *fde); extern void __deregister_frame(const void *fde); // _Unwind_Find_FDE() will locate the FDE if the pc is in some function that has // an associated FDE. Note, Mac OS X 10.6 and later, introduces "compact unwind // info" which the runtime uses in preference to dwarf unwind info. This // function will only work if the target function has an FDE but no compact // unwind info. struct dwarf_eh_bases { uintptr_t tbase; uintptr_t dbase; uintptr_t func; }; extern const void *_Unwind_Find_FDE(const void *pc, struct dwarf_eh_bases *); // This function attempts to find the start (address of first instruction) of // a function given an address inside the function. It only works if the // function has an FDE (dwarf unwind info). // This function is unimplemented on Mac OS X 10.6 and later. Instead, use // _Unwind_Find_FDE() and look at the dwarf_eh_bases.func result. extern void *_Unwind_FindEnclosingFunction(void *pc); // Mac OS X does not support text-rel and data-rel addressing so these functions // are unimplemented extern uintptr_t _Unwind_GetDataRelBase(struct _Unwind_Context *context) LIBUNWIND_UNAVAIL; extern uintptr_t _Unwind_GetTextRelBase(struct _Unwind_Context *context) LIBUNWIND_UNAVAIL; // Mac OS X 10.4 and 10.5 had implementations of these functions in // libgcc_s.dylib, but they never worked. /// These functions are no longer available on Mac OS X. extern void __register_frame_info_bases(const void *fde, void *ob, void *tb, void *db) LIBUNWIND_UNAVAIL; extern void __register_frame_info(const void *fde, void *ob) LIBUNWIND_UNAVAIL; extern void __register_frame_info_table_bases(const void *fde, void *ob, void *tb, void *db) LIBUNWIND_UNAVAIL; extern void __register_frame_info_table(const void *fde, void *ob) LIBUNWIND_UNAVAIL; extern void __register_frame_table(const void *fde) LIBUNWIND_UNAVAIL; extern void *__deregister_frame_info(const void *fde) LIBUNWIND_UNAVAIL; extern void *__deregister_frame_info_bases(const void *fde) LIBUNWIND_UNAVAIL; #ifdef __cplusplus } #endif #endif // __UNWIND_H__ Index: stable/11/contrib/llvm/projects/libunwind/src/DwarfParser.hpp =================================================================== --- stable/11/contrib/llvm/projects/libunwind/src/DwarfParser.hpp (revision 303317) +++ stable/11/contrib/llvm/projects/libunwind/src/DwarfParser.hpp (revision 303318) @@ -1,726 +1,726 @@ //===--------------------------- DwarfParser.hpp --------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // // // Parses DWARF CFIs (FDEs and CIEs). // //===----------------------------------------------------------------------===// #ifndef __DWARF_PARSER_HPP__ #define __DWARF_PARSER_HPP__ #include #include #include #include #include "libunwind.h" #include "dwarf2.h" #include "AddressSpace.hpp" namespace libunwind { /// CFI_Parser does basic parsing of a CFI (Call Frame Information) records. /// See Dwarf Spec for details: /// http://refspecs.linuxbase.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html /// template class CFI_Parser { public: typedef typename A::pint_t pint_t; /// Information encoded in a CIE (Common Information Entry) struct CIE_Info { pint_t cieStart; pint_t cieLength; pint_t cieInstructions; uint8_t pointerEncoding; uint8_t lsdaEncoding; uint8_t personalityEncoding; uint8_t personalityOffsetInCIE; pint_t personality; uint32_t codeAlignFactor; int dataAlignFactor; bool isSignalFrame; bool fdesHaveAugmentationData; uint8_t returnAddressRegister; }; /// Information about an FDE (Frame Description Entry) struct FDE_Info { pint_t fdeStart; pint_t fdeLength; pint_t fdeInstructions; pint_t pcStart; pint_t pcEnd; pint_t lsda; }; enum { - kMaxRegisterNumber = 120 + kMaxRegisterNumber = _LIBUNWIND_MAX_REGISTER }; enum RegisterSavedWhere { kRegisterUnused, kRegisterInCFA, kRegisterOffsetFromCFA, kRegisterInRegister, kRegisterAtExpression, kRegisterIsExpression }; struct RegisterLocation { RegisterSavedWhere location; int64_t value; }; /// Information about a frame layout and registers saved determined /// by "running" the dwarf FDE "instructions" struct PrologInfo { uint32_t cfaRegister; int32_t cfaRegisterOffset; // CFA = (cfaRegister)+cfaRegisterOffset int64_t cfaExpression; // CFA = expression uint32_t spExtraArgSize; uint32_t codeOffsetAtStackDecrement; bool registersInOtherRegisters; bool sameValueUsed; RegisterLocation savedRegisters[kMaxRegisterNumber]; }; struct PrologInfoStackEntry { PrologInfoStackEntry(PrologInfoStackEntry *n, const PrologInfo &i) : next(n), info(i) {} PrologInfoStackEntry *next; PrologInfo info; }; static bool findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart, uint32_t sectionLength, pint_t fdeHint, FDE_Info *fdeInfo, CIE_Info *cieInfo); static const char *decodeFDE(A &addressSpace, pint_t fdeStart, FDE_Info *fdeInfo, CIE_Info *cieInfo); static bool parseFDEInstructions(A &addressSpace, const FDE_Info &fdeInfo, const CIE_Info &cieInfo, pint_t upToPC, PrologInfo *results); static const char *parseCIE(A &addressSpace, pint_t cie, CIE_Info *cieInfo); private: static bool parseInstructions(A &addressSpace, pint_t instructions, pint_t instructionsEnd, const CIE_Info &cieInfo, pint_t pcoffset, PrologInfoStackEntry *&rememberStack, PrologInfo *results); }; /// Parse a FDE into a CIE_Info and an FDE_Info template const char *CFI_Parser::decodeFDE(A &addressSpace, pint_t fdeStart, FDE_Info *fdeInfo, CIE_Info *cieInfo) { pint_t p = fdeStart; pint_t cfiLength = (pint_t)addressSpace.get32(p); p += 4; if (cfiLength == 0xffffffff) { // 0xffffffff means length is really next 8 bytes cfiLength = (pint_t)addressSpace.get64(p); p += 8; } if (cfiLength == 0) return "FDE has zero length"; // end marker uint32_t ciePointer = addressSpace.get32(p); if (ciePointer == 0) return "FDE is really a CIE"; // this is a CIE not an FDE pint_t nextCFI = p + cfiLength; pint_t cieStart = p - ciePointer; const char *err = parseCIE(addressSpace, cieStart, cieInfo); if (err != NULL) return err; p += 4; // parse pc begin and range pint_t pcStart = addressSpace.getEncodedP(p, nextCFI, cieInfo->pointerEncoding); pint_t pcRange = addressSpace.getEncodedP(p, nextCFI, cieInfo->pointerEncoding & 0x0F); // parse rest of info fdeInfo->lsda = 0; // check for augmentation length if (cieInfo->fdesHaveAugmentationData) { pint_t augLen = (pint_t)addressSpace.getULEB128(p, nextCFI); pint_t endOfAug = p + augLen; if (cieInfo->lsdaEncoding != DW_EH_PE_omit) { // peek at value (without indirection). Zero means no lsda pint_t lsdaStart = p; if (addressSpace.getEncodedP(p, nextCFI, cieInfo->lsdaEncoding & 0x0F) != 0) { // reset pointer and re-parse lsda address p = lsdaStart; fdeInfo->lsda = addressSpace.getEncodedP(p, nextCFI, cieInfo->lsdaEncoding); } } p = endOfAug; } fdeInfo->fdeStart = fdeStart; fdeInfo->fdeLength = nextCFI - fdeStart; fdeInfo->fdeInstructions = p; fdeInfo->pcStart = pcStart; fdeInfo->pcEnd = pcStart + pcRange; return NULL; // success } /// Scan an eh_frame section to find an FDE for a pc template bool CFI_Parser::findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart, uint32_t sectionLength, pint_t fdeHint, FDE_Info *fdeInfo, CIE_Info *cieInfo) { //fprintf(stderr, "findFDE(0x%llX)\n", (long long)pc); pint_t p = (fdeHint != 0) ? fdeHint : ehSectionStart; const pint_t ehSectionEnd = p + sectionLength; while (p < ehSectionEnd) { pint_t currentCFI = p; //fprintf(stderr, "findFDE() CFI at 0x%llX\n", (long long)p); pint_t cfiLength = addressSpace.get32(p); p += 4; if (cfiLength == 0xffffffff) { // 0xffffffff means length is really next 8 bytes cfiLength = (pint_t)addressSpace.get64(p); p += 8; } if (cfiLength == 0) return false; // end marker uint32_t id = addressSpace.get32(p); if (id == 0) { // skip over CIEs p += cfiLength; } else { // process FDE to see if it covers pc pint_t nextCFI = p + cfiLength; uint32_t ciePointer = addressSpace.get32(p); pint_t cieStart = p - ciePointer; // validate pointer to CIE is within section if ((ehSectionStart <= cieStart) && (cieStart < ehSectionEnd)) { if (parseCIE(addressSpace, cieStart, cieInfo) == NULL) { p += 4; // parse pc begin and range pint_t pcStart = addressSpace.getEncodedP(p, nextCFI, cieInfo->pointerEncoding); pint_t pcRange = addressSpace.getEncodedP( p, nextCFI, cieInfo->pointerEncoding & 0x0F); // test if pc is within the function this FDE covers if ((pcStart < pc) && (pc <= pcStart + pcRange)) { // parse rest of info fdeInfo->lsda = 0; // check for augmentation length if (cieInfo->fdesHaveAugmentationData) { pint_t augLen = (pint_t)addressSpace.getULEB128(p, nextCFI); pint_t endOfAug = p + augLen; if (cieInfo->lsdaEncoding != DW_EH_PE_omit) { // peek at value (without indirection). Zero means no lsda pint_t lsdaStart = p; if (addressSpace.getEncodedP( p, nextCFI, cieInfo->lsdaEncoding & 0x0F) != 0) { // reset pointer and re-parse lsda address p = lsdaStart; fdeInfo->lsda = addressSpace .getEncodedP(p, nextCFI, cieInfo->lsdaEncoding); } } p = endOfAug; } fdeInfo->fdeStart = currentCFI; fdeInfo->fdeLength = nextCFI - currentCFI; fdeInfo->fdeInstructions = p; fdeInfo->pcStart = pcStart; fdeInfo->pcEnd = pcStart + pcRange; return true; } else { // pc is not in begin/range, skip this FDE } } else { // malformed CIE, now augmentation describing pc range encoding } } else { // malformed FDE. CIE is bad } p = nextCFI; } } return false; } /// Extract info from a CIE template const char *CFI_Parser::parseCIE(A &addressSpace, pint_t cie, CIE_Info *cieInfo) { cieInfo->pointerEncoding = 0; cieInfo->lsdaEncoding = DW_EH_PE_omit; cieInfo->personalityEncoding = 0; cieInfo->personalityOffsetInCIE = 0; cieInfo->personality = 0; cieInfo->codeAlignFactor = 0; cieInfo->dataAlignFactor = 0; cieInfo->isSignalFrame = false; cieInfo->fdesHaveAugmentationData = false; cieInfo->cieStart = cie; pint_t p = cie; pint_t cieLength = (pint_t)addressSpace.get32(p); p += 4; pint_t cieContentEnd = p + cieLength; if (cieLength == 0xffffffff) { // 0xffffffff means length is really next 8 bytes cieLength = (pint_t)addressSpace.get64(p); p += 8; cieContentEnd = p + cieLength; } if (cieLength == 0) return NULL; // CIE ID is always 0 if (addressSpace.get32(p) != 0) return "CIE ID is not zero"; p += 4; // Version is always 1 or 3 uint8_t version = addressSpace.get8(p); if ((version != 1) && (version != 3)) return "CIE version is not 1 or 3"; ++p; // save start of augmentation string and find end pint_t strStart = p; while (addressSpace.get8(p) != 0) ++p; ++p; // parse code aligment factor cieInfo->codeAlignFactor = (uint32_t)addressSpace.getULEB128(p, cieContentEnd); // parse data alignment factor cieInfo->dataAlignFactor = (int)addressSpace.getSLEB128(p, cieContentEnd); // parse return address register uint64_t raReg = addressSpace.getULEB128(p, cieContentEnd); assert(raReg < 255 && "return address register too large"); cieInfo->returnAddressRegister = (uint8_t)raReg; // parse augmentation data based on augmentation string const char *result = NULL; if (addressSpace.get8(strStart) == 'z') { // parse augmentation data length addressSpace.getULEB128(p, cieContentEnd); for (pint_t s = strStart; addressSpace.get8(s) != '\0'; ++s) { switch (addressSpace.get8(s)) { case 'z': cieInfo->fdesHaveAugmentationData = true; break; case 'P': cieInfo->personalityEncoding = addressSpace.get8(p); ++p; cieInfo->personalityOffsetInCIE = (uint8_t)(p - cie); cieInfo->personality = addressSpace .getEncodedP(p, cieContentEnd, cieInfo->personalityEncoding); break; case 'L': cieInfo->lsdaEncoding = addressSpace.get8(p); ++p; break; case 'R': cieInfo->pointerEncoding = addressSpace.get8(p); ++p; break; case 'S': cieInfo->isSignalFrame = true; break; default: // ignore unknown letters break; } } } cieInfo->cieLength = cieContentEnd - cieInfo->cieStart; cieInfo->cieInstructions = p; return result; } /// "run" the dwarf instructions and create the abstact PrologInfo for an FDE template bool CFI_Parser::parseFDEInstructions(A &addressSpace, const FDE_Info &fdeInfo, const CIE_Info &cieInfo, pint_t upToPC, PrologInfo *results) { // clear results memset(results, '\0', sizeof(PrologInfo)); PrologInfoStackEntry *rememberStack = NULL; // parse CIE then FDE instructions return parseInstructions(addressSpace, cieInfo.cieInstructions, cieInfo.cieStart + cieInfo.cieLength, cieInfo, (pint_t)(-1), rememberStack, results) && parseInstructions(addressSpace, fdeInfo.fdeInstructions, fdeInfo.fdeStart + fdeInfo.fdeLength, cieInfo, upToPC - fdeInfo.pcStart, rememberStack, results); } /// "run" the dwarf instructions template bool CFI_Parser::parseInstructions(A &addressSpace, pint_t instructions, pint_t instructionsEnd, const CIE_Info &cieInfo, pint_t pcoffset, PrologInfoStackEntry *&rememberStack, PrologInfo *results) { const bool logDwarf = false; pint_t p = instructions; pint_t codeOffset = 0; PrologInfo initialState = *results; if (logDwarf) fprintf(stderr, "parseInstructions(instructions=0x%0" PRIx64 ")\n", (uint64_t)instructionsEnd); // see Dwarf Spec, section 6.4.2 for details on unwind opcodes while ((p < instructionsEnd) && (codeOffset < pcoffset)) { uint64_t reg; uint64_t reg2; int64_t offset; uint64_t length; uint8_t opcode = addressSpace.get8(p); uint8_t operand; #if !defined(_LIBUNWIND_NO_HEAP) PrologInfoStackEntry *entry; #endif ++p; switch (opcode) { case DW_CFA_nop: if (logDwarf) fprintf(stderr, "DW_CFA_nop\n"); break; case DW_CFA_set_loc: codeOffset = addressSpace.getEncodedP(p, instructionsEnd, cieInfo.pointerEncoding); if (logDwarf) fprintf(stderr, "DW_CFA_set_loc\n"); break; case DW_CFA_advance_loc1: codeOffset += (addressSpace.get8(p) * cieInfo.codeAlignFactor); p += 1; if (logDwarf) fprintf(stderr, "DW_CFA_advance_loc1: new offset=%" PRIu64 "\n", (uint64_t)codeOffset); break; case DW_CFA_advance_loc2: codeOffset += (addressSpace.get16(p) * cieInfo.codeAlignFactor); p += 2; if (logDwarf) fprintf(stderr, "DW_CFA_advance_loc2: new offset=%" PRIu64 "\n", (uint64_t)codeOffset); break; case DW_CFA_advance_loc4: codeOffset += (addressSpace.get32(p) * cieInfo.codeAlignFactor); p += 4; if (logDwarf) fprintf(stderr, "DW_CFA_advance_loc4: new offset=%" PRIu64 "\n", (uint64_t)codeOffset); break; case DW_CFA_offset_extended: reg = addressSpace.getULEB128(p, instructionsEnd); offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; if (reg > kMaxRegisterNumber) { fprintf(stderr, "malformed DW_CFA_offset_extended dwarf unwind, reg too big\n"); return false; } results->savedRegisters[reg].location = kRegisterInCFA; results->savedRegisters[reg].value = offset; if (logDwarf) fprintf(stderr, "DW_CFA_offset_extended(reg=%" PRIu64 ", offset=%" PRId64 ")\n", reg, offset); break; case DW_CFA_restore_extended: reg = addressSpace.getULEB128(p, instructionsEnd); ; if (reg > kMaxRegisterNumber) { fprintf( stderr, "malformed DW_CFA_restore_extended dwarf unwind, reg too big\n"); return false; } results->savedRegisters[reg] = initialState.savedRegisters[reg]; if (logDwarf) fprintf(stderr, "DW_CFA_restore_extended(reg=%" PRIu64 ")\n", reg); break; case DW_CFA_undefined: reg = addressSpace.getULEB128(p, instructionsEnd); if (reg > kMaxRegisterNumber) { fprintf(stderr, "malformed DW_CFA_undefined dwarf unwind, reg too big\n"); return false; } results->savedRegisters[reg].location = kRegisterUnused; if (logDwarf) fprintf(stderr, "DW_CFA_undefined(reg=%" PRIu64 ")\n", reg); break; case DW_CFA_same_value: reg = addressSpace.getULEB128(p, instructionsEnd); if (reg > kMaxRegisterNumber) { fprintf(stderr, "malformed DW_CFA_same_value dwarf unwind, reg too big\n"); return false; } // DW_CFA_same_value unsupported // "same value" means register was stored in frame, but its current // value has not changed, so no need to restore from frame. // We model this as if the register was never saved. results->savedRegisters[reg].location = kRegisterUnused; // set flag to disable conversion to compact unwind results->sameValueUsed = true; if (logDwarf) fprintf(stderr, "DW_CFA_same_value(reg=%" PRIu64 ")\n", reg); break; case DW_CFA_register: reg = addressSpace.getULEB128(p, instructionsEnd); reg2 = addressSpace.getULEB128(p, instructionsEnd); if (reg > kMaxRegisterNumber) { fprintf(stderr, "malformed DW_CFA_register dwarf unwind, reg too big\n"); return false; } if (reg2 > kMaxRegisterNumber) { fprintf(stderr, "malformed DW_CFA_register dwarf unwind, reg2 too big\n"); return false; } results->savedRegisters[reg].location = kRegisterInRegister; results->savedRegisters[reg].value = (int64_t)reg2; // set flag to disable conversion to compact unwind results->registersInOtherRegisters = true; if (logDwarf) fprintf(stderr, "DW_CFA_register(reg=%" PRIu64 ", reg2=%" PRIu64 ")\n", reg, reg2); break; #if !defined(_LIBUNWIND_NO_HEAP) case DW_CFA_remember_state: // avoid operator new, because that would be an upward dependency entry = (PrologInfoStackEntry *)malloc(sizeof(PrologInfoStackEntry)); if (entry != NULL) { entry->next = rememberStack; entry->info = *results; rememberStack = entry; } else { return false; } if (logDwarf) fprintf(stderr, "DW_CFA_remember_state\n"); break; case DW_CFA_restore_state: if (rememberStack != NULL) { PrologInfoStackEntry *top = rememberStack; *results = top->info; rememberStack = top->next; free((char *)top); } else { return false; } if (logDwarf) fprintf(stderr, "DW_CFA_restore_state\n"); break; #endif case DW_CFA_def_cfa: reg = addressSpace.getULEB128(p, instructionsEnd); offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd); if (reg > kMaxRegisterNumber) { fprintf(stderr, "malformed DW_CFA_def_cfa dwarf unwind, reg too big\n"); return false; } results->cfaRegister = (uint32_t)reg; results->cfaRegisterOffset = (int32_t)offset; if (logDwarf) fprintf(stderr, "DW_CFA_def_cfa(reg=%" PRIu64 ", offset=%" PRIu64 ")\n", reg, offset); break; case DW_CFA_def_cfa_register: reg = addressSpace.getULEB128(p, instructionsEnd); if (reg > kMaxRegisterNumber) { fprintf( stderr, "malformed DW_CFA_def_cfa_register dwarf unwind, reg too big\n"); return false; } results->cfaRegister = (uint32_t)reg; if (logDwarf) fprintf(stderr, "DW_CFA_def_cfa_register(%" PRIu64 ")\n", reg); break; case DW_CFA_def_cfa_offset: results->cfaRegisterOffset = (int32_t) addressSpace.getULEB128(p, instructionsEnd); results->codeOffsetAtStackDecrement = (uint32_t)codeOffset; if (logDwarf) fprintf(stderr, "DW_CFA_def_cfa_offset(%d)\n", results->cfaRegisterOffset); break; case DW_CFA_def_cfa_expression: results->cfaRegister = 0; results->cfaExpression = (int64_t)p; length = addressSpace.getULEB128(p, instructionsEnd); p += length; if (logDwarf) fprintf(stderr, "DW_CFA_def_cfa_expression(expression=0x%" PRIx64 ", length=%" PRIu64 ")\n", results->cfaExpression, length); break; case DW_CFA_expression: reg = addressSpace.getULEB128(p, instructionsEnd); if (reg > kMaxRegisterNumber) { fprintf(stderr, "malformed DW_CFA_expression dwarf unwind, reg too big\n"); return false; } results->savedRegisters[reg].location = kRegisterAtExpression; results->savedRegisters[reg].value = (int64_t)p; length = addressSpace.getULEB128(p, instructionsEnd); p += length; if (logDwarf) fprintf(stderr, "DW_CFA_expression(reg=%" PRIu64 ", expression=0x%" PRIx64 ", length=%" PRIu64 ")\n", reg, results->savedRegisters[reg].value, length); break; case DW_CFA_offset_extended_sf: reg = addressSpace.getULEB128(p, instructionsEnd); if (reg > kMaxRegisterNumber) { fprintf( stderr, "malformed DW_CFA_offset_extended_sf dwarf unwind, reg too big\n"); return false; } offset = addressSpace.getSLEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterInCFA; results->savedRegisters[reg].value = offset; if (logDwarf) fprintf(stderr, "DW_CFA_offset_extended_sf(reg=%" PRIu64 ", offset=%" PRId64 ")\n", reg, offset); break; case DW_CFA_def_cfa_sf: reg = addressSpace.getULEB128(p, instructionsEnd); offset = addressSpace.getSLEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; if (reg > kMaxRegisterNumber) { fprintf(stderr, "malformed DW_CFA_def_cfa_sf dwarf unwind, reg too big\n"); return false; } results->cfaRegister = (uint32_t)reg; results->cfaRegisterOffset = (int32_t)offset; if (logDwarf) fprintf(stderr, "DW_CFA_def_cfa_sf(reg=%" PRIu64 ", offset=%" PRId64 ")\n", reg, offset); break; case DW_CFA_def_cfa_offset_sf: results->cfaRegisterOffset = (int32_t) (addressSpace.getSLEB128(p, instructionsEnd) * cieInfo.dataAlignFactor); results->codeOffsetAtStackDecrement = (uint32_t)codeOffset; if (logDwarf) fprintf(stderr, "DW_CFA_def_cfa_offset_sf(%d)\n", results->cfaRegisterOffset); break; case DW_CFA_val_offset: reg = addressSpace.getULEB128(p, instructionsEnd); offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterOffsetFromCFA; results->savedRegisters[reg].value = offset; if (logDwarf) fprintf(stderr, "DW_CFA_val_offset(reg=%" PRIu64 ", offset=%" PRId64 "\n", reg, offset); break; case DW_CFA_val_offset_sf: reg = addressSpace.getULEB128(p, instructionsEnd); if (reg > kMaxRegisterNumber) { fprintf(stderr, "malformed DW_CFA_val_offset_sf dwarf unwind, reg too big\n"); return false; } offset = addressSpace.getSLEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterOffsetFromCFA; results->savedRegisters[reg].value = offset; if (logDwarf) fprintf(stderr, "DW_CFA_val_offset_sf(reg=%" PRIu64 ", offset=%" PRId64 "\n", reg, offset); break; case DW_CFA_val_expression: reg = addressSpace.getULEB128(p, instructionsEnd); if (reg > kMaxRegisterNumber) { fprintf(stderr, "malformed DW_CFA_val_expression dwarf unwind, reg too big\n"); return false; } results->savedRegisters[reg].location = kRegisterIsExpression; results->savedRegisters[reg].value = (int64_t)p; length = addressSpace.getULEB128(p, instructionsEnd); p += length; if (logDwarf) fprintf(stderr, "DW_CFA_val_expression(reg=%" PRIu64 ", expression=0x%" PRIx64 ", length=%" PRIu64 ")\n", reg, results->savedRegisters[reg].value, length); break; case DW_CFA_GNU_args_size: length = addressSpace.getULEB128(p, instructionsEnd); results->spExtraArgSize = (uint32_t)length; if (logDwarf) fprintf(stderr, "DW_CFA_GNU_args_size(%" PRIu64 ")\n", length); break; case DW_CFA_GNU_negative_offset_extended: reg = addressSpace.getULEB128(p, instructionsEnd); if (reg > kMaxRegisterNumber) { fprintf(stderr, "malformed DW_CFA_GNU_negative_offset_extended dwarf " "unwind, reg too big\n"); return false; } offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterInCFA; results->savedRegisters[reg].value = -offset; if (logDwarf) fprintf(stderr, "DW_CFA_GNU_negative_offset_extended(%" PRId64 ")\n", offset); break; default: operand = opcode & 0x3F; switch (opcode & 0xC0) { case DW_CFA_offset: reg = operand; offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd) * cieInfo.dataAlignFactor; results->savedRegisters[reg].location = kRegisterInCFA; results->savedRegisters[reg].value = offset; if (logDwarf) fprintf(stderr, "DW_CFA_offset(reg=%d, offset=%" PRId64 ")\n", operand, offset); break; case DW_CFA_advance_loc: codeOffset += operand * cieInfo.codeAlignFactor; if (logDwarf) fprintf(stderr, "DW_CFA_advance_loc: new offset=%" PRIu64 "\n", (uint64_t)codeOffset); break; case DW_CFA_restore: reg = operand; results->savedRegisters[reg] = initialState.savedRegisters[reg]; if (logDwarf) fprintf(stderr, "DW_CFA_restore(reg=%" PRIu64 ")\n", reg); break; default: if (logDwarf) fprintf(stderr, "unknown CFA opcode 0x%02X\n", opcode); return false; } } } return true; } } // namespace libunwind #endif // __DWARF_PARSER_HPP__ Index: stable/11 =================================================================== --- stable/11 (revision 303317) +++ stable/11 (revision 303318) Property changes on: stable/11 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r302475,303061