dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Make -betterC not disable EH, let -nothrow handle that

Open ryuukk opened this issue 1 year ago • 1 comments

See #16174 for context

-nothrow was added recently, wich is what the user should use to disable EH, otherwise APIs like backtrace can't be used to generate stack traces, wich is useful for debugging

I added a change log entry, but my english might be poor, so please don't hesitate to rephrase it

ryuukk avatar Feb 11 '24 11:02 ryuukk

Thanks for your pull request and interest in making D better, @ryuukk! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#16177"

dlang-bot avatar Feb 11 '24 11:02 dlang-bot

Can someone review this please?

ryuukk avatar Aug 06 '24 07:08 ryuukk

To help understand what this PR does:

For cases where one uses -betterC or uses a custom runtime, it makes it possible to still use debugging APIs like backtrace

Example code:

extern(C) void main()
{
    rt_register_crash_handler();
    crash_me();
}


void crash_me()
{
    int* a;
    *a = 42;
}

(full code + rt_register_crash_handler impl: https://gist.github.com/ryuukk/)e2d5260b4c4acec1b972ad9ce9228753)

The code should crash and print:

-------------------------------------------------------------------+
Received signal 'SIGSEGV' (11)
-------------------------------------------------------------------+
executable: /tmp/dmd_runXn753y
backtrace: 7
    ??:? _start+0x25
    ??:? __libc_start_main+0x8a
    ??:? +0x25cd0
    /run/media/ryuukk/E0C0C01FC0BFFA3C/dev/kdom/./_.d:4 main+0xe
    /run/media/ryuukk/E0C0C01FC0BFFA3C/dev/kdom/./_.d:11 void _.crash_me()+0xe

But if i compile with -betterC or with a custom runtime, i get:

-------------------------------------------------------------------+
Received signal 'SIGSEGV' (11)
-------------------------------------------------------------------+
executable: /tmp/dmd_run1UPD7W
backtrace: 1

Not helpful at all..

This PR solves that

ping @WalterBright

ryuukk avatar Aug 06 '24 07:08 ryuukk