0

I have a C application that is executing in an HP-UX environment and I need to get the stacktrace.

I am attempting to use U_STACK_TRACE, but output to stderr is going somewhere else and I need it printed to a string.

How can I do this?

I.E. How can I take the output from U_STACK_TRACE and put it in a string instead of it being written to stderr.

Malfist
  • 31,179
  • 61
  • 182
  • 269

1 Answers1

1

U_STACK_TRACE() prints a formatted stack trace to standard error. _UNW_STACK_TRACE() produces a formatted stack trace on the output stream indicated by parameter out_file. The stream must be a writable stream for output to be produced.

So, open a file using fopen() and call _UNW_STACK_TRACE() instead of U_STACK_TRACE().

AlastairG
  • 4,119
  • 5
  • 26
  • 41
  • Incidentally, I got the first paragraph from an online MAN page found using Google. You should try that sometime, or in other words, RTFM ;) – AlastairG Sep 22 '11 at 14:39
  • Yes, I've rtfm, but I wanted to capture it as a string, not as a file or stream. Is this possible? – Malfist Sep 22 '11 at 14:44
  • Obviously not, but you could output it to a temp file and then read the file into a buffer. You may be able to create a fifo or pipe and then wrap that with a FILE pointer and then read out from the fifo into your string buffer. – AlastairG Sep 22 '11 at 14:55