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.
Этот коммит содержится в:
родитель
5e05546194
Коммит
b0e963299a
@ -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
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user