Fix whitespace problem in my most recent entry.
[deliverable/binutils-gdb.git] / gdb / xcoffsolib.c
1 /* Shared library support for RS/6000 (xcoff) object files, for GDB.
2 Copyright 1991, 1992, 2001 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 /* If ADDR lies in a shared library, return its name.
33 Note that returned name points to static data whose content is overwritten
34 by each call. */
35
36 char *
37 xcoff_solib_address (CORE_ADDR addr)
38 {
39 static char *buffer = NULL;
40 struct vmap *vp = vmap;
41
42 /* The first vmap entry is for the exec file. */
43
44 if (vp == NULL)
45 return NULL;
46 for (vp = vp->nxt; vp; vp = vp->nxt)
47 if (vp->tstart <= addr && addr < vp->tend)
48 {
49 xfree (buffer);
50 xasprintf (&buffer, "%s%s%s%s",
51 vp->name,
52 *vp->member ? "(" : "",
53 vp->member,
54 *vp->member ? ")" : "");
55 return buffer;
56 }
57 return NULL;
58 }
59
60 static void solib_info (char *, int);
61 static void sharedlibrary_command (char *pattern, int from_tty);
62
63 static void
64 solib_info (char *args, int from_tty)
65 {
66 struct vmap *vp = vmap;
67
68 /* Check for new shared libraries loaded with load (). */
69 if (inferior_pid)
70 xcoff_relocate_symtab (inferior_pid);
71
72 if (vp == NULL || vp->nxt == NULL)
73 {
74 printf_unfiltered ("No shared libraries loaded at this time.\n");
75 return;
76 }
77
78 /* Skip over the first vmap, it is the main program, always loaded. */
79 vp = vp->nxt;
80
81 printf_unfiltered ("\
82 Text Range Data Range Syms Shared Object Library\n");
83
84 for (; vp != NULL; vp = vp->nxt)
85 {
86 printf_unfiltered ("0x%s-0x%s 0x%s-0x%s %s %s%s%s%s\n",
87 paddr (vp->tstart),paddr (vp->tend),
88 paddr (vp->dstart), paddr (vp->dend),
89 vp->loaded ? "Yes" : "No ",
90 vp->name,
91 *vp->member ? "(" : "",
92 vp->member,
93 *vp->member ? ")" : "");
94 }
95 }
96
97 static void
98 sharedlibrary_command (char *pattern, int from_tty)
99 {
100 dont_repeat ();
101
102 /* Check for new shared libraries loaded with load (). */
103 if (inferior_pid)
104 xcoff_relocate_symtab (inferior_pid);
105
106 if (pattern)
107 {
108 char *re_err = re_comp (pattern);
109
110 if (re_err)
111 error ("Invalid regexp: %s", re_err);
112 }
113
114 /* Walk the list of currently loaded shared libraries, and read
115 symbols for any that match the pattern --- or any whose symbols
116 aren't already loaded, if no pattern was given. */
117 {
118 int any_matches = 0;
119 int loaded_any_symbols = 0;
120 struct vmap *vp = vmap;
121
122 if (!vp)
123 return;
124
125 /* skip over the first vmap, it is the main program, always loaded. */
126 for (vp = vp->nxt; vp; vp = vp->nxt)
127 if (! pattern
128 || re_exec (vp->name)
129 || (*vp->member && re_exec (vp->member)))
130 {
131 any_matches = 1;
132
133 if (vp->loaded)
134 {
135 if (from_tty)
136 printf_unfiltered ("Symbols already loaded for %s\n",
137 vp->name);
138 }
139 else
140 {
141 if (vmap_add_symbols (vp))
142 loaded_any_symbols = 1;
143 }
144 }
145
146 if (from_tty && pattern && ! any_matches)
147 printf_unfiltered
148 ("No loaded shared libraries match the pattern `%s'.\n", pattern);
149
150 if (loaded_any_symbols)
151 {
152 /* Getting new symbols may change our opinion about what is
153 frameless. */
154 reinit_frame_cache ();
155 }
156 }
157 }
158
159 void
160 _initialize_solib (void)
161 {
162 add_com ("sharedlibrary", class_files, sharedlibrary_command,
163 "Load shared object library symbols for files matching REGEXP.");
164 add_info ("sharedlibrary", solib_info,
165 "Status of loaded shared object libraries");
166
167 add_show_from_set
168 (add_set_cmd ("auto-solib-add", class_support, var_zinteger,
169 (char *) &auto_solib_add,
170 "Set autoloading of shared library symbols.\n\
171 If nonzero, symbols from all shared object libraries will be loaded\n\
172 automatically when the inferior begins execution or when the dynamic linker\n\
173 informs gdb that a new library has been loaded. Otherwise, symbols\n\
174 must be loaded manually, using `sharedlibrary'.",
175 &setlist),
176 &showlist);
177 }
This page took 0.032414 seconds and 4 git commands to generate.