www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Get variables with call stack

reply ANtlord <antlord92 gmail.com> writes:
Hello! I need to make a some sort of error report system for an 
application. I want to catch base Exception class instance and 
report call stack and with the call stack I want to report all 
variables with their values. There are a couple of services that 
make report using call stack and provides variables' values. 
Sentry.io, New Relic etc.

I see how to get call stack, the book Adam Ruppe writes helps me. 
How to get all variables from every layer of call stack?
Sep 21 2018
parent reply Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
On Friday, 21 September 2018 at 19:08:36 UTC, ANtlord wrote:
 Hello! I need to make a some sort of error report system for an 
 application. I want to catch base Exception class instance and 
 report call stack and with the call stack I want to report all 
 variables with their values. There are a couple of services 
 that make report using call stack and provides variables' 
 values. Sentry.io, New Relic etc.

 I see how to get call stack, the book Adam Ruppe writes helps 
 me. How to get all variables from every layer of call stack?
The only way to do that would be using a debugger. The specifics of the solution would thus depend on the platform. On POSIX, it would probably mean getting gdb to print a detailed backtrace for your project. On Windows, you might be able to achieve this by spawning a thread which then uses dbgeng.dll to get a detailed stack trace.
Sep 21 2018
parent reply Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
On Saturday, 22 September 2018 at 05:43:53 UTC, Vladimir 
Panteleev wrote:
 The only way to do that would be using a debugger.

 The specifics of the solution would thus depend on the 
 platform. On POSIX, it would probably mean getting gdb to print 
 a detailed backtrace for your project. On Windows, you might be 
 able to achieve this by spawning a thread which then uses 
 dbgeng.dll to get a detailed stack trace.
One thing to note: only variables in stack frames since the most top-level exception block will be visible (so, you'll also need to disable D runtime's standard exception handler). The reason for this is that exceptions do not capture the entire stack, but extract only a stack trace during instantiation, so to get the entire stack, you'd need to breakpoint _d_throw or such, but at that point you don't know if you're within an exception frame ready to catch the thrown exception. In short: there is no easy way, in the general sense.
Sep 21 2018
parent Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
On Saturday, 22 September 2018 at 05:49:05 UTC, Vladimir 
Panteleev wrote:
 In short: there is no easy way, in the general sense.
If you can find something that achieves what you need in C++, there's a good chance that it would work to some extent (or could be adapted with reasonable effort) for D, too. D debug information has much in common with C++, however exceptions vary from platform to platform.
Sep 21 2018