This is the mail archive of the gdb-patches@sources.redhat.com 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]

[RFA] Remote symbol lookup protocol (resubmit)


This is a new submission based on feedback, and supercedes all previous
submissions.  This addition to the gdb protocol allows gdb to serve
symbol lookup requests from a remote target.  The debugger will initiate
the transaction by letting the target know that the debugger is ready to
accept symbol lookup requests.  The target may then reply with a symbol
lookup request, or "OK" if the target does not need any symbol lookups
(or of course an empty packet if the target has no idea what gdb is
talking about).

The typical transaction would look like this:

gdb:    qSymbol::
target: qSymbol:<first desired symbol>
gdb:    qSymbol:<value>:<first desired symbol>
target: qSymbol:<next desired symbol>
[...]
target: qSymbol:<last desired symbol>
gdb:    qSymbol:<value>:<last desired symbol>
target: OK

The <value> field may be empty if gdb is not able to find a 
value for the requested symbol.

Eli -- documentation is included.  ;-)
2001-06-12  Michael Snyder  <msnyder@redhat.com>

	* remote.c (show_remote_protocol_qSymbol_packet_cmd, 
	set_remote_protocol_qSymbol_packet_cmd): New functions.
	(init_all_packet_configs, show_remote_cmd): Add qSymbol packet.
	(remote_check_symbols): New function.  Implement qSymbol packet, 
	allowing target to request symbol lookup service from gdb.
	(remote_open_1, remote_async_open_1): Call remote_check_symbols,
	allowing symbol lookup from exec_bfd on connection to target.
	(remote_new_objfile): New function.  Catch new objfile notifications
	from shared library module, and call remote_check_symbols.
	(_initialize_remote): Hook remote_new_objfile into the shared
	library notification chain.  Add "set remote symbol-lookup" command.

2001-06-13  Michael Snyder  <msnyder@redhat.com>

	* gdb.texinfo (Protocol): Add doc for new packet "qSymbol:".

Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.55
diff -c -3 -p -r1.55 remote.c
*** remote.c	2001/05/25 17:46:33	1.55
--- remote.c	2001/06/13 18:04:27
*************** static void record_currthread (int currt
*** 188,196 ****
  
  static int fromhex (int a);
  
! static int hex2bin (const char *hex, char *bin, int);
  
! static int bin2hex (const char *bin, char *hex, int);
  
  static int putpkt_binary (char *buf, int cnt);
  
--- 188,196 ----
  
  static int fromhex (int a);
  
! static int hex2bin (const char *hex, char *bin, int count);
  
! static int bin2hex (const char *bin, char *hex, int count);
  
  static int putpkt_binary (char *buf, int cnt);
  
*************** packet_ok (const char *buf, struct packe
*** 670,675 ****
--- 670,691 ----
      }
  }
  
+ /* Should we try the 'qSymbol' (target symbol lookup service) request? */
+ static struct packet_config remote_protocol_qSymbol;
+ 
+ static void
+ set_remote_protocol_qSymbol_packet_cmd (char *args, int from_tty,
+ 				  struct cmd_list_element *c)
+ {
+   update_packet_config (&remote_protocol_qSymbol);
+ }
+ 
+ static void
+ show_remote_protocol_qSymbol_packet_cmd (char *args, int from_tty)
+ {
+   show_packet_config_cmd (&remote_protocol_qSymbol);
+ }
+ 
  /* Should we try the 'e' (step over range) request? */
  static struct packet_config remote_protocol_e;
  
*************** init_all_packet_configs (void)
*** 2070,2075 ****
--- 2086,2092 ----
    update_packet_config (&remote_protocol_e);
    update_packet_config (&remote_protocol_E);
    update_packet_config (&remote_protocol_P);
+   update_packet_config (&remote_protocol_qSymbol);
    for (i = 0; i < NR_Z_PACKET_TYPES; i++)
      update_packet_config (&remote_protocol_Z[i]);
    /* Force remote_write_bytes to check whether target supports binary
*************** init_all_packet_configs (void)
*** 2077,2083 ****
--- 2094,2138 ----
    update_packet_config (&remote_protocol_binary_download);
  }
  
+ /* Symbol look-up. */
+ 
  static void
+ remote_check_symbols (struct objfile *objfile)
+ {
+   char *msg, *reply, *tmp;
+   struct minimal_symbol *sym;
+   int end;
+ 
+   if (remote_protocol_qSymbol.support == PACKET_DISABLE)
+     return;
+ 
+   msg   = alloca (PBUFSIZ);
+   reply = alloca (PBUFSIZ);
+ 
+   /* Invite target to request symbol lookups. */
+ 
+   putpkt ("qSymbol::");
+   getpkt (reply, PBUFSIZ, 0);
+   packet_ok (reply, &remote_protocol_qSymbol);
+ 
+   while (strncmp (reply, "qSymbol:", 8) == 0)
+     {
+       tmp = &reply[8];
+       end = hex2bin (tmp, msg, strlen (tmp) / 2);
+       msg[end] = '\0';
+       sym = lookup_minimal_symbol (msg, 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);
+     }
+ }
+ 
+ static void
  remote_open_1 (char *name, int from_tty, struct target_ops *target,
  	       int extended_p)
  {
*************** serial device is attached to the remote 
*** 2169,2175 ****
  
    /* Set up to detect and load shared libraries. */
    if (exec_bfd) 	/* No use without an exec file. */
!     SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
  #endif
  }
  
--- 2224,2233 ----
  
    /* Set up to detect and load shared libraries. */
    if (exec_bfd) 	/* No use without an exec file. */
!     {
!       SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
!       remote_check_symbols (symfile_objfile);
!     }
  #endif
  }
  
*************** serial device is attached to the remote 
*** 2279,2285 ****
  
    /* Set up to detect and load shared libraries. */
    if (exec_bfd) 	/* No use without an exec file. */
!     SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
  #endif
  }
  
--- 2337,2346 ----
  
    /* Set up to detect and load shared libraries. */
    if (exec_bfd) 	/* No use without an exec file. */
!     {
!       SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
!       remote_check_symbols (symfile_objfile);
!     }
  #endif
  }
  
*************** Specify the serial device it is connecte
*** 5705,5711 ****
  static void
  set_remote_cmd (char *args, int from_tty)
  {
-   
  }
  
  static void
--- 5766,5771 ----
*************** show_remote_cmd (char *args, int from_tt
*** 5716,5721 ****
--- 5776,5782 ----
    show_remote_protocol_e_packet_cmd (args, from_tty);
    show_remote_protocol_E_packet_cmd (args, from_tty);
    show_remote_protocol_P_packet_cmd (args, from_tty);
+   show_remote_protocol_qSymbol_packet_cmd (args, from_tty);
    show_remote_protocol_binary_download_cmd (args, from_tty);
  }
  
*************** build_remote_gdbarch_data (void)
*** 5729,5734 ****
--- 5790,5812 ----
    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)
+ {
+   if (remote_desc != 0)		/* Have a remote connection */
+     {
+       remote_check_symbols (objfile);
+     }
+   /* 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)
*** 5759,5764 ****
--- 5837,5846 ----
    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 ();
  #endif
*************** in a memory packet.\n",
*** 5858,5863 ****
--- 5940,5952 ----
  
    add_info ("remote-process", remote_info_process,
  	    "Query the remote system for process info.");
+ 
+   add_packet_config_cmd (&remote_protocol_qSymbol,
+ 			 "qSymbol", "symbol-lookup",
+ 			 set_remote_protocol_qSymbol_packet_cmd,
+ 			 show_remote_protocol_qSymbol_packet_cmd,
+ 			 &remote_set_cmdlist, &remote_show_cmdlist,
+ 			 0);
  
    add_packet_config_cmd (&remote_protocol_e,
  			 "e", "step-over-range",
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.39
diff -c -3 -p -r1.39 gdb.texinfo
*** gdb.texinfo	2001/06/13 08:40:22	1.39
--- gdb.texinfo	2001/06/13 18:04:29
*************** Indicate a badly formed request.
*** 10407,10412 ****
--- 10407,10458 ----
  @tab
  When @samp{q}@samp{Rcmd} is not recognized.
  
+ @item symbol lookup
+ @tab @code{q}@code{Symbol::}
+ @tab
+ Notify the target that @value{GDBN} is prepared to serve symbol lookup
+ requests.  Accept requests from the target for the values of symbols.
+ @item
+ @tab
+ @tab
+ @item
+ @tab reply @code{OK}
+ @tab
+ The target does not need to look up any (more) symbols.
+ @item
+ @tab reply @code{q}@code{Symbol:}@var{sym_name}
+ @tab
+ The target requests the value of symbol @var{sym_name} (hex encoded).  
+ @value{GDBN} may provide the value by using the 
+ @code{q}@code{Symbol:}@var{sym_value}:@var{sym_name}
+ message, described below.
+ 
+ @item symbol value
+ @tab @code{q}@code{Symbol:}@var{sym_value}:@var{sym_name}
+ @tab
+ Set the value of SYM_NAME to SYM_VALUE.
+ @item
+ @tab
+ @tab
+ @var{sym_name} (hex encoded) is the name of a symbol whose value
+ the target has previously requested.
+ @item
+ @tab
+ @tab
+ @var{sym_value} (hex) is the value for symbol @var{sym_name}.
+ If @value{GDBN} cannot supply a value for @var{sym_name}, then this
+ field will be empty.
+ @item
+ @tab reply @code{OK}
+ @tab
+ The target does not need to look up any (more) symbols.
+ @item
+ @tab reply @code{q}@code{Symbol:}@var{sym_name}
+ @tab
+ The target requests the value of a new symbol @var{sym_name} (hex encoded).
+ @value{GDBN} will continue to supply the values of symbols (if available),
+ until the target ceases to request them.
+ 
  @end multitable
  
  The following @samp{g}/@samp{G} packets have previously been defined.


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