2001-02-04 Philip Blundell <philb@gnu.org>
[deliverable/binutils-gdb.git] / gdb / xcoffsolib.c
CommitLineData
c906108c
SS
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
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
SS
31
32/* Return the module name of a given text address. Note that returned buffer
33 is not persistent. */
34
35char *
fba45db2 36pc_load_segment_name (CORE_ADDR addr)
c906108c 37{
c5aa993b
JM
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 }
c906108c
SS
51 strcat (buffer, vp->name);
52 return buffer;
c5aa993b
JM
53 }
54 return "(unknown load module)";
c906108c
SS
55}
56
a14ed312 57static void solib_info (char *, int);
63f58cc5 58static void sharedlibrary_command (char *pattern, int from_tty);
c906108c
SS
59
60static void
fba45db2 61solib_info (char *args, int from_tty)
c906108c
SS
62{
63 struct vmap *vp = vmap;
64
65 /* Check for new shared libraries loaded with load (). */
63f58cc5
PS
66 if (inferior_pid)
67 xcoff_relocate_symtab (inferior_pid);
c906108c
SS
68
69 if (vp == NULL || vp->nxt == NULL)
70 {
c5aa993b 71 printf_unfiltered ("No shared libraries loaded at this time.\n");
c906108c
SS
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 ("\
79Text Range Data Range Syms Shared Object Library\n");
80
81 for (; vp != NULL; vp = vp->nxt)
82 {
d4f3574e
SS
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),
c906108c
SS
86 vp->loaded ? "Yes" : "No ",
87 *vp->member ? "(" : "",
88 vp->member,
89 *vp->member ? ") " : "",
90 vp->name);
91 }
92}
93
63f58cc5
PS
94static void
95sharedlibrary_command (char *pattern, int from_tty)
c906108c
SS
96{
97 dont_repeat ();
98
99 /* Check for new shared libraries loaded with load (). */
63f58cc5
PS
100 if (inferior_pid)
101 xcoff_relocate_symtab (inferior_pid);
102
103 if (pattern)
104 {
105 char *re_err = re_comp (pattern);
c906108c 106
63f58cc5
PS
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 }
c906108c
SS
154}
155
156void
fba45db2 157_initialize_solib (void)
c906108c
SS
158{
159 add_com ("sharedlibrary", class_files, sharedlibrary_command,
160 "Load shared object library symbols for files matching REGEXP.");
c5aa993b 161 add_info ("sharedlibrary", solib_info,
c906108c 162 "Status of loaded shared object libraries");
63f58cc5
PS
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\
168If nonzero, symbols from all shared object libraries will be loaded\n\
169automatically when the inferior begins execution or when the dynamic linker\n\
170informs gdb that a new library has been loaded. Otherwise, symbols\n\
171must be loaded manually, using `sharedlibrary'.",
172 &setlist),
173 &showlist);
c906108c 174}
This page took 0.158533 seconds and 4 git commands to generate.