1*65864Sbostic /* Generic symbol file reading for the GNU debugger, GDB.
2*65864Sbostic Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
3*65864Sbostic Contributed by Cygnus Support, using pieces from other GDB modules.
4*65864Sbostic
5*65864Sbostic This file is part of GDB.
6*65864Sbostic
7*65864Sbostic This program is free software; you can redistribute it and/or modify
8*65864Sbostic it under the terms of the GNU General Public License as published by
9*65864Sbostic the Free Software Foundation; either version 2 of the License, or
10*65864Sbostic (at your option) any later version.
11*65864Sbostic
12*65864Sbostic This program is distributed in the hope that it will be useful,
13*65864Sbostic but WITHOUT ANY WARRANTY; without even the implied warranty of
14*65864Sbostic MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*65864Sbostic GNU General Public License for more details.
16*65864Sbostic
17*65864Sbostic You should have received a copy of the GNU General Public License
18*65864Sbostic along with this program; if not, write to the Free Software
19*65864Sbostic Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20*65864Sbostic
21*65864Sbostic #include "defs.h"
22*65864Sbostic #include "symtab.h"
23*65864Sbostic #include "gdbtypes.h"
24*65864Sbostic #include "gdbcore.h"
25*65864Sbostic #include "frame.h"
26*65864Sbostic #include "target.h"
27*65864Sbostic #include "value.h"
28*65864Sbostic #include "symfile.h"
29*65864Sbostic #include "objfiles.h"
30*65864Sbostic #include "gdbcmd.h"
31*65864Sbostic #include "breakpoint.h"
32*65864Sbostic #include "language.h"
33*65864Sbostic
34*65864Sbostic #include <obstack.h>
35*65864Sbostic #include <assert.h>
36*65864Sbostic
37*65864Sbostic #include <sys/types.h>
38*65864Sbostic #include <fcntl.h>
39*65864Sbostic #include <string.h>
40*65864Sbostic #include <sys/stat.h>
41*65864Sbostic #include <ctype.h>
42*65864Sbostic
43*65864Sbostic /* Global variables owned by this file */
44*65864Sbostic
45*65864Sbostic int readnow_symbol_files; /* Read full symbols immediately */
46*65864Sbostic
47*65864Sbostic /* External variables and functions referenced. */
48*65864Sbostic
49*65864Sbostic extern int info_verbose;
50*65864Sbostic
51*65864Sbostic /* Functions this file defines */
52*65864Sbostic
53*65864Sbostic static void
54*65864Sbostic set_initial_language PARAMS ((void));
55*65864Sbostic
56*65864Sbostic static void
57*65864Sbostic load_command PARAMS ((char *, int));
58*65864Sbostic
59*65864Sbostic static void
60*65864Sbostic add_symbol_file_command PARAMS ((char *, int));
61*65864Sbostic
62*65864Sbostic static void
63*65864Sbostic cashier_psymtab PARAMS ((struct partial_symtab *));
64*65864Sbostic
65*65864Sbostic static int
66*65864Sbostic compare_psymbols PARAMS ((const void *, const void *));
67*65864Sbostic
68*65864Sbostic static int
69*65864Sbostic compare_symbols PARAMS ((const void *, const void *));
70*65864Sbostic
71*65864Sbostic static bfd *
72*65864Sbostic symfile_bfd_open PARAMS ((char *));
73*65864Sbostic
74*65864Sbostic static void
75*65864Sbostic find_sym_fns PARAMS ((struct objfile *));
76*65864Sbostic
77*65864Sbostic void
78*65864Sbostic clear_symtab_users_once PARAMS ((void));
79*65864Sbostic
80*65864Sbostic /* List of all available sym_fns. On gdb startup, each object file reader
81*65864Sbostic calls add_symtab_fns() to register information on each format it is
82*65864Sbostic prepared to read. */
83*65864Sbostic
84*65864Sbostic static struct sym_fns *symtab_fns = NULL;
85*65864Sbostic
86*65864Sbostic /* Structures with which to manage partial symbol allocation. */
87*65864Sbostic
88*65864Sbostic struct psymbol_allocation_list global_psymbols = {0}, static_psymbols = {0};
89*65864Sbostic
90*65864Sbostic /* Flag for whether user will be reloading symbols multiple times.
91*65864Sbostic Defaults to ON for VxWorks, otherwise OFF. */
92*65864Sbostic
93*65864Sbostic #ifdef SYMBOL_RELOADING_DEFAULT
94*65864Sbostic int symbol_reloading = SYMBOL_RELOADING_DEFAULT;
95*65864Sbostic #else
96*65864Sbostic int symbol_reloading = 0;
97*65864Sbostic #endif
98*65864Sbostic
99*65864Sbostic /* Structure to manage complaints about symbol file contents. */
100*65864Sbostic
101*65864Sbostic struct complaint complaint_root[1] = {
102*65864Sbostic {(char *) 0, 0, complaint_root},
103*65864Sbostic };
104*65864Sbostic
105*65864Sbostic /* Some actual complaints. */
106*65864Sbostic
107*65864Sbostic struct complaint oldsyms_complaint = {
108*65864Sbostic "Replacing old symbols for `%s'", 0, 0 };
109*65864Sbostic
110*65864Sbostic struct complaint empty_symtab_complaint = {
111*65864Sbostic "Empty symbol table found for `%s'", 0, 0 };
112*65864Sbostic
113*65864Sbostic
114*65864Sbostic /* In the following sort, we always make sure that
115*65864Sbostic register debug symbol declarations always come before regular
116*65864Sbostic debug symbol declarations (as might happen when parameters are
117*65864Sbostic then put into registers by the compiler).
118*65864Sbostic
119*65864Sbostic Since this function is called from within qsort, in an ANSI environment
120*65864Sbostic it must conform to the prototype for qsort, which specifies that the
121*65864Sbostic comparison function takes two "void *" pointers. */
122*65864Sbostic
123*65864Sbostic static int
compare_symbols(s1p,s2p)124*65864Sbostic compare_symbols (s1p, s2p)
125*65864Sbostic const PTR s1p;
126*65864Sbostic const PTR s2p;
127*65864Sbostic {
128*65864Sbostic register struct symbol **s1, **s2;
129*65864Sbostic register int namediff;
130*65864Sbostic
131*65864Sbostic s1 = (struct symbol **) s1p;
132*65864Sbostic s2 = (struct symbol **) s2p;
133*65864Sbostic
134*65864Sbostic /* Compare the initial characters. */
135*65864Sbostic namediff = SYMBOL_NAME (*s1)[0] - SYMBOL_NAME (*s2)[0];
136*65864Sbostic if (namediff != 0) return namediff;
137*65864Sbostic
138*65864Sbostic /* If they match, compare the rest of the names. */
139*65864Sbostic namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2));
140*65864Sbostic if (namediff != 0) return namediff;
141*65864Sbostic
142*65864Sbostic /* For symbols of the same name, registers should come first. */
143*65864Sbostic return ((SYMBOL_CLASS (*s2) == LOC_REGISTER)
144*65864Sbostic - (SYMBOL_CLASS (*s1) == LOC_REGISTER));
145*65864Sbostic }
146*65864Sbostic
147*65864Sbostic /*
148*65864Sbostic
149*65864Sbostic LOCAL FUNCTION
150*65864Sbostic
151*65864Sbostic compare_psymbols -- compare two partial symbols by name
152*65864Sbostic
153*65864Sbostic DESCRIPTION
154*65864Sbostic
155*65864Sbostic Given pointer to two partial symbol table entries, compare
156*65864Sbostic them by name and return -N, 0, or +N (ala strcmp). Typically
157*65864Sbostic used by sorting routines like qsort().
158*65864Sbostic
159*65864Sbostic NOTES
160*65864Sbostic
161*65864Sbostic Does direct compare of first two characters before punting
162*65864Sbostic and passing to strcmp for longer compares. Note that the
163*65864Sbostic original version had a bug whereby two null strings or two
164*65864Sbostic identically named one character strings would return the
165*65864Sbostic comparison of memory following the null byte.
166*65864Sbostic
167*65864Sbostic */
168*65864Sbostic
169*65864Sbostic static int
compare_psymbols(s1p,s2p)170*65864Sbostic compare_psymbols (s1p, s2p)
171*65864Sbostic const PTR s1p;
172*65864Sbostic const PTR s2p;
173*65864Sbostic {
174*65864Sbostic register char *st1 = SYMBOL_NAME ((struct partial_symbol *) s1p);
175*65864Sbostic register char *st2 = SYMBOL_NAME ((struct partial_symbol *) s2p);
176*65864Sbostic
177*65864Sbostic if ((st1[0] - st2[0]) || !st1[0])
178*65864Sbostic {
179*65864Sbostic return (st1[0] - st2[0]);
180*65864Sbostic }
181*65864Sbostic else if ((st1[1] - st2[1]) || !st1[1])
182*65864Sbostic {
183*65864Sbostic return (st1[1] - st2[1]);
184*65864Sbostic }
185*65864Sbostic else
186*65864Sbostic {
187*65864Sbostic return (strcmp (st1 + 2, st2 + 2));
188*65864Sbostic }
189*65864Sbostic }
190*65864Sbostic
191*65864Sbostic void
sort_pst_symbols(pst)192*65864Sbostic sort_pst_symbols (pst)
193*65864Sbostic struct partial_symtab *pst;
194*65864Sbostic {
195*65864Sbostic /* Sort the global list; don't sort the static list */
196*65864Sbostic
197*65864Sbostic qsort (pst -> objfile -> global_psymbols.list + pst -> globals_offset,
198*65864Sbostic pst -> n_global_syms, sizeof (struct partial_symbol),
199*65864Sbostic compare_psymbols);
200*65864Sbostic }
201*65864Sbostic
202*65864Sbostic /* Call sort_block_syms to sort alphabetically the symbols of one block. */
203*65864Sbostic
204*65864Sbostic void
sort_block_syms(b)205*65864Sbostic sort_block_syms (b)
206*65864Sbostic register struct block *b;
207*65864Sbostic {
208*65864Sbostic qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b),
209*65864Sbostic sizeof (struct symbol *), compare_symbols);
210*65864Sbostic }
211*65864Sbostic
212*65864Sbostic /* Call sort_symtab_syms to sort alphabetically
213*65864Sbostic the symbols of each block of one symtab. */
214*65864Sbostic
215*65864Sbostic void
sort_symtab_syms(s)216*65864Sbostic sort_symtab_syms (s)
217*65864Sbostic register struct symtab *s;
218*65864Sbostic {
219*65864Sbostic register struct blockvector *bv;
220*65864Sbostic int nbl;
221*65864Sbostic int i;
222*65864Sbostic register struct block *b;
223*65864Sbostic
224*65864Sbostic if (s == 0)
225*65864Sbostic return;
226*65864Sbostic bv = BLOCKVECTOR (s);
227*65864Sbostic nbl = BLOCKVECTOR_NBLOCKS (bv);
228*65864Sbostic for (i = 0; i < nbl; i++)
229*65864Sbostic {
230*65864Sbostic b = BLOCKVECTOR_BLOCK (bv, i);
231*65864Sbostic if (BLOCK_SHOULD_SORT (b))
232*65864Sbostic sort_block_syms (b);
233*65864Sbostic }
234*65864Sbostic }
235*65864Sbostic
236*65864Sbostic void
sort_all_symtab_syms()237*65864Sbostic sort_all_symtab_syms ()
238*65864Sbostic {
239*65864Sbostic register struct symtab *s;
240*65864Sbostic register struct objfile *objfile;
241*65864Sbostic
242*65864Sbostic for (objfile = object_files; objfile != NULL; objfile = objfile -> next)
243*65864Sbostic {
244*65864Sbostic for (s = objfile -> symtabs; s != NULL; s = s -> next)
245*65864Sbostic {
246*65864Sbostic sort_symtab_syms (s);
247*65864Sbostic }
248*65864Sbostic }
249*65864Sbostic }
250*65864Sbostic
251*65864Sbostic /* Make a copy of the string at PTR with SIZE characters in the symbol obstack
252*65864Sbostic (and add a null character at the end in the copy).
253*65864Sbostic Returns the address of the copy. */
254*65864Sbostic
255*65864Sbostic char *
obsavestring(ptr,size,obstackp)256*65864Sbostic obsavestring (ptr, size, obstackp)
257*65864Sbostic char *ptr;
258*65864Sbostic int size;
259*65864Sbostic struct obstack *obstackp;
260*65864Sbostic {
261*65864Sbostic register char *p = (char *) obstack_alloc (obstackp, size + 1);
262*65864Sbostic /* Open-coded bcopy--saves function call time.
263*65864Sbostic These strings are usually short. */
264*65864Sbostic {
265*65864Sbostic register char *p1 = ptr;
266*65864Sbostic register char *p2 = p;
267*65864Sbostic char *end = ptr + size;
268*65864Sbostic while (p1 != end)
269*65864Sbostic *p2++ = *p1++;
270*65864Sbostic }
271*65864Sbostic p[size] = 0;
272*65864Sbostic return p;
273*65864Sbostic }
274*65864Sbostic
275*65864Sbostic /* Concatenate strings S1, S2 and S3; return the new string.
276*65864Sbostic Space is found in the symbol_obstack. */
277*65864Sbostic
278*65864Sbostic char *
obconcat(obstackp,s1,s2,s3)279*65864Sbostic obconcat (obstackp, s1, s2, s3)
280*65864Sbostic struct obstack *obstackp;
281*65864Sbostic const char *s1, *s2, *s3;
282*65864Sbostic {
283*65864Sbostic register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1;
284*65864Sbostic register char *val = (char *) obstack_alloc (obstackp, len);
285*65864Sbostic strcpy (val, s1);
286*65864Sbostic strcat (val, s2);
287*65864Sbostic strcat (val, s3);
288*65864Sbostic return val;
289*65864Sbostic }
290*65864Sbostic
291*65864Sbostic /* Get the symbol table that corresponds to a partial_symtab.
292*65864Sbostic This is fast after the first time you do it. In fact, there
293*65864Sbostic is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
294*65864Sbostic case inline. */
295*65864Sbostic
296*65864Sbostic struct symtab *
psymtab_to_symtab(pst)297*65864Sbostic psymtab_to_symtab (pst)
298*65864Sbostic register struct partial_symtab *pst;
299*65864Sbostic {
300*65864Sbostic /* If it's been looked up before, return it. */
301*65864Sbostic if (pst->symtab)
302*65864Sbostic return pst->symtab;
303*65864Sbostic
304*65864Sbostic /* If it has not yet been read in, read it. */
305*65864Sbostic if (!pst->readin)
306*65864Sbostic {
307*65864Sbostic (*pst->read_symtab) (pst);
308*65864Sbostic }
309*65864Sbostic
310*65864Sbostic return pst->symtab;
311*65864Sbostic }
312*65864Sbostic
313*65864Sbostic /* Initialize entry point information for this objfile. */
314*65864Sbostic
315*65864Sbostic void
init_entry_point_info(objfile)316*65864Sbostic init_entry_point_info (objfile)
317*65864Sbostic struct objfile *objfile;
318*65864Sbostic {
319*65864Sbostic /* Save startup file's range of PC addresses to help blockframe.c
320*65864Sbostic decide where the bottom of the stack is. */
321*65864Sbostic
322*65864Sbostic if (bfd_get_file_flags (objfile -> obfd) & EXEC_P)
323*65864Sbostic {
324*65864Sbostic /* Executable file -- record its entry point so we'll recognize
325*65864Sbostic the startup file because it contains the entry point. */
326*65864Sbostic objfile -> ei.entry_point = bfd_get_start_address (objfile -> obfd);
327*65864Sbostic }
328*65864Sbostic else
329*65864Sbostic {
330*65864Sbostic /* Examination of non-executable.o files. Short-circuit this stuff. */
331*65864Sbostic /* ~0 will not be in any file, we hope. */
332*65864Sbostic objfile -> ei.entry_point = ~0;
333*65864Sbostic /* set the startup file to be an empty range. */
334*65864Sbostic objfile -> ei.entry_file_lowpc = 0;
335*65864Sbostic objfile -> ei.entry_file_highpc = 0;
336*65864Sbostic }
337*65864Sbostic }
338*65864Sbostic
339*65864Sbostic /* Remember the lowest-addressed loadable section we've seen.
340*65864Sbostic This function is called via bfd_map_over_sections. */
341*65864Sbostic
342*65864Sbostic #if 0 /* Not used yet */
343*65864Sbostic static void
344*65864Sbostic find_lowest_section (abfd, sect, obj)
345*65864Sbostic bfd *abfd;
346*65864Sbostic asection *sect;
347*65864Sbostic PTR obj;
348*65864Sbostic {
349*65864Sbostic asection **lowest = (asection **)obj;
350*65864Sbostic
351*65864Sbostic if (0 == (bfd_get_section_flags (abfd, sect) & SEC_LOAD))
352*65864Sbostic return;
353*65864Sbostic if (!*lowest)
354*65864Sbostic *lowest = sect; /* First loadable section */
355*65864Sbostic else if (bfd_section_vma (abfd, *lowest) >= bfd_section_vma (abfd, sect))
356*65864Sbostic *lowest = sect; /* A lower loadable section */
357*65864Sbostic }
358*65864Sbostic #endif
359*65864Sbostic
360*65864Sbostic /* Process a symbol file, as either the main file or as a dynamically
361*65864Sbostic loaded file.
362*65864Sbostic
363*65864Sbostic NAME is the file name (which will be tilde-expanded and made
364*65864Sbostic absolute herein) (but we don't free or modify NAME itself).
365*65864Sbostic FROM_TTY says how verbose to be. MAINLINE specifies whether this
366*65864Sbostic is the main symbol file, or whether it's an extra symbol file such
367*65864Sbostic as dynamically loaded code. If !mainline, ADDR is the address
368*65864Sbostic where the text segment was loaded. If VERBO, the caller has printed
369*65864Sbostic a verbose message about the symbol reading (and complaints can be
370*65864Sbostic more terse about it). */
371*65864Sbostic
372*65864Sbostic void
syms_from_objfile(objfile,addr,mainline,verbo)373*65864Sbostic syms_from_objfile (objfile, addr, mainline, verbo)
374*65864Sbostic struct objfile *objfile;
375*65864Sbostic CORE_ADDR addr;
376*65864Sbostic int mainline;
377*65864Sbostic int verbo;
378*65864Sbostic {
379*65864Sbostic struct section_offsets *section_offsets;
380*65864Sbostic asection *lowest_sect;
381*65864Sbostic
382*65864Sbostic /* There is a distinction between having no symbol table
383*65864Sbostic (we refuse to read the file, leaving the old set of symbols around)
384*65864Sbostic and having no debugging symbols in your symbol table (we read
385*65864Sbostic the file and end up with a mostly empty symbol table).
386*65864Sbostic
387*65864Sbostic FIXME: This strategy works correctly when the debugging symbols are
388*65864Sbostic intermixed with "normal" symbols. However, when the debugging symbols
389*65864Sbostic are separate, such as with ELF/DWARF, it is perfectly plausible for
390*65864Sbostic the symbol table to be missing but still have all the DWARF info
391*65864Sbostic intact. Thus in general it is wrong to assume that having no symbol
392*65864Sbostic table implies no debugging information. */
393*65864Sbostic
394*65864Sbostic if (!(bfd_get_file_flags (objfile -> obfd) & HAS_SYMS))
395*65864Sbostic return;
396*65864Sbostic
397*65864Sbostic init_entry_point_info (objfile);
398*65864Sbostic find_sym_fns (objfile);
399*65864Sbostic
400*65864Sbostic if (mainline)
401*65864Sbostic {
402*65864Sbostic /* Since no error yet, throw away the old symbol table. */
403*65864Sbostic
404*65864Sbostic if (symfile_objfile != NULL)
405*65864Sbostic {
406*65864Sbostic free_objfile (symfile_objfile);
407*65864Sbostic symfile_objfile = NULL;
408*65864Sbostic }
409*65864Sbostic
410*65864Sbostic (*objfile -> sf -> sym_new_init) (objfile);
411*65864Sbostic }
412*65864Sbostic
413*65864Sbostic /* Convert addr into an offset rather than an absolute address.
414*65864Sbostic We find the lowest address of a loaded segment in the objfile,
415*65864Sbostic and assume that <addr> is where that got loaded. Due to historical
416*65864Sbostic precedent, we warn if that doesn't happen to be the ".text"
417*65864Sbostic segment. */
418*65864Sbostic
419*65864Sbostic if (mainline)
420*65864Sbostic {
421*65864Sbostic addr = 0; /* No offset from objfile addresses. */
422*65864Sbostic }
423*65864Sbostic else
424*65864Sbostic {
425*65864Sbostic lowest_sect = bfd_get_section_by_name (objfile->obfd, ".text");
426*65864Sbostic #if 0
427*65864Sbostic lowest_sect = 0;
428*65864Sbostic bfd_map_over_sections (objfile->obfd, find_lowest_section,
429*65864Sbostic (PTR) &lowest_sect);
430*65864Sbostic #endif
431*65864Sbostic
432*65864Sbostic if (lowest_sect == 0)
433*65864Sbostic warning ("no loadable sections found in added symbol-file %s",
434*65864Sbostic objfile->name);
435*65864Sbostic else if (0 == bfd_get_section_name (objfile->obfd, lowest_sect)
436*65864Sbostic || 0 != strcmp(".text",
437*65864Sbostic bfd_get_section_name (objfile->obfd, lowest_sect)))
438*65864Sbostic warning ("Lowest section in %s is %s at 0x%x",
439*65864Sbostic objfile->name,
440*65864Sbostic bfd_section_name (objfile->obfd, lowest_sect),
441*65864Sbostic bfd_section_vma (objfile->obfd, lowest_sect));
442*65864Sbostic
443*65864Sbostic if (lowest_sect)
444*65864Sbostic addr -= bfd_section_vma (objfile->obfd, lowest_sect);
445*65864Sbostic }
446*65864Sbostic
447*65864Sbostic /* Initialize symbol reading routines for this objfile, allow complaints to
448*65864Sbostic appear for this new file, and record how verbose to be, then do the
449*65864Sbostic initial symbol reading for this file. */
450*65864Sbostic
451*65864Sbostic (*objfile -> sf -> sym_init) (objfile);
452*65864Sbostic clear_complaints (1, verbo);
453*65864Sbostic section_offsets = (*objfile -> sf -> sym_offsets) (objfile, addr);
454*65864Sbostic (*objfile -> sf -> sym_read) (objfile, section_offsets, mainline);
455*65864Sbostic
456*65864Sbostic /* Don't allow char * to have a typename (else would get caddr_t.) */
457*65864Sbostic /* Ditto void *. FIXME should do this for all the builtin types. */
458*65864Sbostic
459*65864Sbostic TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0;
460*65864Sbostic TYPE_NAME (lookup_pointer_type (builtin_type_void)) = 0;
461*65864Sbostic
462*65864Sbostic /* Mark the objfile has having had initial symbol read attempted. Note
463*65864Sbostic that this does not mean we found any symbols... */
464*65864Sbostic
465*65864Sbostic objfile -> flags |= OBJF_SYMS;
466*65864Sbostic }
467*65864Sbostic
468*65864Sbostic /* Perform required actions immediately after either reading in the initial
469*65864Sbostic symbols for a new objfile, or mapping in the symbols from a reusable
470*65864Sbostic objfile. */
471*65864Sbostic
472*65864Sbostic void
new_symfile_objfile(objfile,mainline,verbo)473*65864Sbostic new_symfile_objfile (objfile, mainline, verbo)
474*65864Sbostic struct objfile *objfile;
475*65864Sbostic int mainline;
476*65864Sbostic int verbo;
477*65864Sbostic {
478*65864Sbostic if (mainline)
479*65864Sbostic {
480*65864Sbostic /* OK, make it the "real" symbol file. */
481*65864Sbostic symfile_objfile = objfile;
482*65864Sbostic }
483*65864Sbostic
484*65864Sbostic /* If we have wiped out any old symbol tables, clean up. */
485*65864Sbostic clear_symtab_users_once ();
486*65864Sbostic
487*65864Sbostic /* We're done reading the symbol file; finish off complaints. */
488*65864Sbostic clear_complaints (0, verbo);
489*65864Sbostic
490*65864Sbostic /* Fixup all the breakpoints that may have been redefined by this
491*65864Sbostic symbol file. */
492*65864Sbostic
493*65864Sbostic breakpoint_re_set ();
494*65864Sbostic }
495*65864Sbostic
496*65864Sbostic /* Process a symbol file, as either the main file or as a dynamically
497*65864Sbostic loaded file.
498*65864Sbostic
499*65864Sbostic NAME is the file name (which will be tilde-expanded and made
500*65864Sbostic absolute herein) (but we don't free or modify NAME itself).
501*65864Sbostic FROM_TTY says how verbose to be. MAINLINE specifies whether this
502*65864Sbostic is the main symbol file, or whether it's an extra symbol file such
503*65864Sbostic as dynamically loaded code. If !mainline, ADDR is the address
504*65864Sbostic where the text segment was loaded.
505*65864Sbostic
506*65864Sbostic Upon success, returns a pointer to the objfile that was added.
507*65864Sbostic Upon failure, jumps back to command level (never returns). */
508*65864Sbostic
509*65864Sbostic struct objfile *
symbol_file_add(name,from_tty,addr,mainline,mapped,readnow)510*65864Sbostic symbol_file_add (name, from_tty, addr, mainline, mapped, readnow)
511*65864Sbostic char *name;
512*65864Sbostic int from_tty;
513*65864Sbostic CORE_ADDR addr;
514*65864Sbostic int mainline;
515*65864Sbostic int mapped;
516*65864Sbostic int readnow;
517*65864Sbostic {
518*65864Sbostic struct objfile *objfile;
519*65864Sbostic struct partial_symtab *psymtab;
520*65864Sbostic bfd *abfd;
521*65864Sbostic
522*65864Sbostic /* Open a bfd for the file and then check to see if the file has a
523*65864Sbostic symbol table. There is a distinction between having no symbol table
524*65864Sbostic (we refuse to read the file, leaving the old set of symbols around)
525*65864Sbostic and having no debugging symbols in the symbol table (we read the file
526*65864Sbostic and end up with a mostly empty symbol table, but with lots of stuff in
527*65864Sbostic the minimal symbol table). We need to make the decision about whether
528*65864Sbostic to continue with the file before allocating and building a objfile.
529*65864Sbostic
530*65864Sbostic FIXME: This strategy works correctly when the debugging symbols are
531*65864Sbostic intermixed with "normal" symbols. However, when the debugging symbols
532*65864Sbostic are separate, such as with ELF/DWARF, it is perfectly plausible for
533*65864Sbostic the symbol table to be missing but still have all the DWARF info
534*65864Sbostic intact. Thus in general it is wrong to assume that having no symbol
535*65864Sbostic table implies no debugging information. */
536*65864Sbostic
537*65864Sbostic abfd = symfile_bfd_open (name);
538*65864Sbostic if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
539*65864Sbostic {
540*65864Sbostic error ("%s has no symbol-table", name);
541*65864Sbostic }
542*65864Sbostic
543*65864Sbostic if ((have_full_symbols () || have_partial_symbols ())
544*65864Sbostic && mainline
545*65864Sbostic && from_tty
546*65864Sbostic && !query ("Load new symbol table from \"%s\"? ", name))
547*65864Sbostic error ("Not confirmed.");
548*65864Sbostic
549*65864Sbostic /* Getting new symbols may change our opinion about what is
550*65864Sbostic frameless. */
551*65864Sbostic
552*65864Sbostic reinit_frame_cache ();
553*65864Sbostic
554*65864Sbostic objfile = allocate_objfile (abfd, mapped);
555*65864Sbostic
556*65864Sbostic /* If the objfile uses a mapped symbol file, and we have a psymtab for
557*65864Sbostic it, then skip reading any symbols at this time. */
558*65864Sbostic
559*65864Sbostic if ((objfile -> flags & OBJF_MAPPED) && (objfile -> flags & OBJF_SYMS))
560*65864Sbostic {
561*65864Sbostic /* We mapped in an existing symbol table file that already has had
562*65864Sbostic initial symbol reading performed, so we can skip that part. Notify
563*65864Sbostic the user that instead of reading the symbols, they have been mapped.
564*65864Sbostic */
565*65864Sbostic if (from_tty || info_verbose)
566*65864Sbostic {
567*65864Sbostic printf_filtered ("Mapped symbols for %s...", name);
568*65864Sbostic wrap_here ("");
569*65864Sbostic fflush (stdout);
570*65864Sbostic }
571*65864Sbostic init_entry_point_info (objfile);
572*65864Sbostic find_sym_fns (objfile);
573*65864Sbostic }
574*65864Sbostic else
575*65864Sbostic {
576*65864Sbostic /* We either created a new mapped symbol table, mapped an existing
577*65864Sbostic symbol table file which has not had initial symbol reading
578*65864Sbostic performed, or need to read an unmapped symbol table. */
579*65864Sbostic if (from_tty || info_verbose)
580*65864Sbostic {
581*65864Sbostic printf_filtered ("Reading symbols from %s...", name);
582*65864Sbostic wrap_here ("");
583*65864Sbostic fflush (stdout);
584*65864Sbostic }
585*65864Sbostic syms_from_objfile (objfile, addr, mainline, from_tty);
586*65864Sbostic }
587*65864Sbostic
588*65864Sbostic new_symfile_objfile (objfile, mainline, from_tty);
589*65864Sbostic
590*65864Sbostic /* We now have at least a partial symbol table. Check to see if the
591*65864Sbostic user requested that all symbols be read on initial access via either
592*65864Sbostic the gdb startup command line or on a per symbol file basis. Expand
593*65864Sbostic all partial symbol tables for this objfile if so. */
594*65864Sbostic
595*65864Sbostic if (readnow || readnow_symbol_files)
596*65864Sbostic {
597*65864Sbostic if (from_tty || info_verbose)
598*65864Sbostic {
599*65864Sbostic printf_filtered ("expanding to full symbols...");
600*65864Sbostic wrap_here ("");
601*65864Sbostic fflush (stdout);
602*65864Sbostic }
603*65864Sbostic
604*65864Sbostic for (psymtab = objfile -> psymtabs;
605*65864Sbostic psymtab != NULL;
606*65864Sbostic psymtab = psymtab -> next)
607*65864Sbostic {
608*65864Sbostic psymtab_to_symtab (psymtab);
609*65864Sbostic }
610*65864Sbostic }
611*65864Sbostic
612*65864Sbostic if (from_tty || info_verbose)
613*65864Sbostic {
614*65864Sbostic printf_filtered ("done.\n");
615*65864Sbostic fflush (stdout);
616*65864Sbostic }
617*65864Sbostic
618*65864Sbostic return (objfile);
619*65864Sbostic }
620*65864Sbostic
621*65864Sbostic /* This is the symbol-file command. Read the file, analyze its symbols,
622*65864Sbostic and add a struct symtab to a symtab list. */
623*65864Sbostic
624*65864Sbostic void
symbol_file_command(args,from_tty)625*65864Sbostic symbol_file_command (args, from_tty)
626*65864Sbostic char *args;
627*65864Sbostic int from_tty;
628*65864Sbostic {
629*65864Sbostic char **argv;
630*65864Sbostic char *name = NULL;
631*65864Sbostic struct cleanup *cleanups;
632*65864Sbostic int mapped = 0;
633*65864Sbostic int readnow = 0;
634*65864Sbostic
635*65864Sbostic dont_repeat ();
636*65864Sbostic
637*65864Sbostic if (args == NULL)
638*65864Sbostic {
639*65864Sbostic if ((have_full_symbols () || have_partial_symbols ())
640*65864Sbostic && from_tty
641*65864Sbostic && !query ("Discard symbol table from `%s'? ",
642*65864Sbostic symfile_objfile -> name))
643*65864Sbostic error ("Not confirmed.");
644*65864Sbostic free_all_objfiles ();
645*65864Sbostic symfile_objfile = NULL;
646*65864Sbostic current_source_symtab = NULL;
647*65864Sbostic current_source_line = 0;
648*65864Sbostic if (from_tty)
649*65864Sbostic {
650*65864Sbostic printf ("No symbol file now.\n");
651*65864Sbostic }
652*65864Sbostic }
653*65864Sbostic else
654*65864Sbostic {
655*65864Sbostic if ((argv = buildargv (args)) == NULL)
656*65864Sbostic {
657*65864Sbostic nomem (0);
658*65864Sbostic }
659*65864Sbostic cleanups = make_cleanup (freeargv, (char *) argv);
660*65864Sbostic while (*argv != NULL)
661*65864Sbostic {
662*65864Sbostic if (strcmp (*argv, "-mapped") == 0)
663*65864Sbostic {
664*65864Sbostic mapped = 1;
665*65864Sbostic }
666*65864Sbostic else if (strcmp (*argv, "-readnow") == 0)
667*65864Sbostic {
668*65864Sbostic readnow = 1;
669*65864Sbostic }
670*65864Sbostic else if (**argv == '-')
671*65864Sbostic {
672*65864Sbostic error ("unknown option `%s'", *argv);
673*65864Sbostic }
674*65864Sbostic else
675*65864Sbostic {
676*65864Sbostic name = *argv;
677*65864Sbostic }
678*65864Sbostic argv++;
679*65864Sbostic }
680*65864Sbostic
681*65864Sbostic if (name == NULL)
682*65864Sbostic {
683*65864Sbostic error ("no symbol file name was specified");
684*65864Sbostic }
685*65864Sbostic else
686*65864Sbostic {
687*65864Sbostic symbol_file_add (name, from_tty, (CORE_ADDR)0, 1, mapped, readnow);
688*65864Sbostic set_initial_language ();
689*65864Sbostic }
690*65864Sbostic do_cleanups (cleanups);
691*65864Sbostic }
692*65864Sbostic }
693*65864Sbostic
694*65864Sbostic /* Set the initial language.
695*65864Sbostic
696*65864Sbostic A better solution would be to record the language in the psymtab when reading
697*65864Sbostic partial symbols, and then use it (if known) to set the language. This would
698*65864Sbostic be a win for formats that encode the language in an easily discoverable place,
699*65864Sbostic such as DWARF. For stabs, we can jump through hoops looking for specially
700*65864Sbostic named symbols or try to intuit the language from the specific type of stabs
701*65864Sbostic we find, but we can't do that until later when we read in full symbols.
702*65864Sbostic FIXME. */
703*65864Sbostic
704*65864Sbostic static void
set_initial_language()705*65864Sbostic set_initial_language ()
706*65864Sbostic {
707*65864Sbostic struct partial_symtab *pst;
708*65864Sbostic enum language lang = language_unknown;
709*65864Sbostic
710*65864Sbostic pst = find_main_psymtab ();
711*65864Sbostic if (pst != NULL)
712*65864Sbostic {
713*65864Sbostic if (pst -> filename != NULL)
714*65864Sbostic {
715*65864Sbostic lang = deduce_language_from_filename (pst -> filename);
716*65864Sbostic }
717*65864Sbostic if (lang == language_unknown)
718*65864Sbostic {
719*65864Sbostic /* Make C the default language */
720*65864Sbostic lang = language_c;
721*65864Sbostic }
722*65864Sbostic set_language (lang);
723*65864Sbostic expected_language = current_language; /* Don't warn the user */
724*65864Sbostic }
725*65864Sbostic }
726*65864Sbostic
727*65864Sbostic /* Open file specified by NAME and hand it off to BFD for preliminary
728*65864Sbostic analysis. Result is a newly initialized bfd *, which includes a newly
729*65864Sbostic malloc'd` copy of NAME (tilde-expanded and made absolute).
730*65864Sbostic In case of trouble, error() is called. */
731*65864Sbostic
732*65864Sbostic static bfd *
symfile_bfd_open(name)733*65864Sbostic symfile_bfd_open (name)
734*65864Sbostic char *name;
735*65864Sbostic {
736*65864Sbostic bfd *sym_bfd;
737*65864Sbostic int desc;
738*65864Sbostic char *absolute_name;
739*65864Sbostic
740*65864Sbostic name = tilde_expand (name); /* Returns 1st new malloc'd copy */
741*65864Sbostic
742*65864Sbostic /* Look down path for it, allocate 2nd new malloc'd copy. */
743*65864Sbostic desc = openp (getenv ("PATH"), 1, name, O_RDONLY, 0, &absolute_name);
744*65864Sbostic if (desc < 0)
745*65864Sbostic {
746*65864Sbostic make_cleanup (free, name);
747*65864Sbostic perror_with_name (name);
748*65864Sbostic }
749*65864Sbostic free (name); /* Free 1st new malloc'd copy */
750*65864Sbostic name = absolute_name; /* Keep 2nd malloc'd copy in bfd */
751*65864Sbostic /* It'll be freed in free_objfile(). */
752*65864Sbostic
753*65864Sbostic sym_bfd = bfd_fdopenr (name, NULL, desc);
754*65864Sbostic if (!sym_bfd)
755*65864Sbostic {
756*65864Sbostic close (desc);
757*65864Sbostic make_cleanup (free, name);
758*65864Sbostic error ("\"%s\": can't open to read symbols: %s.", name,
759*65864Sbostic bfd_errmsg (bfd_error));
760*65864Sbostic }
761*65864Sbostic
762*65864Sbostic if (!bfd_check_format (sym_bfd, bfd_object))
763*65864Sbostic {
764*65864Sbostic bfd_close (sym_bfd); /* This also closes desc */
765*65864Sbostic make_cleanup (free, name);
766*65864Sbostic error ("\"%s\": can't read symbols: %s.", name,
767*65864Sbostic bfd_errmsg (bfd_error));
768*65864Sbostic }
769*65864Sbostic
770*65864Sbostic return (sym_bfd);
771*65864Sbostic }
772*65864Sbostic
773*65864Sbostic /* Link a new symtab_fns into the global symtab_fns list. Called on gdb
774*65864Sbostic startup by the _initialize routine in each object file format reader,
775*65864Sbostic to register information about each format the the reader is prepared
776*65864Sbostic to handle. */
777*65864Sbostic
778*65864Sbostic void
add_symtab_fns(sf)779*65864Sbostic add_symtab_fns (sf)
780*65864Sbostic struct sym_fns *sf;
781*65864Sbostic {
782*65864Sbostic sf->next = symtab_fns;
783*65864Sbostic symtab_fns = sf;
784*65864Sbostic }
785*65864Sbostic
786*65864Sbostic
787*65864Sbostic /* Initialize to read symbols from the symbol file sym_bfd. It either
788*65864Sbostic returns or calls error(). The result is an initialized struct sym_fns
789*65864Sbostic in the objfile structure, that contains cached information about the
790*65864Sbostic symbol file. */
791*65864Sbostic
792*65864Sbostic static void
find_sym_fns(objfile)793*65864Sbostic find_sym_fns (objfile)
794*65864Sbostic struct objfile *objfile;
795*65864Sbostic {
796*65864Sbostic struct sym_fns *sf;
797*65864Sbostic
798*65864Sbostic for (sf = symtab_fns; sf != NULL; sf = sf -> next)
799*65864Sbostic {
800*65864Sbostic if (strncmp (bfd_get_target (objfile -> obfd),
801*65864Sbostic sf -> sym_name, sf -> sym_namelen) == 0)
802*65864Sbostic {
803*65864Sbostic objfile -> sf = sf;
804*65864Sbostic return;
805*65864Sbostic }
806*65864Sbostic }
807*65864Sbostic /* XXX What moron thought this error message was cute? */
808*65864Sbostic #ifdef notdef
809*65864Sbostic error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.",
810*65864Sbostic bfd_get_target (objfile -> obfd));
811*65864Sbostic #else
812*65864Sbostic error ("Symbol format `%s' unknown.", bfd_get_target (objfile->obfd));
813*65864Sbostic #endif
814*65864Sbostic }
815*65864Sbostic
816*65864Sbostic /* This function runs the load command of our current target. */
817*65864Sbostic
818*65864Sbostic static void
load_command(arg,from_tty)819*65864Sbostic load_command (arg, from_tty)
820*65864Sbostic char *arg;
821*65864Sbostic int from_tty;
822*65864Sbostic {
823*65864Sbostic target_load (arg, from_tty);
824*65864Sbostic }
825*65864Sbostic
826*65864Sbostic /* This function allows the addition of incrementally linked object files.
827*65864Sbostic It does not modify any state in the target, only in the debugger. */
828*65864Sbostic
829*65864Sbostic /* ARGSUSED */
830*65864Sbostic static void
add_symbol_file_command(args,from_tty)831*65864Sbostic add_symbol_file_command (args, from_tty)
832*65864Sbostic char *args;
833*65864Sbostic int from_tty;
834*65864Sbostic {
835*65864Sbostic char *name = NULL;
836*65864Sbostic CORE_ADDR text_addr;
837*65864Sbostic char *arg;
838*65864Sbostic int readnow = 0;
839*65864Sbostic int mapped = 0;
840*65864Sbostic
841*65864Sbostic dont_repeat ();
842*65864Sbostic
843*65864Sbostic if (args == NULL)
844*65864Sbostic {
845*65864Sbostic error ("add-symbol-file takes a file name and an address");
846*65864Sbostic }
847*65864Sbostic
848*65864Sbostic /* Make a copy of the string that we can safely write into. */
849*65864Sbostic
850*65864Sbostic args = strdup (args);
851*65864Sbostic make_cleanup (free, args);
852*65864Sbostic
853*65864Sbostic /* Pick off any -option args and the file name. */
854*65864Sbostic
855*65864Sbostic while ((*args != '\000') && (name == NULL))
856*65864Sbostic {
857*65864Sbostic while (isspace (*args)) {args++;}
858*65864Sbostic arg = args;
859*65864Sbostic while ((*args != '\000') && !isspace (*args)) {args++;}
860*65864Sbostic if (*args != '\000')
861*65864Sbostic {
862*65864Sbostic *args++ = '\000';
863*65864Sbostic }
864*65864Sbostic if (*arg != '-')
865*65864Sbostic {
866*65864Sbostic name = arg;
867*65864Sbostic }
868*65864Sbostic else if (strcmp (arg, "-mapped") == 0)
869*65864Sbostic {
870*65864Sbostic mapped = 1;
871*65864Sbostic }
872*65864Sbostic else if (strcmp (arg, "-readnow") == 0)
873*65864Sbostic {
874*65864Sbostic readnow = 1;
875*65864Sbostic }
876*65864Sbostic else
877*65864Sbostic {
878*65864Sbostic error ("unknown option `%s'", arg);
879*65864Sbostic }
880*65864Sbostic }
881*65864Sbostic
882*65864Sbostic /* After picking off any options and the file name, args should be
883*65864Sbostic left pointing at the remainder of the command line, which should
884*65864Sbostic be the address expression to evaluate. */
885*65864Sbostic
886*65864Sbostic if ((name == NULL) || (*args == '\000') )
887*65864Sbostic {
888*65864Sbostic error ("add-symbol-file takes a file name and an address");
889*65864Sbostic }
890*65864Sbostic name = tilde_expand (name);
891*65864Sbostic make_cleanup (free, name);
892*65864Sbostic
893*65864Sbostic text_addr = parse_and_eval_address (args);
894*65864Sbostic
895*65864Sbostic if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n",
896*65864Sbostic name, local_hex_string (text_addr)))
897*65864Sbostic error ("Not confirmed.");
898*65864Sbostic
899*65864Sbostic symbol_file_add (name, 0, text_addr, 0, mapped, readnow);
900*65864Sbostic }
901*65864Sbostic
902*65864Sbostic /* Re-read symbols if a symbol-file has changed. */
903*65864Sbostic void
reread_symbols()904*65864Sbostic reread_symbols ()
905*65864Sbostic {
906*65864Sbostic struct objfile *objfile;
907*65864Sbostic long new_modtime;
908*65864Sbostic int reread_one = 0;
909*65864Sbostic struct stat new_statbuf;
910*65864Sbostic int res;
911*65864Sbostic
912*65864Sbostic /* With the addition of shared libraries, this should be modified,
913*65864Sbostic the load time should be saved in the partial symbol tables, since
914*65864Sbostic different tables may come from different source files. FIXME.
915*65864Sbostic This routine should then walk down each partial symbol table
916*65864Sbostic and see if the symbol table that it originates from has been changed */
917*65864Sbostic
918*65864Sbostic the_big_top:
919*65864Sbostic for (objfile = object_files; objfile; objfile = objfile->next) {
920*65864Sbostic if (objfile->obfd) {
921*65864Sbostic #ifdef IBM6000_TARGET
922*65864Sbostic /* If this object is from a shared library, then you should
923*65864Sbostic stat on the library name, not member name. */
924*65864Sbostic
925*65864Sbostic if (objfile->obfd->my_archive)
926*65864Sbostic res = stat (objfile->obfd->my_archive->filename, &new_statbuf);
927*65864Sbostic else
928*65864Sbostic #endif
929*65864Sbostic res = stat (objfile->name, &new_statbuf);
930*65864Sbostic if (res != 0) {
931*65864Sbostic /* FIXME, should use print_sys_errmsg but it's not filtered. */
932*65864Sbostic printf_filtered ("`%s' has disappeared; keeping its symbols.\n",
933*65864Sbostic objfile->name);
934*65864Sbostic continue;
935*65864Sbostic }
936*65864Sbostic new_modtime = new_statbuf.st_mtime;
937*65864Sbostic if (new_modtime != objfile->mtime) {
938*65864Sbostic printf_filtered ("`%s' has changed; re-reading symbols.\n",
939*65864Sbostic objfile->name);
940*65864Sbostic /* FIXME, this should use a different command...that would only
941*65864Sbostic affect this objfile's symbols, and would reset objfile->mtime.
942*65864Sbostic (objfile->mtime = new_modtime;)
943*65864Sbostic HOWEVER, that command isn't written yet -- so call symbol_file_
944*65864Sbostic command, and restart the scan from the top, because it munges
945*65864Sbostic the object_files list. */
946*65864Sbostic symbol_file_command (objfile->name, 0);
947*65864Sbostic reread_one = 1;
948*65864Sbostic goto the_big_top; /* Start over. */
949*65864Sbostic }
950*65864Sbostic }
951*65864Sbostic }
952*65864Sbostic
953*65864Sbostic if (reread_one)
954*65864Sbostic breakpoint_re_set ();
955*65864Sbostic }
956*65864Sbostic
957*65864Sbostic /* Functions to handle complaints during symbol reading. */
958*65864Sbostic
959*65864Sbostic /* How many complaints about a particular thing should be printed before
960*65864Sbostic we stop whining about it? Default is no whining at all, since so many
961*65864Sbostic systems have ill-constructed symbol files. */
962*65864Sbostic
963*65864Sbostic static unsigned stop_whining = 0;
964*65864Sbostic
965*65864Sbostic /* Should each complaint be self explanatory, or should we assume that
966*65864Sbostic a series of complaints is being produced?
967*65864Sbostic case 0: self explanatory message.
968*65864Sbostic case 1: First message of a series that must start off with explanation.
969*65864Sbostic case 2: Subsequent message, when user already knows we are reading
970*65864Sbostic symbols and we can just state our piece. */
971*65864Sbostic
972*65864Sbostic static int complaint_series = 0;
973*65864Sbostic
974*65864Sbostic /* Print a complaint about the input symbols, and link the complaint block
975*65864Sbostic into a chain for later handling. */
976*65864Sbostic
977*65864Sbostic void
complain(complaint,val)978*65864Sbostic complain (complaint, val)
979*65864Sbostic struct complaint *complaint;
980*65864Sbostic char *val;
981*65864Sbostic {
982*65864Sbostic complaint->counter++;
983*65864Sbostic if (complaint->next == 0) {
984*65864Sbostic complaint->next = complaint_root->next;
985*65864Sbostic complaint_root->next = complaint;
986*65864Sbostic }
987*65864Sbostic if (complaint->counter > stop_whining)
988*65864Sbostic return;
989*65864Sbostic wrap_here ("");
990*65864Sbostic
991*65864Sbostic switch (complaint_series + (info_verbose << 1)) {
992*65864Sbostic
993*65864Sbostic /* Isolated messages, must be self-explanatory. */
994*65864Sbostic case 0:
995*65864Sbostic puts_filtered ("During symbol reading, ");
996*65864Sbostic wrap_here("");
997*65864Sbostic printf_filtered (complaint->message, val);
998*65864Sbostic puts_filtered (".\n");
999*65864Sbostic break;
1000*65864Sbostic
1001*65864Sbostic /* First of a series, without `set verbose'. */
1002*65864Sbostic case 1:
1003*65864Sbostic puts_filtered ("During symbol reading...");
1004*65864Sbostic printf_filtered (complaint->message, val);
1005*65864Sbostic puts_filtered ("...");
1006*65864Sbostic wrap_here("");
1007*65864Sbostic complaint_series++;
1008*65864Sbostic break;
1009*65864Sbostic
1010*65864Sbostic /* Subsequent messages of a series, or messages under `set verbose'.
1011*65864Sbostic (We'll already have produced a "Reading in symbols for XXX..." message
1012*65864Sbostic and will clean up at the end with a newline.) */
1013*65864Sbostic default:
1014*65864Sbostic printf_filtered (complaint->message, val);
1015*65864Sbostic puts_filtered ("...");
1016*65864Sbostic wrap_here("");
1017*65864Sbostic }
1018*65864Sbostic }
1019*65864Sbostic
1020*65864Sbostic /* Clear out all complaint counters that have ever been incremented.
1021*65864Sbostic If sym_reading is 1, be less verbose about successive complaints,
1022*65864Sbostic since the messages are appearing all together during a command that
1023*65864Sbostic reads symbols (rather than scattered around as psymtabs get fleshed
1024*65864Sbostic out into symtabs at random times). If noisy is 1, we are in a
1025*65864Sbostic noisy symbol reading command, and our caller will print enough
1026*65864Sbostic context for the user to figure it out. */
1027*65864Sbostic
1028*65864Sbostic void
clear_complaints(sym_reading,noisy)1029*65864Sbostic clear_complaints (sym_reading, noisy)
1030*65864Sbostic int sym_reading;
1031*65864Sbostic int noisy;
1032*65864Sbostic {
1033*65864Sbostic struct complaint *p;
1034*65864Sbostic
1035*65864Sbostic for (p = complaint_root->next; p != complaint_root; p = p->next)
1036*65864Sbostic p->counter = 0;
1037*65864Sbostic
1038*65864Sbostic if (!sym_reading && !noisy && complaint_series > 1) {
1039*65864Sbostic /* Terminate previous series, since caller won't. */
1040*65864Sbostic puts_filtered ("\n");
1041*65864Sbostic }
1042*65864Sbostic
1043*65864Sbostic complaint_series = sym_reading? 1 + noisy: 0;
1044*65864Sbostic }
1045*65864Sbostic
1046*65864Sbostic enum language
deduce_language_from_filename(filename)1047*65864Sbostic deduce_language_from_filename (filename)
1048*65864Sbostic char *filename;
1049*65864Sbostic {
1050*65864Sbostic char *c = strrchr (filename, '.');
1051*65864Sbostic
1052*65864Sbostic if (!c) ; /* Get default. */
1053*65864Sbostic else if(!strcmp(c,".mod"))
1054*65864Sbostic return language_m2;
1055*65864Sbostic else if(!strcmp(c,".c"))
1056*65864Sbostic return language_c;
1057*65864Sbostic else if(!strcmp(c,".cc") || !strcmp(c,".C"))
1058*65864Sbostic return language_cplus;
1059*65864Sbostic
1060*65864Sbostic return language_unknown; /* default */
1061*65864Sbostic }
1062*65864Sbostic
1063*65864Sbostic /* allocate_symtab:
1064*65864Sbostic
1065*65864Sbostic Allocate and partly initialize a new symbol table. Return a pointer
1066*65864Sbostic to it. error() if no space.
1067*65864Sbostic
1068*65864Sbostic Caller must set these fields:
1069*65864Sbostic LINETABLE(symtab)
1070*65864Sbostic symtab->blockvector
1071*65864Sbostic symtab->dirname
1072*65864Sbostic symtab->free_code
1073*65864Sbostic symtab->free_ptr
1074*65864Sbostic initialize any EXTRA_SYMTAB_INFO
1075*65864Sbostic possibly free_named_symtabs (symtab->filename);
1076*65864Sbostic */
1077*65864Sbostic
1078*65864Sbostic struct symtab *
allocate_symtab(filename,objfile)1079*65864Sbostic allocate_symtab (filename, objfile)
1080*65864Sbostic char *filename;
1081*65864Sbostic struct objfile *objfile;
1082*65864Sbostic {
1083*65864Sbostic register struct symtab *symtab;
1084*65864Sbostic
1085*65864Sbostic symtab = (struct symtab *)
1086*65864Sbostic obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symtab));
1087*65864Sbostic memset (symtab, 0, sizeof (*symtab));
1088*65864Sbostic symtab -> filename = obsavestring (filename, strlen (filename),
1089*65864Sbostic &objfile -> symbol_obstack);
1090*65864Sbostic symtab -> fullname = NULL;
1091*65864Sbostic symtab -> language = deduce_language_from_filename (filename);
1092*65864Sbostic
1093*65864Sbostic /* Hook it to the objfile it comes from */
1094*65864Sbostic
1095*65864Sbostic symtab -> objfile = objfile;
1096*65864Sbostic symtab -> next = objfile -> symtabs;
1097*65864Sbostic objfile -> symtabs = symtab;
1098*65864Sbostic
1099*65864Sbostic #ifdef INIT_EXTRA_SYMTAB_INFO
1100*65864Sbostic INIT_EXTRA_SYMTAB_INFO (symtab);
1101*65864Sbostic #endif
1102*65864Sbostic
1103*65864Sbostic return (symtab);
1104*65864Sbostic }
1105*65864Sbostic
1106*65864Sbostic struct partial_symtab *
allocate_psymtab(filename,objfile)1107*65864Sbostic allocate_psymtab (filename, objfile)
1108*65864Sbostic char *filename;
1109*65864Sbostic struct objfile *objfile;
1110*65864Sbostic {
1111*65864Sbostic struct partial_symtab *psymtab;
1112*65864Sbostic
1113*65864Sbostic if (objfile -> free_psymtabs)
1114*65864Sbostic {
1115*65864Sbostic psymtab = objfile -> free_psymtabs;
1116*65864Sbostic objfile -> free_psymtabs = psymtab -> next;
1117*65864Sbostic }
1118*65864Sbostic else
1119*65864Sbostic psymtab = (struct partial_symtab *)
1120*65864Sbostic obstack_alloc (&objfile -> psymbol_obstack,
1121*65864Sbostic sizeof (struct partial_symtab));
1122*65864Sbostic
1123*65864Sbostic memset (psymtab, 0, sizeof (struct partial_symtab));
1124*65864Sbostic psymtab -> filename = obsavestring (filename, strlen (filename),
1125*65864Sbostic &objfile -> psymbol_obstack);
1126*65864Sbostic psymtab -> symtab = NULL;
1127*65864Sbostic
1128*65864Sbostic /* Hook it to the objfile it comes from */
1129*65864Sbostic
1130*65864Sbostic psymtab -> objfile = objfile;
1131*65864Sbostic psymtab -> next = objfile -> psymtabs;
1132*65864Sbostic objfile -> psymtabs = psymtab;
1133*65864Sbostic
1134*65864Sbostic return (psymtab);
1135*65864Sbostic }
1136*65864Sbostic
1137*65864Sbostic
1138*65864Sbostic /* clear_symtab_users_once:
1139*65864Sbostic
1140*65864Sbostic This function is run after symbol reading, or from a cleanup.
1141*65864Sbostic If an old symbol table was obsoleted, the old symbol table
1142*65864Sbostic has been blown away, but the other GDB data structures that may
1143*65864Sbostic reference it have not yet been cleared or re-directed. (The old
1144*65864Sbostic symtab was zapped, and the cleanup queued, in free_named_symtab()
1145*65864Sbostic below.)
1146*65864Sbostic
1147*65864Sbostic This function can be queued N times as a cleanup, or called
1148*65864Sbostic directly; it will do all the work the first time, and then will be a
1149*65864Sbostic no-op until the next time it is queued. This works by bumping a
1150*65864Sbostic counter at queueing time. Much later when the cleanup is run, or at
1151*65864Sbostic the end of symbol processing (in case the cleanup is discarded), if
1152*65864Sbostic the queued count is greater than the "done-count", we do the work
1153*65864Sbostic and set the done-count to the queued count. If the queued count is
1154*65864Sbostic less than or equal to the done-count, we just ignore the call. This
1155*65864Sbostic is needed because reading a single .o file will often replace many
1156*65864Sbostic symtabs (one per .h file, for example), and we don't want to reset
1157*65864Sbostic the breakpoints N times in the user's face.
1158*65864Sbostic
1159*65864Sbostic The reason we both queue a cleanup, and call it directly after symbol
1160*65864Sbostic reading, is because the cleanup protects us in case of errors, but is
1161*65864Sbostic discarded if symbol reading is successful. */
1162*65864Sbostic
1163*65864Sbostic static int clear_symtab_users_queued;
1164*65864Sbostic static int clear_symtab_users_done;
1165*65864Sbostic
1166*65864Sbostic void
clear_symtab_users_once()1167*65864Sbostic clear_symtab_users_once ()
1168*65864Sbostic {
1169*65864Sbostic /* Enforce once-per-`do_cleanups'-semantics */
1170*65864Sbostic if (clear_symtab_users_queued <= clear_symtab_users_done)
1171*65864Sbostic return;
1172*65864Sbostic clear_symtab_users_done = clear_symtab_users_queued;
1173*65864Sbostic
1174*65864Sbostic printf ("Resetting debugger state after updating old symbol tables\n");
1175*65864Sbostic
1176*65864Sbostic /* Someday, we should do better than this, by only blowing away
1177*65864Sbostic the things that really need to be blown. */
1178*65864Sbostic clear_value_history ();
1179*65864Sbostic clear_displays ();
1180*65864Sbostic clear_internalvars ();
1181*65864Sbostic breakpoint_re_set ();
1182*65864Sbostic set_default_breakpoint (0, 0, 0, 0);
1183*65864Sbostic current_source_symtab = 0;
1184*65864Sbostic }
1185*65864Sbostic
1186*65864Sbostic /* Delete the specified psymtab, and any others that reference it. */
1187*65864Sbostic
1188*65864Sbostic static void
cashier_psymtab(pst)1189*65864Sbostic cashier_psymtab (pst)
1190*65864Sbostic struct partial_symtab *pst;
1191*65864Sbostic {
1192*65864Sbostic struct partial_symtab *ps, *pprev;
1193*65864Sbostic int i;
1194*65864Sbostic
1195*65864Sbostic /* Find its previous psymtab in the chain */
1196*65864Sbostic for (ps = pst->objfile->psymtabs; ps; ps = ps->next) {
1197*65864Sbostic if (ps == pst)
1198*65864Sbostic break;
1199*65864Sbostic pprev = ps;
1200*65864Sbostic }
1201*65864Sbostic
1202*65864Sbostic if (ps) {
1203*65864Sbostic /* Unhook it from the chain. */
1204*65864Sbostic if (ps == pst->objfile->psymtabs)
1205*65864Sbostic pst->objfile->psymtabs = ps->next;
1206*65864Sbostic else
1207*65864Sbostic pprev->next = ps->next;
1208*65864Sbostic
1209*65864Sbostic /* FIXME, we can't conveniently deallocate the entries in the
1210*65864Sbostic partial_symbol lists (global_psymbols/static_psymbols) that
1211*65864Sbostic this psymtab points to. These just take up space until all
1212*65864Sbostic the psymtabs are reclaimed. Ditto the dependencies list and
1213*65864Sbostic filename, which are all in the psymbol_obstack. */
1214*65864Sbostic
1215*65864Sbostic /* We need to cashier any psymtab that has this one as a dependency... */
1216*65864Sbostic again:
1217*65864Sbostic for (ps = pst->objfile->psymtabs; ps; ps = ps->next) {
1218*65864Sbostic for (i = 0; i < ps->number_of_dependencies; i++) {
1219*65864Sbostic if (ps->dependencies[i] == pst) {
1220*65864Sbostic cashier_psymtab (ps);
1221*65864Sbostic goto again; /* Must restart, chain has been munged. */
1222*65864Sbostic }
1223*65864Sbostic }
1224*65864Sbostic }
1225*65864Sbostic }
1226*65864Sbostic }
1227*65864Sbostic
1228*65864Sbostic /* If a symtab or psymtab for filename NAME is found, free it along
1229*65864Sbostic with any dependent breakpoints, displays, etc.
1230*65864Sbostic Used when loading new versions of object modules with the "add-file"
1231*65864Sbostic command. This is only called on the top-level symtab or psymtab's name;
1232*65864Sbostic it is not called for subsidiary files such as .h files.
1233*65864Sbostic
1234*65864Sbostic Return value is 1 if we blew away the environment, 0 if not.
1235*65864Sbostic FIXME. The return valu appears to never be used.
1236*65864Sbostic
1237*65864Sbostic FIXME. I think this is not the best way to do this. We should
1238*65864Sbostic work on being gentler to the environment while still cleaning up
1239*65864Sbostic all stray pointers into the freed symtab. */
1240*65864Sbostic
1241*65864Sbostic int
free_named_symtabs(name)1242*65864Sbostic free_named_symtabs (name)
1243*65864Sbostic char *name;
1244*65864Sbostic {
1245*65864Sbostic #if 0
1246*65864Sbostic /* FIXME: With the new method of each objfile having it's own
1247*65864Sbostic psymtab list, this function needs serious rethinking. In particular,
1248*65864Sbostic why was it ever necessary to toss psymtabs with specific compilation
1249*65864Sbostic unit filenames, as opposed to all psymtabs from a particular symbol
1250*65864Sbostic file? -- fnf
1251*65864Sbostic Well, the answer is that some systems permit reloading of particular
1252*65864Sbostic compilation units. We want to blow away any old info about these
1253*65864Sbostic compilation units, regardless of which objfiles they arrived in. --gnu. */
1254*65864Sbostic
1255*65864Sbostic register struct symtab *s;
1256*65864Sbostic register struct symtab *prev;
1257*65864Sbostic register struct partial_symtab *ps;
1258*65864Sbostic struct blockvector *bv;
1259*65864Sbostic int blewit = 0;
1260*65864Sbostic
1261*65864Sbostic /* We only wack things if the symbol-reload switch is set. */
1262*65864Sbostic if (!symbol_reloading)
1263*65864Sbostic return 0;
1264*65864Sbostic
1265*65864Sbostic /* Some symbol formats have trouble providing file names... */
1266*65864Sbostic if (name == 0 || *name == '\0')
1267*65864Sbostic return 0;
1268*65864Sbostic
1269*65864Sbostic /* Look for a psymtab with the specified name. */
1270*65864Sbostic
1271*65864Sbostic again2:
1272*65864Sbostic for (ps = partial_symtab_list; ps; ps = ps->next) {
1273*65864Sbostic if (!strcmp (name, ps->filename)) {
1274*65864Sbostic cashier_psymtab (ps); /* Blow it away...and its little dog, too. */
1275*65864Sbostic goto again2; /* Must restart, chain has been munged */
1276*65864Sbostic }
1277*65864Sbostic }
1278*65864Sbostic
1279*65864Sbostic /* Look for a symtab with the specified name. */
1280*65864Sbostic
1281*65864Sbostic for (s = symtab_list; s; s = s->next)
1282*65864Sbostic {
1283*65864Sbostic if (!strcmp (name, s->filename))
1284*65864Sbostic break;
1285*65864Sbostic prev = s;
1286*65864Sbostic }
1287*65864Sbostic
1288*65864Sbostic if (s)
1289*65864Sbostic {
1290*65864Sbostic if (s == symtab_list)
1291*65864Sbostic symtab_list = s->next;
1292*65864Sbostic else
1293*65864Sbostic prev->next = s->next;
1294*65864Sbostic
1295*65864Sbostic /* For now, queue a delete for all breakpoints, displays, etc., whether
1296*65864Sbostic or not they depend on the symtab being freed. This should be
1297*65864Sbostic changed so that only those data structures affected are deleted. */
1298*65864Sbostic
1299*65864Sbostic /* But don't delete anything if the symtab is empty.
1300*65864Sbostic This test is necessary due to a bug in "dbxread.c" that
1301*65864Sbostic causes empty symtabs to be created for N_SO symbols that
1302*65864Sbostic contain the pathname of the object file. (This problem
1303*65864Sbostic has been fixed in GDB 3.9x). */
1304*65864Sbostic
1305*65864Sbostic bv = BLOCKVECTOR (s);
1306*65864Sbostic if (BLOCKVECTOR_NBLOCKS (bv) > 2
1307*65864Sbostic || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK))
1308*65864Sbostic || BLOCK_NSYMS (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)))
1309*65864Sbostic {
1310*65864Sbostic complain (&oldsyms_complaint, name);
1311*65864Sbostic
1312*65864Sbostic clear_symtab_users_queued++;
1313*65864Sbostic make_cleanup (clear_symtab_users_once, 0);
1314*65864Sbostic blewit = 1;
1315*65864Sbostic } else {
1316*65864Sbostic complain (&empty_symtab_complaint, name);
1317*65864Sbostic }
1318*65864Sbostic
1319*65864Sbostic free_symtab (s);
1320*65864Sbostic }
1321*65864Sbostic else
1322*65864Sbostic {
1323*65864Sbostic /* It is still possible that some breakpoints will be affected
1324*65864Sbostic even though no symtab was found, since the file might have
1325*65864Sbostic been compiled without debugging, and hence not be associated
1326*65864Sbostic with a symtab. In order to handle this correctly, we would need
1327*65864Sbostic to keep a list of text address ranges for undebuggable files.
1328*65864Sbostic For now, we do nothing, since this is a fairly obscure case. */
1329*65864Sbostic ;
1330*65864Sbostic }
1331*65864Sbostic
1332*65864Sbostic /* FIXME, what about the minimal symbol table? */
1333*65864Sbostic return blewit;
1334*65864Sbostic #else
1335*65864Sbostic return (0);
1336*65864Sbostic #endif
1337*65864Sbostic }
1338*65864Sbostic
1339*65864Sbostic /* Allocate and partially fill a partial symtab. It will be
1340*65864Sbostic completely filled at the end of the symbol list.
1341*65864Sbostic
1342*65864Sbostic SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
1343*65864Sbostic is the address relative to which its symbols are (incremental) or 0
1344*65864Sbostic (normal). */
1345*65864Sbostic
1346*65864Sbostic
1347*65864Sbostic struct partial_symtab *
start_psymtab_common(objfile,section_offsets,filename,textlow,global_syms,static_syms)1348*65864Sbostic start_psymtab_common (objfile, section_offsets,
1349*65864Sbostic filename, textlow, global_syms, static_syms)
1350*65864Sbostic struct objfile *objfile;
1351*65864Sbostic struct section_offsets *section_offsets;
1352*65864Sbostic char *filename;
1353*65864Sbostic CORE_ADDR textlow;
1354*65864Sbostic struct partial_symbol *global_syms;
1355*65864Sbostic struct partial_symbol *static_syms;
1356*65864Sbostic {
1357*65864Sbostic struct partial_symtab *psymtab;
1358*65864Sbostic
1359*65864Sbostic psymtab = allocate_psymtab (filename, objfile);
1360*65864Sbostic psymtab -> section_offsets = section_offsets;
1361*65864Sbostic psymtab -> textlow = textlow;
1362*65864Sbostic psymtab -> texthigh = psymtab -> textlow; /* default */
1363*65864Sbostic psymtab -> globals_offset = global_syms - objfile -> global_psymbols.list;
1364*65864Sbostic psymtab -> statics_offset = static_syms - objfile -> static_psymbols.list;
1365*65864Sbostic return (psymtab);
1366*65864Sbostic }
1367*65864Sbostic
1368*65864Sbostic /* Debugging versions of functions that are usually inline macros
1369*65864Sbostic (see symfile.h). */
1370*65864Sbostic
1371*65864Sbostic #if 0 /* Don't quite work nowadays... */
1372*65864Sbostic
1373*65864Sbostic /* Add a symbol with a long value to a psymtab.
1374*65864Sbostic Since one arg is a struct, we pass in a ptr and deref it (sigh). */
1375*65864Sbostic
1376*65864Sbostic void
1377*65864Sbostic add_psymbol_to_list (name, namelength, namespace, class, list, val)
1378*65864Sbostic char *name;
1379*65864Sbostic int namelength;
1380*65864Sbostic enum namespace namespace;
1381*65864Sbostic enum address_class class;
1382*65864Sbostic struct psymbol_allocation_list *list;
1383*65864Sbostic long val;
1384*65864Sbostic {
1385*65864Sbostic ADD_PSYMBOL_VT_TO_LIST (name, namelength, namespace, class, (*list), val,
1386*65864Sbostic SYMBOL_VALUE);
1387*65864Sbostic }
1388*65864Sbostic
1389*65864Sbostic /* Add a symbol with a CORE_ADDR value to a psymtab. */
1390*65864Sbostic
1391*65864Sbostic void
1392*65864Sbostic add_psymbol_addr_to_list (name, namelength, namespace, class, list, val)
1393*65864Sbostic char *name;
1394*65864Sbostic int namelength;
1395*65864Sbostic enum namespace namespace;
1396*65864Sbostic enum address_class class;
1397*65864Sbostic struct psymbol_allocation_list *list;
1398*65864Sbostic CORE_ADDR val;
1399*65864Sbostic {
1400*65864Sbostic ADD_PSYMBOL_VT_TO_LIST (name, namelength, namespace, class, (*list), val,
1401*65864Sbostic SYMBOL_VALUE_ADDRESS);
1402*65864Sbostic }
1403*65864Sbostic
1404*65864Sbostic #endif /* 0 */
1405*65864Sbostic
1406*65864Sbostic void
_initialize_symfile()1407*65864Sbostic _initialize_symfile ()
1408*65864Sbostic {
1409*65864Sbostic
1410*65864Sbostic add_com ("symbol-file", class_files, symbol_file_command,
1411*65864Sbostic "Load symbol table from executable file FILE.\n\
1412*65864Sbostic The `file' command can also load symbol tables, as well as setting the file\n\
1413*65864Sbostic to execute.");
1414*65864Sbostic
1415*65864Sbostic add_com ("add-symbol-file", class_files, add_symbol_file_command,
1416*65864Sbostic "Load the symbols from FILE, assuming FILE has been dynamically loaded.\n\
1417*65864Sbostic The second argument provides the starting address of the file's text.");
1418*65864Sbostic
1419*65864Sbostic add_com ("load", class_files, load_command,
1420*65864Sbostic "Dynamically load FILE into the running program, and record its symbols\n\
1421*65864Sbostic for access from GDB.");
1422*65864Sbostic
1423*65864Sbostic add_show_from_set
1424*65864Sbostic (add_set_cmd ("complaints", class_support, var_zinteger,
1425*65864Sbostic (char *)&stop_whining,
1426*65864Sbostic "Set max number of complaints about incorrect symbols.",
1427*65864Sbostic &setlist),
1428*65864Sbostic &showlist);
1429*65864Sbostic
1430*65864Sbostic add_show_from_set
1431*65864Sbostic (add_set_cmd ("symbol-reloading", class_support, var_boolean,
1432*65864Sbostic (char *)&symbol_reloading,
1433*65864Sbostic "Set dynamic symbol table reloading multiple times in one run.",
1434*65864Sbostic &setlist),
1435*65864Sbostic &showlist);
1436*65864Sbostic
1437*65864Sbostic }
1438