Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* shared libraries and a remote target
@ 2001-07-18 10:54 Stephen Smith
  2001-07-18 11:44 ` Elena Zannoni
  0 siblings, 1 reply; 14+ messages in thread
From: Stephen Smith @ 2001-07-18 10:54 UTC (permalink / raw)
  To: Andrew Cagney, GDB patches, Kevin Buettner

I am re-submitting the patch contained in this email.  The the last of the discussion  is at
     http://sources.redhat.com/ml/gdb/2001-03/msg00234.html

and the original patch submittal is at

    http://sources.redhat.com/ml/gdb-patches/2001-04/msg00185.html

The patches still apply cleanly to the development tree - I tried this morning.

Thanks
sps


    * configure.tgt  add i*86-*-pe* target to be mapped to embed
    * main.c         add remote-shared-libs and no-remote-shared-libs switches to gdb
    * remote.c       add functions - remote_get_list_of_shared_libraries and findFile
                     to support an optional extention to the remote protocol
                     which is enabled with the remote-shared-libs switch.  The default
                     is disabled.
    * symfile.c      make add_symbol_file_command visible visible to functions outside
                     of symfile.c so that remote_get_list_of_shared_libraries can call it.
    * symfile.h      ditto
    * top.c          add the remote_shared_libs variable to hold the state of the
                     remote-shared-libs and no-remote-shared-libs switches.  This variable is
                     used in remote.c
    * top.h          ditto


Index: configure.tgt
===================================================================
RCS file: /cvs/src/src/gdb/configure.tgt,v
retrieving revision 1.33
diff -u -p -r1.33 configure.tgt
--- configure.tgt 2001/07/16 08:52:41 1.33
+++ configure.tgt 2001/07/18 16:52:16
@@ -125,6 +125,7 @@ i[3456]86-*-netware*) gdb_target=i386nw
   configdirs="${configdirs} nlm" ;;
 i[3456]86-*-osf1mk*) gdb_target=i386mk ;;
 i[3456]86-*-cygwin*) gdb_target=cygwin  ;;
+i[3456]86-*-pe*) gdb_target=embed   ;;
 i[3456]86-*-vxworks*) gdb_target=vxworks ;;

 i960-*-bout*)  gdb_target=vxworks960 ;;
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.12
diff -u -p -r1.12 main.c
--- main.c 2001/07/14 18:59:07 1.12
+++ main.c 2001/07/18 16:52:20
@@ -264,6 +264,8 @@ captured_main (void *data)
       {"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
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.61
diff -u -p -r1.61 remote.c
--- remote.c 2001/07/17 01:23:44 1.61
+++ remote.c 2001/07/18 16:52:25
@@ -48,6 +48,7 @@
 #include "inf-loop.h"

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

 #include "gdbcore.h" /* for exec_bfd */
@@ -202,6 +203,10 @@ static void show_packet_config_cmd (stru

 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);
@@ -3061,7 +3066,9 @@ Packet Dropped");
    continue;
  }
     }
+
 got_status:
+  remote_get_list_of_shared_libraries();
   if (thread_num != -1)
     {
       return pid_to_ptid (thread_num);
@@ -3284,6 +3291,7 @@ Packet Dropped");
  }
     }
 got_status:
+  remote_get_list_of_shared_libraries();
   if (thread_num != -1)
     {
       return pid_to_ptid (thread_num);
@@ -6015,4 +6023,136 @@ Set use of remote protocol `Z' packets",
   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;
 }
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.36
diff -u -p -r1.36 symfile.c
--- symfile.c 2001/07/15 18:57:06 1.36
+++ symfile.c 2001/07/18 16:52:26
@@ -112,8 +112,6 @@ static void load_command (char *, int);

 static void symbol_file_add_main_1 (char *args, int from_tty, int flags);

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

 static void cashier_psymtab (struct partial_symtab *);
@@ -1410,7 +1408,7 @@ print_transfer_performance (struct ui_fi
    value to use. We are now discontinuing this type of ad hoc syntax. */

 /* ARGSUSED */
-static void
+void
 add_symbol_file_command (char *args, int from_tty)
 {
   char *filename = NULL;
Index: symfile.h
===================================================================
RCS file: /cvs/src/src/gdb/symfile.h,v
retrieving revision 1.9
diff -u -p -r1.9 symfile.h
--- symfile.h 2001/03/06 08:21:17 1.9
+++ symfile.h 2001/07/18 16:52:27
@@ -280,6 +280,9 @@ extern void symbol_file_add_main (char *
 /* 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 */

 extern void
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.41
diff -u -p -r1.41 top.c
--- top.c 2001/07/17 17:25:14 1.41
+++ top.c 2001/07/18 16:52:32
@@ -165,6 +165,12 @@ int remote_debug = 0;
    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;

Index: top.h
===================================================================
RCS file: /cvs/src/src/gdb/top.h,v
retrieving revision 1.5
diff -u -p -r1.5 top.h
--- top.h 2001/03/06 08:21:17 1.5
+++ top.h 2001/07/18 16:52:32
@@ -55,6 +55,7 @@ extern void set_prompt (char *);
 /* 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] 14+ messages in thread

* Re: shared libraries and a remote target
  2001-07-18 10:54 shared libraries and a remote target Stephen Smith
@ 2001-07-18 11:44 ` Elena Zannoni
  2001-07-18 12:13   ` Stephen Smith
                     ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Elena Zannoni @ 2001-07-18 11:44 UTC (permalink / raw)
  To: Stephen Smith; +Cc: Andrew Cagney, GDB patches, Kevin Buettner

Stephen Smith writes:
 > I am re-submitting the patch contained in this email.  The the last of the discussion  is at
 >      http://sources.redhat.com/ml/gdb/2001-03/msg00234.html
 > 
 > and the original patch submittal is at
 > 
 >     http://sources.redhat.com/ml/gdb-patches/2001-04/msg00185.html
 > 
 > The patches still apply cleanly to the development tree - I tried this morning.
 > 
 > Thanks
 > sps
 > 

Hi Stephen, thanks for your submission. 

Did you get a copyright assignment? One of your earlier
messages indicated that you were having troubles getting one.

A few comments (sorry to be picky, but these are the rules).  Your
patch doesn't fully follow the gnu coding standards.  Comments
shouldn't be in c++ style. Variable names should not be using mixed
upper and lower case, use '_' to separate words instead.  I see a few
missing white spaces before '('.  Don't use 'extern' in .c files: does
remote.c already include top.h?

Instead of using add_symbol_file_command, you should use
symbol_file_add, which is already exported (this would take
symfile.[ch] out of the picture). See its usage in other gdb files.
I believe this would be ok for your purposes.

I am not clear on why we need the option to be set at gdb startup.
Could it be done with a set command by the user, after gdb has started?
This would avoid the need for initializationBlock, I think.

I cannot really comment on the remote protocol side of things, that's
Andrew's baby. Or on shared libraries, that would be Kevin's.

The configure.tgt patch should be submitted separately, because it is
not logically related to the shared library issue.

Thanks
Elena

 > 
 >     * configure.tgt  add i*86-*-pe* target to be mapped to embed
 >     * main.c         add remote-shared-libs and no-remote-shared-libs switches to gdb
 >     * remote.c       add functions - remote_get_list_of_shared_libraries and findFile
 >                      to support an optional extention to the remote protocol
 >                      which is enabled with the remote-shared-libs switch.  The default
 >                      is disabled.
 >     * symfile.c      make add_symbol_file_command visible visible to functions outside
 >                      of symfile.c so that remote_get_list_of_shared_libraries can call it.
 >     * symfile.h      ditto
 >     * top.c          add the remote_shared_libs variable to hold the state of the
 >                      remote-shared-libs and no-remote-shared-libs switches.  This variable is
 >                      used in remote.c
 >     * top.h          ditto
 > 
 > 
 > Index: configure.tgt
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/configure.tgt,v
 > retrieving revision 1.33
 > diff -u -p -r1.33 configure.tgt
 > --- configure.tgt 2001/07/16 08:52:41 1.33
 > +++ configure.tgt 2001/07/18 16:52:16
 > @@ -125,6 +125,7 @@ i[3456]86-*-netware*) gdb_target=i386nw
 >    configdirs="${configdirs} nlm" ;;
 >  i[3456]86-*-osf1mk*) gdb_target=i386mk ;;
 >  i[3456]86-*-cygwin*) gdb_target=cygwin  ;;
 > +i[3456]86-*-pe*) gdb_target=embed   ;;
 >  i[3456]86-*-vxworks*) gdb_target=vxworks ;;
 > 
 >  i960-*-bout*)  gdb_target=vxworks960 ;;
 > Index: main.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/main.c,v
 > retrieving revision 1.12
 > diff -u -p -r1.12 main.c
 > --- main.c 2001/07/14 18:59:07 1.12
 > +++ main.c 2001/07/18 16:52:20
 > @@ -264,6 +264,8 @@ captured_main (void *data)
 >        {"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
 > Index: remote.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/remote.c,v
 > retrieving revision 1.61
 > diff -u -p -r1.61 remote.c
 > --- remote.c 2001/07/17 01:23:44 1.61
 > +++ remote.c 2001/07/18 16:52:25
 > @@ -48,6 +48,7 @@
 >  #include "inf-loop.h"
 > 
 >  #include <signal.h>
 > +#include <string.h>
 >  #include "serial.h"
 > 
 >  #include "gdbcore.h" /* for exec_bfd */
 > @@ -202,6 +203,10 @@ static void show_packet_config_cmd (stru
 > 
 >  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);
 > @@ -3061,7 +3066,9 @@ Packet Dropped");
 >     continue;
 >   }
 >      }
 > +
 >  got_status:
 > +  remote_get_list_of_shared_libraries();
 >    if (thread_num != -1)
 >      {
 >        return pid_to_ptid (thread_num);
 > @@ -3284,6 +3291,7 @@ Packet Dropped");
 >   }
 >      }
 >  got_status:
 > +  remote_get_list_of_shared_libraries();
 >    if (thread_num != -1)
 >      {
 >        return pid_to_ptid (thread_num);
 > @@ -6015,4 +6023,136 @@ Set use of remote protocol `Z' packets",
 >    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;
 >  }
 > Index: symfile.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/symfile.c,v
 > retrieving revision 1.36
 > diff -u -p -r1.36 symfile.c
 > --- symfile.c 2001/07/15 18:57:06 1.36
 > +++ symfile.c 2001/07/18 16:52:26
 > @@ -112,8 +112,6 @@ static void load_command (char *, int);
 > 
 >  static void symbol_file_add_main_1 (char *args, int from_tty, int flags);
 > 
 > -static void add_symbol_file_command (char *, int);
 > -
 >  static void add_shared_symbol_files_command (char *, int);
 > 
 >  static void cashier_psymtab (struct partial_symtab *);
 > @@ -1410,7 +1408,7 @@ print_transfer_performance (struct ui_fi
 >     value to use. We are now discontinuing this type of ad hoc syntax. */
 > 
 >  /* ARGSUSED */
 > -static void
 > +void
 >  add_symbol_file_command (char *args, int from_tty)
 >  {
 >    char *filename = NULL;
 > Index: symfile.h
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/symfile.h,v
 > retrieving revision 1.9
 > diff -u -p -r1.9 symfile.h
 > --- symfile.h 2001/03/06 08:21:17 1.9
 > +++ symfile.h 2001/07/18 16:52:27
 > @@ -280,6 +280,9 @@ extern void symbol_file_add_main (char *
 >  /* 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 */
 > 
 >  extern void
 > Index: top.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/top.c,v
 > retrieving revision 1.41
 > diff -u -p -r1.41 top.c
 > --- top.c 2001/07/17 17:25:14 1.41
 > +++ top.c 2001/07/18 16:52:32
 > @@ -165,6 +165,12 @@ int remote_debug = 0;
 >     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;
 > 
 > Index: top.h
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/top.h,v
 > retrieving revision 1.5
 > diff -u -p -r1.5 top.h
 > --- top.h 2001/03/06 08:21:17 1.5
 > +++ top.h 2001/07/18 16:52:32
 > @@ -55,6 +55,7 @@ extern void set_prompt (char *);
 >  /* 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] 14+ messages in thread

* Re: shared libraries and a remote target
  2001-07-18 11:44 ` Elena Zannoni
@ 2001-07-18 12:13   ` Stephen Smith
  2001-07-19 10:31   ` Stephen Smith
  2001-07-19 15:18   ` Resubmital of: " Stephen Smith
  2 siblings, 0 replies; 14+ messages in thread
From: Stephen Smith @ 2001-07-18 12:13 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: Andrew Cagney, GDB patches, Kevin Buettner

Elena Zannoni wrote:

> Stephen Smith writes:
>  > I am re-submitting the patch contained in this email.  The the last of the discussion  is at
>  >      http://sources.redhat.com/ml/gdb/2001-03/msg00234.html
>  >
>  > and the original patch submittal is at
>  >
>  >     http://sources.redhat.com/ml/gdb-patches/2001-04/msg00185.html
>  >
>  > The patches still apply cleanly to the development tree - I tried this morning.
>  >
>  > Thanks
>  > sps
>  >
>
> Hi Stephen, thanks for your submission.
>
> Did you get a copyright assignment? One of your earlier
> messages indicated that you were having troubles getting one.
>

It is all done!  I even have the document back from the FSF!

>
> A few comments (sorry to be picky, but these are the rules).  Your
> patch doesn't fully follow the gnu coding standards.  Comments
> shouldn't be in c++ style. Variable names should not be using mixed
> upper and lower case, use '_' to separate words instead.  I see a few
> missing white spaces before '('.  Don't use 'extern' in .c files: does
> remote.c already include top.h?
>
> Instead of using add_symbol_file_command, you should use
> symbol_file_add, which is already exported (this would take
> symfile.[ch] out of the picture). See its usage in other gdb files.
> I believe this would be ok for your purposes.
>

Thanks for the comments.  I will work on that.

>
> I am not clear on why we need the option to be set at gdb startup.
> Could it be done with a set command by the user, after gdb has started?
> This would avoid the need for initializationBlock, I think.
>

I initialized the variable so that it had a known value when gdb starts up.  I
had proposed that in the original proposal.


>
> I cannot really comment on the remote protocol side of things, that's
> Andrew's baby. Or on shared libraries, that would be Kevin's.
>

I will wait <grin>

>
> The configure.tgt patch should be submitted separately, because it is
> not logically related to the shared library issue.
>

Will do!

>
> Thanks
> Elena
>


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

* Re: shared libraries and a remote target
  2001-07-18 11:44 ` Elena Zannoni
  2001-07-18 12:13   ` Stephen Smith
@ 2001-07-19 10:31   ` Stephen Smith
  2001-07-19 15:18   ` Resubmital of: " Stephen Smith
  2 siblings, 0 replies; 14+ messages in thread
From: Stephen Smith @ 2001-07-19 10:31 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: Andrew Cagney, GDB patches, Kevin Buettner

I just looked at the code.  I knew there was a reason why I used add_symbol_file_command rather than symbol_file_add:
the string that comes back from the gdb server is in the form of a command line with identical format to what
add_symbol_file_command expects and what the user enters in a console window.  I didn't think that it would be wise to
duplicate the code.

What do you think?  Would you rather that I wrote parsing code - I don't mind.


Elena Zannoni wrote:

> Stephen Smith writes:
>  > I am re-submitting the patch contained in this email.  The the last of the discussion  is at
>  >      http://sources.redhat.com/ml/gdb/2001-03/msg00234.html
>  >
>  > and the original patch submittal is at
>  >
>  >     http://sources.redhat.com/ml/gdb-patches/2001-04/msg00185.html
>  >
>  > The patches still apply cleanly to the development tree - I tried this morning.
>  >
>  > Thanks
>  > sps
>  >
>
> Hi Stephen, thanks for your submission.
>
> Instead of using add_symbol_file_command, you should use
> symbol_file_add, which is already exported (this would take
> symfile.[ch] out of the picture). See its usage in other gdb files.
> I believe this would be ok for your purposes.
>
> Thanks
> Elena
>


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

* Resubmital of: shared libraries and a remote target
  2001-07-18 11:44 ` Elena Zannoni
  2001-07-18 12:13   ` Stephen Smith
  2001-07-19 10:31   ` Stephen Smith
@ 2001-07-19 15:18   ` Stephen Smith
  2001-07-19 17:57     ` Elena Zannoni
  2001-07-20  9:52     ` Improved patch: " Stephen Smith
  2 siblings, 2 replies; 14+ messages in thread
From: Stephen Smith @ 2001-07-19 15:18 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: Andrew Cagney, GDB patches, Kevin Buettner

This patch supersedes one component of  http://sources.redhat.com/ml/gdb-patches/2001-07/msg00448.html
as requested by Elena Zannoni <ezannoni@cygnus.com>. I ran the remote.c code through
indent 2.2.6 asking to to limit line lengths to 80 chars as requested by
Kevin Buettner <kevinb@cygnus.com>

I didn't change the call to symbol_file_add instead of add_symbol_file_command since that
would mean inserting duplicate code into gdb to do the parsing of the input string.

sps

        * main.c (--remote-shared-libs, --no-remote-shared-libs): New
        switches.
        * remote.c (remote_get_list_of_shared_libraries, findFile): New
        functions which support an option extention to the remote protocol.
        * symfile.c (add_symbol_file_command): Make extern.
        * symfile.h (add_symbol_file_command): Add extern declaration.
        * top.c (remote_shared_libs): New global variable.
        * top.h (remote_shared_libs): Likewise.

Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.12
diff -u -p -r1.12 main.c
--- main.c 2001/07/14 18:59:07 1.12
+++ main.c 2001/07/19 21:46:15
@@ -264,6 +264,8 @@ captured_main (void *data)
       {"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
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.61
diff -u -p -r1.61 remote.c
--- remote.c 2001/07/17 01:23:44 1.61
+++ remote.c 2001/07/19 21:46:19
@@ -48,8 +48,9 @@
 #include "inf-loop.h"

 #include <signal.h>
+#include <string.h>
 #include "serial.h"
-
+#include "top.h"     /* for remote_shared_libs */
 #include "gdbcore.h" /* for exec_bfd */

 /* Prototypes for local functions */
@@ -202,6 +203,10 @@ static void show_packet_config_cmd (stru

 static void update_packet_config (struct packet_config *config);

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

 void open_remote_target (char *, int, struct target_ops *, int);
@@ -3061,7 +3066,9 @@ Packet Dropped");
    continue;
  }
     }
+
 got_status:
+  remote_get_list_of_shared_libraries();
   if (thread_num != -1)
     {
       return pid_to_ptid (thread_num);
@@ -3284,6 +3291,7 @@ Packet Dropped");
  }
     }
 got_status:
+  remote_get_list_of_shared_libraries();
   if (thread_num != -1)
     {
       return pid_to_ptid (thread_num);
@@ -6015,4 +6023,134 @@ Set use of remote protocol `Z' packets",
   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)
+{
+  /*  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, first_space;
+
+        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 */
+               first_space = strlen(file);
+               if( (fqn = find_file (file) ) != 0 )
+               {
+                  strcpy( file, fqn );
+                  strcat( file, &buf[first_space] );
+                  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*
+find_file (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;
 }
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.36
diff -u -p -r1.36 symfile.c
--- symfile.c 2001/07/15 18:57:06 1.36
+++ symfile.c 2001/07/19 21:46:20
@@ -112,8 +112,6 @@ static void load_command (char *, int);

 static void symbol_file_add_main_1 (char *args, int from_tty, int flags);

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

 static void cashier_psymtab (struct partial_symtab *);
@@ -1410,7 +1408,7 @@ print_transfer_performance (struct ui_fi
    value to use. We are now discontinuing this type of ad hoc syntax. */

 /* ARGSUSED */
-static void
+void
 add_symbol_file_command (char *args, int from_tty)
 {
   char *filename = NULL;
Index: symfile.h
===================================================================
RCS file: /cvs/src/src/gdb/symfile.h,v
retrieving revision 1.9
diff -u -p -r1.9 symfile.h
--- symfile.h 2001/03/06 08:21:17 1.9
+++ symfile.h 2001/07/19 21:46:20
@@ -280,6 +280,9 @@ extern void symbol_file_add_main (char *
 /* 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 */

 extern void
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.41
diff -u -p -r1.41 top.c
--- top.c 2001/07/17 17:25:14 1.41
+++ top.c 2001/07/19 21:46:21
@@ -165,6 +165,12 @@ int remote_debug = 0;
    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;

Index: top.h
===================================================================
RCS file: /cvs/src/src/gdb/top.h,v
retrieving revision 1.5
diff -u -p -r1.5 top.h
--- top.h 2001/03/06 08:21:17 1.5
+++ top.h 2001/07/19 21:46:21
@@ -55,6 +55,7 @@ extern void set_prompt (char *);
 /* 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] 14+ messages in thread

* Re: Resubmital of: shared libraries and a remote target
  2001-07-19 15:18   ` Resubmital of: " Stephen Smith
@ 2001-07-19 17:57     ` Elena Zannoni
  2001-07-19 22:12       ` Stephen Smith
  2001-07-20  9:52     ` Improved patch: " Stephen Smith
  1 sibling, 1 reply; 14+ messages in thread
From: Elena Zannoni @ 2001-07-19 17:57 UTC (permalink / raw)
  To: Stephen Smith; +Cc: Elena Zannoni, Andrew Cagney, GDB patches, Kevin Buettner

Stephen Smith writes:
 > This patch supersedes one component of  http://sources.redhat.com/ml/gdb-patches/2001-07/msg00448.html
 > as requested by Elena Zannoni <ezannoni@cygnus.com>. I ran the remote.c code through
 > indent 2.2.6 asking to to limit line lengths to 80 chars as requested by
 > Kevin Buettner <kevinb@cygnus.com>
 > 

Looks much better thanks.

 > I didn't change the call to symbol_file_add instead of add_symbol_file_command since that
 > would mean inserting duplicate code into gdb to do the parsing of the input string.
 > 

Actually, I assume you added the qLibraries packet, so you can control
the format of the response, right? Can it be changed?  The command
line functions (*_command) should be used only from the CLI.  The
grand plan is to separate all the CLI code and put it into the cli
subdirectory, where it won't be accessible from other parts of gdb.
So, it would be better if you could manipulate the response to be
better suited for the symbol_file_add command.  Actually you can see
how that function is invoked from the shared libraries files, and
maybe do something similar as well.

I still wonder about the need for startup options, though. The code
would be simpler if there was a command to enable/disable this
feature.  Since this feature works only for remote targets, it
wouldn't make sense if one is running GDB natively. I think of startup
options as something that is always going to work.

Elena


 > sps
 > 
 >         * main.c (--remote-shared-libs, --no-remote-shared-libs): New
 >         switches.
 >         * remote.c (remote_get_list_of_shared_libraries, findFile): New
 >         functions which support an option extention to the remote protocol.
 >         * symfile.c (add_symbol_file_command): Make extern.
 >         * symfile.h (add_symbol_file_command): Add extern declaration.
 >         * top.c (remote_shared_libs): New global variable.
 >         * top.h (remote_shared_libs): Likewise.
 > 
 > Index: main.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/main.c,v
 > retrieving revision 1.12
 > diff -u -p -r1.12 main.c
 > --- main.c 2001/07/14 18:59:07 1.12
 > +++ main.c 2001/07/19 21:46:15
 > @@ -264,6 +264,8 @@ captured_main (void *data)
 >        {"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
 > Index: remote.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/remote.c,v
 > retrieving revision 1.61
 > diff -u -p -r1.61 remote.c
 > --- remote.c 2001/07/17 01:23:44 1.61
 > +++ remote.c 2001/07/19 21:46:19
 > @@ -48,8 +48,9 @@
 >  #include "inf-loop.h"
 > 
 >  #include <signal.h>
 > +#include <string.h>
 >  #include "serial.h"
 > -
 > +#include "top.h"     /* for remote_shared_libs */
 >  #include "gdbcore.h" /* for exec_bfd */
 > 
 >  /* Prototypes for local functions */
 > @@ -202,6 +203,10 @@ static void show_packet_config_cmd (stru
 > 
 >  static void update_packet_config (struct packet_config *config);
 > 
 > +static void remote_get_list_of_shared_libraries(void);
 > +
 > +static char* find_file(char* basename);
 > +
 >  /* Define the target subroutine names */
 > 
 >  void open_remote_target (char *, int, struct target_ops *, int);
 > @@ -3061,7 +3066,9 @@ Packet Dropped");
 >     continue;
 >   }
 >      }
 > +
 >  got_status:
 > +  remote_get_list_of_shared_libraries();
 >    if (thread_num != -1)
 >      {
 >        return pid_to_ptid (thread_num);
 > @@ -3284,6 +3291,7 @@ Packet Dropped");
 >   }
 >      }
 >  got_status:
 > +  remote_get_list_of_shared_libraries();
 >    if (thread_num != -1)
 >      {
 >        return pid_to_ptid (thread_num);
 > @@ -6015,4 +6023,134 @@ Set use of remote protocol `Z' packets",
 >    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)
 > +{
 > +  /*  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, first_space;
 > +
 > +        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 */
 > +               first_space = strlen(file);
 > +               if( (fqn = find_file (file) ) != 0 )
 > +               {
 > +                  strcpy( file, fqn );
 > +                  strcat( file, &buf[first_space] );
 > +                  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*
 > +find_file (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;
 >  }
 > Index: symfile.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/symfile.c,v
 > retrieving revision 1.36
 > diff -u -p -r1.36 symfile.c
 > --- symfile.c 2001/07/15 18:57:06 1.36
 > +++ symfile.c 2001/07/19 21:46:20
 > @@ -112,8 +112,6 @@ static void load_command (char *, int);
 > 
 >  static void symbol_file_add_main_1 (char *args, int from_tty, int flags);
 > 
 > -static void add_symbol_file_command (char *, int);
 > -
 >  static void add_shared_symbol_files_command (char *, int);
 > 
 >  static void cashier_psymtab (struct partial_symtab *);
 > @@ -1410,7 +1408,7 @@ print_transfer_performance (struct ui_fi
 >     value to use. We are now discontinuing this type of ad hoc syntax. */
 > 
 >  /* ARGSUSED */
 > -static void
 > +void
 >  add_symbol_file_command (char *args, int from_tty)
 >  {
 >    char *filename = NULL;
 > Index: symfile.h
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/symfile.h,v
 > retrieving revision 1.9
 > diff -u -p -r1.9 symfile.h
 > --- symfile.h 2001/03/06 08:21:17 1.9
 > +++ symfile.h 2001/07/19 21:46:20
 > @@ -280,6 +280,9 @@ extern void symbol_file_add_main (char *
 >  /* 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 */
 > 
 >  extern void
 > Index: top.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/top.c,v
 > retrieving revision 1.41
 > diff -u -p -r1.41 top.c
 > --- top.c 2001/07/17 17:25:14 1.41
 > +++ top.c 2001/07/19 21:46:21
 > @@ -165,6 +165,12 @@ int remote_debug = 0;
 >     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;
 > 
 > Index: top.h
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/top.h,v
 > retrieving revision 1.5
 > diff -u -p -r1.5 top.h
 > --- top.h 2001/03/06 08:21:17 1.5
 > +++ top.h 2001/07/19 21:46:21
 > @@ -55,6 +55,7 @@ extern void set_prompt (char *);
 >  /* 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] 14+ messages in thread

* Re: shared libraries and a remote target
  2001-07-19 17:57     ` Elena Zannoni
@ 2001-07-19 22:12       ` Stephen Smith
  2001-07-20 12:02         ` Elena Zannoni
  2001-07-20 17:26         ` Andrew Cagney
  0 siblings, 2 replies; 14+ messages in thread
From: Stephen Smith @ 2001-07-19 22:12 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: Andrew Cagney, GDB patches, Kevin Buettner

Elena Zannoni wrote:

> Looks much better thanks.
>
>  > I didn't change the call to symbol_file_add instead of add_symbol_file_command since that
>  > would mean inserting duplicate code into gdb to do the parsing of the input string.
>  >
>
> Actually, I assume you added the qLibraries packet, so you can control
> the format of the response, right? Can it be changed?  The command
> line functions (*_command) should be used only from the CLI.  The
> grand plan is to separate all the CLI code and put it into the cli
> subdirectory, where it won't be accessible from other parts of gdb.
> So, it would be better if you could manipulate the response to be
> better suited for the symbol_file_add command.  Actually you can see
> how that function is invoked from the shared libraries files, and
> maybe do something similar as well.

Actually, some of my internal co-workers are so allergic to changes in gdbserver
that I would rather do something in the patch. [Thinking out load].  Adding more
overhead to the traffic over the wire cause a couple of other developers heartburn.  It
would also mean writing code to do essentially the same thing as the *_command
function because it already parses the string and then calls symbol_file_add.  Since calling
that function isn't what is wanted from an architectural perspective, why don't I "copy" the
code to remote.c (renaming the function in the process) and then then symfile patches
won't be needed and the code should be about the same size.

> I still wonder about the need for startup options, though. The code
> would be simpler if there was a command to enable/disable this
> feature.  Since this feature works only for remote targets, it
> wouldn't make sense if one is running GDB natively. I think of startup
> options as something that is always going to work.

Ok, I can agree.  Now that you have convinced me, how do I do it.  The reason that I
coded the switch was because I couldn't figure out how to add a command that would only
get used in the remote code.



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

* Improved patch: shared libraries and a remote target
  2001-07-19 15:18   ` Resubmital of: " Stephen Smith
  2001-07-19 17:57     ` Elena Zannoni
@ 2001-07-20  9:52     ` Stephen Smith
  2001-07-20 11:10       ` Kevin Buettner
  2001-07-20 17:17       ` Re-submit: " Stephen Smith
  1 sibling, 2 replies; 14+ messages in thread
From: Stephen Smith @ 2001-07-20  9:52 UTC (permalink / raw)
  To: Elena Zannoni, Andrew Cagney, GDB patches, Kevin Buettner

This patch implements the comments in  http://sources.redhat.com/ml/gdb-patches/2001-07/msg00504.html . Unless
someone can point me at how to add the command and then link it to the appropriate variable, the switch is my best
try (sorry Elena).

Other than the switch change this should have everything that was wanted.


        * main.c (--remote-shared-libs, --no-remote-shared-libs): New
        switches.
        * remote.c (remote_get_list_of_shared_libraries, findFile): New
        functions which support an option extention to the remote protocol.
        * top.c (remote_shared_libs): New global variable.
        * top.h (remote_shared_libs): Likewise.

Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.12
diff -u -p -r1.12 main.c
--- main.c 2001/07/14 18:59:07 1.12
+++ main.c 2001/07/20 15:57:01
@@ -264,6 +264,8 @@ captured_main (void *data)
       {"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
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.61
diff -u -p -r1.61 remote.c
--- remote.c 2001/07/17 01:23:44 1.61
+++ remote.c 2001/07/20 15:57:04
@@ -48,8 +48,9 @@
 #include "inf-loop.h"

 #include <signal.h>
+#include <string.h>
 #include "serial.h"
-
+#include "top.h"     /* for remote_shared_libs */
 #include "gdbcore.h" /* for exec_bfd */

 /* Prototypes for local functions */
@@ -202,6 +203,12 @@ static void show_packet_config_cmd (stru

 static void update_packet_config (struct packet_config *config);

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

 void open_remote_target (char *, int, struct target_ops *, int);
@@ -3061,7 +3068,9 @@ Packet Dropped");
    continue;
  }
     }
+
 got_status:
+  remote_get_list_of_shared_libraries();
   if (thread_num != -1)
     {
       return pid_to_ptid (thread_num);
@@ -3284,6 +3293,7 @@ Packet Dropped");
  }
     }
 got_status:
+  remote_get_list_of_shared_libraries();
   if (thread_num != -1)
     {
       return pid_to_ptid (thread_num);
@@ -6015,4 +6025,293 @@ Set use of remote protocol `Z' packets",
   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)
+{
+  /* 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
+     parse_string_from_server() 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, first_space;
+
+      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 */
+   first_space = strlen (file);
+   if ((fqn = find_file (file)) != 0)
+     {
+       strcpy (file, fqn);
+       strcat (file, &buf[first_space]);
+       parse_string_from_server (file);
+     }
+
+   /* 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 *
+find_file (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;
+}
+
+/* This function allows the addition of incrementally linked object files.
+   It does not modify any state in the target, only in the debugger.  */
+/* ARGSUSED */
+  static void
+parse_string_from_server (char *args)
+{
+  char *filename = NULL;
+  int flags = OBJF_USERLOADED;
+  char *arg;
+  int expecting_option = 0;
+  int section_index = 0;
+  int argcnt = 0;
+  int sec_num = 0;
+  int i;
+  int expecting_sec_name = 0;
+  int expecting_sec_addr = 0;
+
+  struct
+  {
+    char *name;
+    char *value;
+  }
+  sect_opts[SECT_OFF_MAX];
+
+  struct section_addr_info section_addrs;
+  struct cleanup *my_cleanups = make_cleanup (null_cleanup, NULL);
+
+  dont_repeat ();
+
+  if (args == NULL)
+    error ("add-symbol-file takes a file name and an address");
+
+  /* Make a copy of the string that we can safely write into. */
+  args = xstrdup (args);
+
+  /* Ensure section_addrs is initialized */
+  memset (&section_addrs, 0, sizeof (section_addrs));
+
+  while (*args != '\000')
+    {
+      /* Any leading spaces? */
+      while (isspace (*args))
+ args++;
+
+      /* Point arg to the beginning of the argument. */
+      arg = args;
+
+      /* Move args pointer over the argument. */
+      while ((*args != '\000') && !isspace (*args))
+ args++;
+
+      /* If there are more arguments, terminate arg and proceed past it. */
+      if (*args != '\000')
+ *args++ = '\000';
+
+      /* Now process the argument. */
+      if (argcnt == 0)
+ {
+   /* The first argument is the file name. */
+   filename = tilde_expand (arg);
+   make_cleanup (xfree, filename);
+ }
+      else if (argcnt == 1)
+ {
+   /* The second argument is always the text address at which to load
+      the program. */
+   sect_opts[section_index].name = ".text";
+   sect_opts[section_index].value = arg;
+   section_index++;
+ }
+      else
+ {
+   /* It's an option (starting with '-') or it's an argument to an
+      option */
+
+   if (*arg == '-')
+     {
+       if (strcmp (arg, "-mapped") == 0)
+  flags |= OBJF_MAPPED;
+       else if (strcmp (arg, "-readnow") == 0)
+  flags |= OBJF_READNOW;
+       else if (strcmp (arg, "-s") == 0)
+  {
+    if (section_index >= SECT_OFF_MAX)
+      error ("Too many sections specified.");
+    expecting_sec_name = 1;
+    expecting_sec_addr = 1;
+  }
+     }
+   else
+     {
+       if (expecting_sec_name)
+  {
+    sect_opts[section_index].name = arg;
+    expecting_sec_name = 0;
+  }
+       else if (expecting_sec_addr)
+  {
+    sect_opts[section_index].value = arg;
+    expecting_sec_addr = 0;
+    section_index++;
+  }
+       else
+  error
+    ("USAGE: add-symbol-file <filename> <textaddress> [-mapped] [-readnow] [-s <secname> <addr>]*");
+     }
+ }
+      argcnt++;
+    }
+
+  /* Print the prompt for the query below. And save the arguments into a
+     sect_addr_info structure to be passed around to other functions.  We have
+     to split this up into separate print statements because local_hex_string
+     returns a local static string. */
+
+  printf_filtered ("add symbol table from file \"%s\" at\n", filename);
+  for (i = 0; i < section_index; i++)
+    {
+      CORE_ADDR addr;
+      char *val = sect_opts[i].value;
+      char *sec = sect_opts[i].name;
+
+      val = sect_opts[i].value;
+      if (val[0] == '0' && val[1] == 'x')
+ addr = strtoul (val + 2, NULL, 16);
+      else
+ addr = strtoul (val, NULL, 10);
+
+      /* Here we store the section offsets in the order they were entered on
+         the command line. */
+      section_addrs.other[sec_num].name = sec;
+      section_addrs.other[sec_num].addr = addr;
+      printf_filtered ("\t%s_addr = %s\n",
+         sec, local_hex_string ((unsigned long) addr));
+      sec_num++;
+
+      /* The object's sections are initialized when a call is made to
+         build_objfile_section_table (objfile). This happens in reread_symbols.
+         At this point, we don't know what file type this is, so we can't
+         determine what section names are valid.  */
+    }
+
+  symbol_file_add (filename, 0, &section_addrs, 0, flags);
+
+  /* Getting new symbols may change our opinion about what is frameless.  */
+  reinit_frame_cache ();
+  do_cleanups (my_cleanups);
 }
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.41
diff -u -p -r1.41 top.c
--- top.c 2001/07/17 17:25:14 1.41
+++ top.c 2001/07/20 15:57:05
@@ -165,6 +165,12 @@ int remote_debug = 0;
    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;

Index: top.h
===================================================================
RCS file: /cvs/src/src/gdb/top.h,v
retrieving revision 1.5
diff -u -p -r1.5 top.h
--- top.h 2001/03/06 08:21:17 1.5
+++ top.h 2001/07/20 15:57:05
@@ -55,6 +55,7 @@ extern void set_prompt (char *);
 /* 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] 14+ messages in thread

* Re: Improved patch: shared libraries and a remote target
  2001-07-20  9:52     ` Improved patch: " Stephen Smith
@ 2001-07-20 11:10       ` Kevin Buettner
  2001-07-20 17:17       ` Re-submit: " Stephen Smith
  1 sibling, 0 replies; 14+ messages in thread
From: Kevin Buettner @ 2001-07-20 11:10 UTC (permalink / raw)
  To: GDB patches, Stephen Smith; +Cc: Elena Zannoni, Andrew Cagney

On Jul 20,  9:53am, Stephen Smith wrote:

> Unless someone can point me at how to add the command and then link
> it to the appropriate variable, the switch is my best try (sorry
> Elena).

Stephen,

Look in _initialize_remote() where a good number of commands are added.
Off the top of my head, I think it might look something like this...

  add_show_from_set
    (add_set_cmd ("remote-shared-libs", no_class,
		  var_boolean, (char *) &remote_shared_libs,
		  "Set whether remote target supports qLibraries packet\n",
		  &setlist),
     &showlist);

Or, perhaps it ought to be one of the packet config commands?...

  add_packet_config_cmd (&remote_protocol_qLibraries,
			 "qLibraries", "shared-library-lookup",
			 set_remote_protocol_qLibraries_packet_cmd,
			 show_remote_protocol_qLibraries_packet_cmd,
			 &remote_set_cmdlist, &remote_show_cmdlist,
			 0);

I'm not sure which is preferable in this case, but this should provide
you with a starting point...

Kevin


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

* Re: shared libraries and a remote target
  2001-07-19 22:12       ` Stephen Smith
@ 2001-07-20 12:02         ` Elena Zannoni
  2001-07-20 17:26         ` Andrew Cagney
  1 sibling, 0 replies; 14+ messages in thread
From: Elena Zannoni @ 2001-07-20 12:02 UTC (permalink / raw)
  To: Stephen Smith; +Cc: Elena Zannoni, Andrew Cagney, GDB patches, Kevin Buettner

Stephen Smith writes:
 > Elena Zannoni wrote:
 > 
 > > Looks much better thanks.
 > >
 > >  > I didn't change the call to symbol_file_add instead of add_symbol_file_command since that
 > >  > would mean inserting duplicate code into gdb to do the parsing of the input string.
 > >  >
 > >
 > > Actually, I assume you added the qLibraries packet, so you can control
 > > the format of the response, right? Can it be changed?  The command
 > > line functions (*_command) should be used only from the CLI.  The
 > > grand plan is to separate all the CLI code and put it into the cli
 > > subdirectory, where it won't be accessible from other parts of gdb.
 > > So, it would be better if you could manipulate the response to be
 > > better suited for the symbol_file_add command.  Actually you can see
 > > how that function is invoked from the shared libraries files, and
 > > maybe do something similar as well.
 > 
 > Actually, some of my internal co-workers are so allergic to changes in gdbserver
 > that I would rather do something in the patch. [Thinking out load].  Adding more
 > overhead to the traffic over the wire cause a couple of other developers heartburn.  It
 > would also mean writing code to do essentially the same thing as the *_command
 > function because it already parses the string and then calls symbol_file_add.  Since calling
 > that function isn't what is wanted from an architectural perspective, why don't I "copy" the
 > code to remote.c (renaming the function in the process) and then then symfile patches
 > won't be needed and the code should be about the same size.

Stephen, sorry, while I can understand that it is hard to revisit
design decisions, I don't think that is a reasonable motivation.
Anyway, I think we are getting a little ahead of ourselves, because
nobody has commented on the actual remote protocol change yet.  So
let's wait on that. It looks to me like the reply packets deviates a
bit from the standard, but I am not the maintainer for that.

 > 
 > > I still wonder about the need for startup options, though. The code
 > > would be simpler if there was a command to enable/disable this
 > > feature.  Since this feature works only for remote targets, it
 > > wouldn't make sense if one is running GDB natively. I think of startup
 > > options as something that is always going to work.
 > 
 > Ok, I can agree.  Now that you have convinced me, how do I do it.  The reason that I
 > coded the switch was because I couldn't figure out how to add a command that would only
 > get used in the remote code.
 > 

Ok. As Kevin said in his reply, look at uses of add_cmd. That's the
usual way to do this. There should be plenty of other examples in gdb
for you to get a template for its usage.


Elena


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

* Re-submit: shared libraries and a remote target
  2001-07-20  9:52     ` Improved patch: " Stephen Smith
  2001-07-20 11:10       ` Kevin Buettner
@ 2001-07-20 17:17       ` Stephen Smith
  2001-07-20 17:52         ` Andrew Cagney
  1 sibling, 1 reply; 14+ messages in thread
From: Stephen Smith @ 2001-07-20 17:17 UTC (permalink / raw)
  To: Elena Zannoni, Andrew Cagney, GDB patches, Kevin Buettner

This patch supersedes http://sources.redhat.com/ml/gdb-patches/2001-07/msg00513.html .
It has all of Elena's and Kevin's comments implemented.


        * remote.c (remote_get_list_of_shared_libraries, find_file,
        parse_string_from_server): New functions which support
        an optional extension to the remote protocol.

Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.61
diff -u -p -r1.61 remote.c
--- remote.c 2001/07/17 01:23:44 1.61
+++ remote.c 2001/07/20 23:59:21
@@ -48,6 +48,7 @@
 #include "inf-loop.h"

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

 #include "gdbcore.h" /* for exec_bfd */
@@ -202,6 +203,12 @@ static void show_packet_config_cmd (stru

 static void update_packet_config (struct packet_config *config);

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

 void open_remote_target (char *, int, struct target_ops *, int);
@@ -686,6 +693,22 @@ show_remote_protocol_qSymbol_packet_cmd
   show_packet_config_cmd (&remote_protocol_qSymbol);
 }

+/* Should we try the 'qLibraries' (remote shared library) protocol? */
+static struct packet_config remote_protocol_qLibraries;
+
+static void
+set_remote_protocol_qLibraries_packet_cmd (char *args, int from_tty,
+      struct cmd_list_element *c)
+{
+  update_packet_config (&remote_protocol_qLibraries);
+}
+
+static void
+show_remote_protocol_qLibraries_packet_cmd (char *args, int from_tty)
+{
+  show_packet_config_cmd (&remote_protocol_qLibraries);
+}
+
 /* Should we try the 'e' (step over range) request? */
 static struct packet_config remote_protocol_e;

@@ -2087,6 +2110,7 @@ init_all_packet_configs (void)
   update_packet_config (&remote_protocol_E);
   update_packet_config (&remote_protocol_P);
   update_packet_config (&remote_protocol_qSymbol);
+  update_packet_config (&remote_protocol_qLibraries);
   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
@@ -3061,7 +3085,9 @@ Packet Dropped");
    continue;
  }
     }
+
 got_status:
+  remote_get_list_of_shared_libraries();
   if (thread_num != -1)
     {
       return pid_to_ptid (thread_num);
@@ -3284,6 +3310,7 @@ Packet Dropped");
  }
     }
 got_status:
+  remote_get_list_of_shared_libraries();
   if (thread_num != -1)
     {
       return pid_to_ptid (thread_num);
@@ -5779,6 +5806,7 @@ show_remote_cmd (char *args, int from_tt
   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_qLibraries_packet_cmd (args, from_tty);
   show_remote_protocol_binary_download_cmd (args, from_tty);
 }

@@ -5950,6 +5978,13 @@ in a memory packet.\n",
     &remote_set_cmdlist, &remote_show_cmdlist,
     0);

+  add_packet_config_cmd (&remote_protocol_qLibraries,
+                         "qLibraries", "shared-library-lookup",
+                         set_remote_protocol_qLibraries_packet_cmd,
+                         show_remote_protocol_qLibraries_packet_cmd,
+                         &remote_set_cmdlist, &remote_show_cmdlist,
+                         0 );
+
   add_packet_config_cmd (&remote_protocol_e,
     "e", "step-over-range",
     set_remote_protocol_e_packet_cmd,
@@ -6015,4 +6050,298 @@ Set use of remote protocol `Z' packets",
   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)
+{
+  /* This is a counter that gets used so that we don't run while the GDB is
+     initializing */
+  static unsigned initializationBlock = 0;
+
+  char *buf = alloca (PBUFSIZ);
+
+  /* Has this feature been disabled? */
+  if (remote_protocol_qLibraries.support == PACKET_DISABLE)
+    {
+      return;
+    }
+
+  /* The first time through, I don't believe we want to do this because gdb
+     isn't completely initialized. With out this flag
+     parse_string_from_server() hangs. */
+  if (initializationBlock < 2)
+    {
+      ++initializationBlock;
+      return;
+    }
+
+  putpkt ("qNewLibraries");
+  getpkt (buf, PBUFSIZ, 0);
+  switch (packet_ok (buf, &remote_protocol_qLibraries))
+    {
+    case PACKET_OK:
+      break;
+    case PACKET_ERROR:
+    case PACKET_UNKNOWN:
+    default:
+      return;
+    }
+
+  if (buf[0] == '\000')
+    {
+      remote_protocol_qLibraries.support = PACKET_DISABLE;
+      return;   /* Return silently.  Stub doesn't support this
+       command. */
+    }
+
+  if (buf[0] == '1')  /* There are new shared libraries */
+    {
+      char *file = alloca (PBUFSIZ), *fqn;
+      int address, values, first_space;
+
+      putpkt ("qLibraries");
+      getpkt (buf, PBUFSIZ, 0);
+      switch (packet_ok (buf, &remote_protocol_qLibraries))
+ {
+ case PACKET_OK:
+   break;
+ case PACKET_ERROR:
+ case PACKET_UNKNOWN:
+ default:
+   return;
+ }
+
+      if (buf[0] == '\000')
+ {
+   remote_protocol_qLibraries.support = PACKET_DISABLE;
+   return;  /* Return silently.  Stub doesn't support this
+       command. */
+ }
+
+      do
+ {
+   /* buff should have the following layout: <filename> <textaddress>
+      [-mapped] [-readnow] [-s <secname> <addr>]* The reason that this
+      format was chosen is that it is file format independent and allows
+      for OS memory layouts that are non-standard. */
+   values = sscanf (buf, "%s %x", file, &address);
+   if (values < 2)
+     break;  /* check to make sure we have a minimum number
+       of fields */
+   first_space = strlen (file);
+   if ((fqn = find_file (file)) != 0)
+     {
+       strcpy (file, fqn);
+       strcat (file, &buf[first_space]);
+       parse_string_from_server (file);
+     }
+
+   /* Get the next file from remote */
+   putpkt ("qLibraries");
+   getpkt (buf, PBUFSIZ, 0);
+   switch (packet_ok (buf, &remote_protocol_qLibraries))
+     {
+     case PACKET_OK:
+       break;
+     case PACKET_ERROR:
+     case PACKET_UNKNOWN:
+     default:
+       return;
+     }
+
+   if (buf[0] == '\000')
+     {
+       remote_protocol_qLibraries.support = PACKET_DISABLE;
+       return;  /* Return silently.  Stub doesn't support this
+       command. */
+     }
+ }
+      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 *
+find_file (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;
+}
+
+/* This function allows the addition of incrementally linked object files.
+   It does not modify any state in the target, only in the debugger.
+   args should have the following layout: <filename> <textaddress>
+   [-mapped] [-readnow] [-s <secname> <addr>]* */
+static void
+parse_string_from_server (char *args)
+{
+  char *filename = NULL;
+  int flags = OBJF_USERLOADED;
+  char *arg;
+  int expecting_option = 0;
+  int section_index = 0;
+  int argcnt = 0;
+  int sec_num = 0;
+  int i;
+  int expecting_sec_name = 0;
+  int expecting_sec_addr = 0;
+
+  struct
+  {
+    char *name;
+    char *value;
+  }
+  sect_opts[SECT_OFF_MAX];
+
+  struct section_addr_info section_addrs;
+  struct cleanup *my_cleanups = make_cleanup (null_cleanup, NULL);
+
+  dont_repeat ();
+
+  if (args == NULL)
+    error ("add-symbol-file takes a file name and an address");
+
+  /* Make a copy of the string that we can safely write into. */
+  args = xstrdup (args);
+
+  /* Ensure section_addrs is initialized */
+  memset (&section_addrs, 0, sizeof (section_addrs));
+
+  while (*args != '\000')
+    {
+      /* Any leading spaces? */
+      while (isspace (*args))
+ args++;
+
+      /* Point arg to the beginning of the argument. */
+      arg = args;
+
+      /* Move args pointer over the argument. */
+      while ((*args != '\000') && !isspace (*args))
+ args++;
+
+      /* If there are more arguments, terminate arg and proceed past it. */
+      if (*args != '\000')
+ *args++ = '\000';
+
+      /* Now process the argument. */
+      if (argcnt == 0)
+ {
+   /* The first argument is the file name. */
+   filename = tilde_expand (arg);
+   make_cleanup (xfree, filename);
+ }
+      else if (argcnt == 1)
+ {
+   /* The second argument is always the text address at which to load
+      the program. */
+   sect_opts[section_index].name = ".text";
+   sect_opts[section_index].value = arg;
+   section_index++;
+ }
+      else
+ {
+   /* It's an option (starting with '-') or it's an argument to an
+      option */
+
+   if (*arg == '-')
+     {
+       if (strcmp (arg, "-mapped") == 0)
+  flags |= OBJF_MAPPED;
+       else if (strcmp (arg, "-readnow") == 0)
+  flags |= OBJF_READNOW;
+       else if (strcmp (arg, "-s") == 0)
+  {
+    if (section_index >= SECT_OFF_MAX)
+      error ("Too many sections specified.");
+    expecting_sec_name = 1;
+    expecting_sec_addr = 1;
+  }
+     }
+   else
+     {
+       if (expecting_sec_name)
+  {
+    sect_opts[section_index].name = arg;
+    expecting_sec_name = 0;
+  }
+       else if (expecting_sec_addr)
+  {
+    sect_opts[section_index].value = arg;
+    expecting_sec_addr = 0;
+    section_index++;
+  }
+       else
+  error
+    ("USAGE: add-symbol-file <filename> <textaddress> [-mapped] [-readnow] [-s <secname> <addr>]*");
+     }
+ }
+      argcnt++;
+    }
+
+  /* Print the prompt for the query below. And save the arguments into a
+     sect_addr_info structure to be passed around to other functions.  We have
+     to split this up into separate print statements because local_hex_string
+     returns a local static string. */
+
+  printf_filtered ("add symbol table from file \"%s\" at\n", filename);
+  for (i = 0; i < section_index; i++)
+    {
+      CORE_ADDR addr;
+      char *val = sect_opts[i].value;
+      char *sec = sect_opts[i].name;
+
+      val = sect_opts[i].value;
+      if (val[0] == '0' && val[1] == 'x')
+ addr = strtoul (val + 2, NULL, 16);
+      else
+ addr = strtoul (val, NULL, 10);
+
+      /* Here we store the section offsets in the order they were entered on
+         the command line. */
+      section_addrs.other[sec_num].name = sec;
+      section_addrs.other[sec_num].addr = addr;
+      printf_filtered ("\t%s_addr = %s\n",
+         sec, local_hex_string ((unsigned long) addr));
+      sec_num++;
+
+      /* The object's sections are initialized when a call is made to
+         build_objfile_section_table (objfile). This happens in reread_symbols.
+         At this point, we don't know what file type this is, so we can't
+         determine what section names are valid.  */
+    }
+
+  symbol_file_add (filename, 0, &section_addrs, 0, flags);
+
+  /* Getting new symbols may change our opinion about what is frameless.  */
+  reinit_frame_cache ();
+  do_cleanups (my_cleanups);
 }



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

* Re: shared libraries and a remote target
  2001-07-19 22:12       ` Stephen Smith
  2001-07-20 12:02         ` Elena Zannoni
@ 2001-07-20 17:26         ` Andrew Cagney
  1 sibling, 0 replies; 14+ messages in thread
From: Andrew Cagney @ 2001-07-20 17:26 UTC (permalink / raw)
  To: Stephen Smith; +Cc: Elena Zannoni, GDB patches

> Actually, some of my internal co-workers are so allergic to changes in gdbserver
> that I would rather do something in the patch. [Thinking out load].  Adding more
> overhead to the traffic over the wire cause a couple of other developers heartburn.  It
> would also mean writing code to do essentially the same thing as the *_command
> function because it already parses the string and then calls symbol_file_add.  Since calling
> that function isn't what is wanted from an architectural perspective, why don't I "copy" the
> code to remote.c (renaming the function in the process) and then then symfile patches
> won't be needed and the code should be about the same size.


Sorry to hear this.  Unfortunatly the GDB protocol is a public document 
and proposed changes are only accepted after careful public review.

Could you please post to ``GDB Discussion <gdb@sources.redhat.com>'' a 
RFC for the new packet.  Could you also include an example.  If you look 
through the archives you'll see that Michael Snyder recently did this 
for the qSymbol packet.

Also, would you be able to post a working example of the stub?

	Andrew


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

* Re: Re-submit: shared libraries and a remote target
  2001-07-20 17:17       ` Re-submit: " Stephen Smith
@ 2001-07-20 17:52         ` Andrew Cagney
  2001-07-23  0:22           ` Stephen Smith
  0 siblings, 1 reply; 14+ messages in thread
From: Andrew Cagney @ 2001-07-20 17:52 UTC (permalink / raw)
  To: Stephen Smith; +Cc: Elena Zannoni, GDB patches, Kevin Buettner

> This patch supersedes http://sources.redhat.com/ml/gdb-patches/2001-07/msg00513.html .
> It has all of Elena's and Kevin's comments implemented.
> 
> 
>         * remote.c (remote_get_list_of_shared_libraries, find_file,
>         parse_string_from_server): New functions which support
>         an optional extension to the remote protocol.


Hmm, I suspect the ChangeLog needs to be fleshed out a little.

You didn't mention anything about the remote_protocol_qLibraries global 
variable or the associated functions.  This is a shame because all that 
is fine!


> +#include <string.h>


FYI, gdb uses "gdb_string.h".  Also mention this in the ChangeLog.


> +  remote_get_list_of_shared_libraries();


FYI ``foo ()'' not ``foo()''


> +static void
> +remote_get_list_of_shared_libraries (void)


These new function should be before _initialize*().

Taking a quick glance at the actual code, I suspect that once the 
protocol is sorted out much of this will be simplified.

	Andrew




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

* Re: Re-submit: shared libraries and a remote target
  2001-07-20 17:52         ` Andrew Cagney
@ 2001-07-23  0:22           ` Stephen Smith
  0 siblings, 0 replies; 14+ messages in thread
From: Stephen Smith @ 2001-07-23  0:22 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Elena Zannoni, GDB patches, Kevin Buettner

I will save sending out a new patch until you are happy with the protocol.  I don't
want to continue the re-coding - I would rather do it once <grin>.

Andrew Cagney wrote:

> > This patch supersedes http://sources.redhat.com/ml/gdb-patches/2001-07/msg00513.html .
> > It has all of Elena's and Kevin's comments implemented.
> >
> >
> >         * remote.c (remote_get_list_of_shared_libraries, find_file,
> >         parse_string_from_server): New functions which support
> >         an optional extension to the remote protocol.
>
> Hmm, I suspect the ChangeLog needs to be fleshed out a little.
>
> You didn't mention anything about the remote_protocol_qLibraries global
> variable or the associated functions.  This is a shame because all that
> is fine!
>
> > +#include <string.h>
>
> FYI, gdb uses "gdb_string.h".  Also mention this in the ChangeLog.
>
> > +  remote_get_list_of_shared_libraries();
>
> FYI ``foo ()'' not ``foo()''
>
> > +static void
> > +remote_get_list_of_shared_libraries (void)
>
> These new function should be before _initialize*().
>
> Taking a quick glance at the actual code, I suspect that once the
> protocol is sorted out much of this will be simplified.
>
>         Andrew


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

end of thread, other threads:[~2001-07-23  0:22 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-18 10:54 shared libraries and a remote target Stephen Smith
2001-07-18 11:44 ` Elena Zannoni
2001-07-18 12:13   ` Stephen Smith
2001-07-19 10:31   ` Stephen Smith
2001-07-19 15:18   ` Resubmital of: " Stephen Smith
2001-07-19 17:57     ` Elena Zannoni
2001-07-19 22:12       ` Stephen Smith
2001-07-20 12:02         ` Elena Zannoni
2001-07-20 17:26         ` Andrew Cagney
2001-07-20  9:52     ` Improved patch: " Stephen Smith
2001-07-20 11:10       ` Kevin Buettner
2001-07-20 17:17       ` Re-submit: " Stephen Smith
2001-07-20 17:52         ` Andrew Cagney
2001-07-23  0:22           ` Stephen Smith

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