llvm-project/lldb/lit/SymbolFile/Breakpad
Pavel Labath a8b284eeec Unwind: Add a stack scanning mechanism to support win32 unwinding
Summary:
Windows unwinding is weird. The unwind rules do not (always) describe
the precise layout of the stack, but rather expect the debugger to scan
the stack for something which looks like a plausible return address, and
the unwind based on that. The reason this works somewhat reliably is
because the the unwinder also has access to the frame sizes of the
functions on the stack. This allows it (in most cases) to skip function
pointers in local variables or function arguments, which could otherwise
be mistaken for return addresses.

Implementing this kind of unwind mechanism in lldb was a bit challenging
because we expect to be able to statically describe (in the UnwindPlan)
structure, the layout of the stack for any given instruction. Giving a
precise desription of this is not possible, because it requires
correlating information from two functions -- the pushed arguments to a
function are considered a part of the callers stack frame, and their
size needs to be considered when unwinding the caller, but they are only
present in the unwind entry of the callee. The callee may end up being
in a completely different module, or it may not even be possible to
determine it statically (indirect calls).

This patch implements this functionality by introducing a couple of new
APIs:
SymbolFile::GetParameterStackSize - return the amount of stack space
  taken up by parameters of this function.
SymbolFile::GetOwnFrameSize - the size of this function's frame. This
  excludes the parameters, but includes stuff like local variables and
  spilled registers.

These functions are then used by the unwinder to compute the estimated
location of the return address. This address is not always exact,
because the stack may contain some additional values -- for instance, if
we're getting ready to call a function then the stack will also contain
partially set up arguments, but we will not know their size because we
haven't called the function yet. For this reason the unwinder will crawl
up the stack from the return address position, and look for something
that looks like a possible return address. Currently, we assume that
something is a valid return address if it ends up pointing to an
executable section.

All of this logic kicks in when the UnwindPlan sets the value of CFA as
"isHeuristicallyDetected", which is also the final new API here. Right
now, only SymbolFileBreakpad implements these APIs, but in the future
SymbolFilePDB will use them too.

Differential Revision: https://reviews.llvm.org/D66638

llvm-svn: 373072
2019-09-27 12:10:06 +00:00
..
Inputs Unwind: Add a stack scanning mechanism to support win32 unwinding 2019-09-27 12:10:06 +00:00
line-table-discontinuous-file-ids.test Breakpad: auto-detect path style of file entries 2019-02-11 14:11:00 +00:00
line-table-edgecases.test Breakpad: auto-detect path style of file entries 2019-02-11 14:11:00 +00:00
line-table-missing-file.test Breakpad: auto-detect path style of file entries 2019-02-11 14:11:00 +00:00
line-table-mixed-path-styles.test Breakpad: auto-detect path style of file entries 2019-02-11 14:11:00 +00:00
line-table.test Breakpad: auto-detect path style of file entries 2019-02-11 14:11:00 +00:00
stack-cfi-parsing.test [FuncUnwinders] Use "symbol file" unwind plans for unwinding 2019-05-24 09:54:39 +00:00
symtab-macho.test Fix symtab-macho.test broken by r358500 2019-04-16 16:57:41 +00:00
symtab.test breakpad: Add FUNC records to the symtab 2019-01-22 04:56:31 +00:00
unwind-via-raSearch.test Unwind: Add a stack scanning mechanism to support win32 unwinding 2019-09-27 12:10:06 +00:00
unwind-via-stack-cfi.test [FuncUnwinders] Use "symbol file" unwind plans for unwinding 2019-05-24 09:54:39 +00:00
unwind-via-stack-win.test Breakpad: Basic support for STACK WIN unwinding 2019-09-05 07:05:15 +00:00