digitalmars.D.learn - Better diagnostics for null classes dereferencing
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (5/5) Jul 10 2018 Is it possible to change run-time behaviour of null-class
- Steven Schveighoffer (10/16) Jul 10 2018 Yes, call this function on startup:
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (3/20) Jul 10 2018 Okay thanks. When would you not want that behavior to be default?
- Steven Schveighoffer (5/28) Jul 10 2018 It was controversial at the time, and considered a hack. It's also only
- Seb (3/28) Jul 10 2018 https://github.com/dlang/druntime/pull/2249
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (2/3) Jul 11 2018 Thanks!
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (4/5) Jul 10 2018 Needs to be:
- Adam D. Ruppe (4/7) Jul 10 2018 Run the program in a debugger, or run `ulimit -c unlimited` to
- kdevel (12/15) Jul 10 2018 Works for null ptr deref but how do I enforce core dumps in this
- Steven Schveighoffer (7/24) Jul 10 2018 Core dumps are triggered from the process accessing memory it doesn't
- kdevel (11/15) Jul 10 2018 On Tuesday, 10 July 2018 at 21:09:23 UTC, Steven Schveighoffer
- Steven Schveighoffer (4/22) Jul 10 2018 More difficult. You'd have to have a special runtime, and change the
- Adam D. Ruppe (5/7) Jul 10 2018 Turn off rtTrapExceptions....
- kdevel (13/16) Jul 10 2018 extern (C) __gshared bool rt_trapExceptions;
- Neia Neutuladh (15/20) Jul 10 2018 This will catch exceptions raised in main and in static
- Seb (5/10) Jul 10 2018 On a Systemd system coredumps are typically configured to be
Is it possible to change run-time behaviour of null-class dereferencing, on Linux, so that it gives some other diagnostics than: Program exited with code -11 Does DMD and LDC provide different alternatives here?
Jul 10 2018
On 7/10/18 3:01 PM, Per Nordlöw wrote:Is it possible to change run-time behaviour of null-class dereferencing, on Linux, so that it gives some other diagnostics than: Program exited with code -11 Does DMD and LDC provide different alternatives here?Yes, call this function on startup: import etc.linux : registerMemoryErrorHandler; void main() { registerMemoryErrorHandler(); ... } No, it's not documented anywhere. Probably should be... -Steve
Jul 10 2018
On Tuesday, 10 July 2018 at 19:27:07 UTC, Steven Schveighoffer wrote:On 7/10/18 3:01 PM, Per Nordlöw wrote:Okay thanks. When would you not want that behavior to be default?Is it possible to change run-time behaviour of null-class dereferencing, on Linux, so that it gives some other diagnostics than: Program exited with code -11 Does DMD and LDC provide different alternatives here?Yes, call this function on startup: import etc.linux : registerMemoryErrorHandler; void main() { registerMemoryErrorHandler(); ... } No, it's not documented anywhere. Probably should be... -Steve
Jul 10 2018
On 7/10/18 4:02 PM, Per Nordlöw wrote:On Tuesday, 10 July 2018 at 19:27:07 UTC, Steven Schveighoffer wrote:It was controversial at the time, and considered a hack. It's also only supported on Linux. So I don't know the reason why it's not always done for Linux, I really think it should be. -SteveOn 7/10/18 3:01 PM, Per Nordlöw wrote:Okay thanks. When would you not want that behavior to be default?Is it possible to change run-time behaviour of null-class dereferencing, on Linux, so that it gives some other diagnostics than: Program exited with code -11 Does DMD and LDC provide different alternatives here?Yes, call this function on startup: import etc.linux : registerMemoryErrorHandler; void main() { registerMemoryErrorHandler(); ... } No, it's not documented anywhere. Probably should be...
Jul 10 2018
On Tuesday, 10 July 2018 at 20:57:02 UTC, Steven Schveighoffer wrote:On 7/10/18 4:02 PM, Per Nordlöw wrote:https://github.com/dlang/druntime/pull/2249On Tuesday, 10 July 2018 at 19:27:07 UTC, Steven Schveighoffer wrote:It was controversial at the time, and considered a hack. It's also only supported on Linux. So I don't know the reason why it's not always done for Linux, I really think it should be. -SteveOn 7/10/18 3:01 PM, Per Nordlöw wrote:Okay thanks. When would you not want that behavior to be default?[...]Yes, call this function on startup: import etc.linux : registerMemoryErrorHandler; void main() { registerMemoryErrorHandler(); ... } No, it's not documented anywhere. Probably should be...
Jul 10 2018
On Wednesday, 11 July 2018 at 04:17:49 UTC, Seb wrote:https://github.com/dlang/druntime/pull/2249Thanks!
Jul 11 2018
On Tuesday, 10 July 2018 at 19:27:07 UTC, Steven Schveighoffer wrote:import etc.linux : registerMemoryErrorHandler;Needs to be: import etc.linux.memoryerror : registerMemoryErrorHandler;
Jul 10 2018
On Tuesday, 10 July 2018 at 19:01:22 UTC, Per Nordlöw wrote:Is it possible to change run-time behaviour of null-class dereferencing, on Linux, so that it gives some other diagnostics than:Run the program in a debugger, or run `ulimit -c unlimited` to enable core dumps so you can run a debugger on the dead program after the fact.
Jul 10 2018
On Tuesday, 10 July 2018 at 20:10:54 UTC, Adam D. Ruppe wrote:On Tuesday, 10 July 2018 at 19:01:22 UTC, Per Nordlöw wrote:[...]Run the program in a debugger, or run `ulimit -c unlimited` to enable core dumps [...]Works for null ptr deref but how do I enforce core dumps in this code: dumpme2.d --- void main () { int [1] a; auto s = a[2 .. $]; } ---
Jul 10 2018
On 7/10/18 5:01 PM, kdevel wrote:On Tuesday, 10 July 2018 at 20:10:54 UTC, Adam D. Ruppe wrote:Core dumps are triggered from the process accessing memory it doesn't own. As far as the OS is concerned, a[2 .. $] is within the process memory limit. Of course, that's an out of bounds access, so the compiler or the bounds check *should* complain. -SteveOn Tuesday, 10 July 2018 at 19:01:22 UTC, Per Nordlöw wrote:[...]Run the program in a debugger, or run `ulimit -c unlimited` to enable core dumps [...]Works for null ptr deref but how do I enforce core dumps in this code: dumpme2.d --- void main () { int [1] a; auto s = a[2 .. $]; } ---
Jul 10 2018
On Tuesday, 10 July 2018 at 21:09:23 UTC, Steven Schveighoffer wrote: [...]As far as the OS is concerned, a[2 .. $] is within the process memory limit. Of course, that's an out of bounds access, so the compiler or the bounds check *should* complain.It complains at runtime > ./dumpme2 core.exception.RangeError dumpme2.d(4): Range violation ---------------- ??:? _d_arrayboundsp [0x42bb1e] dumpme2.d:4 _Dmain [0x42ba42] but how do I force the runtime to generate a coredump for real post-mortem analysis?
Jul 10 2018
On 7/10/18 5:18 PM, kdevel wrote:On Tuesday, 10 July 2018 at 21:09:23 UTC, Steven Schveighoffer wrote: [...]More difficult. You'd have to have a special runtime, and change the constructor for RangeError to access a null pointer. -SteveAs far as the OS is concerned, a[2 .. $] is within the process memory limit. Of course, that's an out of bounds access, so the compiler or the bounds check *should* complain.It complains at runtime > ./dumpme2 core.exception.RangeError dumpme2.d(4): Range violation ---------------- ??:? _d_arrayboundsp [0x42bb1e] dumpme2.d:4 _Dmain [0x42ba42] but how do I force the runtime to generate a coredump for real post-mortem analysis?
Jul 10 2018
On Tuesday, 10 July 2018 at 21:18:01 UTC, kdevel wrote:but how do I force the runtime to generate a coredump for real post-mortem analysis?Turn off rtTrapExceptions.... though the command line switch PR is STILL NOT MERGED https://github.com/dlang/druntime/pull/2035 come on, people.
Jul 10 2018
On Tuesday, 10 July 2018 at 22:31:54 UTC, Adam D. Ruppe wrote:Turn off rtTrapExceptions.... though the command line switch PR is STILL NOT MERGED https://github.com/dlang/druntime/pull/2035extern (C) __gshared bool rt_trapExceptions; static this () { rt_trapExceptions = false; } plus -L-zmuldefs is required for linking. It works. But why is that -zmuldefs linker option required? The "double extern" version extern extern (C) __gshared bool rt_trapExceptions; compiles and links but does not behave seem to set the same variable.
Jul 10 2018
On Tuesday, 10 July 2018 at 22:53:25 UTC, kdevel wrote:extern (C) __gshared bool rt_trapExceptions; static this () { rt_trapExceptions = false; }This will catch exceptions raised in main and in static constructors that run after this one. However, if you put that code in the module that includes main(), it's probably going to be the last static constructor run. That means it doesn't impact other static constructors. The only fix for that is putting this code in its own module that you add as the first import in every module. And if you depend on any library with a static constructor anywhere inside, you have to modify that library. But exceptions can be thrown before any static constructor is run. The function that calls static constructors might detect a cycle straight off, for instance. That's why the This Week In D post injected it into the C main function.
Jul 10 2018
On Tuesday, 10 July 2018 at 19:01:22 UTC, Per Nordlöw wrote:Is it possible to change run-time behaviour of null-class dereferencing, on Linux, so that it gives some other diagnostics than: Program exited with code -11 Does DMD and LDC provide different alternatives here?On a Systemd system coredumps are typically configured to be automatically generated and saved. For example you can start up gdb at the most recent crash: coredumpctl gdb -1
Jul 10 2018