📄 710-debian_thread-db-multiple-libraries.patch
字号:
Support loading two libthread_db DSOs. In this case, the LinuxThreadsand NPTL ones.Index: gdb-6.3/gdb/thread-db.c===================================================================--- gdb-6.3.orig/gdb/thread-db.c 2004-11-10 10:46:24.000000000 -0500+++ gdb-6.3/gdb/thread-db.c 2004-11-10 11:22:34.858812426 -0500@@ -79,53 +79,63 @@ static td_thragent_t *thread_agent; /* Pointers to the libthread_db functions. */ -static td_err_e (*td_init_p) (void);+struct thread_db_pointers+{+ const char *filename;++ td_err_e (*td_init_p) (void); -static td_err_e (*td_ta_new_p) (struct ps_prochandle * ps,- td_thragent_t **ta);-static td_err_e (*td_ta_map_id2thr_p) (const td_thragent_t *ta, thread_t pt,- td_thrhandle_t *__th);-static td_err_e (*td_ta_map_lwp2thr_p) (const td_thragent_t *ta,- lwpid_t lwpid, td_thrhandle_t *th);-static td_err_e (*td_ta_thr_iter_p) (const td_thragent_t *ta,- td_thr_iter_f *callback, void *cbdata_p,- td_thr_state_e state, int ti_pri,- sigset_t *ti_sigmask_p,- unsigned int ti_user_flags);-static td_err_e (*td_ta_event_addr_p) (const td_thragent_t *ta,- td_event_e event, td_notify_t *ptr);-static td_err_e (*td_ta_set_event_p) (const td_thragent_t *ta,- td_thr_events_t *event);-static td_err_e (*td_ta_event_getmsg_p) (const td_thragent_t *ta,- td_event_msg_t *msg);--static td_err_e (*td_thr_validate_p) (const td_thrhandle_t *th);-static td_err_e (*td_thr_get_info_p) (const td_thrhandle_t *th,- td_thrinfo_t *infop);-static td_err_e (*td_thr_getfpregs_p) (const td_thrhandle_t *th,- gdb_prfpregset_t *regset);-static td_err_e (*td_thr_getgregs_p) (const td_thrhandle_t *th,- prgregset_t gregs);-static td_err_e (*td_thr_setfpregs_p) (const td_thrhandle_t *th,- const gdb_prfpregset_t *fpregs);-static td_err_e (*td_thr_setgregs_p) (const td_thrhandle_t *th,- prgregset_t gregs);-static td_err_e (*td_thr_event_enable_p) (const td_thrhandle_t *th,- int event);--static td_err_e (*td_thr_tls_get_addr_p) (const td_thrhandle_t *th,- void *map_address,- size_t offset, void **address);+ td_err_e (*td_ta_new_p) (struct ps_prochandle * ps,+ td_thragent_t **ta);+ td_err_e (*td_ta_map_id2thr_p) (const td_thragent_t *ta, thread_t pt,+ td_thrhandle_t *__th);+ td_err_e (*td_ta_map_lwp2thr_p) (const td_thragent_t *ta,+ lwpid_t lwpid, td_thrhandle_t *th);++ td_err_e (*td_ta_thr_iter_p) (const td_thragent_t *ta,+ td_thr_iter_f *callback, void *cbdata_p,+ td_thr_state_e state, int ti_pri,+ sigset_t *ti_sigmask_p,+ unsigned int ti_user_flags);+ td_err_e (*td_ta_event_addr_p) (const td_thragent_t *ta,+ td_event_e event, td_notify_t *ptr);+ td_err_e (*td_ta_set_event_p) (const td_thragent_t *ta,+ td_thr_events_t *event);+ td_err_e (*td_ta_event_getmsg_p) (const td_thragent_t *ta,+ td_event_msg_t *msg);++ td_err_e (*td_thr_validate_p) (const td_thrhandle_t *th);+ td_err_e (*td_thr_get_info_p) (const td_thrhandle_t *th,+ td_thrinfo_t *infop);+ td_err_e (*td_thr_getfpregs_p) (const td_thrhandle_t *th,+ gdb_prfpregset_t *regset);+ td_err_e (*td_thr_getgregs_p) (const td_thrhandle_t *th,+ prgregset_t gregs);+ td_err_e (*td_thr_setfpregs_p) (const td_thrhandle_t *th,+ const gdb_prfpregset_t *fpregs);+ td_err_e (*td_thr_setgregs_p) (const td_thrhandle_t *th,+ prgregset_t gregs);+ td_err_e (*td_thr_event_enable_p) (const td_thrhandle_t *th,+ int event);++ td_err_e (*td_thr_tls_get_addr_p) (const td_thrhandle_t *th,+ void *map_address,+ size_t offset, void **address);++ struct thread_db_pointers *next;+}; /* Location of the thread creation event breakpoint. The code at this location in the child process will be called by the pthread library whenever a new thread is created. By setting a special breakpoint at this location, GDB can detect when a new thread is created. We obtain this location via the td_ta_event_addr call. */-static CORE_ADDR td_create_bp_addr;+CORE_ADDR td_create_bp_addr; /* Location of the thread death event breakpoint. */-static CORE_ADDR td_death_bp_addr;+CORE_ADDR td_death_bp_addr;++static struct thread_db_pointers *current_pointers, *all_pointers; /* Prototypes for local functions. */ static void thread_db_find_new_threads (void);@@ -262,7 +272,7 @@ thread_get_info_callback (const td_thrha struct thread_info *thread_info; ptid_t thread_ptid; - err = td_thr_get_info_p (thp, &ti);+ err = current_pointers->td_thr_get_info_p (thp, &ti); if (err != TD_OK) error ("thread_get_info_callback: cannot get thread info: %s", thread_db_err_str (err));@@ -316,8 +326,9 @@ thread_db_map_id2thr (struct thread_info if (thread_info->private->th_valid) return; - err = td_ta_map_id2thr_p (thread_agent, GET_THREAD (thread_info->ptid),- &thread_info->private->th);+ err = current_pointers->td_ta_map_id2thr_p (thread_agent,+ GET_THREAD (thread_info->ptid),+ &thread_info->private->th); if (err != TD_OK) { if (fatal)@@ -340,8 +351,8 @@ thread_db_get_info (struct thread_info * if (!thread_info->private->th_valid) thread_db_map_id2thr (thread_info, 1); - err =- td_thr_get_info_p (&thread_info->private->th, &thread_info->private->ti);+ err = current_pointers->td_thr_get_info_p (&thread_info->private->th,+ &thread_info->private->ti); if (err != TD_OK) error ("thread_db_get_info: cannot get thread info: %s", thread_db_err_str (err));@@ -365,7 +376,8 @@ thread_from_lwp (ptid_t ptid) gdb_assert (is_lwp (ptid)); - err = td_ta_map_lwp2thr_p (thread_agent, GET_LWP (ptid), &th);+ err = current_pointers->td_ta_map_lwp2thr_p (thread_agent, GET_LWP (ptid),+ &th); if (err != TD_OK) error ("Cannot find user-level thread for LWP %ld: %s", GET_LWP (ptid), thread_db_err_str (err));@@ -420,85 +432,102 @@ verbose_dlsym (void *handle, const char return sym; } -static int-thread_db_load (void)+static struct thread_db_pointers *+thread_db_load (const char *name) {+ struct thread_db_pointers *ptrs;+ Dl_info info; void *handle; td_err_e err; - handle = dlopen (LIBTHREAD_DB_SO, RTLD_NOW);+ ptrs = xcalloc (1, sizeof (struct thread_db_pointers));++ handle = dlopen (name, RTLD_NOW); if (handle == NULL) {- fprintf_filtered (gdb_stderr, "\n\ndlopen failed on '%s' - %s\n",- LIBTHREAD_DB_SO, dlerror ());- fprintf_filtered (gdb_stderr,- "GDB will not be able to debug pthreads.\n\n");+ if (all_pointers == NULL)+ {+ fprintf_filtered (gdb_stderr, "\n\ndlopen failed on '%s' - %s\n",+ name, dlerror ());+ fprintf_filtered (gdb_stderr,+ "GDB will not be able to debug pthreads.\n\n");+ } return 0; } /* Initialize pointers to the dynamic library functions we will use. Essential functions first. */ - td_init_p = verbose_dlsym (handle, "td_init");- if (td_init_p == NULL)+ ptrs->td_init_p = verbose_dlsym (handle, "td_init");+ if (ptrs->td_init_p == NULL) return 0; - td_ta_new_p = verbose_dlsym (handle, "td_ta_new");- if (td_ta_new_p == NULL)+ ptrs->td_ta_new_p = verbose_dlsym (handle, "td_ta_new");+ if (ptrs->td_ta_new_p == NULL) return 0; - td_ta_map_id2thr_p = verbose_dlsym (handle, "td_ta_map_id2thr");- if (td_ta_map_id2thr_p == NULL)+ ptrs->td_ta_map_id2thr_p = verbose_dlsym (handle, "td_ta_map_id2thr");+ if (ptrs->td_ta_map_id2thr_p == NULL) return 0; - td_ta_map_lwp2thr_p = verbose_dlsym (handle, "td_ta_map_lwp2thr");- if (td_ta_map_lwp2thr_p == NULL)+ ptrs->td_ta_map_lwp2thr_p = verbose_dlsym (handle, "td_ta_map_lwp2thr");+ if (ptrs->td_ta_map_lwp2thr_p == NULL) return 0; - td_ta_thr_iter_p = verbose_dlsym (handle, "td_ta_thr_iter");- if (td_ta_thr_iter_p == NULL)+ ptrs->td_ta_thr_iter_p = verbose_dlsym (handle, "td_ta_thr_iter");+ if (ptrs->td_ta_thr_iter_p == NULL) return 0; - td_thr_validate_p = verbose_dlsym (handle, "td_thr_validate");- if (td_thr_validate_p == NULL)+ ptrs->td_thr_validate_p = verbose_dlsym (handle, "td_thr_validate");+ if (ptrs->td_thr_validate_p == NULL) return 0; - td_thr_get_info_p = verbose_dlsym (handle, "td_thr_get_info");- if (td_thr_get_info_p == NULL)+ ptrs->td_thr_get_info_p = verbose_dlsym (handle, "td_thr_get_info");+ if (ptrs->td_thr_get_info_p == NULL) return 0; - td_thr_getfpregs_p = verbose_dlsym (handle, "td_thr_getfpregs");- if (td_thr_getfpregs_p == NULL)+ ptrs->td_thr_getfpregs_p = verbose_dlsym (handle, "td_thr_getfpregs");+ if (ptrs->td_thr_getfpregs_p == NULL) return 0; - td_thr_getgregs_p = verbose_dlsym (handle, "td_thr_getgregs");- if (td_thr_getgregs_p == NULL)+ ptrs->td_thr_getgregs_p = verbose_dlsym (handle, "td_thr_getgregs");+ if (ptrs->td_thr_getgregs_p == NULL) return 0; - td_thr_setfpregs_p = verbose_dlsym (handle, "td_thr_setfpregs");- if (td_thr_setfpregs_p == NULL)+ ptrs->td_thr_setfpregs_p = verbose_dlsym (handle, "td_thr_setfpregs");+ if (ptrs->td_thr_setfpregs_p == NULL) return 0; - td_thr_setgregs_p = verbose_dlsym (handle, "td_thr_setgregs");- if (td_thr_setgregs_p == NULL)+ ptrs->td_thr_setgregs_p = verbose_dlsym (handle, "td_thr_setgregs");+ if (ptrs->td_thr_setgregs_p == NULL) return 0; /* Initialize the library. */- err = td_init_p ();+ err = ptrs->td_init_p (); if (err != TD_OK) { warning ("Cannot initialize libthread_db: %s", thread_db_err_str (err));+ xfree (ptrs); return 0; } /* These are not essential. */- td_ta_event_addr_p = dlsym (handle, "td_ta_event_addr");- td_ta_set_event_p = dlsym (handle, "td_ta_set_event");- td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg");- td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable");- td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr");+ ptrs->td_ta_event_addr_p = dlsym (handle, "td_ta_event_addr");+ ptrs->td_ta_set_event_p = dlsym (handle, "td_ta_set_event");+ ptrs->td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg");+ ptrs->td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable");+ ptrs->td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr");++ if (dladdr (ptrs->td_ta_new_p, &info) != 0)+ ptrs->filename = info.dli_fname;++ /* Try dlinfo? */++ if (ptrs->filename == NULL)+ /* Paranoid - don't let a NULL path slip through. */+ ptrs->filename = name; - return 1;+ return ptrs; } static td_err_e@@ -508,7 +537,7 @@ enable_thread_event (td_thragent_t *thre td_err_e err; /* Get the breakpoint address for thread EVENT. */- err = td_ta_event_addr_p (thread_agent, event, ¬ify);+ err = current_pointers->td_ta_event_addr_p (thread_agent, event, ¬ify); if (err != TD_OK)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -