Skip to content

Commit 0d0f311

Browse files
committed
Always provide /PDB option to linker if generating debug info.
radlink by default places the .PDB file in the working directory, even if /OUT says to place it elsewhere, unlike link.exe, which places it next to the executable by default. So, if compiling using -debug, we generate a PDB path even if -pdb-name wasn't used to override it.
1 parent 7853a1d commit 0d0f311

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/build_settings.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,10 +2066,6 @@ gb_internal bool init_build_paths(String init_filename) {
20662066
}
20672067
}
20682068

2069-
if (bc->pdb_filepath.len > 0) {
2070-
bc->build_paths[BuildPath_PDB] = path_from_string(ha, bc->pdb_filepath);
2071-
}
2072-
20732069
if ((bc->command_kind & Command__does_build) && (!bc->ignore_microsoft_magic)) {
20742070
// NOTE(ic): It would be nice to extend this so that we could specify the Visual Studio version that we want instead of defaulting to the latest.
20752071
Find_Result find_result = find_visual_studio_and_windows_sdk();
@@ -2268,6 +2264,18 @@ gb_internal bool init_build_paths(String init_filename) {
22682264
bc->build_paths[BuildPath_Output] = output_path;
22692265
}
22702266

2267+
if (build_context.metrics.os == TargetOs_windows && build_context.ODIN_DEBUG) {
2268+
if (bc->pdb_filepath.len > 0) {
2269+
bc->build_paths[BuildPath_PDB] = path_from_string(ha, bc->pdb_filepath);
2270+
} else {
2271+
Path pdb_path;
2272+
pdb_path.basename = copy_string(ha, bc->build_paths[BuildPath_Output].basename);
2273+
pdb_path.name = copy_string(ha, bc->build_paths[BuildPath_Output].name);
2274+
pdb_path.ext = copy_string(ha, STR_LIT("pdb"));
2275+
bc->build_paths[BuildPath_PDB] = pdb_path;
2276+
}
2277+
}
2278+
22712279
// Do we have an extension? We might not if the output filename was supplied.
22722280
if (bc->build_paths[BuildPath_Output].ext.len == 0) {
22732281
if (build_context.metrics.os == TargetOs_windows || is_arch_wasm() || build_context.build_mode != BuildMode_Executable) {

src/linker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ try_cross_linking:;
281281
link_settings = gb_string_append_fmt(link_settings, " /ENTRY:mainCRTStartup");
282282
}
283283

284-
if (build_context.pdb_filepath != "") {
284+
if (build_context.build_paths[BuildPath_PDB].name != "") {
285285
String pdb_path = path_to_string(heap_allocator(), build_context.build_paths[BuildPath_PDB]);
286286
link_settings = gb_string_append_fmt(link_settings, " /PDB:\"%.*s\"", LIT(pdb_path));
287287
}

0 commit comments

Comments
 (0)