VS2017 在使用 pdb 文件调试时阻止不存在的目标文件
我们正在将 Visual C++ 项目切换到 vc141 工具链(VS 2017).我们遇到了一个问题,即 Visual Studio 无法使用源 .obj
文件不再存在的 .pdb
文件(例如,因为它们已在构建服务器).
We are in the process of switching Visual C++ projects to the vc141 toolchain (VS 2017). We have encountered a problem where Visual Studio is unable to use a .pdb
file whose source .obj
files don't exist anymore (for example because they have been compiled on a build server).
我们来看一个非常简单的可执行项目:
Let's take a very simple executable project:
#include <iostream>
int main() {
std::cout << "Hello world
";
std::cin.ignore();
}
.vcxproj
文件都是默认的,除了<GenerateDebugInformation>true</GenerateDebugInformation>
生成pdb文件.
The .vcxproj
file is all default, except for <GenerateDebugInformation>true</GenerateDebugInformation>
to generate the pdb file.
复现步骤,一律使用VS2017:
Reproduction steps are, always using VS2017:
- 编译项??目
- 在
main
中放置断点 - 删除包含
.obj
文件的中间Debug/
目录 - 通过配置管理器禁用 build-on-run(因此不会重新创建它们)
- 开始调试会话
这适用于 vc100 (VS 2010) 工具链,并且断点有效,但它会立即触发 vc141 的以下错误:
This works fine with the vc100 (VS 2010) toolchain, and the breakpoint works, but it immediately triggers the following error with vc141:
错误:无法打开文件
<路径>调试main.obj.错误代码 = 0x80070003.
Error: Unable to open file
<path>Debugmain.obj. Error code = 0x80070003.
这个非常通用的错误代码确实对应于 FACILITY_WIN32/ERROR_PATH_NOT_FOUND
.main.obj
的路径可以在两个版本的 .pdb
文件中找到,因此我们不清楚为什么 VS 在找不到它时会突然崩溃.
This very generic error code corresponds indeed to FACILITY_WIN32/ERROR_PATH_NOT_FOUND
. The path to main.obj
can be found inside both versions of the .pdb
file, thus it is unclear to us why VS suddenly breaks down when it doesn't find it.
模块"视图显示 .pdb
文件似乎已正确加载.此外,断点的工具提示显示以下错误:
The "Modules" view shows that the .pdb
file seems to be loaded correctly. Additionally, the breakpoint's tooltip shows the following error:
当前不会命中断点.处理 MyUser_141.exe 时出现意外的符号读取器错误.
The breakpoint will not currently be hit. Unexpected symbol reader error while processing MyUser_141.exe.
鉴于我们无法在实际应用程序中编译二进制文件的机器上进行调试,有什么办法可以解决这个问题?
What could be a solution or a workaround for this problem, given that we cannot debug on the machine that compiles the binaries in our real-case application?
这是完整的 .vcxproj
文件:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<RootNamespace>MyUser_141</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
<ProjectGuid>{90982029-29B8-4C9B-AFB7-B8F555F15C1E}</ProjectGuid>
</PropertyGroup>
<Import Project="$(VCTargetsPath)Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
<小时>
进一步研究:
我们尝试了其他一些工具链版本.该错误在 v14.0(VS 2015)中不存在,但在 14.11(VS2017 15.3)中出现.
Further research:
We tried some other toolchain versions. The bug is not present in v14.0 (VS 2015), but is present as soon as 14.11 (VS2017 15.3).
使用
v141_xp
,据我们所知,它使用相同的工具链,但系统库较旧,工作.Using
v141_xp
, which as far as we can tell uses the same toolchain but older system libraries, works.推荐答案
要解决此问题,请在构建可执行文件和 DLL 的项目的属性页中进行以下更改:
To fix this, make the following change in the property pages of the project(s) that build your executable(s) and DLL(s):
p>
配置属性 -> 链接器 -> 调试 -> 生成调试信息 -> 生成为共享和发布而优化的调试信息
静态库,没有链接步骤,不需要这个..EXE 和 DLL 可以.
Static libraries, having no link step, don't need this. .EXEs and DLLs do.
相关文章