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