1
1

Adding a new function to return the stack trace (not including the call to the function itself)

as a string (which must be freed by the caller).

This commit was SVN r23160.
Этот коммит содержится в:
Abhishek Kulkarni 2010-05-17 22:57:42 +00:00
родитель 5e05546194
Коммит b0e963299a
2 изменённых файлов: 44 добавлений и 0 удалений

Просмотреть файл

@ -39,6 +39,7 @@
#include "opal/constants.h"
#include "opal/util/output.h"
#include "opal/util/show_help.h"
#include "opal/util/argv.h"
#ifndef _NSIG
#define _NSIG 32
@ -401,6 +402,43 @@ void opal_stackframe_output(int stream)
}
}
char *opal_stackframe_output_string(void)
{
int traces_size, i;
size_t len;
char *output, **traces;
len = 0;
if (OPAL_SUCCESS != opal_backtrace_buffer(&traces, &traces_size)) {
return NULL;
}
/* Calculate the space needed for the string */
for (i = 3; i < traces_size; i++) {
if (NULL == traces[i]) {
break;
}
len += strlen(traces[i]) + 1;
}
output = (char *) malloc(len + 1);
if (NULL == output) {
return NULL;
}
*output = '\0';
for (i = 3; i < traces_size; i++) {
if (NULL == traces[i]) {
break;
}
strcat(output, traces[i]);
strcat(output, "\n");
}
free(traces);
return output;
}
#endif /* OPAL_WANT_PRETTY_PRINT_STACKTRACE && ! defined(__WINDOWS__) */
/**

Просмотреть файл

@ -30,6 +30,12 @@
*/
OPAL_DECLSPEC void opal_stackframe_output(int stream);
/**
* Return the current stack trace (not including the call to this
* function) as a string (which must be freed by the caller).
*/
OPAL_DECLSPEC char *opal_stackframe_output_string(void);
/**
* Here we register the opal_show_stackframe function for signals
* passed to OpenMPI by the mpi_signal-parameter passed to mpirun