* limitations under the License.
*
* Authors: Adrian Szyndela <adrian.s@samsung.com>
- * Łukasz Stelmach <l.stelmach@samsung.com>
- * Rafał Pietruch <r.pietruch@samsung.com>
+ * Łukasz Stelmach <l.stelmach@samsung.com>
+ * Rafał Pietruch <r.pietruch@samsung.com>
*/
#define _GNU_SOURCE 1
fprintf(outputfile, "%s:\n", buf);
f = fopen(buf, "r");
- if (NULL == f)
- {
+ if (NULL == f) {
fprintf(errfile, "Failed to open %s: %m\n", buf);
return;
}
while ((r = fread(buf, 1, sizeof(buf), f)) > 0)
- {
fwrite(buf, r, 1, outputfile);
- }
fclose(f);
pid_t stopped_pid;
status = __attachable(pid, tid);
- if (-1 == status)
- {
+ if (-1 == status) {
fprintf(errfile, "failed to read /proc/%d/task/%d/stat: %m\n", pid, tid);
return NULL;
}
- if (!status)
- {
+ if (!status) {
__print_not_attachable_process_info(pid, tid);
return NULL;
}
return NULL;
}
-#if _ELFUTILS_PREREQ(0,158)
+#if _ELFUTILS_PREREQ(0, 158)
if (dwfl_linux_proc_attach(dwfl, tid, true) < 0) {
fprintf(errfile, "process %d : dwfl attach failed (%s)\n", tid, dwfl_errmsg(-1));
dwfl_end(dwfl);
*/
static void __crash_stack_print_signal(int signo)
{
+#define DEF_STR(name) [name] = #name
const char* const signal_table[] = {
- [SIGHUP]="SIGHUP", [SIGINT]="SIGINT", [SIGQUIT]="SIGQUIT",
- [SIGILL]="SIGILL", [SIGTRAP]="SIGTRAP", [SIGABRT]="SIGABRT",
- /* [SIGIOT]="SIGIOT", */ [SIGBUS]="SIGBUS", [SIGFPE]="SIGFPE",
- [SIGKILL]="SIGKILL", [SIGUSR1]="SIGUSR1", [SIGSEGV]="SIGSEGV",
- [SIGUSR2]="SIGUSR2", [SIGPIPE]="SIGPIPE", [SIGALRM]="SIGALRM",
- [SIGTERM]="SIGTERM", [SIGSTKFLT]="SIGSTKFLT", [SIGCHLD]="SIGCHLD",
- [SIGCONT]="SIGCONT", [SIGSTOP]="SIGSTOP", [SIGTSTP]="SIGTSTP",
- [SIGTTIN]="SIGTTIN", [SIGTTOU]="SIGTTOU", [SIGURG]="SIGURG",
- [SIGXCPU]="SIGXCPU", [SIGXFSZ]="SIGXFSZ", [SIGVTALRM]="SIGVTALRM",
- [SIGPROF]="SIGPROF", [SIGWINCH]="SIGWINCH", [SIGIO]="SIGIO",
- [SIGPWR]="SIGPWR", [SIGSYS]="SIGSYS", /* [SIGUNUSED]="SIGUNUSED", */
+ DEF_STR(SIGHUP),
+ DEF_STR(SIGINT),
+ DEF_STR(SIGQUIT),
+ DEF_STR(SIGILL),
+ DEF_STR(SIGTRAP),
+ DEF_STR(SIGABRT),
+ DEF_STR(SIGBUS),
+ DEF_STR(SIGFPE),
+ DEF_STR(SIGKILL),
+ DEF_STR(SIGUSR1),
+ DEF_STR(SIGUSR2),
+ DEF_STR(SIGPIPE),
+ DEF_STR(SIGSEGV),
+ DEF_STR(SIGTERM),
+ DEF_STR(SIGSTKFLT),
+ DEF_STR(SIGCHLD),
+ DEF_STR(SIGCONT),
+ DEF_STR(SIGSTOP),
+ DEF_STR(SIGTSTP),
+ DEF_STR(SIGTTIN),
+ DEF_STR(SIGTTOU),
+ DEF_STR(SIGURG),
+ DEF_STR(SIGXCPU),
+ DEF_STR(SIGXFSZ),
+ DEF_STR(SIGVTALRM),
+ DEF_STR(SIGPROF),
+ DEF_STR(SIGWINCH),
+ DEF_STR(SIGPOLL),
+ DEF_STR(SIGIO),
+ DEF_STR(SIGPWR),
+ DEF_STR(SIGSYS)
};
+#undef DEF_STR
if (SIGHUP > signo || signo > SIGSYS) {
fprintf(errfile, "Invalid signal number: %d\n", signo);
if (symbol) {
free(proc_info->name);
proc_info->name = strdup(symbol);
- }
- else if (proc_info->module_name != NULL) {
+ } else if (proc_info->module_name != NULL)
__find_symbol_in_elf(proc_info, mapping_start);
- }
}
}
*/
static void __crash_stack_print_threads(FILE* outputfile, pid_t pid, pid_t tid)
{
- int threadnum=1;
+ int threadnum = 1;
DIR *dir;
- struct dirent *dentry=NULL;
+ struct dirent *dentry = NULL;
char task_path[PATH_MAX];
struct stat sb;
-
snprintf(task_path, PATH_MAX, "/proc/%d/task", pid);
- if (stat(task_path, &sb) == -1) {
+ if (stat(task_path, &sb) == -1)
return;
- }
threadnum = sb.st_nlink - 2;
if ((fd = open(file_path, O_RDONLY)) < 0) {
fprintf(errfile, "[crash-stack] cannot open %s\n", file_path);
- } else {
- /* parsing the maps to get code segment address*/
- head = get_addr_list_from_maps(fd);
- close(fd);
- }
- if (head == NULL) {
- return;
+ } else {
+ /* parsing the maps to get code segment address*/
+ head = get_addr_list_from_maps(fd);
+ close(fd);
}
+ if (head == NULL)
+ return;
t_node = head;
fprintf(outputfile, "\nMaps Information\n");
static struct addr_node *get_addr_list_from_maps(int fd)
{
- int fpath_len, result;
- uintptr_t saddr;
- uintptr_t eaddr;
- char perm[PERM_LEN];
- char path[PATH_MAX];
- char addr[ADDR_LEN * 2 + 2];
- char linebuf[BUF_SIZE];
- struct addr_node *head = NULL;
- struct addr_node *tail = NULL;
- struct addr_node *t_node = NULL;
-
- /* parsing the maps to get executable code address */
- while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
- memset(path, 0, PATH_MAX);
- result = sscanf(linebuf, "%s %s %*s %*s %*s %s ", addr, perm, path);
- if (result < 0)
- continue;
- perm[PERM_LEN - 1] = 0;
- /* rwxp */
- if ((perm[2] == 'x' && path[0] == '/') ||
- (perm[1] == 'w' && path[0] != '/'))
- {
+ int fpath_len, result;
+ uintptr_t saddr;
+ uintptr_t eaddr;
+ char perm[PERM_LEN];
+ char path[PATH_MAX];
+ char addr[ADDR_LEN * 2 + 2];
+ char linebuf[BUF_SIZE];
+ struct addr_node *head = NULL;
+ struct addr_node *tail = NULL;
+ struct addr_node *t_node = NULL;
+
+ /* parsing the maps to get executable code address */
+ while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
+ memset(path, 0, PATH_MAX);
+ result = sscanf(linebuf, "%s %s %*s %*s %*s %s ", addr, perm, path);
+ if (result < 0)
+ continue;
+ perm[PERM_LEN - 1] = 0;
+ /* rwxp */
+ if ((perm[2] == 'x' && path[0] == '/') ||
+ (perm[1] == 'w' && path[0] != '/')) {
char* addr2 = strchr(addr, '-');
*(addr2++) = '\0';
/* add addr node to list */
static char *fgets_fd(char *str, int len, int fd)
{
- char ch;
- register char *cs;
- int num = 0;
-
- cs = str;
- while (--len > 0 && (num = read(fd, &ch, 1) > 0)) {
- if ((*cs++ = ch) == '\n')
- break;
- }
- *cs = '\0';
- return (num == 0 && cs == str) ? NULL : str;
+ char ch;
+ register char *cs;
+ int num = 0;
+
+ cs = str;
+ while (--len > 0 && (num = read(fd, &ch, 1) > 0)) {
+ if ((*cs++ = ch) == '\n')
+ break;
+ }
+ *cs = '\0';
+ return (num == 0 && cs == str) ? NULL : str;
}
/**
fprintf(outputfile, "\nMemory information\n");
- if ((fd = open("/proc/meminfo", O_RDONLY)) < 0) {
- fprintf(errfile, "[crash-stack] cannot open /proc/meminfo\n");
- } else {
- while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
- sscanf(linebuf, "%s %s %*s", infoname, memsize);
- if (strcmp("MemTotal:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n", infoname, memsize);
- } else if (strcmp("MemFree:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n", infoname, memsize);
- } else if (strcmp("Buffers:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n", infoname, memsize);
- } else if (strcmp("Cached:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n", infoname, memsize);
- break;
- }
- }
- close(fd);
- }
+ if ((fd = open("/proc/meminfo", O_RDONLY)) < 0) {
+ fprintf(errfile, "[crash-stack] cannot open /proc/meminfo\n");
+ } else {
+ while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
+ sscanf(linebuf, "%s %s %*s", infoname, memsize);
+ if (strcmp("MemTotal:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n", infoname, memsize);
+ } else if (strcmp("MemFree:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n", infoname, memsize);
+ } else if (strcmp("Buffers:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n", infoname, memsize);
+ } else if (strcmp("Cached:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n", infoname, memsize);
+ break;
+ }
+ }
+ close(fd);
+ }
snprintf(file_path, PATH_MAX, "/proc/%d/status", pid);
- if ((fd = open(file_path, O_RDONLY)) < 0) {
- fprintf(errfile, "[crash-stack] cannot open %s\n", file_path);
- } else {
- while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
- sscanf(linebuf, "%s %s %*s", infoname, memsize);
- if (strcmp("VmPeak:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n", infoname,
- memsize);
- } else if (strcmp("VmSize:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n", infoname,
- memsize);
- } else if (strcmp("VmLck:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n", infoname,
- memsize);
- } else if (strcmp("VmPin:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n", infoname,
- memsize);
- } else if (strcmp("VmHWM:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n",
- infoname, memsize);
- } else if (strcmp("VmRSS:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n",
- infoname, memsize);
- } else if (strcmp("VmData:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n",
- infoname, memsize);
- } else if (strcmp("VmStk:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n",
- infoname, memsize);
- } else if (strcmp("VmExe:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n",
- infoname, memsize);
- } else if (strcmp("VmLib:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n",
- infoname, memsize);
- } else if (strcmp("VmPTE:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n",
- infoname, memsize);
- } else if (strcmp("VmSwap:", infoname) == 0) {
- fprintf(outputfile, "%s %8s KB\n",
- infoname, memsize);
- break;
- }
- }
- close(fd);
- }
+ if ((fd = open(file_path, O_RDONLY)) < 0) {
+ fprintf(errfile, "[crash-stack] cannot open %s\n", file_path);
+ } else {
+ while (fgets_fd(linebuf, BUF_SIZE, fd) != NULL) {
+ sscanf(linebuf, "%s %s %*s", infoname, memsize);
+ if (strcmp("VmPeak:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n", infoname,
+ memsize);
+ } else if (strcmp("VmSize:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n", infoname,
+ memsize);
+ } else if (strcmp("VmLck:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n", infoname,
+ memsize);
+ } else if (strcmp("VmPin:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n", infoname,
+ memsize);
+ } else if (strcmp("VmHWM:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmRSS:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmData:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmStk:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmExe:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmLib:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmPTE:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n",
+ infoname, memsize);
+ } else if (strcmp("VmSwap:", infoname) == 0) {
+ fprintf(outputfile, "%s %8s KB\n",
+ infoname, memsize);
+ break;
+ }
+ }
+ close(fd);
+ }
}
/**
struct stat sb;
snprintf(task_path, PATH_MAX, "/proc/%d/task", pid);
- if (stat(task_path, &sb) == -1) {
+ if (stat(task_path, &sb) == -1)
return -1;
- }
threadnum = sb.st_nlink - 2;