Fix whitespace problem in my most recent entry.
[deliverable/binutils-gdb.git] / gdb / xcoffsolib.c
CommitLineData
c906108c 1/* Shared library support for RS/6000 (xcoff) object files, for GDB.
a8079a9b 2 Copyright 1991, 1992, 2001 Free Software Foundation.
c906108c
SS
3 Contributed by IBM Corporation.
4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b
JM
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. */
c906108c 21
c906108c
SS
22#include "defs.h"
23#include "bfd.h"
24#include "xcoffsolib.h"
25#include "inferior.h"
63f58cc5
PS
26#include "gdbcmd.h"
27#include "symfile.h"
28#include "frame.h"
29#include "gdb_regex.h"
c5aa993b 30
c906108c 31
a8079a9b
PS
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. */
c906108c
SS
35
36char *
a8079a9b 37xcoff_solib_address (CORE_ADDR addr)
c906108c 38{
a8079a9b 39 static char *buffer = NULL;
c5aa993b
JM
40 struct vmap *vp = vmap;
41
a8079a9b
PS
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)
c5aa993b
JM
47 if (vp->tstart <= addr && addr < vp->tend)
48 {
a8079a9b
PS
49 xfree (buffer);
50 xasprintf (&buffer, "%s%s%s%s",
51 vp->name,
52 *vp->member ? "(" : "",
53 vp->member,
54 *vp->member ? ")" : "");
c906108c 55 return buffer;
c5aa993b 56 }
a8079a9b 57 return NULL;
c906108c
SS
58}
59
a14ed312 60static void solib_info (char *, int);
63f58cc5 61static void sharedlibrary_command (char *pattern, int from_tty);
c906108c
SS
62
63static void
fba45db2 64solib_info (char *args, int from_tty)
c906108c
SS
65{
66 struct vmap *vp = vmap;
67
68 /* Check for new shared libraries loaded with load (). */
63f58cc5
PS
69 if (inferior_pid)
70 xcoff_relocate_symtab (inferior_pid);
c906108c
SS
71
72 if (vp == NULL || vp->nxt == NULL)
73 {
c5aa993b 74 printf_unfiltered ("No shared libraries loaded at this time.\n");
c906108c
SS
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 ("\
82Text Range Data Range Syms Shared Object Library\n");
83
84 for (; vp != NULL; vp = vp->nxt)
85 {
d4f3574e
SS
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),
c906108c 89 vp->loaded ? "Yes" : "No ",
a8079a9b 90 vp->name,
c906108c
SS
91 *vp->member ? "(" : "",
92 vp->member,
a8079a9b 93 *vp->member ? ")" : "");
c906108c
SS
94 }
95}
96
63f58cc5
PS
97static void
98sharedlibrary_command (char *pattern, int from_tty)
c906108c
SS
99{
100 dont_repeat ();
101
102 /* Check for new shared libraries loaded with load (). */
63f58cc5
PS
103 if (inferior_pid)
104 xcoff_relocate_symtab (inferior_pid);
105
106 if (pattern)
107 {
108 char *re_err = re_comp (pattern);
c906108c 109
63f58cc5
PS
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 }
c906108c
SS
157}
158
159void
fba45db2 160_initialize_solib (void)
c906108c
SS
161{
162 add_com ("sharedlibrary", class_files, sharedlibrary_command,
163 "Load shared object library symbols for files matching REGEXP.");
c5aa993b 164 add_info ("sharedlibrary", solib_info,
c906108c 165 "Status of loaded shared object libraries");
63f58cc5
PS
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\
171If nonzero, symbols from all shared object libraries will be loaded\n\
172automatically when the inferior begins execution or when the dynamic linker\n\
173informs gdb that a new library has been loaded. Otherwise, symbols\n\
174must be loaded manually, using `sharedlibrary'.",
175 &setlist),
176 &showlist);
c906108c 177}
This page took 0.109202 seconds and 4 git commands to generate.