Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support call stacks on Windows #11461

Merged

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Nov 16, 2021

Closes #10612. Some of the code is taken from there, some other from JochenKalmbach/StackWalker.

  • Uses the StackWalk64 API. Column numbers are omitted because DbgHelp doesn't seem to expose it, short of parsing the PDB ourselves (apparently it is also problematic for most Windows tools, including the Visual Studio debugger).
  • Always generates a PDB file unless --no-debug is specified. Also no longer emits DWARF debug information on Windows.
  • Renames the environment variable CRYSTAL_LOAD_DWARF to CRYSTAL_LOAD_DEBUG_INFO to be platform-independent.
> type test.cr
[1, 2, 3][5]

> crystal test.cr
Unhandled exception: Index out of bounds (IndexError)
  from src\indexable.cr:903 in '[]'
  from test.cr:1 in '__crystal_main'
  from src\crystal\main.cr:110 in 'main_user_code'
  from src\crystal\main.cr:96 in 'main'
  from src\crystal\main.cr:119 in 'main'
  from d:\a01\_work\20\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288 in '__scrt_common_main_seh'
  from C:\WINDOWS\System32\KERNEL32.DLL +94260 in 'BaseThreadInitThunk'
  from C:\WINDOWS\SYSTEM32\ntdll.dll +337489 in 'RtlUserThreadStart'

Note that this doesn't catch access violation (0xC0000005) and stack overflow (0xC00000FD) yet.

Related: #5430

src/exception/call_stack/stackwalk.cr Outdated Show resolved Hide resolved
src/exception/call_stack/stackwalk.cr Outdated Show resolved Hide resolved
src/compiler/crystal/compiler.cr Outdated Show resolved Hide resolved
src/exception/call_stack/stackwalk.cr Outdated Show resolved Hide resolved
src/exception/call_stack/stackwalk.cr Outdated Show resolved Hide resolved
src/exception/call_stack/stackwalk.cr Outdated Show resolved Hide resolved
src/lib_c/x86_64-windows-msvc/c/dbghelp.cr Show resolved Hide resolved
src/exception/call_stack/stackwalk.cr Outdated Show resolved Hide resolved
@straight-shoota straight-shoota added this to the 1.3.0 milestone Nov 22, 2021
@straight-shoota straight-shoota merged commit 90218d9 into crystal-lang:master Nov 24, 2021
@HertzDevil HertzDevil deleted the feature/msvc-call-stack branch November 29, 2021 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stacktrace on win32
4 participants