From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28588 invoked by alias); 15 Apr 2004 21:42:54 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 28566 invoked from network); 15 Apr 2004 21:42:51 -0000 Received: from unknown (HELO gateway.sf.frob.com) (64.81.54.130) by sources.redhat.com with SMTP; 15 Apr 2004 21:42:51 -0000 Received: from magilla.sf.frob.com (magilla.sf.frob.com [198.49.250.228]) by gateway.sf.frob.com (Postfix) with ESMTP id 56C6D357B; Thu, 15 Apr 2004 14:42:50 -0700 (PDT) Received: from magilla.sf.frob.com (localhost.localdomain [127.0.0.1]) by magilla.sf.frob.com (8.12.9/8.12.9) with ESMTP id i3FLgoOi008926; Thu, 15 Apr 2004 14:42:50 -0700 Received: (from roland@localhost) by magilla.sf.frob.com (8.12.9/8.12.9/Submit) id i3FLgnA0008922; Thu, 15 Apr 2004 14:42:49 -0700 Date: Thu, 15 Apr 2004 21:42:00 -0000 Message-Id: <200404152142.i3FLgnA0008922@magilla.sf.frob.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit From: Roland McGrath To: gdb-patches@sources.redhat.com Subject: Re: [PATCH] add-symbol-file-from-memory command In-Reply-To: Jim Blandy's message of , 15 April 2004 13:08:15 -0500 X-Antipastobozoticataclysm: When George Bush projectile vomits antipasto on the Japanese. X-SW-Source: 2004-04/txt/msg00330.txt.bz2 > This looks fine. If neither you nor Daniel feel it should be a > 'maint' command, that's okay. Please commit. Committed, and here it is again (unchanged but for a little merging). 2004-04-15 Roland McGrath * symfile.c (symbol_file_add_with_addrs_or_offsets): Take ABFD as argument instead of NAME. (symbol_file_add, reread_separate_symbols): Call symfile_bfd_open in call to symbol_file_add_with_addrs_or_offsets. (build_addr_info): New function, helper for ... (symbol_file_add_from_memory): New function. (add_symbol_file_from_memory_command): New function using that. (_initialize_symfile): Register it for add-symbol-file-from-memory. (pre_add_symbol_hook): Add const to argument type. * symfile.h (symbol_file_add_from_memory): Declare it. gdbtk/ 2004-04-15 Roland McGrath * generic/gdbtk-hooks.c (gdbtk_pre_add_symbol): Add const to arg type. (pre_add_symbol): Likewise in extern decl. Index: symfile.c =================================================================== RCS file: /cvs/src/src/gdb/symfile.c,v retrieving revision 1.125 retrieving revision 1.126 diff -b -p -u -r1.125 -r1.126 --- symfile.c 8 Apr 2004 21:18:13 -0000 1.125 +++ symfile.c 15 Apr 2004 21:39:27 -0000 1.126 @@ -78,7 +78,7 @@ void (*show_load_progress) (const char * unsigned long section_size, unsigned long total_sent, unsigned long total_size); -void (*pre_add_symbol_hook) (char *); +void (*pre_add_symbol_hook) (const char *); void (*post_add_symbol_hook) (void); void (*target_new_objfile_hook) (struct objfile *); @@ -760,8 +760,8 @@ new_symfile_objfile (struct objfile *obj /* Process a symbol file, as either the main file or as a dynamically loaded file. - NAME is the file name (which will be tilde-expanded and made - absolute herein) (but we don't free or modify NAME itself). + ABFD is a BFD already open on the file, as from symfile_bfd_open. + This BFD will be closed on error, and is always consumed by this function. FROM_TTY says how verbose to be. @@ -775,7 +775,7 @@ new_symfile_objfile (struct objfile *obj Upon success, returns a pointer to the objfile that was added. Upon failure, jumps back to command level (never returns). */ static struct objfile * -symbol_file_add_with_addrs_or_offsets (char *name, int from_tty, +symbol_file_add_with_addrs_or_offsets (bfd *abfd, int from_tty, struct section_addr_info *addrs, struct section_offsets *offsets, int num_offsets, @@ -784,14 +784,14 @@ symbol_file_add_with_addrs_or_offsets (c struct objfile *objfile; struct partial_symtab *psymtab; char *debugfile; - bfd *abfd; struct section_addr_info *orig_addrs; struct cleanup *my_cleanups; + const char *name = bfd_get_filename (abfd); - /* Open a bfd for the file, and give user a chance to burp if we'd be - interactively wiping out any existing symbols. */ + my_cleanups = make_cleanup_bfd_close (abfd); - abfd = symfile_bfd_open (name); + /* Give user a chance to burp if we'd be + interactively wiping out any existing symbols. */ if ((have_full_symbols () || have_partial_symbols ()) && mainline @@ -800,6 +800,7 @@ symbol_file_add_with_addrs_or_offsets (c error ("Not confirmed."); objfile = allocate_objfile (abfd, flags); + discard_cleanups (my_cleanups); orig_addrs = alloc_section_addr_info (bfd_count_sections (abfd)); my_cleanups = make_cleanup (xfree, orig_addrs); @@ -916,7 +917,8 @@ struct objfile * symbol_file_add (char *name, int from_tty, struct section_addr_info *addrs, int mainline, int flags) { - return symbol_file_add_with_addrs_or_offsets (name, from_tty, addrs, 0, 0, + return symbol_file_add_with_addrs_or_offsets (symfile_bfd_open (name), + from_tty, addrs, 0, 0, mainline, flags); } @@ -1766,6 +1768,87 @@ add_shared_symbol_files_command (char *a #endif } +/* Read inferior memory at ADDR to find the header of a loaded object file + and read its in-core symbols out of inferior memory. TEMPL is a bfd + representing the target's format. */ +struct objfile * +symbol_file_add_from_memory (bfd *templ, CORE_ADDR addr, int from_tty) +{ + struct objfile *objf; + bfd *nbfd; + asection *sec; + bfd_vma loadbase; + struct section_addr_info *sai; + unsigned int i; + + if (bfd_get_flavour (templ) != bfd_target_elf_flavour) + error ("add-symbol-file-from-memory not supported for this target"); + + nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, &loadbase, + target_read_memory); + if (nbfd == NULL) + { + error ("Failed to read a valid object file image from memory."); + return NULL; + } + + nbfd->filename = xstrdup ("shared object read from target memory"); + + if (!bfd_check_format (nbfd, bfd_object)) + { + /* FIXME: should be checking for errors from bfd_close (for one thing, + on error it does not free all the storage associated with the + bfd). */ + bfd_close (nbfd); + error ("Got object file from memory but can't read symbols: %s.", + bfd_errmsg (bfd_get_error ())); + return NULL; + } + + sai = alloc_section_addr_info (bfd_count_sections (nbfd)); + make_cleanup (xfree, sai); + i = 0; + for (sec = nbfd->sections; sec != NULL; sec = sec->next) + if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0) + { + sai->other[i].addr = bfd_get_section_vma (nbfd, sec) + loadbase; + sai->other[i].name = (char *) bfd_get_section_name (nbfd, sec); + sai->other[i].sectindex = sec->index; + ++i; + } + + objf = symbol_file_add_with_addrs_or_offsets (nbfd, from_tty, + sai, NULL, 0, 0, OBJF_SHARED); + + /* This might change our ideas about frames already looked at. */ + reinit_frame_cache (); + + return objf; +} + +static void +add_symbol_file_from_memory_command (char *args, int from_tty) +{ + CORE_ADDR addr; + bfd *templ; + + if (args == NULL) + error ("add-symbol-file-from-memory requires an expression argument"); + + addr = parse_and_eval_address (args); + + /* We need some representative bfd to know the target we are looking at. */ + if (symfile_objfile != NULL) + templ = symfile_objfile->obfd; + else + templ = exec_bfd; + if (templ == NULL) + error ("\ +Must use symbol-file or exec-file before add-symbol-file-from-memory."); + + (void) symbol_file_add_from_memory (templ, addr, from_tty); +} + /* Re-read symbols if a symbol-file has changed. */ void reread_symbols (void) @@ -2022,7 +2105,7 @@ reread_separate_symbols (struct objfile Preserve the flags from objfile that make sense. */ objfile->separate_debug_objfile = (symbol_file_add_with_addrs_or_offsets - (debug_file, + (symfile_bfd_open (debug_file), info_verbose, /* from_tty: Don't override the default. */ 0, /* No addr table. */ objfile->section_offsets, objfile->num_sections, @@ -3525,6 +3608,13 @@ with the text. SECT is a section name t &cmdlist); set_cmd_completer (c, filename_completer); + c = add_cmd ("add-symbol-file-from-memory", class_files, + add_symbol_file_from_memory_command, + "\ +Load the symbols out of memory from a dynamically loaded object file.\n\ +Give an expression for the address of the file's shared object file header.", + &cmdlist); + c = add_cmd ("add-shared-symbol-files", class_files, add_shared_symbol_files_command, "Load the symbols from shared objects in the dynamic linker's link map.", Index: symfile.h =================================================================== RCS file: /cvs/src/src/gdb/symfile.h,v retrieving revision 1.28 retrieving revision 1.29 diff -b -p -u -r1.28 -r1.29 --- symfile.h 2 Apr 2004 19:23:05 -0000 1.28 +++ symfile.h 15 Apr 2004 21:39:27 -0000 1.29 @@ -302,6 +302,12 @@ extern CORE_ADDR symbol_overlayed_addres /* Load symbols from a file. */ extern void symbol_file_add_main (char *args, int from_tty); +/* Read inferior memory at ADDR to find the header of a loaded object file + and read its in-core symbols out of inferior memory. TEMPL is a bfd + representing the target's format. */ +extern struct objfile *symbol_file_add_from_memory (bfd *templ, CORE_ADDR addr, + int from_tty); + /* Clear GDB symbol tables. */ extern void symbol_file_clear (int from_tty); Index: gdbtk/generic/gdbtk-hooks.c =================================================================== RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-hooks.c,v retrieving revision 1.31 retrieving revision 1.32 diff -b -p -u -r1.31 -r1.32 --- gdbtk/generic/gdbtk-hooks.c 12 Feb 2003 16:02:03 -0000 1.31 +++ gdbtk/generic/gdbtk-hooks.c 15 Apr 2004 21:39:35 -0000 1.32 @@ -73,7 +73,7 @@ extern void gdbtk_create_tracepoint (int extern void gdbtk_delete_tracepoint (int); extern void gdbtk_modify_tracepoint (int); -extern void (*pre_add_symbol_hook) (char *); +extern void (*pre_add_symbol_hook) (const char *); extern void (*post_add_symbol_hook) (void); extern void (*selected_frame_level_changed_hook) (int); extern int (*ui_loop_hook) (int); @@ -599,7 +599,7 @@ gdbtk_load_hash (const char *section, un /* This hook is called whenever we are ready to load a symbol file so that the UI can notify the user... */ static void -gdbtk_pre_add_symbol (char *name) +gdbtk_pre_add_symbol (const char *name) { gdbtk_two_elem_cmd ("gdbtk_tcl_pre_add_symbol", name); }