1130812Smarcel/* Shared library support for RS/6000 (xcoff) object files, for GDB. 2130812Smarcel Copyright 1991, 1992, 1995, 1996, 1999, 2000, 2001 3130812Smarcel Free Software Foundation, Inc. 4130812Smarcel Contributed by IBM Corporation. 5130812Smarcel 6130812Smarcel This file is part of GDB. 7130812Smarcel 8130812Smarcel This program is free software; you can redistribute it and/or modify 9130812Smarcel it under the terms of the GNU General Public License as published by 10130812Smarcel the Free Software Foundation; either version 2 of the License, or 11130812Smarcel (at your option) any later version. 12130812Smarcel 13130812Smarcel This program is distributed in the hope that it will be useful, 14130812Smarcel but WITHOUT ANY WARRANTY; without even the implied warranty of 15130812Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16130812Smarcel GNU General Public License for more details. 17130812Smarcel 18130812Smarcel You should have received a copy of the GNU General Public License 19130812Smarcel along with this program; if not, write to the Free Software 20130812Smarcel Foundation, Inc., 59 Temple Place - Suite 330, 21130812Smarcel Boston, MA 02111-1307, USA. */ 22130812Smarcel 23130812Smarcel#include "defs.h" 24130812Smarcel#include "bfd.h" 25130812Smarcel#include "xcoffsolib.h" 26130812Smarcel#include "inferior.h" 27130812Smarcel#include "gdbcmd.h" 28130812Smarcel#include "symfile.h" 29130812Smarcel#include "frame.h" 30130812Smarcel#include "gdb_regex.h" 31130812Smarcel 32130812Smarcel 33130812Smarcel/* If ADDR lies in a shared library, return its name. 34130812Smarcel Note that returned name points to static data whose content is overwritten 35130812Smarcel by each call. */ 36130812Smarcel 37130812Smarcelchar * 38130812Smarcelxcoff_solib_address (CORE_ADDR addr) 39130812Smarcel{ 40130812Smarcel static char *buffer = NULL; 41130812Smarcel struct vmap *vp = vmap; 42130812Smarcel 43130812Smarcel /* The first vmap entry is for the exec file. */ 44130812Smarcel 45130812Smarcel if (vp == NULL) 46130812Smarcel return NULL; 47130812Smarcel for (vp = vp->nxt; vp; vp = vp->nxt) 48130812Smarcel if (vp->tstart <= addr && addr < vp->tend) 49130812Smarcel { 50130812Smarcel xfree (buffer); 51130812Smarcel xasprintf (&buffer, "%s%s%s%s", 52130812Smarcel vp->name, 53130812Smarcel *vp->member ? "(" : "", 54130812Smarcel vp->member, 55130812Smarcel *vp->member ? ")" : ""); 56130812Smarcel return buffer; 57130812Smarcel } 58130812Smarcel return NULL; 59130812Smarcel} 60130812Smarcel 61130812Smarcelstatic void solib_info (char *, int); 62130812Smarcelstatic void sharedlibrary_command (char *pattern, int from_tty); 63130812Smarcel 64130812Smarcelstatic void 65130812Smarcelsolib_info (char *args, int from_tty) 66130812Smarcel{ 67130812Smarcel struct vmap *vp = vmap; 68130812Smarcel 69130812Smarcel /* Check for new shared libraries loaded with load (). */ 70130812Smarcel if (! ptid_equal (inferior_ptid, null_ptid)) 71130812Smarcel xcoff_relocate_symtab (PIDGET (inferior_ptid)); 72130812Smarcel 73130812Smarcel if (vp == NULL || vp->nxt == NULL) 74130812Smarcel { 75130812Smarcel printf_unfiltered ("No shared libraries loaded at this time.\n"); 76130812Smarcel return; 77130812Smarcel } 78130812Smarcel 79130812Smarcel /* Skip over the first vmap, it is the main program, always loaded. */ 80130812Smarcel vp = vp->nxt; 81130812Smarcel 82130812Smarcel printf_unfiltered ("\ 83130812SmarcelText Range Data Range Syms Shared Object Library\n"); 84130812Smarcel 85130812Smarcel for (; vp != NULL; vp = vp->nxt) 86130812Smarcel { 87130812Smarcel printf_unfiltered ("0x%s-0x%s 0x%s-0x%s %s %s%s%s%s\n", 88130812Smarcel paddr (vp->tstart),paddr (vp->tend), 89130812Smarcel paddr (vp->dstart), paddr (vp->dend), 90130812Smarcel vp->loaded ? "Yes" : "No ", 91130812Smarcel vp->name, 92130812Smarcel *vp->member ? "(" : "", 93130812Smarcel vp->member, 94130812Smarcel *vp->member ? ")" : ""); 95130812Smarcel } 96130812Smarcel} 97130812Smarcel 98130812Smarcelstatic void 99130812Smarcelsharedlibrary_command (char *pattern, int from_tty) 100130812Smarcel{ 101130812Smarcel dont_repeat (); 102130812Smarcel 103130812Smarcel /* Check for new shared libraries loaded with load (). */ 104130812Smarcel if (! ptid_equal (inferior_ptid, null_ptid)) 105130812Smarcel xcoff_relocate_symtab (PIDGET (inferior_ptid)); 106130812Smarcel 107130812Smarcel if (pattern) 108130812Smarcel { 109130812Smarcel char *re_err = re_comp (pattern); 110130812Smarcel 111130812Smarcel if (re_err) 112130812Smarcel error ("Invalid regexp: %s", re_err); 113130812Smarcel } 114130812Smarcel 115130812Smarcel /* Walk the list of currently loaded shared libraries, and read 116130812Smarcel symbols for any that match the pattern --- or any whose symbols 117130812Smarcel aren't already loaded, if no pattern was given. */ 118130812Smarcel { 119130812Smarcel int any_matches = 0; 120130812Smarcel int loaded_any_symbols = 0; 121130812Smarcel struct vmap *vp = vmap; 122130812Smarcel 123130812Smarcel if (!vp) 124130812Smarcel return; 125130812Smarcel 126130812Smarcel /* skip over the first vmap, it is the main program, always loaded. */ 127130812Smarcel for (vp = vp->nxt; vp; vp = vp->nxt) 128130812Smarcel if (! pattern 129130812Smarcel || re_exec (vp->name) 130130812Smarcel || (*vp->member && re_exec (vp->member))) 131130812Smarcel { 132130812Smarcel any_matches = 1; 133130812Smarcel 134130812Smarcel if (vp->loaded) 135130812Smarcel { 136130812Smarcel if (from_tty) 137130812Smarcel printf_unfiltered ("Symbols already loaded for %s\n", 138130812Smarcel vp->name); 139130812Smarcel } 140130812Smarcel else 141130812Smarcel { 142130812Smarcel if (vmap_add_symbols (vp)) 143130812Smarcel loaded_any_symbols = 1; 144130812Smarcel } 145130812Smarcel } 146130812Smarcel 147130812Smarcel if (from_tty && pattern && ! any_matches) 148130812Smarcel printf_unfiltered 149130812Smarcel ("No loaded shared libraries match the pattern `%s'.\n", pattern); 150130812Smarcel 151130812Smarcel if (loaded_any_symbols) 152130812Smarcel { 153130812Smarcel /* Getting new symbols may change our opinion about what is 154130812Smarcel frameless. */ 155130812Smarcel reinit_frame_cache (); 156130812Smarcel } 157130812Smarcel } 158130812Smarcel} 159130812Smarcel 160130812Smarcel/* LOCAL FUNCTION 161130812Smarcel 162130812Smarcel no_shared_libraries -- handle command to explicitly discard symbols 163130812Smarcel from shared libraries. 164130812Smarcel 165130812Smarcel DESCRIPTION 166130812Smarcel 167130812Smarcel Implements the command "nosharedlibrary", which discards symbols 168130812Smarcel that have been auto-loaded from shared libraries. Symbols from 169130812Smarcel shared libraries that were added by explicit request of the user 170130812Smarcel are not discarded. Also called from remote.c. */ 171130812Smarcel 172130812Smarcelvoid 173130812Smarcelno_shared_libraries (char *ignored, int from_tty) 174130812Smarcel{ 175130812Smarcel /* FIXME */ 176130812Smarcel} 177130812Smarcel 178130812Smarcelvoid 179130812Smarcel_initialize_xcoffsolib (void) 180130812Smarcel{ 181130812Smarcel add_com ("sharedlibrary", class_files, sharedlibrary_command, 182130812Smarcel "Load shared object library symbols for files matching REGEXP."); 183130812Smarcel add_info ("sharedlibrary", solib_info, 184130812Smarcel "Status of loaded shared object libraries"); 185130812Smarcel 186130812Smarcel add_show_from_set 187130812Smarcel (add_set_cmd ("auto-solib-add", class_support, var_boolean, 188130812Smarcel (char *) &auto_solib_add, 189130812Smarcel "Set autoloading of shared library symbols.\n\ 190130812SmarcelIf \"on\", symbols from all shared object libraries will be loaded\n\ 191130812Smarcelautomatically when the inferior begins execution, when the dynamic linker\n\ 192130812Smarcelinforms gdb that a new library has been loaded, or when attaching to the\n\ 193130812Smarcelinferior. Otherwise, symbols must be loaded manually, using `sharedlibrary'.", 194130812Smarcel &setlist), 195130812Smarcel &showlist); 196130812Smarcel} 197