[PATCH] D79760: [WinEH64] Fix a crush issue when c++ exception nested in a particular form.
Pengfei Wang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 13 01:34:53 PDT 2020
pengfei added a comment.
In D79760#2033315 <https://reviews.llvm.org/D79760#2033315>, @tentzen wrote:
> I meant did you debug into the crash of your test case in https://bugs.llvm.org/show_bug.cgi?id=42266 ?
Yes. I dumped the RSP/ESP value using below code
#include <stdio.h>
#if _WIN64
unsigned long long rbp, rsp;
#define DUMP_REGS(STR, ...) \
asm("mov %%rbp, %0\nmov %%rsp, %1" : "=m"(rbp), "=m"(rsp)); \
printf(STR "\tRSP = %llx\tRBP = %llx\n", __VA_ARGS__, rsp, rbp);
#else
unsigned long ebp, esp;
#define DUMP_REGS(STR, ...) \
asm("mov %%ebp, %0\nmov %%esp, %1" : "=m"(ebp), "=m"(esp)); \
printf(STR "\tESP = %llx\tEBP = %llx\n", __VA_ARGS__, esp, ebp);
#endif
void foo()
{
DUMP_REGS("**FOO**")
try {
throw 1;
}
catch (int x) {
DUMP_REGS("Catch %d", x)
try {
try {
throw 2;
}
catch (int x) {
DUMP_REGS("Catch %d", x)
throw 3;
}
}
catch (int x) {
DUMP_REGS("Catch %d", x)
}
DUMP_REGS("Catch %d", x)
}
DUMP_REGS("FOO ret")
};
int main()
{
foo();
}
The output on 64 bits is something like this
**FOO** RSP = bc583bf880 RBP = bc583bf900
Catch 1 RSP = bc583bd640 RBP = bc583bf900
Catch 2 RSP = bc583bb400 RBP = bc583bf900
Catch 3 RSP = bc583b91c0 RBP = bc583bf900
Catch 1 RSP = bc583bb400 RBP = bc583bf900
FOO ret RSP = bc583bd640 RBP = bc583bf900
Which made me guess it caused by the runtime that not set the proper stack value. Then I compared each structure LLVM generated with MSVC and found the order of try map table is the key.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79760/new/
https://reviews.llvm.org/D79760
More information about the llvm-commits
mailing list