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

How to get non-inlined stack traces during crashes #61

Open
tleyden opened this issue Apr 11, 2024 · 2 comments
Open

How to get non-inlined stack traces during crashes #61

tleyden opened this issue Apr 11, 2024 · 2 comments

Comments

@tleyden
Copy link

tleyden commented Apr 11, 2024

I recently had a bug in my own code that was causing a crash, but it was difficult to debug because the stack traces were misleading due to function inlining. For example I was getting a thread crash with:

Thread 17 Crashed:
0   MyApp 0x10135eec8 screen_capture(captureFrontmostWindow:skipCaptureAllBlackImg:frontmostAppPid:) + 916
1   MyApp 0x10135eb58 screen_capture(captureFrontmostWindow:skipCaptureAllBlackImg:frontmostAppPid:) + 36
2   MyApp 0x10135eb2c screen_capture_swift + 12

but I know for a fact that the actual crash was emanating from a different swift function, func getFrontmostAppWindowID(frontmostAppPid: Int) -> Int, which is invoked by the screen_capture(..) function.

I was able to improve the situation by adding the DEBUG=true env variable, which I noticed here:

swift-rs/src-rs/build.rs

Lines 222 to 224 in 50a909d

let debug = env::var("DEBUG").unwrap() == "true";
let configuration = if debug { "debug" } else { "release" };
let rust_target = RustTarget::from_env();

The new and improved stack trace showed the crash emanating from the expected function:

Thread 31 Crashed:
0   MyApp 0x100afc9a0 specialized getFrontmostAppWindowID(frontmostAppPid:) + 1860
1   MyApp 0x100afc9a0 specialized getFrontmostAppWindowID(frontmostAppPid:) + 1860
2   MyApp 0x100afc9c4 specialized screen_capture(captureFrontmostWindow:skipCaptureAllBlackImg:frontmostAppPid:) + 32
3   MyApp 0x100af6ebc screen_capture_swift + 12

NOTE that I also tried decorating the function in question with @inline(never), but it didn't seem to help. Maybe since it was defaulting to a release build it was ignoring those compiler hints.

I didn't see the DEBUG flag mentioned in the docs, but maybe I missed it. If it's not there, would you take a PR to update the README?

swift-rs has been working great for me, and thanks again @Brendonovich for creating this project!

@Brendonovich
Copy link
Owner

DEBUG is an env var set by cargo for build scripts, it should be true by default when compiling in debug mode. Were you compiling in debug or release mode?
I'm not familiar with @inline(never) and the like.

@tleyden
Copy link
Author

tleyden commented Apr 25, 2024

@Brendonovich I'm compiling via Tauri+yarn (which invokes cargo), and it was happening with both yarn tauri dev and yarn tauri release.

Maybe they don't set DEBUG?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants