hanchenye-llvm-project/lldb/unittests
Aleksandr Urakov 4538ed3b85 [x86] Fix issues with a realigned stack in MSVC compiled applications
Summary:
This patch fixes issues with a stack realignment.

MSVC maintains two frame pointers (`ebx` and `ebp`) for a realigned stack - one
is used for access to function parameters, while another is used for access to
locals. To support this the patch:
- adds an alternative frame pointer (`ebx`);
- considers stack realignment instructions (e.g. `and esp, -32`);
- along with CFA (Canonical Frame Address) which point to the position next to
  the saved return address (or to the first parameter on the stack) introduces
  AFA (Aligned Frame Address) which points to the position of the stack pointer
  right after realignment. AFA is used for access to registers saved after the
  realignment (see the test);

Here is an example of the code with the realignment:
```
struct __declspec(align(256)) OverAligned {
  char c;
};

void foo(int foo_arg) {
  OverAligned oa_foo = { 1 };
  auto aaa_foo = 1234;
}

void bar(int bar_arg) {
  OverAligned oa_bar = { 2 };
  auto aaa_bar = 5678;
  foo(1111);
}

int main() {
  bar(2222);
  return 0;
}
```
and here is the `bar` disassembly:
```
push    ebx
mov     ebx, esp
sub     esp, 8
and     esp, -100h
add     esp, 4
push    ebp
mov     ebp, [ebx+4]
mov     [esp+4], ebp
mov     ebp, esp
sub     esp, 200h
mov     byte ptr [ebp-200h], 2
mov     dword ptr [ebp-4], 5678
push    1111            ; foo_arg
call    j_?foo@@YAXH@Z  ; foo(int)
add     esp, 4
mov     esp, ebp
pop     ebp
mov     esp, ebx
pop     ebx
retn
```

Reviewers: labath, zturner, jasonmolenda, stella.stamenova

Reviewed By: jasonmolenda

Subscribers: abidh, lldb-commits

Tags: #lldb

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

llvm-svn: 345577
2018-10-30 10:07:08 +00:00
..
Breakpoint Rename Error -> Status. 2017-05-12 04:51:55 +00:00
Core Fix typos. 2018-10-04 22:33:39 +00:00
Disassembler If we fail to get an armv7em-- disassembler from llvm, skip the 2018-09-12 19:30:03 +00:00
Editline Move PseudoTerminal to the lldb_private namespace 2017-12-11 10:09:14 +00:00
Expression Really fix ClangParserTest 2018-06-05 10:29:48 +00:00
Host [unittest] Fix NativeProcessProtocolTest.cpp (NFC) 2018-09-26 10:09:44 +00:00
Interpreter Change TestCompletion to only ever look inside of BaseDir 2018-09-04 23:09:49 +00:00
Language Move the column marking functionality to the Highlighter framework 2018-08-30 00:09:21 +00:00
ObjectFile ELF: Replace the header-extension unit test with a lit one 2018-07-19 14:38:30 +00:00
Platform Fix a bug PlatformDarwin::SDKSupportsModule. 2018-10-25 15:30:43 +00:00
Process Add support for parsing Breakpad minidump files that can have extra padding in the module, thread and memory lists. 2018-07-23 14:16:08 +00:00
ScriptInterpreter Added new API to SBStructuredData class 2017-05-29 08:25:46 +00:00
Signals
Symbol [NFC] Refactor SetBaseClasses and DeleteBaseClasses. 2018-10-25 20:44:56 +00:00
SymbolFile [PDB] Fix `SymbolFilePDBTests` after r345313 2018-10-26 09:36:26 +00:00
Target Remove UUID::SetFromCString 2018-06-21 15:24:39 +00:00
TestingSupport cmake + xcode: prevent gtests from using includes from project root 2017-10-03 21:20:18 +00:00
UnwindAssembly [x86] Fix issues with a realigned stack in MSVC compiled applications 2018-10-30 10:07:08 +00:00
Utility [lldb] Add support in Status::AsCString to retrieve win32 system error strings 2018-10-19 18:58:24 +00:00
debugserver [CMake] Need to set WITH_LOCKDOWN on debugserver target 2017-09-06 20:15:43 +00:00
tools [cmake] Add option to skip building lldb-server 2018-08-23 18:05:45 +00:00
CMakeLists.txt Add the Disassembler unit test dir. 2018-09-07 18:51:10 +00:00
gtest_common.h