| 1 | /* Shared library support for RS/6000 (xcoff) object files, for GDB. |
| 2 | Copyright 1991, 1992 Free Software Foundation. |
| 3 | Contributed by IBM Corporation. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | Boston, MA 02111-1307, USA. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include "bfd.h" |
| 24 | #include "xcoffsolib.h" |
| 25 | #include "inferior.h" |
| 26 | #include "gdbcmd.h" |
| 27 | #include "symfile.h" |
| 28 | #include "frame.h" |
| 29 | #include "gdb_regex.h" |
| 30 | |
| 31 | |
| 32 | /* Return the module name of a given text address. Note that returned buffer |
| 33 | is not persistent. */ |
| 34 | |
| 35 | char * |
| 36 | pc_load_segment_name (CORE_ADDR addr) |
| 37 | { |
| 38 | static char buffer[BUFSIZ]; |
| 39 | struct vmap *vp = vmap; |
| 40 | |
| 41 | buffer[0] = buffer[1] = '\0'; |
| 42 | for (; vp; vp = vp->nxt) |
| 43 | if (vp->tstart <= addr && addr < vp->tend) |
| 44 | { |
| 45 | if (*vp->member) |
| 46 | { |
| 47 | buffer[0] = '('; |
| 48 | strcat (&buffer[1], vp->member); |
| 49 | strcat (buffer, ")"); |
| 50 | } |
| 51 | strcat (buffer, vp->name); |
| 52 | return buffer; |
| 53 | } |
| 54 | return "(unknown load module)"; |
| 55 | } |
| 56 | |
| 57 | static void solib_info (char *, int); |
| 58 | static void sharedlibrary_command (char *pattern, int from_tty); |
| 59 | |
| 60 | static void |
| 61 | solib_info (char *args, int from_tty) |
| 62 | { |
| 63 | struct vmap *vp = vmap; |
| 64 | |
| 65 | /* Check for new shared libraries loaded with load (). */ |
| 66 | if (inferior_pid) |
| 67 | xcoff_relocate_symtab (inferior_pid); |
| 68 | |
| 69 | if (vp == NULL || vp->nxt == NULL) |
| 70 | { |
| 71 | printf_unfiltered ("No shared libraries loaded at this time.\n"); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | /* Skip over the first vmap, it is the main program, always loaded. */ |
| 76 | vp = vp->nxt; |
| 77 | |
| 78 | printf_unfiltered ("\ |
| 79 | Text Range Data Range Syms Shared Object Library\n"); |
| 80 | |
| 81 | for (; vp != NULL; vp = vp->nxt) |
| 82 | { |
| 83 | printf_unfiltered ("0x%s-0x%s 0x%s-0x%s %s %s%s%s%s\n", |
| 84 | paddr (vp->tstart),paddr (vp->tend), |
| 85 | paddr (vp->dstart), paddr (vp->dend), |
| 86 | vp->loaded ? "Yes" : "No ", |
| 87 | *vp->member ? "(" : "", |
| 88 | vp->member, |
| 89 | *vp->member ? ") " : "", |
| 90 | vp->name); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | static void |
| 95 | sharedlibrary_command (char *pattern, int from_tty) |
| 96 | { |
| 97 | dont_repeat (); |
| 98 | |
| 99 | /* Check for new shared libraries loaded with load (). */ |
| 100 | if (inferior_pid) |
| 101 | xcoff_relocate_symtab (inferior_pid); |
| 102 | |
| 103 | if (pattern) |
| 104 | { |
| 105 | char *re_err = re_comp (pattern); |
| 106 | |
| 107 | if (re_err) |
| 108 | error ("Invalid regexp: %s", re_err); |
| 109 | } |
| 110 | |
| 111 | /* Walk the list of currently loaded shared libraries, and read |
| 112 | symbols for any that match the pattern --- or any whose symbols |
| 113 | aren't already loaded, if no pattern was given. */ |
| 114 | { |
| 115 | int any_matches = 0; |
| 116 | int loaded_any_symbols = 0; |
| 117 | struct vmap *vp = vmap; |
| 118 | |
| 119 | if (!vp) |
| 120 | return; |
| 121 | |
| 122 | /* skip over the first vmap, it is the main program, always loaded. */ |
| 123 | for (vp = vp->nxt; vp; vp = vp->nxt) |
| 124 | if (! pattern |
| 125 | || re_exec (vp->name) |
| 126 | || (*vp->member && re_exec (vp->member))) |
| 127 | { |
| 128 | any_matches = 1; |
| 129 | |
| 130 | if (vp->loaded) |
| 131 | { |
| 132 | if (from_tty) |
| 133 | printf_unfiltered ("Symbols already loaded for %s\n", |
| 134 | vp->name); |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | if (vmap_add_symbols (vp)) |
| 139 | loaded_any_symbols = 1; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | if (from_tty && pattern && ! any_matches) |
| 144 | printf_unfiltered |
| 145 | ("No loaded shared libraries match the pattern `%s'.\n", pattern); |
| 146 | |
| 147 | if (loaded_any_symbols) |
| 148 | { |
| 149 | /* Getting new symbols may change our opinion about what is |
| 150 | frameless. */ |
| 151 | reinit_frame_cache (); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | void |
| 157 | _initialize_solib (void) |
| 158 | { |
| 159 | add_com ("sharedlibrary", class_files, sharedlibrary_command, |
| 160 | "Load shared object library symbols for files matching REGEXP."); |
| 161 | add_info ("sharedlibrary", solib_info, |
| 162 | "Status of loaded shared object libraries"); |
| 163 | |
| 164 | add_show_from_set |
| 165 | (add_set_cmd ("auto-solib-add", class_support, var_zinteger, |
| 166 | (char *) &auto_solib_add, |
| 167 | "Set autoloading of shared library symbols.\n\ |
| 168 | If nonzero, symbols from all shared object libraries will be loaded\n\ |
| 169 | automatically when the inferior begins execution or when the dynamic linker\n\ |
| 170 | informs gdb that a new library has been loaded. Otherwise, symbols\n\ |
| 171 | must be loaded manually, using `sharedlibrary'.", |
| 172 | &setlist), |
| 173 | &showlist); |
| 174 | } |