llvm-project/lldb/source/Plugins/Process/Utility
Ulrich Weigand 7793ba86d1 Fix unwind failures when PC points beyond the end of a function
RegisterContextLLDB::InitializeNonZerothFrame already has code to attempt
to detect and handle the case where the PC points beyond the end of a
function, but there are certain cases where this doesn't work correctly.

In fact, there are *two* different places where this detection is attempted,
and the failure is in fact a result of an unfortunate interaction between
those two separate attempts.

First, the ResolveSymbolContextForAddress routine is called with the
resolve_tail_call_address flag set to true.  This causes the routine
to internally accept a PC pointing beyond the end of a function, and
still resolving the PC to that function symbol.

Second, the InitializeNonZerothFrame routine itself maintains a
"decr_pc_and_recompute_addr_range" flag and, if that turns out to
be true, itself decrements the PC by one and searches again for
a symbol at that new PC value.

Both approaches correctly identify the symbol associated with the PC.
However, the problem is now that later on, we also need to find the
DWARF CFI record associated with the PC.  This is done in the
RegisterContextLLDB::GetFullUnwindPlanForFrame routine, and uses
the "m_current_offset_backed_up_one" member variable.

However, that variable only actually contains the PC "backed up by
one" if the *second* approach above was taken.  If the function was
already identified via the first approach above, that member variable
is *not* backed up by one but simply points to the original PC.
This in turn causes GetEHFrameUnwindPlan to not correctly identify
the DWARF CFI record associated with the PC.

Now, in many cases, if the first method had to back up the PC by one,
we *still* use the second method too, because of this piece of code:

    // Or if we're in the middle of the stack (and not "above" an asynchronous event like sigtramp),
    // and our "current" pc is the start of a function...
    if (m_sym_ctx_valid
        && GetNextFrame()->m_frame_type != eTrapHandlerFrame
        && GetNextFrame()->m_frame_type != eDebuggerFrame
        && addr_range.GetBaseAddress().IsValid()
        && addr_range.GetBaseAddress().GetSection() == m_current_pc.GetSection()
        && addr_range.GetBaseAddress().GetOffset() == m_current_pc.GetOffset())
    {
        decr_pc_and_recompute_addr_range = true;
    }

In many cases, when the PC is one beyond the end of the current function,
it will indeed then be exactly at the start of the next function.  But this
is not always the case, e.g. if there happens to be alignment padding
between the end of one function and the start of the next.

In those cases, we may sucessfully look up the function symbol via
ResolveSymbolContextForAddress, but *not* set decr_pc_and_recompute_addr_range,
and therefore fail to find the correct DWARF CFI record.

A very simple fix for this problem is to just never use the first method.
Call ResolveSymbolContextForAddress with resolve_tail_call_address set
to false, which will cause it to fail if the PC is beyond the end of
the current function; or else, identify the next function if the PC
is also at the start of the next function.  In either case, we will
then set the decr_pc_and_recompute_addr_range variable and back up the
PC anyway, but this time also find the correct DWARF CFI.

A related problem is that the ResolveSymbolContextForAddress sometimes
returns a "symbol" with empty name.  This turns out to be an ELF section
symbol.  Now, usually those get type eSymbolTypeInvalid.  However, there
is code in ObjectFileELF::ParseSymbols that tries to change the type of
invalid symbols to eSymbolTypeCode or eSymbolTypeData if the symbol
lies within the code or data section.

Unfortunately, this check also hits the symbol for the code section
itself, which is then marked as eSymbolTypeCode.  While the size of
the section symbol is 0 according to the ELF file, LLDB considers
this size invalid and attempts to figure out the "correct" size.
Depending on how this goes, we may end up with a symbol that overlays
part of the code section, even outside areas covered by real function
symbols.

Therefore, if we call ResolveSymbolContextForAddress with PC pointing
beyond the end of a function, we may get this bogus section symbol.
This again means InitializeNonZerothFrame thinks we have a valid PC,
but then we don't find any unwind info for it.

The fix for this problem is me to simply always leave ELF section
symbols as type eSymbolTypeInvalid.

Differential Revision: http://reviews.llvm.org/D18975

llvm-svn: 267363
2016-04-24 20:49:56 +00:00
..
ARMDefines.h Handle thumb IT instructions correctly all the time. 2014-12-09 23:31:02 +00:00
ARMUtils.h Fix typos. 2014-07-08 18:05:41 +00:00
CMakeLists.txt Support Linux on SystemZ as platform 2016-04-14 14:28:34 +00:00
DynamicRegisterInfo.cpp Clean up register naming conventions inside lldb. 2015-09-15 23:20:34 +00:00
DynamicRegisterInfo.h Added XML to the host layer. 2015-05-26 18:00:51 +00:00
FreeBSDSignals.cpp [LLDB] Insert names with same signo as alias instead of a new entry 2015-10-20 07:05:46 +00:00
FreeBSDSignals.h Refactor Unix signals. 2015-07-14 01:09:28 +00:00
GDBRemoteSignals.cpp Refactor Unix signals. 2015-07-14 01:09:28 +00:00
GDBRemoteSignals.h Refactor Unix signals. 2015-07-14 01:09:28 +00:00
HistoryThread.cpp Remove unused class variable and update all callers/users. 2014-09-09 06:14:23 +00:00
HistoryThread.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
HistoryUnwind.cpp Remove unused class variable and update all callers/users. 2014-09-09 06:14:23 +00:00
HistoryUnwind.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
InferiorCallPOSIX.cpp Add a DiagnosticManager replace error streams in the expression parser. 2016-03-19 00:03:59 +00:00
InferiorCallPOSIX.h Prevent infinite recursive loop in AppleObjCTrampolineHandler constructor 2016-01-08 20:32:35 +00:00
InstructionUtils.h A << operation would be undefined for a bit-selecting 2014-10-17 01:52:30 +00:00
LinuxSignals.cpp [LLDB] Insert names with same signo as alias instead of a new entry 2015-10-20 07:05:46 +00:00
LinuxSignals.h Refactor Unix signals. 2015-07-14 01:09:28 +00:00
MipsLinuxSignals.cpp [LLDB] Insert names with same signo as alias instead of a new entry 2015-10-20 07:05:46 +00:00
MipsLinuxSignals.h Refactor Unix signals. 2015-07-14 01:09:28 +00:00
NetBSDSignals.cpp Welcome to NetBSD signals 2015-12-15 00:50:19 +00:00
NetBSDSignals.h Welcome to NetBSD signals 2015-12-15 00:50:19 +00:00
RegisterContextDarwin_arm.cpp Some 32-bit arm corefiles on darwin may have their general purpose 2016-01-20 05:17:13 +00:00
RegisterContextDarwin_arm.h Some 32-bit arm corefiles on darwin may have their general purpose 2016-01-20 05:17:13 +00:00
RegisterContextDarwin_arm64.cpp Make lldb::endian::InlHostByteOrder() private. 2015-11-07 04:40:13 +00:00
RegisterContextDarwin_arm64.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextDarwin_i386.cpp Clean up register naming conventions inside lldb. 2015-09-15 23:20:34 +00:00
RegisterContextDarwin_i386.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextDarwin_x86_64.cpp Make lldb::endian::InlHostByteOrder() private. 2015-11-07 04:40:13 +00:00
RegisterContextDarwin_x86_64.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextDummy.cpp Clean up register naming conventions inside lldb. 2015-09-15 23:20:34 +00:00
RegisterContextDummy.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextFreeBSD_arm.cpp Add 64/128 bit arm neon register definitions on linux 2015-11-26 15:02:31 +00:00
RegisterContextFreeBSD_arm.h Limit scope of RegisterContextPOSIX.h header 2015-09-14 13:16:59 +00:00
RegisterContextFreeBSD_arm64.cpp Handle FreeBSD/arm64 core files 2015-03-26 14:20:00 +00:00
RegisterContextFreeBSD_arm64.h Limit scope of RegisterContextPOSIX.h header 2015-09-14 13:16:59 +00:00
RegisterContextFreeBSD_i386.cpp Same issue as in D8685 but for i386. 2015-04-21 23:00:58 +00:00
RegisterContextFreeBSD_i386.h Limit scope of RegisterContextPOSIX.h header 2015-09-14 13:16:59 +00:00
RegisterContextFreeBSD_mips64.cpp [LLDB][MIPS] Fix offsets of all register sets and add MSA regset and FRE=1 mode support 2015-08-17 13:40:17 +00:00
RegisterContextFreeBSD_mips64.h Limit scope of RegisterContextPOSIX.h header 2015-09-14 13:16:59 +00:00
RegisterContextFreeBSD_powerpc.cpp Implement initial Altivec support 2015-02-05 07:12:01 +00:00
RegisterContextFreeBSD_powerpc.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextFreeBSD_x86_64.cpp Fix FreeBSD crash after r233837 2015-04-03 20:49:08 +00:00
RegisterContextFreeBSD_x86_64.h Limit scope of RegisterContextPOSIX.h header 2015-09-14 13:16:59 +00:00
RegisterContextHistory.cpp Clean up register naming conventions inside lldb. 2015-09-15 23:20:34 +00:00
RegisterContextHistory.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextLLDB.cpp Fix unwind failures when PC points beyond the end of a function 2016-04-24 20:49:56 +00:00
RegisterContextLLDB.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextLinux_arm.cpp Add 64/128 bit arm neon register definitions on linux 2015-11-26 15:02:31 +00:00
RegisterContextLinux_arm.h Limit scope of RegisterContextPOSIX.h header 2015-09-14 13:16:59 +00:00
RegisterContextLinux_arm64.cpp Fix the handling of FPR offsets in Linux arm/aarch64 register contexts 2015-09-07 10:11:23 +00:00
RegisterContextLinux_arm64.h Limit scope of RegisterContextPOSIX.h header 2015-09-14 13:16:59 +00:00
RegisterContextLinux_i386.cpp X86: Change FTAG register size in FXSAVE structure 2015-10-12 09:57:00 +00:00
RegisterContextLinux_i386.h Limit scope of RegisterContextPOSIX.h header 2015-09-14 13:16:59 +00:00
RegisterContextLinux_mips.cpp [LLDB][MIPS] Fix GetUserRegisterInfoCount to count no of regs which are physically present 2015-11-03 09:13:45 +00:00
RegisterContextLinux_mips.h [LLDB][MIPS] Fix GetUserRegisterInfoCount to count no of regs which are physically present 2015-11-03 09:13:45 +00:00
RegisterContextLinux_mips64.cpp [LLDB][MIPS] Fix GetUserRegisterInfoCount to count no of regs which are physically present 2015-11-03 09:13:45 +00:00
RegisterContextLinux_mips64.h [LLDB][MIPS] Fix GetUserRegisterInfoCount to count no of regs which are physically present 2015-11-03 09:13:45 +00:00
RegisterContextLinux_s390x.cpp Support Linux on SystemZ as platform 2016-04-14 14:28:34 +00:00
RegisterContextLinux_s390x.h Support Linux on SystemZ as platform 2016-04-14 14:28:34 +00:00
RegisterContextLinux_x86_64.cpp Set orig_eax to -1 for Linux x86 platforms 2015-08-13 09:05:11 +00:00
RegisterContextLinux_x86_64.h Limit scope of RegisterContextPOSIX.h header 2015-09-14 13:16:59 +00:00
RegisterContextMacOSXFrameBackchain.cpp LLGS Android target support - for Andy Chien : http://reviews.llvm.org/D6166 2014-11-08 01:41:49 +00:00
RegisterContextMacOSXFrameBackchain.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextMach_arm.cpp
RegisterContextMach_arm.h
RegisterContextMach_i386.cpp
RegisterContextMach_i386.h
RegisterContextMach_x86_64.cpp
RegisterContextMach_x86_64.h
RegisterContextMemory.cpp Replace uint32_t by lldb::RegisterKing in register context API. 2014-07-02 09:51:28 +00:00
RegisterContextMemory.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextNetBSD_x86_64.cpp [NetBSD] Remove dead code. 2016-02-03 20:13:50 +00:00
RegisterContextNetBSD_x86_64.h NetBSD: Define initial RegisterContextNetBSD_x86_64 2016-02-02 03:47:44 +00:00
RegisterContextPOSIX_arm.cpp Add 64/128 bit arm neon register definitions on linux 2015-11-26 15:02:31 +00:00
RegisterContextPOSIX_arm.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextPOSIX_arm64.cpp Create NativeRegisterContext for android-arm64 2015-03-13 11:36:47 +00:00
RegisterContextPOSIX_arm64.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextPOSIX_mips64.cpp Replace uint32_t by lldb::RegisterKing in register context API. 2014-07-02 09:51:28 +00:00
RegisterContextPOSIX_mips64.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextPOSIX_powerpc.cpp Quiet Coverity 2015-02-12 05:31:31 +00:00
RegisterContextPOSIX_powerpc.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextPOSIX_s390x.cpp Support Linux on SystemZ as platform 2016-04-14 14:28:34 +00:00
RegisterContextPOSIX_s390x.h Support Linux on SystemZ as platform 2016-04-14 14:28:34 +00:00
RegisterContextPOSIX_x86.cpp Rename lldb registers to contain lldb_ prefix. 2014-11-21 02:00:21 +00:00
RegisterContextPOSIX_x86.h [LLDB] Fix Clang-tidy modernize-use-override warnings in some headers in source/Plugins/Process/Utility; other minor fixes. 2015-10-17 00:19:57 +00:00
RegisterContextThreadMemory.cpp Make sure if a thread specifies a 'register_data_addr' in a python operating system plug-in, that is is used to fetch the register values. 2014-12-11 23:53:52 +00:00
RegisterContextThreadMemory.h Fix Clang-tidy modernize-use-override warnings in some files in source/Plugins; other minor fixes. 2015-10-21 18:46:17 +00:00
RegisterContext_mips.h Clean up register naming conventions inside lldb. 2015-09-15 23:20:34 +00:00
RegisterContext_powerpc.h Clean up register naming conventions inside lldb. 2015-09-15 23:20:34 +00:00
RegisterContext_s390x.h Support Linux on SystemZ as platform 2016-04-14 14:28:34 +00:00
RegisterContext_x86.h X86: Change FTAG register size in FXSAVE structure 2015-10-12 09:57:00 +00:00
RegisterInfoInterface.h Add missing include to RegisterInfoInterface.h 2015-08-13 10:41:55 +00:00
RegisterInfos_arm.h Add 64/128 bit arm neon register definitions on linux 2015-11-26 15:02:31 +00:00
RegisterInfos_arm64.h Fix Clang-tidy modernize-use-nullptr warnings in source/Plugins/Process/Utility headers; other minor fixes. 2015-10-30 00:55:29 +00:00
RegisterInfos_i386.h Fix Clang-tidy modernize-use-nullptr warnings in source/Plugins/Process/Utility headers; other minor fixes. 2015-10-30 00:55:29 +00:00
RegisterInfos_mips.h Fix Clang-tidy modernize-use-nullptr warnings in source/Plugins/Process/Utility headers; other minor fixes. 2015-10-30 00:55:29 +00:00
RegisterInfos_mips64.h Fix Clang-tidy modernize-use-nullptr warnings in source/Plugins/Process/Utility headers; other minor fixes. 2015-10-30 00:55:29 +00:00
RegisterInfos_powerpc.h Clean up register naming conventions inside lldb. 2015-09-15 23:20:34 +00:00
RegisterInfos_s390x.h Support Linux on SystemZ as platform 2016-04-14 14:28:34 +00:00
RegisterInfos_x86_64.h Fix Clang-tidy modernize-use-nullptr warnings in source/Plugins/Process/Utility headers; other minor fixes. 2015-10-30 00:55:29 +00:00
StopInfoMachException.cpp The SetStopInfo from a Mach Exception was setting the stop 2016-02-03 19:45:31 +00:00
StopInfoMachException.h Fix Clang-tidy modernize-use-override warnings in some files in source/Plugins; other minor fixes. 2015-10-21 18:46:17 +00:00
ThreadMemory.cpp Fix stepping a virtual thread when the python operating system was enabled. 2015-04-07 22:17:41 +00:00
ThreadMemory.h Fix Clang-tidy modernize-use-nullptr warnings in source/Plugins/Process/Utility headers; other minor fixes. 2015-10-30 00:55:29 +00:00
UnwindLLDB.cpp Fix to solve Bug 23139 & Bug 23560 2015-11-13 10:47:49 +00:00
UnwindLLDB.h Fix to solve Bug 23139 & Bug 23560 2015-11-13 10:47:49 +00:00
UnwindMacOSXFrameBackchain.cpp Roll back the changes I made in r193907 which created a new Frame 2013-11-04 09:33:30 +00:00
UnwindMacOSXFrameBackchain.h Fix Clang-tidy modernize-use-override warnings in some files in source/Plugins; other minor fixes. 2015-10-21 18:46:17 +00:00
lldb-arm-register-enums.h Add 64/128 bit arm neon register definitions on linux 2015-11-26 15:02:31 +00:00
lldb-arm64-register-enums.h Create NativeRegisterContext for android-arm64 2015-03-13 11:36:47 +00:00
lldb-mips-freebsd-register-enums.h [LLDB][MIPS] Fix offsets of all register sets and add MSA regset and FRE=1 mode support 2015-08-17 13:40:17 +00:00
lldb-mips-linux-register-enums.h [LLDB][MIPS] Fix offsets of all register sets and add MSA regset and FRE=1 mode support 2015-08-17 13:40:17 +00:00
lldb-s390x-register-enums.h Support Linux on SystemZ as platform 2016-04-14 14:28:34 +00:00
lldb-x86-register-enums.h Fixing TestRegisters on Linux with LLGS 2015-01-23 22:57:00 +00:00