为什么在 Windows 上将 -ffreestanding 指定为 clang++ 会阻止 Visual Studio 在调试时显示调用堆栈?

问题描述

在Windows上编译C++时,对于Windows,使用LLVM 12的clang++;为什么指定 -ffreestanding 会阻止输出某些调试信息,从而导致调试器(例如 Visual Studio 2019)无法显示调用堆栈?

给定以下简单的示例程序:

// call a few functions deep so there's something to look at in the debugger
int f1()
{
  return 1;
}

int f2()
{
  return f1() + 2;
}

int f3()
{
  return f2() + 3;
}

int main()
{
  return f3();
}

// include the CRT entry point,since we aren't linking with a CRT
int mainCRTStartup()
{
  return main();
}

使用和不使用 -ffreestanding 进行编译:

clang++ -g -c main.cpp -o main.hosted.o
lld-link -debug main.hosted.o -out:hosted.exe

clang++ -ffreestanding -g -c main.cpp -o main.freestanding.o
lld-link -debug main.freestanding.o -out:freestanding.exe

生成一个可执行文件 -hosted.exe- 在调试时显示调用堆栈,另一个 -freestanding.exe- 不显示

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)