Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/agent/src/os/linux/libthread_db.c
38833 views
/*1* Copyright (C) 2013 The Android Open Source Project2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516#include <dirent.h>17#include <stdint.h>18#include <stdio.h>19#include <stdlib.h>20#include <string.h>21#include <sys/ptrace.h>22#include <thread_db.h>23#include <unistd.h>2425extern pid_t ps_getpid(struct ps_prochandle*);2627// We don't have any symbols to cache.28char const** td_symbol_list(void) {29static char const* symbols[] = { NULL };30return symbols;31}3233//34// Thread agents.35//3637td_err_e td_ta_new(struct ps_prochandle* proc_handle, td_thragent_t** agent_out) {38td_thragent_t* agent = (td_thragent_t*) calloc(1, sizeof(td_thragent_t));39if (!agent) {40return TD_MALLOC;41}4243agent->pid = ps_getpid(proc_handle);44agent->ph = proc_handle;45*agent_out = agent;4647return TD_OK;48}495051td_err_e td_ta_delete(td_thragent_t* ta) {52free(ta);53return TD_OK;54}5556td_err_e td_ta_map_lwp2thr(td_thragent_t const* agent, lwpid_t lwpid, td_thrhandle_t* th) {57th->pid = ps_getpid(agent->ph);58th->tid = lwpid;59return TD_OK;60}6162td_err_e td_ta_thr_iter(td_thragent_t const* agent,63td_thr_iter_f* func,64void* cookie,65td_thr_state_e state,66int32_t prio,67sigset_t* sigmask,68uint32_t user_flags) {69td_err_e err = TD_OK;70char path[32];71DIR * dir;72struct dirent * entry;73td_thrhandle_t handle;7475snprintf(path, sizeof(path), "/proc/%d/task/", agent->pid);76dir = opendir(path);77if (!dir) {78return TD_NOEVENT;79}8081handle.pid = agent->pid;82while ((entry = readdir(dir)) != NULL) {83if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {84continue;85}86handle.tid = atoi(entry->d_name);87if (func(&handle, cookie) != 0) {88err = TD_DBERR;89break;90}91}9293closedir(dir);9495return err;96}9798//99// Threads.100//101102td_err_e td_thr_get_info(td_thrhandle_t const* handle, td_thrinfo_t* info) {103info->ti_tid = handle->tid;104info->ti_lid = handle->tid; // Our pthreads uses kernel ids for tids105info->ti_state = TD_THR_SLEEP; /* XXX this needs to be read from /proc/<pid>/task/<tid>.106This is only used to see if the thread is a zombie or not */107return TD_OK;108}109110//111// TLS.112//113114td_err_e td_thr_tlsbase(const td_thrhandle_t* unused1, unsigned long int unused2, psaddr_t* unused3) {115return TD_NOAPLIC; // TODO: fix this if/when we support ELF TLS.116}117118td_err_e td_thr_tls_get_addr(const td_thrhandle_t* unused1, psaddr_t unused2, size_t unused3, psaddr_t* unused4) {119return TD_NOAPLIC; // TODO: fix this if/when we support ELF TLS.120}121122//123// Thread events.124//125126// Thread events are no longer used by gdb >= 7.0.127// Because we link gdbserver statically, though, we need definitions.128td_err_e td_ta_set_event(td_thragent_t const* agent, td_thr_events_t* events) {129abort();130}131td_err_e td_ta_event_getmsg(td_thragent_t const* agent, td_event_msg_t* event) {132abort();133}134td_err_e td_thr_event_enable(const td_thrhandle_t* handle, int event) {135abort();136}137td_err_e td_ta_clear_event(const td_thragent_t* ta_arg, td_thr_events_t* event) {138abort();139}140td_err_e td_ta_event_addr(td_thragent_t const* agent, td_event_e event, td_notify_t* notify_out) {141abort();142}143144145