The great thing about this list is that you can expect an answer to any reasonable technical question here. You are the best, guys.
Now the question ;-). Does anybody know how to generate a core file from within a process without terminating it on Linux or Solaris? I know that at any point I can call abort() and have the core, or send itself a signal that terminates a process with generating a core file. But it is not what I need, unfortunately.
I hold little hope for a positive answer as I am in Unix C/C++ development for around 15 years, however maybe I am missing something.
Here's the problem. In my C++ program I have an exception class, say, NoSuchElementException. It is being handled accordingly throughout the code, however there are some places where it sneaks through. I want to get an execution stack at the time when the exception is first created so that I can trace where it was thrown from (much like in Ruby where you can get #backtrace from an exception, Ruby rules !!!) .
So I thought if I could generate a core file from NoSuchElementException's constructor and let it go on, I would be able to analyze the last core file and pin-point the place immediately (now I have to put more trace output to find it).
Thanks a lot,
Gennady.
P.S. I also tried to use gdb and specify command to be executed at a given breakpoint (like { backtrace, continue }). It works fine, however, executing a program from within gdb is not always an option in a production environment :-(, you often need to do post-mortem analysis.
If a stack trace of relevant process threads, instead of a full core
dump would be good enough, Solaris has a very valuable little utility
called pstack - it dumps stack traces for all threads to stdout.
Maybe you can call it from your exception c'tor. Beware, pstack freezes
the process for several hundred msec.
Best reqards,
Alexey Verkhovsky
···
On Fri, 2004-07-23 at 21:37, Gennady wrote:
Now the question ;-). Does anybody know how to generate a core file from
within a process without terminating it on Linux or Solaris?
Gennady writes:
> Hi, guys
>
> The great thing about this list is that you can expect an answer to any
> reasonable technical question here. You are the best, guys.
>
> Now the question ;-). Does anybody know how to generate a core file from
> within a process without terminating it on Linux or Solaris? I know that
> at any point I can call abort() and have the core, or send itself a
> signal that terminates a process with generating a core file. But it is
> not what I need, unfortunately.
Here's an idea, could you fork and then abort() the new
process immediately?
~ > file core.14075
core.14075: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV),
SVR4-style, from 'bash'
you could call it with a system call. also, it seems like forking and then
calling abort would do?
regards.
-a
···
On Sat, 24 Jul 2004, Gennady wrote:
Hi, guys
The great thing about this list is that you can expect an answer to any
reasonable technical question here. You are the best, guys.
Now the question ;-). Does anybody know how to generate a core file from
within a process without terminating it on Linux or Solaris? I know that
at any point I can call abort() and have the core, or send itself a
signal that terminates a process with generating a core file. But it is
not what I need, unfortunately.
I hold little hope for a positive answer as I am in Unix C/C++
development for around 15 years, however maybe I am missing something.
Here's the problem. In my C++ program I have an exception class, say,
NoSuchElementException. It is being handled accordingly throughout the
code, however there are some places where it sneaks through. I want to
get an execution stack at the time when the exception is first created
so that I can trace where it was thrown from (much like in Ruby where
you can get #backtrace from an exception, Ruby rules !!!) .
So I thought if I could generate a core file from
NoSuchElementException's constructor and let it go on, I would be able
to analyze the last core file and pin-point the place immediately (now I
have to put more trace output to find it).
Thanks a lot,
Gennady.
P.S. I also tried to use gdb and specify command to be executed at a
given breakpoint (like { backtrace, continue }). It works fine, however,
executing a program from within gdb is not always an option in a
production environment :-(, you often need to do post-mortem analysis.
--
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it;
and a weed grows, even though we do not love it. --Dogen
You see, I was right about greatness of this list (as if somebody doubts it ;-)). Thanks a lot for all suggestions, I like the forking idea best. Simple and effective. However, for what I need it for, pstack (thanks, Alexey) seems most suitable. It is available on Linux as well, by the way.
Thank you, guys, once again. You saved my day
Gennady.
Ara.T.Howard wrote:
...
···
~ > echo $$
14075
~ > gcore $$
~ > file core.14075
core.14075: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV),
SVR4-style, from 'bash'
you could call it with a system call. also, it seems like forking and then
calling abort would do?
regards.
-a
--
> EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
> PHONE :: 303.497.6469
> A flower falls, even though we love it;
> and a weed grows, even though we do not love it. | --Dogen