This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gdbserver] Make the qSymbol support useable by more than one module


I'm going to need to have the tracepoints module request symbols from GDB
(using the qSymbol support).  Ony problem we need to address to make
that possible, is that the current qSymbol support pretty much assumes
only thread_db.c uses the infrastructure.  E.g.,
`proc->all_symbols_looked_up' refers to thread_db symbols only, and
look_up_one_symbol has an internal check for this flag, which means 
other modules can use look_up_one_symbol as is independently from
thread_db symbols having been resolved or not.

So, to address this limitation, this patch moves the
proc->all_symbols_looked_up flag from the process_info struct to the
thread_db.c private thread_db structure, and, adds a new parameter to
look_up_one_symbol, so that other modules can maintain their own
"all_symbols_looked_up" kind of flag for their own symbols of interest.

Tested on x86_64-linux and applied.

-- 
Pedro Alves

2010-05-03  Pedro Alves  <pedro@codesourcery.com>

	gdb/gdbserver/
	* proc-service.c (ps_pglobal_lookup): Use
	thread_db_look_up_one_symbol.
	* remote-utils.c (look_up_one_symbol): Add new `may_ask_gdb'
	parameter.  Use it instead of all_symbols_looked_up.
	* server.h (struct process_info) <all_symbols_looked_up>: Delete
	field.
	(all_symbols_looked_up): Don't declare.
	(look_up_one_symbol): Add new `may_ask_gdb' parameter.
	* thread-db.c (struct thread_db) <all_symbols_looked_up>: New
	field.
	(thread_db_look_up_symbols): Adjust call to look_up_one_symbol.
	Set all_symbols_looked_up here.
	(thread_db_look_up_one_symbol): New.
	(thread_db_get_tls_address): Adjust.
	(thread_db_load_search, try_thread_db_load_1): Always allocate the
	thread_db object on the heap, and tentatively set it in the
	process structure.
	(thread_db_init): Don't set all_symbols_looked_up here.
	* linux-low.h (thread_db_look_up_one_symbol): Declare.

---
 gdb/gdbserver/linux-low.h    |    1 
 gdb/gdbserver/proc-service.c |    2 
 gdb/gdbserver/remote-utils.c |   14 ++----
 gdb/gdbserver/server.h       |    7 ---
 gdb/gdbserver/thread-db.c    |  100 +++++++++++++++++++++++++++----------------
 5 files changed, 72 insertions(+), 52 deletions(-)

Index: src/gdb/gdbserver/proc-service.c
===================================================================
--- src.orig/gdb/gdbserver/proc-service.c	2010-05-03 19:06:55.000000000 +0100
+++ src/gdb/gdbserver/proc-service.c	2010-05-03 19:07:29.000000000 +0100
@@ -65,7 +65,7 @@ ps_pglobal_lookup (gdb_ps_prochandle_t p
 {
   CORE_ADDR addr;
 
-  if (look_up_one_symbol (name, &addr) == 0)
+  if (thread_db_look_up_one_symbol (name, &addr) == 0)
     return PS_NOSYM;
 
   *sym_addr = (psaddr_t) (unsigned long) addr;
Index: src/gdb/gdbserver/remote-utils.c
===================================================================
--- src.orig/gdb/gdbserver/remote-utils.c	2010-05-03 19:07:17.000000000 +0100
+++ src/gdb/gdbserver/remote-utils.c	2010-05-03 19:07:17.000000000 +0100
@@ -1411,11 +1411,12 @@ clear_symbol_cache (struct sym_cache **s
   *symcache_p = NULL;
 }
 
-/* Ask GDB for the address of NAME, and return it in ADDRP if found.
+/* Get the address of NAME, and return it in ADDRP if found.  if
+   MAY_ASK_GDB is false, assume symbol cache misses are failures.
    Returns 1 if the symbol is found, 0 if it is not, -1 on error.  */
 
 int
-look_up_one_symbol (const char *name, CORE_ADDR *addrp)
+look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb)
 {
   char own_buf[266], *p, *q;
   int len;
@@ -1432,12 +1433,9 @@ look_up_one_symbol (const char *name, CO
 	return 1;
       }
 
-  /* If we've passed the call to thread_db_look_up_symbols, then
-     anything not in the cache must not exist; we're not interested
-     in any libraries loaded after that point, only in symbols in
-     libpthread.so.  It might not be an appropriate time to look
-     up a symbol, e.g. while we're trying to fetch registers.  */
-  if (proc->all_symbols_looked_up)
+  /* It might not be an appropriate time to look up a symbol,
+     e.g. while we're trying to fetch registers.  */
+  if (!may_ask_gdb)
     return 0;
 
   /* Send the request.  */
Index: src/gdb/gdbserver/server.h
===================================================================
--- src.orig/gdb/gdbserver/server.h	2010-05-03 19:06:55.000000000 +0100
+++ src/gdb/gdbserver/server.h	2010-05-03 19:07:17.000000000 +0100
@@ -238,10 +238,6 @@ struct process_info
   /* The symbol cache.  */
   struct sym_cache *symbol_cache;
 
-  /* If this flag has been set, assume symbol cache misses are
-     failures.  */
-  int all_symbols_looked_up;
-
   /* The list of memory breakpoints.  */
   struct breakpoint *breakpoints;
 
@@ -359,7 +355,6 @@ extern void hostio_last_error_from_errno
 /* From remote-utils.c */
 
 extern int remote_debug;
-extern int all_symbols_looked_up;
 extern int noack_mode;
 extern int transport_is_reliable;
 
@@ -411,7 +406,7 @@ int remote_escape_output (const gdb_byte
 char *unpack_varlen_hex (char *buff,  ULONGEST *result);
 
 void clear_symbol_cache (struct sym_cache **symcache_p);
-int look_up_one_symbol (const char *name, CORE_ADDR *addrp);
+int look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb);
 
 void monitor_output (const char *msg);
 
Index: src/gdb/gdbserver/thread-db.c
===================================================================
--- src.orig/gdb/gdbserver/thread-db.c	2010-05-03 19:06:55.000000000 +0100
+++ src/gdb/gdbserver/thread-db.c	2010-05-03 19:07:17.000000000 +0100
@@ -47,6 +47,11 @@ struct thread_db
   /* Connection to the libthread_db library.  */
   td_thragent_t *thread_agent;
 
+  /* If this flag has been set, we've already asked GDB for all
+     symbols we might need; assume symbol cache misses are
+     failures.  */
+  int all_symbols_looked_up;
+
 #ifndef USE_LIBTHREAD_DB_DIRECTLY
   /* Handle of the libthread_db from dlopen.  */
   void *handle;
@@ -452,7 +457,25 @@ thread_db_look_up_symbols (void)
   CORE_ADDR unused;
 
   for (sym_list = thread_db->td_symbol_list_p (); *sym_list; sym_list++)
-    look_up_one_symbol (*sym_list, &unused);
+    look_up_one_symbol (*sym_list, &unused, 1);
+
+  /* We're not interested in any other libraries loaded after this
+     point, only in symbols in libpthread.so.  */
+  thread_db->all_symbols_looked_up = 1;
+}
+
+int
+thread_db_look_up_one_symbol (const char *name, CORE_ADDR *addrp)
+{
+  struct thread_db *thread_db = current_process ()->private->thread_db;
+  int may_ask_gdb = !thread_db->all_symbols_looked_up;
+
+  /* If we've passed the call to thread_db_look_up_symbols, then
+     anything not in the cache must not exist; we're not interested
+     in any libraries loaded after that point, only in symbols in
+     libpthread.so.  It might not be an appropriate time to look
+     up a symbol, e.g. while we're trying to fetch registers.  */
+  return look_up_one_symbol (name, addrp, may_ask_gdb);
 }
 
 int
@@ -470,7 +493,7 @@ thread_db_get_tls_address (struct thread
   thread_db = proc->private->thread_db;
 
   /* If the thread layer is not (yet) initialized, fail.  */
-  if (!proc->all_symbols_looked_up)
+  if (!thread_db->all_symbols_looked_up)
     return TD_ERR;
 
   if (thread_db->td_thr_tls_get_addr_p == NULL)
@@ -506,41 +529,41 @@ static int
 thread_db_load_search (void)
 {
   td_err_e err;
-  struct thread_db tdb;
+  struct thread_db *tdb;
   struct process_info *proc = current_process ();
 
   if (proc->private->thread_db != NULL)
     fatal ("unexpected: proc->private->thread_db != NULL");
 
-  memset (&tdb, 0, sizeof (tdb));
+  tdb = xcalloc (1, sizeof (*tdb));
+  proc->private->thread_db = tdb;
 
-  tdb.td_ta_new_p = &td_ta_new;
+  tdb->td_ta_new_p = &td_ta_new;
 
   /* Attempt to open a connection to the thread library.  */
-  err = tdb.td_ta_new_p (&tdb.proc_handle, &tdb.thread_agent);
+  err = tdb->td_ta_new_p (&tdb->proc_handle, &tdb->thread_agent);
   if (err != TD_OK)
     {
       if (debug_threads)
 	fprintf (stderr, "td_ta_new(): %s\n", thread_db_err_str (err));
+      free (tdb);
+      proc->private->thread_db = NULL;
       return 0;
     }
 
-  tdb.td_ta_map_lwp2thr_p = &td_ta_map_lwp2thr;
-  tdb.td_thr_get_info_p = &td_thr_get_info;
-  tdb.td_ta_thr_iter_p = &td_ta_thr_iter;
-  tdb.td_symbol_list_p = &td_symbol_list;
+  tdb->td_ta_map_lwp2thr_p = &td_ta_map_lwp2thr;
+  tdb->td_thr_get_info_p = &td_thr_get_info;
+  tdb->td_ta_thr_iter_p = &td_ta_thr_iter;
+  tdb->td_symbol_list_p = &td_symbol_list;
 
   /* This is required only when thread_db_use_events is on.  */
-  tdb.td_thr_event_enable_p = &td_thr_event_enable;
+  tdb->td_thr_event_enable_p = &td_thr_event_enable;
 
   /* These are not essential.  */
-  tdb.td_ta_event_addr_p = &td_ta_event_addr;
-  tdb.td_ta_set_event_p = &td_ta_set_event;
-  tdb.td_ta_event_getmsg_p = &td_ta_event_getmsg;
-  tdb.td_thr_tls_get_addr_p = &td_thr_tls_get_addr;
-
-  proc->private->thread_db = xmalloc (sizeof (tdb));
-  memcpy (proc->private->thread_db, &tdb, sizeof (tdb));
+  tdb->td_ta_event_addr_p = &td_ta_event_addr;
+  tdb->td_ta_set_event_p = &td_ta_set_event;
+  tdb->td_ta_event_getmsg_p = &td_ta_event_getmsg;
+  tdb->td_thr_tls_get_addr_p = &td_thr_tls_get_addr;
 
   return 1;
 }
@@ -551,15 +574,16 @@ static int
 try_thread_db_load_1 (void *handle)
 {
   td_err_e err;
-  struct thread_db tdb;
+  struct thread_db *tdb;
   struct process_info *proc = current_process ();
 
   if (proc->private->thread_db != NULL)
     fatal ("unexpected: proc->private->thread_db != NULL");
 
-  memset (&tdb, 0, sizeof (tdb));
+  tdb = xcalloc (1, sizeof (*tdb));
+  proc->private->thread_db = tdb;
 
-  tdb.handle = handle;
+  tdb->handle = handle;
 
   /* Initialize pointers to the dynamic library functions we will use.
      Essential functions first.  */
@@ -572,42 +596,45 @@ try_thread_db_load_1 (void *handle)
 	  if (debug_threads)					\
 	    fprintf (stderr, "dlsym: %s\n", dlerror ());	\
 	  if (required)						\
-	    return 0;						\
+	    {							\
+	      free (tdb);					\
+	      proc->private->thread_db = NULL;			\
+	      return 0;						\
+	    }							\
 	}							\
     }								\
   while (0)
 
-  CHK (1, tdb.td_ta_new_p = dlsym (handle, "td_ta_new"));
+  CHK (1, tdb->td_ta_new_p = dlsym (handle, "td_ta_new"));
 
   /* Attempt to open a connection to the thread library.  */
-  err = tdb.td_ta_new_p (&tdb.proc_handle, &tdb.thread_agent);
+  err = tdb->td_ta_new_p (&tdb->proc_handle, &tdb->thread_agent);
   if (err != TD_OK)
     {
       if (debug_threads)
 	fprintf (stderr, "td_ta_new(): %s\n", thread_db_err_str (err));
+      free (tdb);
+      proc->private->thread_db = NULL;
       return 0;
     }
 
-  CHK (1, tdb.td_ta_map_lwp2thr_p = dlsym (handle, "td_ta_map_lwp2thr"));
-  CHK (1, tdb.td_thr_get_info_p = dlsym (handle, "td_thr_get_info"));
-  CHK (1, tdb.td_ta_thr_iter_p = dlsym (handle, "td_ta_thr_iter"));
-  CHK (1, tdb.td_symbol_list_p = dlsym (handle, "td_symbol_list"));
+  CHK (1, tdb->td_ta_map_lwp2thr_p = dlsym (handle, "td_ta_map_lwp2thr"));
+  CHK (1, tdb->td_thr_get_info_p = dlsym (handle, "td_thr_get_info"));
+  CHK (1, tdb->td_ta_thr_iter_p = dlsym (handle, "td_ta_thr_iter"));
+  CHK (1, tdb->td_symbol_list_p = dlsym (handle, "td_symbol_list"));
 
   /* This is required only when thread_db_use_events is on.  */
   CHK (thread_db_use_events,
-       tdb.td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable"));
+       tdb->td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable"));
 
   /* These are not essential.  */
-  CHK (0, tdb.td_ta_event_addr_p = dlsym (handle, "td_ta_event_addr"));
-  CHK (0, tdb.td_ta_set_event_p = dlsym (handle, "td_ta_set_event"));
-  CHK (0, tdb.td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg"));
-  CHK (0, tdb.td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr"));
+  CHK (0, tdb->td_ta_event_addr_p = dlsym (handle, "td_ta_event_addr"));
+  CHK (0, tdb->td_ta_set_event_p = dlsym (handle, "td_ta_set_event"));
+  CHK (0, tdb->td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg"));
+  CHK (0, tdb->td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr"));
 
 #undef CHK
 
-  proc->private->thread_db = xmalloc (sizeof (tdb));
-  memcpy (proc->private->thread_db, &tdb, sizeof (tdb));
-
   return 1;
 }
 
@@ -763,7 +790,6 @@ thread_db_init (int use_events)
 	}
       thread_db_find_new_threads ();
       thread_db_look_up_symbols ();
-      proc->all_symbols_looked_up = 1;
       return 1;
     }
 
Index: src/gdb/gdbserver/linux-low.h
===================================================================
--- src.orig/gdb/gdbserver/linux-low.h	2010-05-03 19:06:55.000000000 +0100
+++ src/gdb/gdbserver/linux-low.h	2010-05-03 19:07:17.000000000 +0100
@@ -231,3 +231,4 @@ void thread_db_mourn (struct process_inf
 int thread_db_handle_monitor_command (char *);
 int thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
 			       CORE_ADDR load_module, CORE_ADDR *address);
+int thread_db_look_up_one_symbol (const char *name, CORE_ADDR *addrp);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]