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

Assert Failure/Out of bounds error inside DLL on Windows doesn't throw stack traces and shows no message #4426

Closed
MrcSnm opened this issue Jun 20, 2023 · 9 comments

Comments

@MrcSnm
Copy link

MrcSnm commented Jun 20, 2023

Tested with 1.33.0-beta1

Since I have been developing mostly inside a DLL, it gets very frustrating since all it does is halting.
Those errors can only be checked when inside a debugger. Would be nice to get the default behavior which is throwing a stack trace together with exiting the program.

@MrcSnm
Copy link
Author

MrcSnm commented Jun 20, 2023

Also, it shows no message assertion message. Basically all of those are produces the errors but doesn't does anything besides halting:

Visual Studio debugger shows "Unhandled exception at 0x00007FFEB104CD29 in hipreme_engine.exe: Microsoft C++ exception: core.exception.AssertError "

assert(false);
assert(false, "Some error occurred");
int[] arr;
arr[10] = 500;
arr[0..10] = 50;

@MrcSnm
Copy link
Author

MrcSnm commented Jun 20, 2023

Oh yea, I'm using mixin SimpleDLLMain for the DLL entry point.

@MrcSnm
Copy link
Author

MrcSnm commented Jun 20, 2023

Update 1: The error is catchable. But toString can't be called on them too

@MrcSnm MrcSnm changed the title Assert Failure/Out of bounds error inside DLL on Windows doesn't throw stack traces Assert Failure/Out of bounds error inside DLL on Windows doesn't throw stack traces and shows no message Jun 20, 2023
@kinke
Copy link
Member

kinke commented Jul 4, 2023

Oh yea, I'm using mixin SimpleDLLMain for the DLL entry point.

Shouldn't be required when linking both DLL and the .exe against shared druntime/Phobos via -link-defaultlib-shared. I guess that's missing for your .exe.

@kinke
Copy link
Member

kinke commented Jul 4, 2023

Yep, -link-defaultlib-shared makes this work:

dlldummy.d:

export void myDllDummy(int[] a) {
    a[5] = 123;
}

app.d:

import dlldummy;

void main() {
    int[5] a;
    myDllDummy(a);
}
> ldc2 -shared dlldummy.d
> ldc2 app.d dlldummy.lib -link-defaultlib-shared
> app.exe

[email protected](2): index [5] is out of bounds for array of length 5
----------------
0x00007FF8B2562F02 in onArrayIndexError
0x00007FF8B2563525 in d_arraybounds_index
0x00007FF8CE69105D in void dlldummy.myDllDummy(int[])
0x00007FF7531D1026
0x00007FF8B2590184 in void rt.dmain2._d_run_main2(char[][], ulong, extern (C) int function(char[][])*).runAll()
0x00007FF8B258FCB0 in d_run_main2
0x00007FF8B258FFE4 in d_wrun_main
0x00007FF7531D1054
0x00007FF7531D1930
0x00007FF8E44C7034 in BaseThreadInitThunk
0x00007FF8E4A3CEC1 in RtlUserThreadStart

@MrcSnm
Copy link
Author

MrcSnm commented Jul 4, 2023

Humm I was able to also reproduce this functionality by using Runtime.loadLibrary.
Though when I test with my project (and dub), I get a lot of linker errors.
I remember Adam saying that the problem was the usage of a DFLAG which changes any kind of global state (such as boundscheck or even this one).

So, you said "it should not be required". Then the only way to actually share the druntime is with -link-defaultlib-shared?

@kinke
Copy link
Member

kinke commented Jul 4, 2023

For a dub .exe with static-lib dependencies, see dlang/dub#2660 - you'll currently need to set DFLAGS=-link-defaultlib-shared for the dub invocation building the .exe (edit: and possibly specify --build=debug explicitly for the default debug build mode flags).

Then the only way to actually share the druntime is with -link-defaultlib-shared?

Yes, for Posix too.

@MrcSnm
Copy link
Author

MrcSnm commented Aug 7, 2023

Updated the wiki here: https://wiki.dlang.org/Win32_DLLs_in_D#Shared_D_Runtime.28LDC.29
Thanks for the help

@MrcSnm MrcSnm closed this as completed Aug 7, 2023
@JohanEngelen
Copy link
Member

Updated the wiki here: https://wiki.dlang.org/Win32_DLLs_in_D#Shared_D_Runtime.28LDC.29 Thanks for the help

thank you for updating the wiki!

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

3 participants