Page 1 of 1

Getting C++Builder stack trace from call site

Posted: Wed Jun 07, 2017 12:00 pm
by jussi
I am trying to evaluate madExcept for our BCB 10.2 Tokyo project. We use the 32bit clang toolchain. Everything looks very good apart from not being able to show stack trace which would begin at the original throw site.

So for example:

Code: Select all

void test()
{
    throw new std::exception("test");
}

void __fastcall TForm7::Button2Click(TObject *Sender)
{
    try
    {
        test();
    }
    catch(...)
    {
        HandleException();
    }
}
Will show no exception information (not even EEFFACE, just Unknown) and the stack trace begins from the HandleException line. I would like to see the stack trace start from the throw line.

Code: Select all

main thread ($513fc):
00000000 +000 ???
76527908 +026 USER32.dll                               GetMessageW
004449a3 +2f7 Project17.exe  Madexcept                 HandleException
00404b47 +0df Project17.exe  Unit7.cpp         62   +8 TForm7.Button2Click
50ab5287 +073 vcl250.bpl     Vcl.Controls    7442   +9 TControl.Click
50adaf8a +01e vcl250.bpl     Vcl.StdCtrls    5441   +3 TCustomButton.Click
50adba98 +010 vcl250.bpl     Vcl.StdCtrls    5902   +1 TCustomButton.CNCommand
If the try/catch is commented out and madExcept handles the exception in Delphi side, it works as expected:

Code: Select all

void __fastcall TForm7::Button2Click(TObject *Sender)
{
    //try
    //{
        test();
    //}
    //catch(...)
    //{
    //    HandleException();
    //}
}

Code: Select all

main thread ($50e18):
75efc41f +058 KERNELBASE.dll                          RaiseException
3222d751 +07d CC32C250MT.DLL                          ___cxa_throw
004045a7 +0d7 Project17.exe  Unit7.cpp        28   +2 test
00404a74 +00c Project17.exe  Unit7.cpp        58   +4 TForm7.Button2Click
50ab5287 +073 vcl250.bpl     Vcl.Controls   7442   +9 TControl.Click
50adaf8a +01e vcl250.bpl     Vcl.StdCtrls   5441   +3 TCustomButton.Click
50adba98 +010 vcl250.bpl     Vcl.StdCtrls   5902   +1 TCustomButton.CNCommand
Should this work in c++ code?

Thanks!

Jussi

Re: Getting C++Builder stack trace from call site

Posted: Wed Jun 14, 2017 9:20 am
by madshi
That actually is supposed to work, I'm not sure why it fails. Could it have to do with runtime packages being enabled or disabled, or dynamic RTL being enabled or disabled? These 2 options result in 4 different possible situations which madExcept needs to handle. Does switching those options make any difference?

Does this problem only occur in your main project, or also in a brand new almost empty test project?

Re: Getting C++Builder stack trace from call site

Posted: Wed Jun 14, 2017 1:37 pm
by jussi
I tried all the different options (runtime packages and dynamic RTL) with the same result. The project was created just for this. I now did a new fresh project just to check and the trace is now good!

I did have to modify some library paths for the first project before it found madexcept.obj or similar. Now I did not have to do that.

Re: Getting C++Builder stack trace from call site

Posted: Wed Jun 14, 2017 1:41 pm
by madshi
Strange! So it works now with the brand new project? I'm not sure why it didn't work before!

Anyway, does this mean the problem is "solved" for you?

Re: Getting C++Builder stack trace from call site

Posted: Fri Jun 16, 2017 9:45 am
by jussi
Yes. It is now solved. Thank you!

Re: Getting C++Builder stack trace from call site

Posted: Tue Sep 11, 2018 1:02 pm
by jussi
I finally got back to evaluating madExcept. It turns out the problem still exists. For the other project I had the default bcc32 compiler and with that I would get correct trace. Unfortunately that would not work for the real application.

Is this something you can reproduce or is it just my setup?

Re: Getting C++Builder stack trace from call site

Posted: Tue Sep 11, 2018 1:24 pm
by madshi
Does it still work with the test project for you? In that case it might make sense to try finding out in which way the test project differs from your real project. E.g. you could try to copy your real project's project options over to the test project step-by-step. Maybe that way you can find which option breaks the functionality for you?

(Last time I checked, it worked for me.)