1 // REQUIRES: system-windows
2 //
3 // RUN: %dexter --fail-lt 1.0 -w --builder 'clang-cl_vs2015' \
4 // RUN:      --debugger 'dbgeng' --cflags '/Od /Z7 /Zi' \
5 // RUN:      --ldflags '/Od /Z7 /Zi' -- %s
6 //
7 // RUN: %dexter --fail-lt 1.0 -w --builder 'clang-cl_vs2015' \
8 // RUN:      --debugger 'dbgeng' --cflags '/O2 /Z7 /Zi' \
9 // RUN:      --ldflags '/O2 /Z7 /Zi' -- %s
10 
11 // This code is structured to have an early exit with an epilogue in the middle
12 // of the function, which creates a gap between the beginning of the inlined
13 // code region and the end. Previously, this confused cdb.
14 
15 volatile bool shutting_down_ = true;
16 volatile bool tearing_down_ = true;
17 
setCrashString(const char *)18 void __attribute__((optnone)) setCrashString(const char *) {}
doTailCall()19 void __attribute__((optnone)) doTailCall() {}
20 extern "C" void __declspec(noreturn) abort();
21 
inlineCrashFrame()22 void __forceinline inlineCrashFrame() {
23   if (shutting_down_ || tearing_down_) {
24     setCrashString("crashing");
25     // MSVC lays out calls to abort out of line, gets the layout we want.
26     abort(); // DexLabel('stop')
27   }
28 }
29 
callerOfInlineCrashFrame(bool is_keeping_alive)30 void __declspec(noinline) callerOfInlineCrashFrame(bool is_keeping_alive) {
31   if (is_keeping_alive)
32     inlineCrashFrame();
33   else
34     doTailCall();
35 }
36 
main()37 int __attribute__((optnone)) main() {
38   callerOfInlineCrashFrame(true);
39 }
40 
41 /*
42 DexExpectProgramState({'frames':[
43      {'function': 'inlineCrashFrame', 'location':{'lineno' : 'stop'} },
44      {'function': 'callerOfInlineCrashFrame'},
45      {'function': 'main'}
46 ]})
47 */
48