digitalmars.D.learn - Why sometimes stacktraces are printed and sometimes not?
- JN (6/6) Sep 29 2021 What makes the difference on whether a crash stacktrace gets
- Steven Schveighoffer (13/19) Sep 29 2021 segmentation faults are memory access errors. It means you are accessing...
- Steven Schveighoffer (5/6) Sep 29 2021 Sorry, it's `etc.linux.memoryerror`
- bauss (14/36) Sep 30 2021 You might also mention that even if you had a stacktrace where
- wjoe (11/24) Sep 30 2021 So on Linux, I don't know the behavior on other OSs, the kernel
What makes the difference on whether a crash stacktrace gets printed or not? Sometimes I get a nice clean stacktrace with line numbers, sometimes all I get is "segmentation fault error -1265436346" (pseudo example) and I need to run under debugger to get the crash location.
Sep 29 2021
On 9/29/21 6:57 AM, JN wrote:What makes the difference on whether a crash stacktrace gets printed or not? Sometimes I get a nice clean stacktrace with line numbers, sometimes all I get is "segmentation fault error -1265436346" (pseudo example) and I need to run under debugger to get the crash location.segmentation faults are memory access errors. It means you are accessing a memory address that is not valid for your application. If you are accessing the wrong memory, it means something is terribly wrong in your program. Note that on Windows in 32-bit mode, I believe you get a stack trace. On Linux, there is the undocumented `etc.linux.memoryhandler` which allows you to register an error-throwing signal handler. Signals are not really easy to deal with in terms of properly throwing an exception. This only works on Linux, so I don't know if it's possible to port to other OSes. I've also found sometimes that it doesn't work right, so I only enable it when I am debugging. -Steve
Sep 29 2021
On 9/29/21 8:15 AM, Steven Schveighoffer wrote:On Linux, there is the undocumented `etc.linux.memoryhandler`Sorry, it's `etc.linux.memoryerror` Here is the code: https://github.com/dlang/druntime/blob/master/src/etc/linux/memoryerror.d -Steve
Sep 29 2021
On Wednesday, 29 September 2021 at 12:15:30 UTC, Steven Schveighoffer wrote:On 9/29/21 6:57 AM, JN wrote:You might also mention that even if you had a stacktrace where the error happened, that's usually not where the error was caused. It's most likely a completely different place in the code. The only time where you somewhat can be sure where it happens is when you try to access ex. a reference type that hasn't been instantiated. violation, but you get a NullReferenceException. It's not a concept D has, so it defaults to segfault/access violation. Which means you're in really deep water when you encounter one because you have no idea what caused it and where it was caused.What makes the difference on whether a crash stacktrace gets printed or not? Sometimes I get a nice clean stacktrace with line numbers, sometimes all I get is "segmentation fault error -1265436346" (pseudo example) and I need to run under debugger to get the crash location.segmentation faults are memory access errors. It means you are accessing a memory address that is not valid for your application. If you are accessing the wrong memory, it means something is terribly wrong in your program. Note that on Windows in 32-bit mode, I believe you get a stack trace. On Linux, there is the undocumented `etc.linux.memoryhandler` which allows you to register an error-throwing signal handler. Signals are not really easy to deal with in terms of properly throwing an exception. This only works on Linux, so I don't know if it's possible to port to other OSes. I've also found sometimes that it doesn't work right, so I only enable it when I am debugging. -Steve
Sep 30 2021
On Wednesday, 29 September 2021 at 12:15:30 UTC, Steven Schveighoffer wrote:On 9/29/21 6:57 AM, JN wrote:So on Linux, I don't know the behavior on other OSs, the kernel sends SIGSEGV to your process which, if unhandled, simply terminates your program. It's an abnormal termination and thus the D runtime or whatever library that in a normal case takes care of printing the traces doesn't get a chance to do so anymore. You also change the signal in your handler to get a core dump, look here http://www.alexonlinux.com/how-to-handle-sigsegv-but-also-generate-core-dumpWhat makes the difference on whether a crash stacktrace gets printed or not? Sometimes I get a nice clean stacktrace with line numbers, sometimes all I get is "segmentation fault error -1265436346" (pseudo example) and I need to run under debugger to get the crash location.segmentation faults are memory access errors. It means you are accessing a memory address that is not valid for your application. If you are accessing the wrong memory, it means something is terribly wrong in your program. [...]
Sep 30 2021