From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Snyder To: gdb-patches@sources.redhat.com Cc: jtc@redback.com Subject: [RFC] Extend remote protocol to allow symbol look-up service. Date: Tue, 17 Apr 2001 16:29:00 -0000 Message-id: <3ADCD1B8.772C5247@cygnus.com> X-SW-Source: 2001-04/msg00183.html Surprising as it may seem, there are circumstances when a remote target stub may need to know the values of symbols in the debuggee. The case that I'm working from is multi-threaded debugging under Solaris and Linux. Both platforms make use of a debugging support library called libthread-db, which exports a debugging interface into the native thread library. It shields the debugger from knowledge about the thread library internals, but in return it needs to know the addresses of thread library data objects in the child, so that it can go rooting around in them. The scheme that I propose is this: whenever the debugger detects a new shared library being loaded in the remote child process, it will send a notification to the remote stub in the form of a 'Q' (miscelaneous set value) packet, like this: QSharedObject:libc.so.1 The target may as usual reply with an empty packet meaning "I don't understand", or with an "OK" acknowledgement, but in addition to those the target may reply with a request for the value of a symbol: qSymbol:__pthread_max_threads If the reply is of that form, the debugger will attempt a symbol lookup. If successful, it will send a new declaratory message to the target like so: QSymbol::__pthread_max_threads Or, if the lookup is unsuccessful, QSymbol::__pthread_max_threads (indicating no address or value is available). The target may ask for the symbol again when a new shared library shows up. The target's replies to the QSymbol message are the same as for the QSharedObject message: an empty reply, an "OK" ack, or a new request for another symbol. Thus the process can continue until the target doesn't need any more symbols. Here is a patch to remote.c that would implement the debugger side of the proposed protocol. I have implemented the target side in the soon-to-be-released (knock on wood) libremote library. 2001-04-17 Michael Snyder * remote.c (remote_new_objfile): New function. Called by the target new_objfile hook whenever a new (shared library) objfile is detected. Notifies the remote target, and accepts symbol lookup requests. (remote_new_objfile_chain): Function pointer which hooks remote_new_objfile into the new objfile notification chain. (_initialize_remote): Hook remote_new_objfile function into the new objfile notification chain. Index: remote.c =================================================================== RCS file: /cvs/src/src/gdb/remote.c,v retrieving revision 1.45 diff -c -3 -p -r1.45 remote.c *** remote.c 2001/04/17 20:31:00 1.45 --- remote.c 2001/04/17 23:13:03 *************** build_remote_gdbarch_data (void) *** 5691,5696 **** --- 5691,5751 ---- remote_address_size = TARGET_ADDR_BIT; } + /* Saved pointer to previous owner of the new_objfile event. */ + static void (*remote_new_objfile_chain) (struct objfile *); + + /* Function to be called whenever a new objfile (shlib) is detected. */ + static void + remote_new_objfile (struct objfile *objfile) + { + char *msg, *reply, *prev, *tmp; + struct minimal_symbol *sym; + + printf ("\n", (unsigned long) objfile); + + if (remote_desc != 0) /* Have a remote connection */ + { + msg = alloca (PBUFSIZ); + reply = alloca (PBUFSIZ); + + /* Inform target of new objfile. */ + + /* NOTE: you might say that I should use SLASH_CHAR here, but + not so! SLASH_CHAR is defined for the host, while the shared + libraries are relevant to the target. */ + if (objfile) + { + tmp = strrchr (objfile->name, '/'); + if (tmp == NULL) + tmp = strrchr (objfile->name, '\\'); + if (tmp == NULL) + tmp = objfile->name; + sprintf (msg, "QSharedObject:%s", tmp); + } + else + strcpy (msg, "QSharedObject:"); + + putpkt (msg); + getpkt (reply, PBUFSIZ, 0); + while (strncmp (reply, "qSymbol:", 8) == 0) + { + sym = lookup_minimal_symbol (&reply[8], NULL, NULL); + if (sym == NULL) + sprintf (msg, "QSymbol::%s", &reply[8]); + else + sprintf (msg, "QSymbol:%s:%s", + paddr_nz (SYMBOL_VALUE_ADDRESS (sym)), + &reply[8]); + putpkt (msg); + getpkt (reply, PBUFSIZ, 0); + } + } + /* Call predecessor on chain, if any. */ + if (remote_new_objfile_chain != 0 && + remote_desc == 0) + remote_new_objfile_chain (objfile); + } + void _initialize_remote (void) { *************** _initialize_remote (void) *** 5720,5725 **** --- 5775,5784 ---- init_remote_cisco_ops (); add_target (&remote_cisco_ops); + + /* Hook into new objfile notification. */ + remote_new_objfile_chain = target_new_objfile_hook; + target_new_objfile_hook = remote_new_objfile; #if 0 init_remote_threadtests (); >From ac131313@cygnus.com Tue Apr 17 16:30:00 2001 From: Andrew Cagney To: GDB Patches Subject: [5.1/rfc] Obsolete MPW host Date: Tue, 17 Apr 2001 16:30:00 -0000 Message-id: <3ADCD1D5.9AA0B1AC@cygnus.com> X-SW-Source: 2001-04/msg00184.html Content-length: 10008 Hello, This is the last of the systems on the 5.1 hit list. enjoy, Andrew 2001-04-17 Andrew Cagney * source.c (openp): Obsolete #ifdef MPW code. (open_source_file): Ditto. * event-top.c (display_gdb_prompt): Ditto. * utils.c (query): Ditto. (init_page_info): Ditto. (init_page_info): Delete #ifndef MPW. * top.c (gdb_readline): Ditto. * mac-xdep.c: Obsolete. * mac-gdb.r: Obsolete. * config/powerpc/xm-mpw.h: Obsolete. * config/xm-mpw.h: Obsolete. * mpw-make.sed: Obsolete. * mpw-config.in: Obsolete. * TODO: Update * NEWS: Update Index: NEWS =================================================================== RCS file: /cvs/src/src/gdb/NEWS,v retrieving revision 1.22 diff -p -r1.22 NEWS *** NEWS 2001/04/17 21:20:48 1.22 --- NEWS 2001/04/17 22:28:52 *************** PowerPC Netware powerpc-*-netware* *** 27,32 **** --- 27,33 ---- SunOS 4.0.Xi on i386 i[3456]86-*-sunos* Sony NEWS (68K) running NEWSOS 3.x m68*-sony-sysv news ISI Optimum V (3.05) under 4.3bsd. m68*-isi-* + Apple Macintosh (MPW) host N/A stuff.c (Program to stuff files into a specially prepared space in kdb) kdb-start.c (Main loop for the standalone kernel debugger) Index: TODO =================================================================== RCS file: /cvs/src/src/gdb/TODO,v retrieving revision 1.79 diff -p -r1.79 TODO *** TODO 2001/04/17 21:20:48 1.79 --- TODO 2001/04/17 22:28:52 *************** MAINTAINERS file. *** 160,167 **** o arm-* vs NetBSD's lack of ``unix'' o arm-* vs IRIX (see below) - o delete mpw? - -- 2001-03-15 Obsolete some targets. --- 160,165 ---- *************** Steps: *** 201,206 **** --- 199,206 ---- powerpc-*-netware* powerpc - ppc-nw yes w65-*-* w65 - w65 yes i[3456]86-*-sunos* i386 sun386 sun386 yes + mpw m68k mpw mpw yes + mpw powerpc mpw mpw yes (DONE) Index: event-top.c =================================================================== RCS file: /cvs/src/src/gdb/event-top.c,v retrieving revision 1.13 diff -p -r1.13 event-top.c *** event-top.c 2001/03/06 08:21:07 1.13 --- event-top.c 2001/04/17 22:28:54 *************** display_gdb_prompt (char *new_prompt) *** 302,312 **** the user is not accounted for. */ fputs_unfiltered (new_prompt, gdb_stdout); ! #ifdef MPW ! /* Move to a new line so the entered line doesn't have a prompt ! on the front of it. */ ! fputs_unfiltered ("\n", gdb_stdout); ! #endif /* MPW */ gdb_flush (gdb_stdout); } } --- 302,312 ---- the user is not accounted for. */ fputs_unfiltered (new_prompt, gdb_stdout); ! /* OBSOLETE #ifdef MPW */ ! /* OBSOLETE /* Move to a new line so the entered line doesn't have a prompt */ ! /* OBSOLETE on the front of it. */ ! /* OBSOLETE fputs_unfiltered ("\n", gdb_stdout); */ ! /* OBSOLETE #endif /* MPW */ */ gdb_flush (gdb_stdout); } } Index: source.c =================================================================== RCS file: /cvs/src/src/gdb/source.c,v retrieving revision 1.12 diff -p -r1.12 source.c *** source.c 2001/04/05 02:02:13 1.12 --- source.c 2001/04/17 22:28:56 *************** done: *** 609,630 **** filename, NULL); } } ! #ifdef MPW ! /* This is a debugging hack that can go away when all combinations ! of Mac and Unix names are handled reasonably. */ ! { ! extern int debug_openp; ! ! if (debug_openp) ! { ! printf ("openp on %s, path %s mode %d prot %d\n returned %d", ! string, path, mode, prot, fd); ! if (*filename_opened) ! printf (" (filename is %s)", *filename_opened); ! printf ("\n"); ! } ! } ! #endif /* MPW */ return fd; } --- 609,630 ---- filename, NULL); } } ! /* OBSOLETE #ifdef MPW */ ! /* OBSOLETE /* This is a debugging hack that can go away when all combinations */ ! /* OBSOLETE of Mac and Unix names are handled reasonably. */ ! /* OBSOLETE { */ ! /* OBSOLETE extern int debug_openp; */ ! /* OBSOLETE */ ! /* OBSOLETE if (debug_openp) */ ! /* OBSOLETE { */ ! /* OBSOLETE printf ("openp on %s, path %s mode %d prot %d\n returned %d", */ ! /* OBSOLETE string, path, mode, prot, fd); */ ! /* OBSOLETE if (*filename_opened) */ ! /* OBSOLETE printf (" (filename is %s)", *filename_opened); */ ! /* OBSOLETE printf ("\n"); */ ! /* OBSOLETE } */ ! /* OBSOLETE } */ ! /* OBSOLETE #endif *//* MPW */ return fd; } *************** open_source_file (struct symtab *s) *** 710,731 **** if (p != s->filename) result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname); } ! #ifdef MPW ! if (result < 0) ! { ! /* Didn't work. Try using just the MPW basename. */ ! p = (char *) mpw_basename (s->filename); ! if (p != s->filename) ! result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname); ! } ! if (result < 0) ! { ! /* Didn't work. Try using the mixed Unix/MPW basename. */ ! p = (char *) mpw_mixed_basename (s->filename); ! if (p != s->filename) ! result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname); ! } ! #endif /* MPW */ if (result >= 0) { --- 710,731 ---- if (p != s->filename) result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname); } ! /* OBSOLETE #ifdef MPW */ ! /* OBSOLETE if (result < 0) */ ! /* OBSOLETE { */ ! /* OBSOLETE /* Didn't work. Try using just the MPW basename. */ ! /* OBSOLETE p = (char *) mpw_basename (s->filename); */ ! /* OBSOLETE if (p != s->filename) */ ! /* OBSOLETE result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname); */ ! /* OBSOLETE } */ ! /* OBSOLETE if (result < 0) */ ! /* OBSOLETE { */ ! /* OBSOLETE /* Didn't work. Try using the mixed Unix/MPW basename. */ ! /* OBSOLETE p = (char *) mpw_mixed_basename (s->filename); */ ! /* OBSOLETE if (p != s->filename) */ ! /* OBSOLETE result = openp (path, 0, p, OPEN_MODE, 0, &s->fullname); */ ! /* OBSOLETE } */ ! /* OBSOLETE #endif /* MPW */ if (result >= 0) { Index: top.c =================================================================== RCS file: /cvs/src/src/gdb/top.c,v retrieving revision 1.31 diff -p -r1.31 top.c *** top.c 2001/04/05 15:19:42 1.31 --- top.c 2001/04/17 22:28:56 *************** gdb_readline (char *prompt_arg) *** 1001,1011 **** character position to be off, since the newline we read from the user is not accounted for. */ fputs_unfiltered (prompt_arg, gdb_stdout); ! #ifdef MPW ! /* Move to a new line so the entered line doesn't have a prompt ! on the front of it. */ ! fputs_unfiltered ("\n", gdb_stdout); ! #endif /* MPW */ gdb_flush (gdb_stdout); } --- 1001,1011 ---- character position to be off, since the newline we read from the user is not accounted for. */ fputs_unfiltered (prompt_arg, gdb_stdout); ! /* OBSOLETE #ifdef MPW */ ! /* OBSOLETE Move to a new line so the entered line doesn't have a prompt */ ! /* OBSOLETE on the front of it. */ ! /* OBSOLETE fputs_unfiltered ("\n", gdb_stdout); */ ! /* OBSOLETE #endif /* MPW */ gdb_flush (gdb_stdout); } Index: utils.c =================================================================== RCS file: /cvs/src/src/gdb/utils.c,v retrieving revision 1.39 diff -p -r1.39 utils.c *** utils.c 2001/03/23 23:39:57 1.39 --- utils.c 2001/04/17 22:29:03 *************** query (char *ctlstr,...) *** 1262,1272 **** /* Automatically answer "yes" if input is not from a terminal. */ if (!input_from_terminal_p ()) return 1; ! #ifdef MPW ! /* FIXME Automatically answer "yes" if called from MacGDB. */ ! if (mac_app) ! return 1; ! #endif /* MPW */ while (1) { --- 1262,1272 ---- /* Automatically answer "yes" if input is not from a terminal. */ if (!input_from_terminal_p ()) return 1; ! /* OBSOLETE #ifdef MPW */ ! /* OBSOLETE /* FIXME Automatically answer "yes" if called from MacGDB. */ ! /* OBSOLETE if (mac_app) */ ! /* OBSOLETE return 1; */ ! /* OBSOLETE #endif MPW */ while (1) { *************** query (char *ctlstr,...) *** 1282,1293 **** if (annotation_level > 1) printf_filtered ("\n\032\032query\n"); ! #ifdef MPW ! /* If not in MacGDB, move to a new line so the entered line doesn't ! have a prompt on the front of it. */ ! if (!mac_app) ! fputs_unfiltered ("\n", gdb_stdout); ! #endif /* MPW */ wrap_here (""); gdb_flush (gdb_stdout); --- 1282,1293 ---- if (annotation_level > 1) printf_filtered ("\n\032\032query\n"); ! /* OBSOLETE #ifdef MPW */ ! /* OBSOLETE /* If not in MacGDB, move to a new line so the entered line doesn't */ ! /* OBSOLETE have a prompt on the front of it. */ */ ! /* OBSOLETE if (!mac_app) */ ! /* OBSOLETE fputs_unfiltered ("\n", gdb_stdout); */ ! /* OBSOLETE #endif /* MPW */ */ wrap_here (""); gdb_flush (gdb_stdout); *************** init_page_info (void) *** 1562,1568 **** lines_per_page = 24; chars_per_line = 80; ! #if !defined (MPW) && !defined (_WIN32) /* No termcap under MPW, although might be cool to do something by looking at worksheet or console window sizes. */ /* Initialize the screen height and width from termcap. */ --- 1562,1568 ---- lines_per_page = 24; chars_per_line = 80; ! #if !defined (_WIN32) /* No termcap under MPW, although might be cool to do something by looking at worksheet or console window sizes. */ /* Initialize the screen height and width from termcap. */ >From ischis2@home.com Tue Apr 17 16:38:00 2001 From: Stephen Smith To: gdb-patches@sourceware.cygnus.com Subject: shared libraries and a remote target Date: Tue, 17 Apr 2001 16:38:00 -0000 Message-id: <3ADCD4F9.5D99D35D@home.com> X-SW-Source: 2001-04/msg00185.html Content-length: 18202 Here are the patches that I used to get a working version of GDB that would support shared libraries on a remote target. Kevin said that I should send the patches now: > It's okay to send the patch to gdb-patches anyway. You'll get > feedback on what (if anything) will need to be changed before it > can go into the mainline sources. > >Kevin I made the changes as self-contained as possible so that the side effects would be minimized. sps ---------------------------- patches ------------------------- diff -r -P -c -w -b -B insight-20010306-orig/gdb/main.c insight-20010306/gdb/main.c *** insight-20010306-orig/gdb/main.c Fri Jan 26 17:43:25 2001 --- insight-20010306/gdb/main.c Thu Apr 12 15:20:01 2001 *************** *** 283,288 **** --- 283,290 ---- {"windows", no_argument, &use_windows, 1}, {"statistics", no_argument, 0, 13}, {"write", no_argument, &write_files, 1}, + {"remote-shared-libs", no_argument, &remote_shared_libs, 1}, + {"no-remote-shared-libs", no_argument, &remote_shared_libs, 0}, /* Allow machine descriptions to add more options... */ #ifdef ADDITIONAL_OPTIONS ADDITIONAL_OPTIONS diff -r -P -c -w -b -B insight-20010306-orig/gdb/remote.c insight-20010306/gdb/remote.c *** insight-20010306-orig/gdb/remote.c Wed Feb 28 18:39:21 2001 --- insight-20010306/gdb/remote.c Thu Apr 12 15:59:32 2001 *************** *** 48,53 **** --- 48,54 ---- #include "inf-loop.h" #include + #include #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: + [-mapped] [-readnow] [-s ]* + */ + 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 + #include #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: + [-mapped] [-readnow] [-s ]* + */ + 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 *);