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]

shared libraries and a remote target


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

Kevin said that I should send the patches now:

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

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

sps

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

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

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

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

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

  static void update_packet_config (struct packet_config *config);

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

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

  static void load_command (char *, int);

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

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

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

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

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

  /* From dwarfread.c */

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

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

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

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

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

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

  static void update_packet_config (struct packet_config *config);

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

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

  static void load_command (char *, int);

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

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

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

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

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

  /* From dwarfread.c */

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

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

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

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


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