summaryrefslogtreecommitdiff
path: root/src/crash-stack
diff options
context:
space:
mode:
authorŁukasz Stelmach <l.stelmach@samsung.com>2016-12-14 14:51:14 +0100
committerŁukasz Stelmach <l.stelmach@samsung.com>2016-12-14 16:10:02 +0100
commitd798192a609c2c5f558447e43cd219fac34333ac (patch)
treee2909b2a8f30e0d829f282723ef9b0db475432dc /src/crash-stack
parenta13582d0dc5dd553fa19aa7a4f60ea6b10ed44a9 (diff)
downloadcrash-worker-d798192a609c2c5f558447e43cd219fac34333ac.tar.gz
crash-worker-d798192a609c2c5f558447e43cd219fac34333ac.tar.bz2
crash-worker-d798192a609c2c5f558447e43cd219fac34333ac.zip
crash-stack: print information about threads
Change-Id: Ib0e2d9c2bdbd5fd4eacc0608a8c5ecccdfd4f2a8
Diffstat (limited to 'src/crash-stack')
-rw-r--r--src/crash-stack/crash-stack.c64
1 files changed, 59 insertions, 5 deletions
diff --git a/src/crash-stack/crash-stack.c b/src/crash-stack/crash-stack.c
index 0ec8990..2e3b86f 100644
--- a/src/crash-stack/crash-stack.c
+++ b/src/crash-stack/crash-stack.c
@@ -48,6 +48,8 @@
#include <sys/uio.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <dirent.h>
+#include <sys/syscall.h>
static siginfo_t __siginfo;
static FILE *outputfile = NULL; ///< global output stream
@@ -646,9 +648,10 @@ static Elf_Data *__get_registers_core(Elf *core, const char *core_file_name, Map
static void __print_callstack(Callstack *callstack, Dwfl *dwfl, Elf *core, pid_t pid,
Elf_Data *notes)
{
- fprintf(outputfile, "Call stack");
- if (pid > 1) fprintf(outputfile, " for PID %d", pid);
- fprintf(outputfile, ":\n");
+ fprintf(outputfile, "\nCallstack Information");
+ if (pid > 1) fprintf(outputfile, " (PID:%d)", pid);
+ fprintf(outputfile, "\n");
+ fprintf(outputfile, "Call Stack Count: %d\n", (int)callstack->elems);
char *dem_buffer = NULL;
size_t it;
@@ -694,6 +697,54 @@ static void __print_callstack(Callstack *callstack, Dwfl *dwfl, Elf *core, pid_t
fprintf(outputfile, "unknown function\n");
}
}
+ fprintf(outputfile, "End of Call Stack\n");
+}
+
+/**
+ * @brief Print thread information
+ *
+ * @param outputfile File handle for printing report.
+ * @param pid PID of the inspected process
+ * @param tid TID of the inspected thread
+ */
+static void __crash_stack_print_threads(FILE* outputfile, pid_t pid, pid_t tid)
+{
+ int threadnum=1;
+ DIR *dir;
+ struct dirent entry;
+ 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) {
+ return;
+ }
+
+ threadnum = sb.st_nlink - 2;
+
+ if (threadnum > 1) {
+ fprintf(outputfile, "\nThreads Information\n");
+ fprintf(outputfile,
+ "Threads: %d\nPID = %d TID = %d\n",
+ threadnum, pid, tid);
+ /* print thread */
+ dir = opendir(task_path);
+ if (!dir) {
+ fprintf(stderr, "[crash-stack] cannot open %s\n", task_path);
+ } else {
+ while (readdir_r(dir, &entry, &dentry) == 0 && dentry) {
+ if (strcmp(dentry->d_name, ".") == 0 ||
+ strcmp(dentry->d_name, "..") == 0)
+ continue;
+ fprintf(outputfile, "%s ", dentry->d_name);
+ }
+ closedir(dir);
+ fprintf(outputfile, "\n");
+ }
+ }
+
}
/**
@@ -712,7 +763,7 @@ int main(int argc, char **argv)
{
int c, i;
pid_t pid = 0;
- /* pid_t tid = 0; */
+ pid_t tid = 0;
const char *core_file_name;
@@ -724,7 +775,7 @@ int main(int argc, char **argv)
pid = atoi(optarg);
break;
case OPT_TID:
- /* tid = atoi(optarg); */
+ tid = atoi(optarg);
break;
case OPT_OUTPUTFILE:
outputfile = fopen(optarg, "w");
@@ -804,6 +855,9 @@ int main(int argc, char **argv)
/* Print registers */
_crash_stack_print_regs(outputfile);
+ /* Threads */
+ __crash_stack_print_threads(outputfile, pid, tid);
+
/* Print the results */
__print_callstack(&callstack, dwfl, core, pid, notes);