Reputation: 4328
I want to write a Dtrace so that i can analyse if overflow_error
is happening in a process
i am executing . I just know that this is an error thrown as std::overflow_error
. I don't have much idea about how to write a D-Trace . I need some beginner guide and if someone can let me know how to write it . The process name i am running is say superbug_returns
. How can i write a D-Trace for it analyzing if above scenario is happening or not? I am working on solaris
Upvotes: 0
Views: 394
Reputation: 18217
I second the suggestion to try the debugger with this - there's usually a command to break-on-C++-exception. It's simpler to go that way.
If you insist on DTrace:
A few years ago, Sun published a whitepaper how to use DTrace with C++ - read that.
It's not trivial to apply the techniques described there to the "trace exceptions" usecase, unfortunately, because exception throwing/handling is in the C++ runtime and done through internal (nonexposed) function calls. In gcc-compiled code, throw ...
becomes __cxa_throw(...)
whereas in SunStudio-compiled code (which uses a different name mangling scheme) a function (unmangled / mangled):
void __Crun::ex_throw(void*,const __Crun::static_type_info*,void(*)(void*))
__1cG__CrunIex_throw6Fpvpkn0AQstatic_type_info_pF1_v_v_
is called. Note that this depends on your compiler version; SunStudio changed their mangling scheme / C++ runtime at some point in the past. In both cases though, std::...
would be passed as argument, so it you'd want to DTrace for a specific exception class only you'd need secondary filtering (a D probe predicate that tests whether the exception thrown is really the one you're interested in). You'd need to find out what args to the above function[s] correspond to std::overflow
being thrown and filter for those.
Without your actual object file, I can't give more advice than that. For a start, try:
gcc:
dtrace -n '
pid<your-process-pid>::__cxa_throw:entry
{
@exloc[ustack()] = count();
}'
SunStudio:
dtrace -n '
pid<your-process-pid>::__1cG__CrunIex_throw6Fpvpkn0AQstatic_type_info_pF1_v_v_:entry
{
@exloc[ustack()] = count();
}'
to find places in your code where exceptions are being thrown (Ctrl+C to terminate the DTrace gives you the statistics). Then iterate from there (try to dump the args, see if you can identify std::overflow
, filter for that by adding a /arg0 == .../
or similar to the probe).
Upvotes: 1
Reputation: 24546
It would be probably much easier to run the program in the debugger (dbx), and have it stop on thrown exceptions.
Upvotes: 1