Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFC] Extend remote protocol to allow symbol look-up service.
@ 2001-04-17 16:29 Michael Snyder
  2001-04-17 18:50 ` Jonathan Larmour
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Michael Snyder @ 2001-04-17 16:29 UTC (permalink / raw)
  To: gdb-patches; +Cc: jtc

 
Surprising as  it may seem, there are circumstances when a remote
target stub may need to know the values of symbols in the debuggee.
The case that I'm working from is multi-threaded debugging under
Solaris and Linux.  Both platforms make use of a debugging support
library called libthread-db, which exports a debugging interface
into the native thread library.  It shields the debugger from 
knowledge about the thread library internals, but in return it 
needs to know the addresses of thread library data objects in the
child, so that it can go rooting around in them.

The scheme that I propose is this: whenever the debugger detects
a new shared library being loaded in the remote child process, 
it will send a notification to the remote stub in the form of
a 'Q' (miscelaneous set value) packet, like this:

	QSharedObject:libc.so.1

The target may as usual reply with an empty packet meaning
"I don't understand", or with an "OK" acknowledgement, but
in addition to those the target may reply with a request
for the value of a symbol:

	qSymbol:__pthread_max_threads

If the reply is of that form, the debugger will attempt a 
symbol lookup.  If successful, it will send a new declaratory
message to the target like so:

	QSymbol:<hex address>:__pthread_max_threads

Or, if the lookup is unsuccessful, 

	QSymbol::__pthread_max_threads

(indicating no address or value is available).  The target may
ask for the symbol again when a new shared library shows up.

The target's replies to the QSymbol message are the same as for
the QSharedObject message: an empty reply, an "OK" ack, or a
new request for another symbol.  Thus the process can continue
until the target doesn't need any more symbols.

Here is a patch to remote.c that would implement the debugger side
of the proposed protocol.  I have implemented the target side in
the soon-to-be-released (knock on wood) libremote library.

2001-04-17  Michael Snyder  <msnyder@redhat.com>

	* remote.c (remote_new_objfile): New function.  Called by the
	target new_objfile hook whenever a new (shared library) objfile
	is detected.  Notifies the remote target, and accepts symbol
	lookup requests.
	(remote_new_objfile_chain): Function pointer which hooks 
	remote_new_objfile into the new objfile notification chain.
	(_initialize_remote): Hook remote_new_objfile function into 
	the new objfile notification chain.

Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.45
diff -c -3 -p -r1.45 remote.c
*** remote.c	2001/04/17 20:31:00	1.45
--- remote.c	2001/04/17 23:13:03
*************** build_remote_gdbarch_data (void)
*** 5691,5696 ****
--- 5691,5751 ----
    remote_address_size = TARGET_ADDR_BIT;
  }
  
+ /* Saved pointer to previous owner of the new_objfile event. */
+ static void (*remote_new_objfile_chain) (struct objfile *);
+ 
+ /* Function to be called whenever a new objfile (shlib) is detected. */
+ static void
+ remote_new_objfile (struct objfile *objfile)
+ {
+   char *msg, *reply, *prev, *tmp;
+   struct minimal_symbol *sym;
+ 
+   printf ("<remote_new_objfile: %08x>\n", (unsigned long) objfile);
+ 
+   if (remote_desc != 0)		/* Have a remote connection */
+     {
+       msg   = alloca (PBUFSIZ);
+       reply = alloca (PBUFSIZ);
+ 
+       /* Inform target of new objfile. */
+ 
+       /* NOTE: you might say that I should use SLASH_CHAR here, but
+ 	 not so!  SLASH_CHAR is defined for the host, while the shared
+ 	 libraries are relevant to the target. */
+       if (objfile)
+ 	{
+ 	  tmp = strrchr (objfile->name, '/');
+ 	  if (tmp == NULL)
+ 	    tmp = strrchr (objfile->name, '\\');
+ 	  if (tmp == NULL)
+ 	    tmp = objfile->name;
+ 	  sprintf (msg, "QSharedObject:%s", tmp);
+ 	}
+       else
+ 	strcpy (msg, "QSharedObject:");
+ 
+       putpkt (msg);
+       getpkt (reply, PBUFSIZ, 0);
+       while (strncmp (reply, "qSymbol:", 8) == 0)
+ 	{
+ 	  sym = lookup_minimal_symbol (&reply[8], NULL, NULL);
+ 	  if (sym == NULL)
+ 	    sprintf (msg, "QSymbol::%s", &reply[8]);
+ 	  else
+ 	    sprintf (msg, "QSymbol:%s:%s", 
+ 		     paddr_nz (SYMBOL_VALUE_ADDRESS (sym)),
+ 		     &reply[8]);
+ 	  putpkt (msg);
+ 	  getpkt (reply, PBUFSIZ, 0);
+ 	}
+     }
+   /* Call predecessor on chain, if any. */
+   if (remote_new_objfile_chain != 0 &&
+       remote_desc == 0)
+     remote_new_objfile_chain (objfile);
+ }
+ 
  void
  _initialize_remote (void)
  {
*************** _initialize_remote (void)
*** 5720,5725 ****
--- 5775,5784 ----
  
    init_remote_cisco_ops ();
    add_target (&remote_cisco_ops);
+ 
+   /* Hook into new objfile notification.  */
+   remote_new_objfile_chain = target_new_objfile_hook;
+   target_new_objfile_hook  = remote_new_objfile;
  
  #if 0
    init_remote_threadtests ();
From ac131313@cygnus.com Tue Apr 17 16:30:00 2001
From: Andrew Cagney <ac131313@cygnus.com>
To: GDB Patches <gdb-patches@sourceware.cygnus.com>
Subject: [5.1/rfc] Obsolete MPW host
Date: Tue, 17 Apr 2001 16:30:00 -0000
Message-id: <3ADCD1D5.9AA0B1AC@cygnus.com>
X-SW-Source: 2001-04/msg00184.html
Content-length: 10008

Hello,

This is the last of the systems on the 5.1 hit list.

	enjoy,
		Andrew
2001-04-17  Andrew Cagney  <ac131313@redhat.com>

	* source.c (openp): Obsolete #ifdef MPW code.
	(open_source_file): Ditto.
	* event-top.c (display_gdb_prompt): Ditto.
	* utils.c (query): Ditto.
	(init_page_info): Ditto.
	(init_page_info): Delete #ifndef MPW.
	* top.c (gdb_readline): Ditto.
	* mac-xdep.c: Obsolete.
	* mac-gdb.r: Obsolete.
	* config/powerpc/xm-mpw.h: Obsolete.
	* config/xm-mpw.h: Obsolete.
	* mpw-make.sed: Obsolete.
	* mpw-config.in: Obsolete.
	* TODO: Update
	* NEWS: Update

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.22
diff -p -r1.22 NEWS
*** NEWS	2001/04/17 21:20:48	1.22
--- NEWS	2001/04/17 22:28:52
*************** PowerPC Netware					powerpc-*-netware*
*** 27,32 ****
--- 27,33 ----
  SunOS 4.0.Xi on i386				i[3456]86-*-sunos*
  Sony NEWS (68K) running NEWSOS 3.x		m68*-sony-sysv news
  ISI Optimum V (3.05) under 4.3bsd.		m68*-isi-*
+ Apple Macintosh (MPW) host			N/A
  
  stuff.c (Program to stuff files into a specially prepared space in kdb)
  kdb-start.c (Main loop for the standalone kernel debugger)
Index: TODO
===================================================================
RCS file: /cvs/src/src/gdb/TODO,v
retrieving revision 1.79
diff -p -r1.79 TODO
*** TODO	2001/04/17 21:20:48	1.79
--- TODO	2001/04/17 22:28:52
*************** MAINTAINERS file.
*** 160,167 ****
  	o	arm-* vs NetBSD's lack of ``unix''
  	o	arm-* vs IRIX (see below)
  
- 	o	delete mpw?
- 
  -- 2001-03-15
  
  			Obsolete some targets.
--- 160,165 ----
*************** Steps:		   
*** 201,206 ****
--- 199,206 ----
  		  powerpc-*-netware*	powerpc  -	  ppc-nw     yes
  		  w65-*-*		w65	 -	  w65        yes
  		  i[3456]86-*-sunos*	i386	 sun386	  sun386     yes
+ 		  mpw			m68k	 mpw	  mpw	     yes
+ 		  mpw			powerpc	 mpw	  mpw	     yes
  
  		(DONE)
  
Index: event-top.c
===================================================================
RCS file: /cvs/src/src/gdb/event-top.c,v
retrieving revision 1.13
diff -p -r1.13 event-top.c
*** event-top.c	2001/03/06 08:21:07	1.13
--- event-top.c	2001/04/17 22:28:54
*************** display_gdb_prompt (char *new_prompt)
*** 302,312 ****
           the user is not accounted for.  */
        fputs_unfiltered (new_prompt, gdb_stdout);
  
! #ifdef MPW
!       /* Move to a new line so the entered line doesn't have a prompt
!          on the front of it. */
!       fputs_unfiltered ("\n", gdb_stdout);
! #endif /* MPW */
        gdb_flush (gdb_stdout);
      }
  }
--- 302,312 ----
           the user is not accounted for.  */
        fputs_unfiltered (new_prompt, gdb_stdout);
  
!       /* OBSOLETE #ifdef MPW */
!       /* OBSOLETE       /* Move to a new line so the entered line doesn't have a prompt */
!       /* OBSOLETE          on the front of it. */
!       /* OBSOLETE       fputs_unfiltered ("\n", gdb_stdout); */
!       /* OBSOLETE #endif /* MPW */ */
        gdb_flush (gdb_stdout);
      }
  }
Index: source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.12
diff -p -r1.12 source.c
*** source.c	2001/04/05 02:02:13	1.12
--- source.c	2001/04/17 22:28:56
*************** done:
*** 609,630 ****
  				     filename, NULL);
  	}
      }
! #ifdef MPW
!   /* This is a debugging hack that can go away when all combinations
!      of Mac and Unix names are handled reasonably.  */
!   {
!     extern int debug_openp;
! 
!     if (debug_openp)
!       {
! 	printf ("openp on %s, path %s mode %d prot %d\n  returned %d",
! 		string, path, mode, prot, fd);
! 	if (*filename_opened)
! 	  printf (" (filename is %s)", *filename_opened);
! 	printf ("\n");
!       }
!   }
! #endif /* MPW */
  
    return fd;
  }
--- 609,630 ----
  				     filename, NULL);
  	}
      }
!   /* OBSOLETE #ifdef MPW  */
!   /* OBSOLETE   /* This is a debugging hack that can go away when all combinations */
!   /* OBSOLETE      of Mac and Unix names are handled reasonably.  */
!   /* OBSOLETE   { */
!   /* OBSOLETE     extern int debug_openp; */
!   /* OBSOLETE  */
!   /* OBSOLETE     if (debug_openp) */
!   /* OBSOLETE       { */
!   /* OBSOLETE 	printf ("openp on %s, path %s mode %d prot %d\n  returned %d", */
!   /* OBSOLETE 		string, path, mode, prot, fd); */
!   /* OBSOLETE 	if (*filename_opened) */
!   /* OBSOLETE 	  printf (" (filename is %s)", *filename_opened); */
!   /* OBSOLETE 	printf ("\n"); */
!   /* OBSOLETE       } */
!   /* OBSOLETE   } */
!   /* OBSOLETE #endif  *//* MPW */
  
    return fd;
  }
*************** open_source_file (struct symtab *s)
*** 710,731 ****
        if (p != s->filename)
  	result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname);
      }
! #ifdef MPW
!   if (result < 0)
!     {
!       /* Didn't work.  Try using just the MPW basename. */
!       p = (char *) mpw_basename (s->filename);
!       if (p != s->filename)
! 	result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname);
!     }
!   if (result < 0)
!     {
!       /* Didn't work.  Try using the mixed Unix/MPW basename. */
!       p = (char *) mpw_mixed_basename (s->filename);
!       if (p != s->filename)
! 	result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname);
!     }
! #endif /* MPW */
  
    if (result >= 0)
      {
--- 710,731 ----
        if (p != s->filename)
  	result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname);
      }
!   /* OBSOLETE #ifdef MPW */
!   /* OBSOLETE   if (result < 0) */
!   /* OBSOLETE     { */
!   /* OBSOLETE       /* Didn't work.  Try using just the MPW basename. */
!   /* OBSOLETE       p = (char *) mpw_basename (s->filename); */
!   /* OBSOLETE       if (p != s->filename) */
!   /* OBSOLETE 	result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname); */
!   /* OBSOLETE     } */
!   /* OBSOLETE   if (result < 0) */
!   /* OBSOLETE     { */
!   /* OBSOLETE       /* Didn't work.  Try using the mixed Unix/MPW basename. */
!   /* OBSOLETE       p = (char *) mpw_mixed_basename (s->filename); */
!   /* OBSOLETE       if (p != s->filename) */
!   /* OBSOLETE 	result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname); */
!   /* OBSOLETE     } */
!   /* OBSOLETE #endif /* MPW */
  
    if (result >= 0)
      {
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.31
diff -p -r1.31 top.c
*** top.c	2001/04/05 15:19:42	1.31
--- top.c	2001/04/17 22:28:56
*************** gdb_readline (char *prompt_arg)
*** 1001,1011 ****
           character position to be off, since the newline we read from
           the user is not accounted for.  */
        fputs_unfiltered (prompt_arg, gdb_stdout);
! #ifdef MPW
!       /* Move to a new line so the entered line doesn't have a prompt
!          on the front of it. */
!       fputs_unfiltered ("\n", gdb_stdout);
! #endif /* MPW */
        gdb_flush (gdb_stdout);
      }
  
--- 1001,1011 ----
           character position to be off, since the newline we read from
           the user is not accounted for.  */
        fputs_unfiltered (prompt_arg, gdb_stdout);
!       /* OBSOLETE #ifdef MPW */
!       /* OBSOLETE          Move to a new line so the entered line doesn't have a prompt */
!       /* OBSOLETE          on the front of it. */
!       /* OBSOLETE       fputs_unfiltered ("\n", gdb_stdout); */
!       /* OBSOLETE #endif /* MPW */
        gdb_flush (gdb_stdout);
      }
  
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.39
diff -p -r1.39 utils.c
*** utils.c	2001/03/23 23:39:57	1.39
--- utils.c	2001/04/17 22:29:03
*************** query (char *ctlstr,...)
*** 1262,1272 ****
    /* Automatically answer "yes" if input is not from a terminal.  */
    if (!input_from_terminal_p ())
      return 1;
! #ifdef MPW
!   /* FIXME Automatically answer "yes" if called from MacGDB.  */
!   if (mac_app)
!     return 1;
! #endif /* MPW */
  
    while (1)
      {
--- 1262,1272 ----
    /* Automatically answer "yes" if input is not from a terminal.  */
    if (!input_from_terminal_p ())
      return 1;
!   /* OBSOLETE #ifdef MPW */
!   /* OBSOLETE   /* FIXME Automatically answer "yes" if called from MacGDB.  */
!   /* OBSOLETE   if (mac_app) */
!   /* OBSOLETE     return 1; */
!   /* OBSOLETE #endif MPW */
  
    while (1)
      {
*************** query (char *ctlstr,...)
*** 1282,1293 ****
        if (annotation_level > 1)
  	printf_filtered ("\n\032\032query\n");
  
! #ifdef MPW
!       /* If not in MacGDB, move to a new line so the entered line doesn't
!          have a prompt on the front of it. */
!       if (!mac_app)
! 	fputs_unfiltered ("\n", gdb_stdout);
! #endif /* MPW */
  
        wrap_here ("");
        gdb_flush (gdb_stdout);
--- 1282,1293 ----
        if (annotation_level > 1)
  	printf_filtered ("\n\032\032query\n");
  
!       /* OBSOLETE #ifdef MPW */
!       /* OBSOLETE       /* If not in MacGDB, move to a new line so the entered line doesn't */
!       /* OBSOLETE          have a prompt on the front of it. */ */
!       /* OBSOLETE       if (!mac_app) */
!       /* OBSOLETE 	fputs_unfiltered ("\n", gdb_stdout); */
!       /* OBSOLETE #endif /* MPW */ */
  
        wrap_here ("");
        gdb_flush (gdb_stdout);
*************** init_page_info (void)
*** 1562,1568 ****
        lines_per_page = 24;
        chars_per_line = 80;
  
! #if !defined (MPW) && !defined (_WIN32)
        /* No termcap under MPW, although might be cool to do something
           by looking at worksheet or console window sizes. */
        /* Initialize the screen height and width from termcap.  */
--- 1562,1568 ----
        lines_per_page = 24;
        chars_per_line = 80;
  
! #if !defined (_WIN32)
        /* No termcap under MPW, although might be cool to do something
           by looking at worksheet or console window sizes. */
        /* Initialize the screen height and width from termcap.  */
From ischis2@home.com Tue Apr 17 16:38:00 2001
From: Stephen Smith <ischis2@home.com>
To: gdb-patches@sourceware.cygnus.com
Subject: shared libraries and a remote target
Date: Tue, 17 Apr 2001 16:38:00 -0000
Message-id: <3ADCD4F9.5D99D35D@home.com>
X-SW-Source: 2001-04/msg00185.html
Content-length: 18202

Here are the patches that I used to get a working version of GDB that would support shared libraries on a remote target.

Kevin said that I should send the patches now:

> It's okay to send the patch to gdb-patches anyway.  You'll get
> feedback on what (if anything) will need to be changed before it
> can go into the mainline sources.
>
>Kevin

I made the changes as self-contained as possible so that the side effects would be minimized.

sps

---------------------------- patches -------------------------

diff -r -P -c -w -b -B insight-20010306-orig/gdb/main.c insight-20010306/gdb/main.c

*** insight-20010306-orig/gdb/main.c Fri Jan 26 17:43:25 2001
--- insight-20010306/gdb/main.c Thu Apr 12 15:20:01 2001
***************
*** 283,288 ****
--- 283,290 ----
        {"windows", no_argument, &use_windows, 1},
        {"statistics", no_argument, 0, 13},
        {"write", no_argument, &write_files, 1},
+       {"remote-shared-libs", no_argument, &remote_shared_libs, 1},
+       {"no-remote-shared-libs", no_argument, &remote_shared_libs, 0},
  /* Allow machine descriptions to add more options... */
  #ifdef ADDITIONAL_OPTIONS
        ADDITIONAL_OPTIONS
diff -r -P -c -w -b -B insight-20010306-orig/gdb/remote.c insight-20010306/gdb/remote.c
*** insight-20010306-orig/gdb/remote.c Wed Feb 28 18:39:21 2001
--- insight-20010306/gdb/remote.c Thu Apr 12 15:59:32 2001
***************
*** 48,53 ****
--- 48,54 ----
  #include "inf-loop.h"

  #include <signal.h>
+ #include <string.h>
  #include "serial.h"

  /* Prototypes for local functions */
***************
*** 195,200 ****
--- 196,205 ----

  static void update_packet_config (struct packet_config *config);

+ static void remote_get_list_of_shared_libraries(void);
+
+ static char* findFile(char* basename);
+
  /* Define the target subroutine names */

  void open_remote_target (char *, int, struct target_ops *, int);
***************
*** 2782,2788 ****
--- 2787,2795 ----
            continue;
          }
      }
+
  got_status:
+   remote_get_list_of_shared_libraries();
    if (thread_num != -1)
      {
        return thread_num;
***************
*** 3007,3012 ****
--- 3014,3020 ----
          }
      }
  got_status:
+   remote_get_list_of_shared_libraries();
    if (thread_num != -1)
      {
        return thread_num;
***************
*** 5701,5704 ****
--- 5709,5845 ----
    add_cmd ("Z-packet", class_obscure, show_remote_protocol_Z_packet_cmd,
             "Show use of remote protocol `Z' packets ",
             &remote_show_cmdlist);
+ }
+
+
+ static void
+ remote_get_list_of_shared_libraries (void)
+ {
+   extern int remote_shared_libs;
+
+   // This is a counter that gets used so that we don't run while the GDB is initializing
+   static unsigned initializationBlock = 0;
+
+   /* We can't just check for a starting E for errors because the file name may start with one*/
+   char *error_string = "ENN: ";
+
+   char *buf = alloca (PBUFSIZ);
+   static char remote_does_not_suport = 0; /* If the remote doesn't support this, then we will
+                                              turn off this function */
+
+   // Has the user asked for this feature:  Command line option: remote-shared-libs
+   if( remote_shared_libs == 0 )
+      return;
+
+
+   /* The first times through, I don't believe we want to do this because gdb isn't completely initialized.
+      With out this flag add_symbol_file_command() hangs. */
+   if( initializationBlock < 2 )
+   {
+      ++initializationBlock;
+      return;
+   }
+
+   if ( remote_does_not_suport ) /* We've checked this and the stub doesn't support this functionality */
+   {
+      return;
+   }
+
+   putpkt ("qNewLibraries");
+   getpkt (buf, PBUFSIZ, 0);
+
+   if (buf[0] == '\000')
+      {
+        remote_does_not_suport = 1;  /* short circuit this function */
+        return;                      /* Return silently.  Stub doesn't support
+                                        this command. */
+      }
+
+   if (strncmp( buf, error_string, strlen(error_string)) == 0 )
+     {
+       warning ("Remote failure reply: %s", buf);
+       return;
+     }
+
+   if (buf[0] == '1') /* There are new shared libraries */
+     {
+         char *file = alloca (PBUFSIZ), *fqn;
+         int   address, values, firstSpace;
+
+         putpkt ("qLibraries");
+         getpkt (buf, PBUFSIZ, 0);
+
+         if (buf[0] == '\000')
+            {
+              remote_does_not_suport = 1;  /* short circuit this function */
+              return;                      /* Return silently.  Stub doesn't support
+                                              this command. */
+            }
+
+         if (strncmp( buf, error_string, strlen(error_string)) == 0 )
+            {
+              warning ("Remote failure reply: %s", buf);
+              return;
+            }
+
+         do
+            {   /*  buff should have the following layout:
+                       <filename> <textaddress> [-mapped] [-readnow] [-s <secname> <addr>]*
+                 */
+                values = sscanf( buf, "%s %x", file, &address );
+                if( values < 2) break; /* check to make sure we have a minimum number of fields */
+                firstSpace = strlen(file);
+                if( (fqn = findFile (file) ) != 0 )
+                {
+                   strcpy( file, fqn );
+                   strcat( file, &buf[firstSpace] );
+                   add_symbol_file_command( file, 0 );
+                }
+
+                /* Get the next file from remote */
+                putpkt ("qLibraries");
+                getpkt (buf, PBUFSIZ, 0);
+
+                /* Check for errors*/
+                if ( strncmp( buf, error_string, strlen(error_string)) == 0 )
+                  {
+                    warning ("Remote failure reply: %s", buf);
+                    break;
+                  }
+            } while (buf[0] != '\000');
+
+     }
+   else if (buf[0] == '0')
+     {
+       /* There are no new shared libraries */
+     }
+   else
+     {
+       warning ("Remote reply is unrecognized: %s", buf);
+       return;
+     }
+
+   return;
+ }
+
+ static char*
+ findFile (char* basename)
+ {
+   int found_file;
+   static char* filename;
+   /* Search the $PATH environment variable. */
+   found_file = openp (getenv ("PATH"), 1, basename, O_RDONLY, 0, &filename);
+
+   /* If not found, next search $LD_LIBRARY_PATH environment variable. */
+   if (found_file < 0 )
+     found_file = openp (getenv ("LD_LIBRARY_PATH"), 1, basename, O_RDONLY, 0, &filename);
+
+   /* We really don't want the file open here, we just wanted the side effects of
+      this function call.  If the file was opened, close it. */
+   if (found_file >= 0 )
+     close( found_file );
+   else
+     return 0; /* Report that a file wasn't found */
+
+   return filename;
  }
diff -r -P -c -w -b -B insight-20010306-orig/gdb/symfile.c insight-20010306/gdb/symfile.c
*** insight-20010306-orig/gdb/symfile.c Mon Feb 19 11:56:11 2001
--- insight-20010306/gdb/symfile.c Fri Mar 23 17:22:43 2001
***************
*** 110,117 ****

  static void load_command (char *, int);

- static void add_symbol_file_command (char *, int);
-
  static void add_shared_symbol_files_command (char *, int);

  static void cashier_psymtab (struct partial_symtab *);
--- 110,115 ----
***************
*** 1399,1405 ****
     value to use. We are now discontinuing this type of ad hoc syntax. */

  /* ARGSUSED */
! static void
  add_symbol_file_command (char *args, int from_tty)
  {
    char *filename = NULL;
--- 1397,1403 ----
     value to use. We are now discontinuing this type of ad hoc syntax. */

  /* ARGSUSED */
! void
  add_symbol_file_command (char *args, int from_tty)
  {
    char *filename = NULL;
diff -r -P -c -w -b -B insight-20010306-orig/gdb/symfile.h insight-20010306/gdb/symfile.h
*** insight-20010306-orig/gdb/symfile.h Fri Jan 26 17:43:25 2001
--- insight-20010306/gdb/symfile.h Fri Mar 23 15:42:56 2001
***************
*** 278,283 ****
--- 278,286 ----

  /* Clear GDB symbol tables. */
  extern void symbol_file_clear (int from_tty);
+
+ /* Add a file to the symbol table */
+ extern void add_symbol_file_command (char *args, int from_tty);

  /* From dwarfread.c */

diff -r -P -c -w -b -B insight-20010306-orig/gdb/top.c insight-20010306/gdb/top.c
*** insight-20010306-orig/gdb/top.c Mon Feb  5 21:17:03 2001
--- insight-20010306/gdb/top.c Fri Apr 13 08:57:33 2001
***************
*** 220,225 ****
--- 220,231 ----
     target is off and running, which gdb is doing something else. */
  int target_executing = 0;

+ /* This variable is added to control the loading of shared libraries
+    by a remote stub or by gdbserver.  The default is set to 0 so that
+    the behaviour will remain unchanged by default - i.e. we won't ask about
+    shared libraries.  */
+ int remote_shared_libs = 0;
+
  /* Level of control structure.  */
  static int control_level;

diff -r -P -c -w -b -B insight-20010306-orig/gdb/top.h insight-20010306/gdb/top.h
*** insight-20010306-orig/gdb/top.h Wed Jul  5 03:36:41 2000
--- insight-20010306/gdb/top.h Thu Apr 12 15:55:16 2001
***************
*** 54,59 ****
--- 54,60 ----
  /* From random places.  */
  extern int mapped_symbol_files;
  extern int readnow_symbol_files;
+ extern int remote_shared_libs;

  /* Perform _initialize initialization */
  extern void gdb_init (char *);
diff -r -P -c -w -b -B insight-20010306-orig/gdb/main.c insight-20010306/gdb/main.c
*** insight-20010306-orig/gdb/main.c Fri Jan 26 17:43:25 2001
--- insight-20010306/gdb/main.c Thu Apr 12 15:20:01 2001
***************
*** 283,288 ****
--- 283,290 ----
        {"windows", no_argument, &use_windows, 1},
        {"statistics", no_argument, 0, 13},
        {"write", no_argument, &write_files, 1},
+       {"remote-shared-libs", no_argument, &remote_shared_libs, 1},
+       {"no-remote-shared-libs", no_argument, &remote_shared_libs, 0},
  /* Allow machine descriptions to add more options... */
  #ifdef ADDITIONAL_OPTIONS
        ADDITIONAL_OPTIONS
diff -r -P -c -w -b -B insight-20010306-orig/gdb/remote.c insight-20010306/gdb/remote.c
*** insight-20010306-orig/gdb/remote.c Wed Feb 28 18:39:21 2001
--- insight-20010306/gdb/remote.c Thu Apr 12 15:59:32 2001
***************
*** 48,53 ****
--- 48,54 ----
  #include "inf-loop.h"

  #include <signal.h>
+ #include <string.h>
  #include "serial.h"

  /* Prototypes for local functions */
***************
*** 195,200 ****
--- 196,205 ----

  static void update_packet_config (struct packet_config *config);

+ static void remote_get_list_of_shared_libraries(void);
+
+ static char* findFile(char* basename);
+
  /* Define the target subroutine names */

  void open_remote_target (char *, int, struct target_ops *, int);
***************
*** 2782,2788 ****
--- 2787,2795 ----
            continue;
          }
      }
+
  got_status:
+   remote_get_list_of_shared_libraries();
    if (thread_num != -1)
      {
        return thread_num;
***************
*** 3007,3012 ****
--- 3014,3020 ----
          }
      }
  got_status:
+   remote_get_list_of_shared_libraries();
    if (thread_num != -1)
      {
        return thread_num;
***************
*** 5701,5704 ****
--- 5709,5845 ----
    add_cmd ("Z-packet", class_obscure, show_remote_protocol_Z_packet_cmd,
             "Show use of remote protocol `Z' packets ",
             &remote_show_cmdlist);
+ }
+
+
+ static void
+ remote_get_list_of_shared_libraries (void)
+ {
+   extern int remote_shared_libs;
+
+   // This is a counter that gets used so that we don't run while the GDB is initializing
+   static unsigned initializationBlock = 0;
+
+   /* We can't just check for a starting E for errors because the file name may start with one*/
+   char *error_string = "ENN: ";
+
+   char *buf = alloca (PBUFSIZ);
+   static char remote_does_not_suport = 0; /* If the remote doesn't support this, then we will
+                                              turn off this function */
+
+   // Has the user asked for this feature:  Command line option: remote-shared-libs
+   if( remote_shared_libs == 0 )
+      return;
+
+
+   /* The first times through, I don't believe we want to do this because gdb isn't completely initialized.
+      With out this flag add_symbol_file_command() hangs. */
+   if( initializationBlock < 2 )
+   {
+      ++initializationBlock;
+      return;
+   }
+
+   if ( remote_does_not_suport ) /* We've checked this and the stub doesn't support this functionality */
+   {
+      return;
+   }
+
+   putpkt ("qNewLibraries");
+   getpkt (buf, PBUFSIZ, 0);
+
+   if (buf[0] == '\000')
+      {
+        remote_does_not_suport = 1;  /* short circuit this function */
+        return;                      /* Return silently.  Stub doesn't support
+                                        this command. */
+      }
+
+   if (strncmp( buf, error_string, strlen(error_string)) == 0 )
+     {
+       warning ("Remote failure reply: %s", buf);
+       return;
+     }
+
+   if (buf[0] == '1') /* There are new shared libraries */
+     {
+         char *file = alloca (PBUFSIZ), *fqn;
+         int   address, values, firstSpace;
+
+         putpkt ("qLibraries");
+         getpkt (buf, PBUFSIZ, 0);
+
+         if (buf[0] == '\000')
+            {
+              remote_does_not_suport = 1;  /* short circuit this function */
+              return;                      /* Return silently.  Stub doesn't support
+                                              this command. */
+            }
+
+         if (strncmp( buf, error_string, strlen(error_string)) == 0 )
+            {
+              warning ("Remote failure reply: %s", buf);
+              return;
+            }
+
+         do
+            {   /*  buff should have the following layout:
+                       <filename> <textaddress> [-mapped] [-readnow] [-s <secname> <addr>]*
+                 */
+                values = sscanf( buf, "%s %x", file, &address );
+                if( values < 2) break; /* check to make sure we have a minimum number of fields */
+                firstSpace = strlen(file);
+                if( (fqn = findFile (file) ) != 0 )
+                {
+                   strcpy( file, fqn );
+                   strcat( file, &buf[firstSpace] );
+                   add_symbol_file_command( file, 0 );
+                }
+
+                /* Get the next file from remote */
+                putpkt ("qLibraries");
+                getpkt (buf, PBUFSIZ, 0);
+
+                /* Check for errors*/
+                if ( strncmp( buf, error_string, strlen(error_string)) == 0 )
+                  {
+                    warning ("Remote failure reply: %s", buf);
+                    break;
+                  }
+            } while (buf[0] != '\000');
+
+     }
+   else if (buf[0] == '0')
+     {
+       /* There are no new shared libraries */
+     }
+   else
+     {
+       warning ("Remote reply is unrecognized: %s", buf);
+       return;
+     }
+
+   return;
+ }
+
+ static char*
+ findFile (char* basename)
+ {
+   int found_file;
+   static char* filename;
+   /* Search the $PATH environment variable. */
+   found_file = openp (getenv ("PATH"), 1, basename, O_RDONLY, 0, &filename);
+
+   /* If not found, next search $LD_LIBRARY_PATH environment variable. */
+   if (found_file < 0 )
+     found_file = openp (getenv ("LD_LIBRARY_PATH"), 1, basename, O_RDONLY, 0, &filename);
+
+   /* We really don't want the file open here, we just wanted the side effects of
+      this function call.  If the file was opened, close it. */
+   if (found_file >= 0 )
+     close( found_file );
+   else
+     return 0; /* Report that a file wasn't found */
+
+   return filename;
  }
diff -r -P -c -w -b -B insight-20010306-orig/gdb/symfile.c insight-20010306/gdb/symfile.c
*** insight-20010306-orig/gdb/symfile.c Mon Feb 19 11:56:11 2001
--- insight-20010306/gdb/symfile.c Fri Mar 23 17:22:43 2001
***************
*** 110,117 ****

  static void load_command (char *, int);

- static void add_symbol_file_command (char *, int);
-
  static void add_shared_symbol_files_command (char *, int);

  static void cashier_psymtab (struct partial_symtab *);
--- 110,115 ----
***************
*** 1399,1405 ****
     value to use. We are now discontinuing this type of ad hoc syntax. */

  /* ARGSUSED */
! static void
  add_symbol_file_command (char *args, int from_tty)
  {
    char *filename = NULL;
--- 1397,1403 ----
     value to use. We are now discontinuing this type of ad hoc syntax. */

  /* ARGSUSED */
! void
  add_symbol_file_command (char *args, int from_tty)
  {
    char *filename = NULL;
diff -r -P -c -w -b -B insight-20010306-orig/gdb/symfile.h insight-20010306/gdb/symfile.h
*** insight-20010306-orig/gdb/symfile.h Fri Jan 26 17:43:25 2001
--- insight-20010306/gdb/symfile.h Fri Mar 23 15:42:56 2001
***************
*** 278,283 ****
--- 278,286 ----

  /* Clear GDB symbol tables. */
  extern void symbol_file_clear (int from_tty);
+
+ /* Add a file to the symbol table */
+ extern void add_symbol_file_command (char *args, int from_tty);

  /* From dwarfread.c */

diff -r -P -c -w -b -B insight-20010306-orig/gdb/top.c insight-20010306/gdb/top.c
*** insight-20010306-orig/gdb/top.c Mon Feb  5 21:17:03 2001
--- insight-20010306/gdb/top.c Fri Apr 13 08:57:33 2001
***************
*** 220,225 ****
--- 220,231 ----
     target is off and running, which gdb is doing something else. */
  int target_executing = 0;

+ /* This variable is added to control the loading of shared libraries
+    by a remote stub or by gdbserver.  The default is set to 0 so that
+    the behaviour will remain unchanged by default - i.e. we won't ask about
+    shared libraries.  */
+ int remote_shared_libs = 0;
+
  /* Level of control structure.  */
  static int control_level;

diff -r -P -c -w -b -B insight-20010306-orig/gdb/top.h insight-20010306/gdb/top.h
*** insight-20010306-orig/gdb/top.h Wed Jul  5 03:36:41 2000
--- insight-20010306/gdb/top.h Thu Apr 12 15:55:16 2001
***************
*** 54,59 ****
--- 54,60 ----
  /* From random places.  */
  extern int mapped_symbol_files;
  extern int readnow_symbol_files;
+ extern int remote_shared_libs;

  /* Perform _initialize initialization */
  extern void gdb_init (char *);


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Extend remote protocol to allow symbol look-up service.
  2001-04-17 16:29 [RFC] Extend remote protocol to allow symbol look-up service Michael Snyder
@ 2001-04-17 18:50 ` Jonathan Larmour
  2001-04-19 13:40 ` Jim Blandy
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Jonathan Larmour @ 2001-04-17 18:50 UTC (permalink / raw)
  To: msnyder; +Cc: gdb-patches

In article < 3ADCD1B8.772C5247@cygnus.com > you write:
>Surprising as  it may seem, there are circumstances when a remote
>target stub may need to know the values of symbols in the debuggee.
>The case that I'm working from is multi-threaded debugging under
>Solaris and Linux.  Both platforms make use of a debugging support
>library called libthread-db, which exports a debugging interface
>into the native thread library.  It shields the debugger from 
>knowledge about the thread library internals, but in return it 
>needs to know the addresses of thread library data objects in the
>child, so that it can go rooting around in them.

I had a very similar situation with the libremote work I was doing,
which involved grubbing around in the target. For libremote
to be able to ask for a symbol would have made life much easier
than what I ended up implementing. libremote can be put in a
difficult situation - it neither has the knowledge of the debugger
nor the knowledge of the target/executing program. It is mostly
just a conduit.

>The scheme that I propose is this: whenever the debugger detects
>a new shared library being loaded in the remote child process, 
>it will send a notification to the remote stub in the form of
>a 'Q' (miscelaneous set value) packet, like this:
>
>	QSharedObject:libc.so.1
>
>The target may as usual reply with an empty packet meaning
>"I don't understand", or with an "OK" acknowledgement, but
>in addition to those the target may reply with a request
>for the value of a symbol:
>
>	qSymbol:__pthread_max_threads

The situation I would have used it for had nothing to do with shared
libraries. I would much prefer it if the qSymbol could be received
at any point, and not just after a QSharedObject primitive.

Thanks,

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Extend remote protocol to allow symbol look-up service.
  2001-04-17 16:29 [RFC] Extend remote protocol to allow symbol look-up service Michael Snyder
  2001-04-17 18:50 ` Jonathan Larmour
@ 2001-04-19 13:40 ` Jim Blandy
  2001-04-19 15:07   ` Michael Snyder
  2001-04-21 16:35 ` Andrew Cagney
  2001-04-21 16:40 ` Andrew Cagney
  3 siblings, 1 reply; 10+ messages in thread
From: Jim Blandy @ 2001-04-19 13:40 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches, jtc

Michael Snyder <msnyder@cygnus.com> writes:
> Surprising as  it may seem, there are circumstances when a remote
> target stub may need to know the values of symbols in the debuggee.
> The case that I'm working from is multi-threaded debugging under
> Solaris and Linux.  Both platforms make use of a debugging support
> library called libthread-db, which exports a debugging interface
> into the native thread library.  It shields the debugger from 
> knowledge about the thread library internals, but in return it 
> needs to know the addresses of thread library data objects in the
> child, so that it can go rooting around in them.

This sounds half-baked.

libthread-db is something that gets linked into a debugger, not a
stub.  What is libthread-db doing getting linked into a stub?

And if it is on the stub, and there's some sort of dynamic linker
there on the target, why can't it ask the dynamic linker for the
symbol values?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Extend remote protocol to allow symbol look-up service.
  2001-04-19 13:40 ` Jim Blandy
@ 2001-04-19 15:07   ` Michael Snyder
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Snyder @ 2001-04-19 15:07 UTC (permalink / raw)
  To: Jim Blandy; +Cc: gdb-patches, jtc

Jim Blandy wrote:
> 
> Michael Snyder <msnyder@cygnus.com> writes:
> > Surprising as  it may seem, there are circumstances when a remote
> > target stub may need to know the values of symbols in the debuggee.
> > The case that I'm working from is multi-threaded debugging under
> > Solaris and Linux.  Both platforms make use of a debugging support
> > library called libthread-db, which exports a debugging interface
> > into the native thread library.  It shields the debugger from
> > knowledge about the thread library internals, but in return it
> > needs to know the addresses of thread library data objects in the
> > child, so that it can go rooting around in them.
> 
> This sounds half-baked.
> 
> libthread-db is something that gets linked into a debugger, not a
> stub.  What is libthread-db doing getting linked into a stub?

Because I'd have to add even more new protocol if I put it on 
the debugger side.  For example, when one thread stops and I need
to stop all the rest.  There's no way to express that in the 
remote protocol.  And even if there was, it would be too slow:
the threads would get all out of sync.

> And if it is on the stub, and there's some sort of dynamic linker
> there on the target, why can't it ask the dynamic linker for the
> symbol values?

Because I'm asking for symbols from the child, which is not
linked into the stub.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Extend remote protocol to allow symbol look-up service.
  2001-04-17 16:29 [RFC] Extend remote protocol to allow symbol look-up service Michael Snyder
  2001-04-17 18:50 ` Jonathan Larmour
  2001-04-19 13:40 ` Jim Blandy
@ 2001-04-21 16:35 ` Andrew Cagney
  2001-04-26 14:22   ` Michael Snyder
  2001-04-21 16:40 ` Andrew Cagney
  3 siblings, 1 reply; 10+ messages in thread
From: Andrew Cagney @ 2001-04-21 16:35 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches, jtc

Michael Snyder wrote:
[....]

The protocol appears to overlaps two separate but related operations -
shared library load and symbol load. If I remember right, a symbol can
also be loaded using things like ``(gdb) symbol file''.  Is the shared
library notification even needed and should this be tied to the shared
library hook?

What happens if the target program has no shared libraries?  Will the
target still get an oportunity to request a symbol?

Could a target encounter a situtation where it needed symbol values
before it could report back a program status?  The problem is very much
like the input/output cases where the target is wanting to nest a query
request within the normal packet flow.  Should input/output and this
query all use the same mechanism?

	Andrew


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Extend remote protocol to allow symbol look-up service.
  2001-04-17 16:29 [RFC] Extend remote protocol to allow symbol look-up service Michael Snyder
                   ` (2 preceding siblings ...)
  2001-04-21 16:35 ` Andrew Cagney
@ 2001-04-21 16:40 ` Andrew Cagney
  2001-04-26 14:26   ` Michael Snyder
  3 siblings, 1 reply; 10+ messages in thread
From: Andrew Cagney @ 2001-04-21 16:40 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches, jtc

Just FYI,

Some quick comments on the protocol as it currently stands.  I'd suggest
waiting until the actual protocol spec has been resolved first though.

	Andrew

--

>         QSharedObject:libc.so.1

Given that the replies are:

	""
	OK
	Some value

I would strongly prefer the ``q'' packet over the ``Q'' packet (I think
the latter is redundant :-).  The ``q'' packet implicitly allows a value
to be returned - which in turn gives the RPC mechanims that you're
implementing.

--

The symbol and file value is being passed as ascii text.  I think they
should be hex encoded so that we're 100% certain that they will never
contain unprintable or protocol data.  This was the rationale behind the
qRcmd packet carrying HEX data.

--

Is the protocol stateless?  That is, would repeating the query:

	qSymbol::__pthread_max_threads

always return the same value?

	Andrew


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Extend remote protocol to allow symbol look-up service.
  2001-04-21 16:35 ` Andrew Cagney
@ 2001-04-26 14:22   ` Michael Snyder
  2001-04-27  7:54     ` Andrew Cagney
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Snyder @ 2001-04-26 14:22 UTC (permalink / raw)
  To: Andrew Cagney, gdb-patches

Andrew Cagney wrote:
> 
> Michael Snyder wrote:
> [....]
> 
> The protocol appears to overlaps two separate but related operations -
> shared library load and symbol load. If I remember right, a symbol can
> also be loaded using things like ``(gdb) symbol file''.  Is the shared
> library notification even needed and should this be tied to the shared
> library hook?

The shared library notification from gdb to the target simply lets
the target know that new symbols may be available.  The target could
of course use the notification for other purposes (but I don't know
of any).  I could see extending the notification to cover the "symbol-file"
command as well, but since I don't need that, I might leave it for 
someone else to do.

> What happens if the target program has no shared libraries?  Will the
> target still get an oportunity to request a symbol?

No -- I'm aware of that short-coming, but haven't thought of a solution yet.
Perhaps I could send down a symbol file notification from remote_open?


> Could a target encounter a situtation where it needed symbol values
> before it could report back a program status?  The problem is very much
> like the input/output cases where the target is wanting to nest a query
> request within the normal packet flow.  Should input/output and this
> query all use the same mechanism?

I can't see it.  The target may need the symbols earlier, but until the
shared library is loaded, they aren't available.  Should the target just
keep polling gdb for the symbols?  That would be terribly inefficient.
This way, the target won't ask for them until there's at least some 
reason to believe that they might have become available.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Extend remote protocol to allow symbol look-up service.
  2001-04-21 16:40 ` Andrew Cagney
@ 2001-04-26 14:26   ` Michael Snyder
  2001-04-27  8:20     ` Andrew Cagney
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Snyder @ 2001-04-26 14:26 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches, jtc

Andrew Cagney wrote:
> 
> Just FYI,
> 
> Some quick comments on the protocol as it currently stands.  I'd suggest
> waiting until the actual protocol spec has been resolved first though.
> 
>         Andrew
> 
> --
> 
> >         QSharedObject:libc.so.1
> 
> Given that the replies are:
> 
>         ""
>         OK
>         Some value
> 
> I would strongly prefer the ``q'' packet over the ``Q'' packet (I think
> the latter is redundant :-).  The ``q'' packet implicitly allows a value
> to be returned - which in turn gives the RPC mechanims that you're
> implementing.

You keep calling it 'rpc'.  I don't see how it is rpc.  It's just a query.
But I don't mind changing it from 'Q' to 'q', even though it doesn't make
sense to me.  The shared library message is more of a notification than
a query, I think.

> The symbol and file value is being passed as ascii text.  I think they
> should be hex encoded so that we're 100% certain that they will never
> contain unprintable or protocol data.  This was the rationale behind the
> qRcmd packet carrying HEX data.

Does anyone else have an opinion?  I don't like unreadable messages.

> Is the protocol stateless?  That is, would repeating the query:
> 
>         qSymbol::__pthread_max_threads
> 
> always return the same value?

It's not stateless; both the target and the debugger have state.
On the debugger, the 'state' is whether the symbol is available or not.
On the target, the state is whether this symbol's value has been obtained.
Also whether it has been requested since the last shared library event.
The target should ask for a given symbol only once per shared library
event.  There won't be any harm in asking for the same symbol twice --
except for the possibility of getting into an infinite loop.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Extend remote protocol to allow symbol look-up service.
  2001-04-26 14:22   ` Michael Snyder
@ 2001-04-27  7:54     ` Andrew Cagney
  0 siblings, 0 replies; 10+ messages in thread
From: Andrew Cagney @ 2001-04-27  7:54 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches

[this really belongs on gdb@]

> > Could a target encounter a situtation where it needed symbol values
> > before it could report back a program status?  The problem is very much
> > like the input/output cases where the target is wanting to nest a query
> > request within the normal packet flow.  Should input/output and this
> > query all use the same mechanism?
> 
> I can't see it.  The target may need the symbols earlier, but until the
> shared library is loaded, they aren't available.  Should the target just
> keep polling gdb for the symbols?  That would be terribly inefficient.
> This way, the target won't ask for them until there's at least some
> reason to believe that they might have become available.

Ah, yes, ok.  It's a trade off between:

	a)	GDB learning new symbol info
		and prompting the target.

	b)	The target finding it would
		like a symbol and prompting
		GDB.

For case a) could there be a situtation where, when GDB discovers more
symbols and informs the target but the target doesn't yet know all the
symbols that it will need?  Given you've got your thread-db code working
I'd guess that you've solved this problem for your case.

--

SinceGDB is prompting the target is because it has discovered new symbol
info rather than it has loaded a shared library, should the initiation
be a message saying ``psst target, wana buy some new symbol info?''
rather than ``so, nudge nudge, wink wink, its a shared library, ...''. 
That way the exact purpose of the query is clear.  It should also mean
that the cases:

	o	static program with all
		symbols available

	o	symbols loaded via symbol
		file or such command.

can eventually be fixed without a further protocol change.  In each
case, since new symbol info has become available, the target should be
notified.

	Andrew


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Extend remote protocol to allow symbol look-up service.
  2001-04-26 14:26   ` Michael Snyder
@ 2001-04-27  8:20     ` Andrew Cagney
  0 siblings, 0 replies; 10+ messages in thread
From: Andrew Cagney @ 2001-04-27  8:20 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches, jtc

> Does anyone else have an opinion?  I don't like unreadable messages.

The packet intent is still readable, just not the symbol.  I know its a
pain.  However I'd rather that pain then have to later go and
re-implement the packet because it did turn up problems. Look at the
constant retro-fitting required by the X packet.

> > Is the protocol stateless?  That is, would repeating the query:
> >
> >         qSymbol::__pthread_max_threads
> >
> > always return the same value?

Oops, not quite the right question.

> It's not stateless; both the target and the debugger have state.
> On the debugger, the 'state' is whether the symbol is available or not.
> On the target, the state is whether this symbol's value has been obtained.
> Also whether it has been requested since the last shared library event.
> The target should ask for a given symbol only once per shared library
> event.  There won't be any harm in asking for the same symbol twice --
> except for the possibility of getting into an infinite loop.

Would the following sequence (first line is GDB -> target) occure:

	-> qSymbol:4321:sym1
	<- qSymbol:sym2

	-> qSymbol:4321:sym1
	<- qSymbol:sym2

	-> qSymbol:1234:sym2
	<- qSymbol:sym3

From what you've said, I think that is the case and that I think that is
the correct behavour. The target should be using the last symbol it
received from GDB to determine the next symbol.  It should not be solely
reliant on internal state.

Compare this to the ThreadInfo packet :-(

--

What about a simplification along the lines of:

	-> qSymbol
	<- ""	Don't know what you're talking about
	<- OK	Thanks, that's all
	<- HEX-SYMBOL
		please try to tell me the value of the symbol.

	-> qSymbol:BE-HEX-VAL:HEX-SYMBOL
	<- ""	Don't know what you're talking about
	<- OK	Thanks, that's all
	<- HEX-SYMBOL
		please try to tell me the value of the symbol.

With a note that the target must use the packet contents when
determining the next symbol to request query.

	Andrew


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2001-04-27  8:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-17 16:29 [RFC] Extend remote protocol to allow symbol look-up service Michael Snyder
2001-04-17 18:50 ` Jonathan Larmour
2001-04-19 13:40 ` Jim Blandy
2001-04-19 15:07   ` Michael Snyder
2001-04-21 16:35 ` Andrew Cagney
2001-04-26 14:22   ` Michael Snyder
2001-04-27  7:54     ` Andrew Cagney
2001-04-21 16:40 ` Andrew Cagney
2001-04-26 14:26   ` Michael Snyder
2001-04-27  8:20     ` Andrew Cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox