Skip to content

Commit

Permalink
Make Windows PDB lookup relative to running executable (#11493)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Nov 26, 2021
1 parent c88be0c commit 07b2065
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/compiler/crystal/compiler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,12 @@ module Crystal
object_arg = Process.quote_windows(object_names)
output_arg = Process.quote_windows("/Fe#{output_filename}")

args = %(/nologo #{object_arg} #{output_arg} /link#{" /DEBUG:FULL" unless debug.none?} #{lib_flags} #{@link_flags}).gsub("\n", " ")
link_args = [] of String
link_args << "/DEBUG:FULL /PDBALTPATH:%_PDB%" unless debug.none?
link_args << lib_flags
@link_flags.try { |flags| link_args << flags }

args = %(/nologo #{object_arg} #{output_arg} /link #{link_args.join(' ')}).gsub("\n", " ")
cmd = "#{CL} #{args}"

if cmd.to_utf16.size > 32000
Expand Down
4 changes: 3 additions & 1 deletion src/exception/call_stack/stackwalk.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ struct Exception::CallStack
# TODO: figure out if and when to call SymCleanup (it cannot be done in
# `at_exit` because unhandled exceptions in `main_user_code` are printed
# after those handlers)
if LibC.SymInitializeW(LibC.GetCurrentProcess, nil, 1) == 0
executable_path = Process.executable_path
executable_path_ptr = executable_path ? File.dirname(executable_path).to_utf16.to_unsafe : Pointer(LibC::WCHAR).null
if LibC.SymInitializeW(LibC.GetCurrentProcess, executable_path_ptr, 1) == 0
raise RuntimeError.from_winerror("SymInitializeW")
end
LibC.SymSetOptions(LibC.SymGetOptions | LibC::SYMOPT_UNDNAME | LibC::SYMOPT_LOAD_LINES | LibC::SYMOPT_FAIL_CRITICAL_ERRORS | LibC::SYMOPT_NO_PROMPTS)
Expand Down

0 comments on commit 07b2065

Please sign in to comment.