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]

Re: shared libraries and a remote target


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 *);
 > 


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