This commit was generated by cvs2svn to track changes on a CVS vendor
[external/binutils.git] / gdb / xcoffsolib.c
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, Boston, MA 02111-1307, USA.  */
20
21 #if 0
22 #include <sys/types.h>
23 #include <sys/ldr.h>
24 #endif
25
26 #include "defs.h"
27 #include "bfd.h"
28 #include "xcoffsolib.h"
29 #include "inferior.h"
30 #include "command.h"
31
32 /* Hook to relocate symbols at runtime.  If gdb is build natively, this
33    hook is initialized in by rs6000-nat.c.  If not, it is currently left
34    NULL and never called. */
35
36 void (*xcoff_relocate_symtab_hook) PARAMS ((unsigned int)) = NULL;
37
38 #ifdef SOLIB_SYMBOLS_MANUAL
39
40 extern struct symtab *current_source_symtab;
41 extern int            current_source_line;
42
43 /* The real work of adding a shared library file to the symtab and
44    the section list.  */
45
46 void
47 solib_add (arg_string, from_tty, target)
48      char *arg_string;
49      int from_tty;
50      struct target_ops *target;
51 {       
52   char *val;
53   struct vmap *vp = vmap;
54   struct objfile *obj;
55   struct symtab *saved_symtab;
56   int saved_line;
57
58   int loaded = 0;                       /* true if any shared obj loaded */
59   int matched = 0;                      /* true if any shared obj matched */
60
61   if (arg_string == 0)
62       re_comp (".");
63   else if (val = (char *) re_comp (arg_string)) {
64       error ("Invalid regexp: %s", val);
65   }
66   if (!vp || !vp->nxt)
67     return;
68
69   /* save current symbol table and line number, in case they get changed
70      in symbol loading process. */
71  
72   saved_symtab = current_source_symtab;
73   saved_line = current_source_line;
74
75   /* skip over the first vmap, it is the main program, always loaded. */
76   vp = vp->nxt;
77
78   for (; vp; vp = vp->nxt) {
79
80     if (re_exec (vp->name) || (*vp->member && re_exec (vp->member))) {
81
82       matched = 1;
83
84       /* if already loaded, continue with the next one. */
85       if (vp->loaded) {
86         
87         printf_unfiltered ("%s%s%s%s: already loaded.\n",
88           *vp->member ? "(" : "",
89           vp->member,
90           *vp->member ? ") " : "",
91           vp->name);
92         continue;
93       }
94
95       printf_unfiltered ("Loading  %s%s%s%s...",
96           *vp->member ? "(" : "",
97           vp->member,
98           *vp->member ? ") " : "",
99           vp->name);
100       gdb_flush (gdb_stdout);
101
102       /* This is gross and doesn't work.  If this code is re-enabled,
103          just stick a objfile member into the struct vmap; that's the
104          way solib.c (for SunOS/SVR4) does it.  */
105         obj = lookup_objfile_bfd (vp->bfd);
106         if (!obj) {
107           warning ("\nObj structure for the shared object not found. Loading failed.");
108           continue;
109         }
110
111         syms_from_objfile (obj, 0, 0, 0);
112         new_symfile_objfile (obj, 0, 0);
113         vmap_symtab (vp, 0, 0);
114         printf_unfiltered ("Done.\n");
115         loaded = vp->loaded = 1;
116     }
117   }
118   /* if any shared object is loaded, then misc_func_vector needs sorting. */
119   if (loaded) {
120 #if 0
121     sort_misc_function_vector ();
122 #endif
123     current_source_symtab = saved_symtab;
124     current_source_line = saved_line;
125
126     /* Getting new symbols might change our opinion about what is frameless.
127        Is this correct?? FIXME. */
128 /*    reinit_frame_cache(); */
129   }
130   else if (!matched)
131     printf_unfiltered ("No matching shared object found.\n");
132 }
133 #endif /* SOLIB_SYMBOLS_MANUAL */
134
135 /* Return the module name of a given text address. Note that returned buffer
136    is not persistent. */
137
138 char *
139 pc_load_segment_name (addr)
140 CORE_ADDR addr;
141 {
142    static char buffer [BUFSIZ];
143    struct vmap *vp = vmap;
144
145    buffer [0] = buffer [1] = '\0';
146    for (; vp; vp = vp->nxt)
147      if (vp->tstart <= addr && addr < vp->tend) {
148         if (*vp->member) {
149           buffer [0] = '(';
150           strcat (&buffer[1], vp->member);
151           strcat (buffer, ")");
152         }
153         strcat (buffer, vp->name);
154         return buffer;
155      }
156    return "(unknown load module)";
157 }
158
159 static void solib_info PARAMS ((char *, int));
160
161 static void
162 solib_info (args, from_tty)
163      char *args;
164      int from_tty;
165 {
166   struct vmap *vp = vmap;
167
168   /* Check for new shared libraries loaded with load ().  */
169   if (xcoff_relocate_symtab_hook != NULL)
170     (*xcoff_relocate_symtab_hook) (inferior_pid);
171
172   if (vp == NULL || vp->nxt == NULL)
173     {
174       printf_unfiltered ("No shared libraries loaded at this time.\n"); 
175       return;
176     }
177
178   /* Skip over the first vmap, it is the main program, always loaded.  */
179   vp = vp->nxt;
180
181   printf_unfiltered ("\
182 Text Range              Data Range              Syms    Shared Object Library\n");
183
184   for (; vp != NULL; vp = vp->nxt)
185     {
186       printf_unfiltered ("0x%08x-0x%08x 0x%08x-0x%08x   %s      %s%s%s%s\n",
187                          vp->tstart, vp->tend,
188                          vp->dstart, vp->dend,
189                          vp->loaded ? "Yes" : "No ",
190                          *vp->member ? "(" : "",
191                          vp->member,
192                          *vp->member ? ") " : "",
193                          vp->name);
194     }
195 }
196
197 void
198 sharedlibrary_command (args, from_tty)
199      char *args;
200      int from_tty;
201 {
202   dont_repeat ();
203
204   /* Check for new shared libraries loaded with load ().  */
205   if (xcoff_relocate_symtab_hook != NULL)
206     (*xcoff_relocate_symtab_hook) (inferior_pid);
207
208 #ifdef SOLIB_SYMBOLS_MANUAL
209   solib_add (args, from_tty, (struct target_ops *)0);
210 #endif /* SOLIB_SYMBOLS_MANUAL */
211 }
212
213 void
214 _initialize_solib()
215 {
216   add_com ("sharedlibrary", class_files, sharedlibrary_command,
217            "Load shared object library symbols for files matching REGEXP.");
218   add_info ("sharedlibrary", solib_info, 
219             "Status of loaded shared object libraries");
220 }