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