< prev index next >
src/jdk.hotspot.agent/linux/native/libsaproc/libproc_impl.c
Print this page
*** 26,35 ****
--- 26,37 ----
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#ifdef INCLUDE_SA_ATTACH
#include <thread_db.h>
+ #else
+ #include <dirent.h>
#endif
#include "libproc_impl.h"
#define SA_ALTROOT "SA_ALTROOT"
*** 302,314 ****
if (ptr->callback(ptr->ph, ti.ti_tid, ti.ti_lid) != true)
return TD_ERR;
return TD_OK;
}
! // read thread_info using libthread_db
bool read_thread_info(struct ps_prochandle* ph, thread_info_callback cb) {
struct thread_db_client_data mydata;
td_thragent_t* thread_agent = NULL;
if (td_ta_new(ph, &thread_agent) != TD_OK) {
print_debug("can't create libthread_db agent\n");
return false;
--- 304,319 ----
if (ptr->callback(ptr->ph, ti.ti_tid, ti.ti_lid) != true)
return TD_ERR;
return TD_OK;
}
+ #endif // INCLUDE_SA_ATTACH
! // read thread_info using libthread_db or by iterating through the entries
! // in /proc/<pid>/task/
bool read_thread_info(struct ps_prochandle* ph, thread_info_callback cb) {
+ #ifdef INCLUDE_SA_ATTACH
struct thread_db_client_data mydata;
td_thragent_t* thread_agent = NULL;
if (td_ta_new(ph, &thread_agent) != TD_OK) {
print_debug("can't create libthread_db agent\n");
return false;
*** 325,337 ****
return false;
}
// delete thread agent
td_ta_delete(thread_agent);
return true;
}
- #endif // INCLUDE_SA_ATTACH
// get number of threads
int get_num_threads(struct ps_prochandle* ph) {
return ph->num_threads;
}
--- 330,365 ----
return false;
}
// delete thread agent
td_ta_delete(thread_agent);
+ #else
+ DIR *dir = NULL;
+ struct dirent *ent = NULL;
+ char taskpath[80];
+ pid_t pid = ph->pid;
+
+ // Find the lwpids to attach to by traversing the /proc/<pid>/task/ directory.
+ snprintf(taskpath, sizeof (taskpath), "/proc/%ld/task", (unsigned long)pid);
+ if ((dir = opendir(taskpath)) != NULL) {
+ while ((ent = readdir(dir)) != NULL) {
+ unsigned long lwp;
+
+ if ((lwp = strtoul(ent->d_name, NULL, 10)) != 0) {
+ // Create and add the thread info.
+ (*cb)(ph, 0, lwp);
+ }
+ }
+ } else {
+ print_debug("Could not open /proc/%ld/task.\n", (unsigned long)pid);
+ return false;
+ }
+
+ closedir(dir);
+ #endif
return true;
}
// get number of threads
int get_num_threads(struct ps_prochandle* ph) {
return ph->num_threads;
}
< prev index next >