#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
}
}
+/**
+ * @brief Print thread information
+ *
+ * @param outputfile File handle for printing report.
+ */
+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];
+
+ snprintf(task_path, PATH_MAX, "/proc/%d/task", pid);
+
+ if (threadnum > 0) {
+ 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");
+ }
+ }
+
+}
+
/**
* @brief Main function.
*
{
int c, i;
pid_t pid = 0;
- /* pid_t tid = 0; */
+ pid_t tid = 0;
const char *core_file_name;
pid = atoi(optarg);
break;
case OPT_TID:
- /* tid = atoi(optarg); */
+ tid = atoi(optarg);
break;
case OPT_OUTPUTFILE:
outputfile = fopen(optarg, "w");
/* 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);