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

Fix crash stack trace decoding on macOS #14335

Merged

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Feb 29, 2024

Adds a Exception::CallStack.decode_address call to account for ASLR on macOS systems, which caller / Exception::CallStack.unwind already uses. Example: (run with CRYSTAL_LOAD_DEBUG_INFO=1 or call caller beforehand, since Unix-like systems do not currently load debug info upon crashes)

def foo
  x = Pointer(UInt8).null
  y = x.value
end

foo

Before:

[0x10043b4f4] *Exception::CallStack::print_backtrace:Nil +104 in /Users/quinton/.cache/crystal/crystal-run-small.tmp
[0x1004270f0] ~procProc(Int32, Pointer(LibC::SiginfoT), Pointer(Void), Nil)@src/crystal/system/unix/signal.cr:135 +320 in /Users/quinton/.cache/crystal/crystal-run-small.tmp
[0x18cb49a24] _sigtramp +56 in /usr/lib/system/libsystem_platform.dylib
[0x1004274ac] *foo:UInt8 +20 in /Users/quinton/.cache/crystal/crystal-run-small.tmp
[0x10041a868] __crystal_main +984 in /Users/quinton/.cache/crystal/crystal-run-small.tmp
[0x1004cbae8] *Crystal::main_user_code<Int32, Pointer(Pointer(UInt8))>:Nil +12 in /Users/quinton/.cache/crystal/crystal-run-small.tmp
[0x1004cba50] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +60 in /Users/quinton/.cache/crystal/crystal-run-small.tmp
[0x1004238c4] main +12 in /Users/quinton/.cache/crystal/crystal-run-small.tmp

After:

[0x1021f74f0] print_backtrace at /Users/quinton/crystal/crystal/src/exception/call_stack/libunwind.cr:100:5
[0x1021e30ec] -> at /Users/quinton/crystal/crystal/src/crystal/system/unix/signal.cr:162:5
[0x18cb49a24] _sigtramp +56 in /usr/lib/system/libsystem_platform.dylib
[0x1021e34a8] foo at /Users/quinton/crystal/crystal/usr/small.cr:36:3
[0x1021d6864] __crystal_main at /Users/quinton/crystal/crystal/usr/small.cr:40:1
[0x102287ae8] main_user_code at /Users/quinton/crystal/crystal/src/crystal/main.cr:129:5
[0x102287a50] main at /Users/quinton/crystal/crystal/src/crystal/main.cr:115:7
[0x1021df8c0] main at /Users/quinton/crystal/crystal/src/crystal/main.cr:141:3

@straight-shoota straight-shoota added this to the 1.12.0 milestone Feb 29, 2024
@straight-shoota straight-shoota merged commit 3072e8f into crystal-lang:master Mar 1, 2024
57 checks passed
@HertzDevil HertzDevil deleted the bug/macos-crash-stack-trace branch March 8, 2024 13:53
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.

2 participants