Emitting the stack as a single string avoids
its accidental split and is better when receiving
monitoring events.
Change-Id: I74c16f36f026b4af4a42064f694ac1f4a342cc1f
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
#define _GNU_SOURCE
#include <stdlib.h>
#define _GNU_SOURCE
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <setjmp.h>
#include <signal.h>
#include <string.h>
#include <setjmp.h>
/*
* Dumps the current stack
*/
/*
* Dumps the current stack
*/
-static void dumpstack(int crop)
+static void dumpstack(int crop, int signum)
- int idx, count;
- void *addresses[1000];
+ int idx, count, rc;
+ void *addresses[100];
+ char buffer[8000];
+ size_t pos, length;
count = backtrace(addresses, sizeof addresses / sizeof *addresses);
count = backtrace(addresses, sizeof addresses / sizeof *addresses);
- locations = backtrace_symbols(addresses, count);
+ if (count <= crop)
+ crop = 0;
+ count -= crop;
+ locations = backtrace_symbols(&addresses[crop], count);
if (locations == NULL)
ERROR("can't get the backtrace (returned %d addresses)", count);
else {
if (locations == NULL)
ERROR("can't get the backtrace (returned %d addresses)", count);
else {
- for (idx = crop; idx < count; idx++)
- ERROR("[BACKTRACE %d/%d] %s", idx - crop + 1, count - crop, locations[idx]);
+ length = sizeof buffer - 1;
+ pos = 0;
+ idx = 0;
+ while (pos < length && idx < count) {
+ rc = snprintf(&buffer[pos], length - pos, " [%d/%d] %s\n", idx + 1, count, locations[idx]);
+ pos += rc >= 0 ? rc : 0;
+ idx++;
+ }
+ buffer[length] = 0;
+ if (signum)
+ ERROR("BACKTRACE due to signal %s/%d:\n%s", strsignal(signum), signum, buffer);
+ else
+ ERROR("BACKTRACE:\n%s", buffer);
{
ERROR("Terminating signal %d received: %s", signum, strsignal(signum));
if (signum == SIGABRT)
{
ERROR("Terminating signal %d received: %s", signum, strsignal(signum));
if (signum == SIGABRT)
if (error_handler == NULL && signum == SIG_FOR_TIMER)
return;
if (error_handler == NULL && signum == SIG_FOR_TIMER)
return;
// unlock signal to allow a new signal to come
if (error_handler != NULL) {
// unlock signal to allow a new signal to come
if (error_handler != NULL) {
.traceevent .content {
clear: both;
.traceevent .content {
clear: both;
}
.traceevent, .x-button {
}
.traceevent, .x-button {
cls = 'key';
} else {
cls = 'string';
cls = 'key';
} else {
cls = 'string';
+ match = match.replace(/\\n/g, "\\n<br>");
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';