OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [os9kread.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 markom
/* Read os9/os9k symbol tables and convert to internal format, for GDB.
2
   Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 96, 1998
3
   Free Software Foundation, Inc.
4
 
5
   This file is part of GDB.
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 2 of the License, or
10
   (at your option) any later version.
11
 
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 59 Temple Place - Suite 330,
20
   Boston, MA 02111-1307, USA.  */
21
 
22
/* This module provides three functions: os9k_symfile_init,
23
   which initializes to read a symbol file; os9k_new_init, which
24
   discards existing cached information when all symbols are being
25
   discarded; and os9k_symfile_read, which reads a symbol table
26
   from a file.
27
 
28
   os9k_symfile_read only does the minimum work necessary for letting the
29
   user "name" things symbolically; it does not read the entire symtab.
30
   Instead, it reads the external and static symbols and puts them in partial
31
   symbol tables.  When more extensive information is requested of a
32
   file, the corresponding partial symbol table is mutated into a full
33
   fledged symbol table by going back and reading the symbols
34
   for real.  os9k_psymtab_to_symtab() is the function that does this */
35
 
36
#include "defs.h"
37
#include "gdb_string.h"
38
#include <stdio.h>
39
 
40
#if defined(USG) || defined(__CYGNUSCLIB__)
41
#include <sys/types.h>
42
#include <fcntl.h>
43
#endif
44
 
45
#include "obstack.h"
46
#include "gdb_stat.h"
47
#include <ctype.h>
48
#include "symtab.h"
49
#include "breakpoint.h"
50
#include "command.h"
51
#include "target.h"
52
#include "gdbcore.h"            /* for bfd stuff */
53
#include "libaout.h"            /* FIXME Secret internal BFD stuff for a.out */
54
#include "symfile.h"
55
#include "objfiles.h"
56
#include "buildsym.h"
57
#include "gdb-stabs.h"
58
#include "demangle.h"
59
#include "language.h"           /* Needed inside partial-stab.h */
60
#include "complaints.h"
61
#include "os9k.h"
62
#include "stabsread.h"
63
 
64
extern void _initialize_os9kread PARAMS ((void));
65
 
66
/* Each partial symbol table entry contains a pointer to private data for the
67
   read_symtab() function to use when expanding a partial symbol table entry
68
   to a full symbol table entry.
69
 
70
   For dbxread this structure contains the offset within the file symbol table
71
   of first local symbol for this file, and count of the section
72
   of the symbol table devoted to this file's symbols (actually, the section
73
   bracketed may contain more than just this file's symbols).  It also contains
74
   further information needed to locate the symbols if they are in an ELF file.
75
 
76
   If ldsymcnt is 0, the only reason for this thing's existence is the
77
   dependency list.  Nothing else will happen when it is read in.  */
78
 
79
#define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
80
#define LDSYMCNT(p) (((struct symloc *)((p)->read_symtab_private))->ldsymnum)
81
 
82
struct symloc
83
  {
84
    int ldsymoff;
85
    int ldsymnum;
86
  };
87
 
88
/* Remember what we deduced to be the source language of this psymtab. */
89
static enum language psymtab_language = language_unknown;
90
 
91
/* keep partial symbol table file nested depth */
92
static int psymfile_depth = 0;
93
 
94
/* keep symbol table file nested depth */
95
static int symfile_depth = 0;
96
 
97
/* Nonzero means give verbose info on gdb action.  From main.c.  */
98
extern int info_verbose;
99
 
100
extern int previous_stab_code;
101
 
102
/* Name of last function encountered.  Used in Solaris to approximate
103
   object file boundaries.  */
104
static char *last_function_name;
105
 
106
/* Complaints about the symbols we have encountered.  */
107
extern struct complaint lbrac_complaint;
108
 
109
extern struct complaint unknown_symtype_complaint;
110
 
111
extern struct complaint unknown_symchar_complaint;
112
 
113
extern struct complaint lbrac_rbrac_complaint;
114
 
115
extern struct complaint repeated_header_complaint;
116
 
117
extern struct complaint repeated_header_name_complaint;
118
 
119
#if 0
120
static struct complaint lbrac_unmatched_complaint =
121
{"unmatched Increment Block Entry before symtab pos %d", 0, 0};
122
 
123
static struct complaint lbrac_mismatch_complaint =
124
{"IBE/IDE symbol mismatch at symtab pos %d", 0, 0};
125
#endif
126
 
127
/* Local function prototypes */
128
 
129
static void
130
read_minimal_symbols PARAMS ((struct objfile *));
131
 
132
static void
133
os9k_read_ofile_symtab PARAMS ((struct partial_symtab *));
134
 
135
static void
136
os9k_psymtab_to_symtab PARAMS ((struct partial_symtab *));
137
 
138
static void
139
os9k_psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
140
 
141
static void
142
read_os9k_psymtab PARAMS ((struct objfile *, CORE_ADDR, int));
143
 
144
static int
145
fill_sym PARAMS ((FILE *, bfd *));
146
 
147
static void
148
os9k_symfile_init PARAMS ((struct objfile *));
149
 
150
static void
151
os9k_new_init PARAMS ((struct objfile *));
152
 
153
static void
154
os9k_symfile_read PARAMS ((struct objfile *, int));
155
 
156
static void
157
os9k_symfile_finish PARAMS ((struct objfile *));
158
 
159
static void
160
os9k_process_one_symbol PARAMS ((int, int, CORE_ADDR, char *,
161
                               struct section_offsets *, struct objfile *));
162
 
163
static struct partial_symtab *
164
  os9k_start_psymtab PARAMS ((struct objfile *, char *,
165
                              CORE_ADDR, int, int, struct partial_symbol **,
166
                              struct partial_symbol **));
167
 
168
static struct partial_symtab *
169
  os9k_end_psymtab PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
170
                            struct partial_symtab **, int));
171
 
172
static void
173
record_minimal_symbol PARAMS ((char *, CORE_ADDR, int, struct objfile *));
174
 
175
#define HANDLE_RBRAC(val) \
176
  if ((val) > pst->texthigh) pst->texthigh = (val);
177
 
178
#define SWAP_STBHDR(hdrp, abfd) \
179
  { \
180
    (hdrp)->fmtno = bfd_get_16(abfd, (unsigned char *)&(hdrp)->fmtno); \
181
    (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \
182
    (hdrp)->offset = bfd_get_32(abfd, (unsigned char *)&(hdrp)->offset); \
183
    (hdrp)->nsym = bfd_get_32(abfd, (unsigned char *)&(hdrp)->nsym); \
184
  }
185
#define SWAP_STBSYM(symp, abfd) \
186
  { \
187
    (symp)->value = bfd_get_32(abfd, (unsigned char *)&(symp)->value); \
188
    (symp)->type = bfd_get_16(abfd, (unsigned char *)&(symp)->type); \
189
    (symp)->stroff = bfd_get_32(abfd, (unsigned char *)&(symp)->stroff); \
190
  }
191
#define N_DATA 0
192
#define N_BSS 1
193
#define N_RDATA 2
194
#define N_IDATA 3
195
#define N_TEXT 4
196
#define N_ABS 6
197
 
198
static void
199
record_minimal_symbol (name, address, type, objfile)
200
     char *name;
201
     CORE_ADDR address;
202
     int type;
203
     struct objfile *objfile;
204
{
205
  enum minimal_symbol_type ms_type;
206
 
207
  switch (type)
208
    {
209
    case N_TEXT:
210
      ms_type = mst_text;
211
      address += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
212
      break;
213
    case N_DATA:
214
      ms_type = mst_data;
215
      break;
216
    case N_BSS:
217
      ms_type = mst_bss;
218
      break;
219
    case N_RDATA:
220
      ms_type = mst_bss;
221
      break;
222
    case N_IDATA:
223
      ms_type = mst_data;
224
      break;
225
    case N_ABS:
226
      ms_type = mst_abs;
227
      break;
228
    default:
229
      ms_type = mst_unknown;
230
      break;
231
    }
232
 
233
  prim_record_minimal_symbol (name, address, ms_type, objfile);
234
}
235
 
236
/* read and process .stb file and store in minimal symbol table */
237
typedef char mhhdr[80];
238
struct stbhdr
239
  {
240
    mhhdr comhdr;
241
    char *name;
242
    short fmtno;
243
    int crc;
244
    int offset;
245
    int nsym;
246
    char *pad;
247
  };
248
struct stbsymbol
249
  {
250
    int value;
251
    short type;
252
    int stroff;
253
  };
254
#define STBSYMSIZE 10
255
 
256
static void
257
read_minimal_symbols (objfile)
258
     struct objfile *objfile;
259
{
260
  FILE *fp;
261
  bfd *abfd;
262
  struct stbhdr hdr;
263
  struct stbsymbol sym;
264
  int ch, i, j, off;
265
  char buf[64], buf1[128];
266
 
267
  fp = objfile->auxf1;
268
  if (fp == NULL)
269
    return;
270
  abfd = objfile->obfd;
271
  fread (&hdr.comhdr[0], sizeof (mhhdr), 1, fp);
272
  i = 0;
273
  ch = getc (fp);
274
  while (ch != -1)
275
    {
276
      buf[i] = (char) ch;
277
      i++;
278
      if (ch == 0)
279
        break;
280
      ch = getc (fp);
281
    };
282
  if (i % 2)
283
    ch = getc (fp);
284
  hdr.name = &buf[0];
285
 
286
  fread (&hdr.fmtno, sizeof (hdr.fmtno), 1, fp);
287
  fread (&hdr.crc, sizeof (hdr.crc), 1, fp);
288
  fread (&hdr.offset, sizeof (hdr.offset), 1, fp);
289
  fread (&hdr.nsym, sizeof (hdr.nsym), 1, fp);
290
  SWAP_STBHDR (&hdr, abfd);
291
 
292
  /* read symbols */
293
  init_minimal_symbol_collection ();
294
  off = hdr.offset;
295
  for (i = hdr.nsym; i > 0; i--)
296
    {
297
      fseek (fp, (long) off, 0);
298
      fread (&sym.value, sizeof (sym.value), 1, fp);
299
      fread (&sym.type, sizeof (sym.type), 1, fp);
300
      fread (&sym.stroff, sizeof (sym.stroff), 1, fp);
301
      SWAP_STBSYM (&sym, abfd);
302
      fseek (fp, (long) sym.stroff, 0);
303
      j = 0;
304
      ch = getc (fp);
305
      while (ch != -1)
306
        {
307
          buf1[j] = (char) ch;
308
          j++;
309
          if (ch == 0)
310
            break;
311
          ch = getc (fp);
312
        };
313
      record_minimal_symbol (buf1, sym.value, sym.type & 7, objfile);
314
      off += STBSYMSIZE;
315
    };
316
  install_minimal_symbols (objfile);
317
  return;
318
}
319
 
320
/* Scan and build partial symbols for a symbol file.
321
   We have been initialized by a call to os9k_symfile_init, which
322
   put all the relevant info into a "struct os9k_symfile_info",
323
   hung off the objfile structure.
324
 
325
   MAINLINE is true if we are reading the main symbol
326
   table (as opposed to a shared lib or dynamically loaded file).  */
327
 
328
static void
329
os9k_symfile_read (objfile, mainline)
330
     struct objfile *objfile;
331
     int mainline;              /* FIXME comments above */
332
{
333
  bfd *sym_bfd;
334
  struct cleanup *back_to;
335
 
336
  sym_bfd = objfile->obfd;
337
  /* If we are reinitializing, or if we have never loaded syms yet, init */
338
  if (mainline || objfile->global_psymbols.size == 0 ||
339
      objfile->static_psymbols.size == 0)
340
    init_psymbol_list (objfile, DBX_SYMCOUNT (objfile));
341
 
342
  free_pending_blocks ();
343
  back_to = make_cleanup (really_free_pendings, 0);
344
 
345
  make_cleanup ((make_cleanup_func) discard_minimal_symbols, 0);
346
  read_minimal_symbols (objfile);
347
 
348
  /* Now that the symbol table data of the executable file are all in core,
349
     process them and define symbols accordingly.  */
350
  read_os9k_psymtab (objfile,
351
                     DBX_TEXT_ADDR (objfile),
352
                     DBX_TEXT_SIZE (objfile));
353
 
354
  do_cleanups (back_to);
355
}
356
 
357
/* Initialize anything that needs initializing when a completely new
358
   symbol file is specified (not just adding some symbols from another
359
   file, e.g. a shared library).  */
360
 
361
static void
362
os9k_new_init (ignore)
363
     struct objfile *ignore;
364
{
365
  stabsread_new_init ();
366
  buildsym_new_init ();
367
  psymfile_depth = 0;
368
/*
369
   init_header_files ();
370
 */
371
}
372
 
373
/* os9k_symfile_init ()
374
   It is passed a struct objfile which contains, among other things,
375
   the BFD for the file whose symbols are being read, and a slot for a pointer
376
   to "private data" which we fill with goodies.
377
 
378
   Since BFD doesn't know how to read debug symbols in a format-independent
379
   way (and may never do so...), we have to do it ourselves.  We will never
380
   be called unless this is an a.out (or very similar) file.
381
   FIXME, there should be a cleaner peephole into the BFD environment here.  */
382
 
383
static void
384
os9k_symfile_init (objfile)
385
     struct objfile *objfile;
386
{
387
  bfd *sym_bfd = objfile->obfd;
388
  char *name = bfd_get_filename (sym_bfd);
389
  char dbgname[512], stbname[512];
390
  FILE *symfile = 0;
391
  FILE *minfile = 0;
392
  asection *text_sect;
393
 
394
  strcpy (dbgname, name);
395
  strcat (dbgname, ".dbg");
396
  strcpy (stbname, name);
397
  strcat (stbname, ".stb");
398
 
399
  if ((symfile = fopen (dbgname, "r")) == NULL)
400
    {
401
      warning ("Symbol file %s not found", dbgname);
402
    }
403
  objfile->auxf2 = symfile;
404
 
405
  if ((minfile = fopen (stbname, "r")) == NULL)
406
    {
407
      warning ("Symbol file %s not found", stbname);
408
    }
409
  objfile->auxf1 = minfile;
410
 
411
  /* Allocate struct to keep track of the symfile */
412
  objfile->sym_stab_info = (struct dbx_symfile_info *)
413
    xmmalloc (objfile->md, sizeof (struct dbx_symfile_info));
414
  DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;
415
 
416
  text_sect = bfd_get_section_by_name (sym_bfd, ".text");
417
  if (!text_sect)
418
    error ("Can't find .text section in file");
419
  DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
420
  DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
421
 
422
  DBX_SYMBOL_SIZE (objfile) = 0; /* variable size symbol */
423
  DBX_SYMCOUNT (objfile) = 0;    /* used to be bfd_get_symcount(sym_bfd) */
424
  DBX_SYMTAB_OFFSET (objfile) = 0;       /* used to be SYMBOL_TABLE_OFFSET */
425
}
426
 
427
/* Perform any local cleanups required when we are done with a particular
428
   objfile.  I.E, we are in the process of discarding all symbol information
429
   for an objfile, freeing up all memory held for it, and unlinking the
430
   objfile struct from the global list of known objfiles. */
431
 
432
static void
433
os9k_symfile_finish (objfile)
434
     struct objfile *objfile;
435
{
436
  if (objfile->sym_stab_info != NULL)
437
    {
438
      mfree (objfile->md, objfile->sym_stab_info);
439
    }
440
/*
441
   free_header_files ();
442
 */
443
}
444
 
445
 
446
struct st_dbghdr
447
{
448
  int sync;
449
  short rev;
450
  int crc;
451
  short os;
452
  short cpu;
453
};
454
#define SYNC            (int)0xefbefeca
455
 
456
#define SWAP_DBGHDR(hdrp, abfd) \
457
  { \
458
    (hdrp)->sync = bfd_get_32(abfd, (unsigned char *)&(hdrp)->sync); \
459
    (hdrp)->rev = bfd_get_16(abfd, (unsigned char *)&(hdrp)->rev); \
460
    (hdrp)->crc = bfd_get_32(abfd, (unsigned char *)&(hdrp)->crc); \
461
    (hdrp)->os = bfd_get_16(abfd, (unsigned char *)&(hdrp)->os); \
462
    (hdrp)->cpu = bfd_get_16(abfd, (unsigned char *)&(hdrp)->cpu); \
463
  }
464
 
465
#define N_SYM_CMPLR     0
466
#define N_SYM_SLINE     1
467
#define N_SYM_SYM       2
468
#define N_SYM_LBRAC     3
469
#define N_SYM_RBRAC     4
470
#define N_SYM_SE        5
471
 
472
struct internal_symstruct
473
  {
474
    short n_type;
475
    short n_desc;
476
    long n_value;
477
    char *n_strx;
478
  };
479
static struct internal_symstruct symbol;
480
static struct internal_symstruct *symbuf = &symbol;
481
static char strbuf[4096];
482
static struct st_dbghdr dbghdr;
483
static short cmplrid;
484
 
485
#define VER_PRE_ULTRAC  ((short)4)
486
#define VER_ULTRAC      ((short)5)
487
 
488
static int
489
fill_sym (dbg_file, abfd)
490
     FILE *dbg_file;
491
     bfd *abfd;
492
{
493
  short si, nmask;
494
  long li;
495
  int ii;
496
  char *p;
497
 
498
  int nbytes = fread (&si, sizeof (si), 1, dbg_file);
499
  if (nbytes == 0)
500
    return 0;
501
  if (nbytes < 0)
502
    perror_with_name ("reading .dbg file.");
503
  symbuf->n_desc = 0;
504
  symbuf->n_value = 0;
505
  symbuf->n_strx = NULL;
506
  symbuf->n_type = bfd_get_16 (abfd, (unsigned char *) &si);
507
  symbuf->n_type = 0xf & symbuf->n_type;
508
  switch (symbuf->n_type)
509
    {
510
    case N_SYM_CMPLR:
511
      fread (&si, sizeof (si), 1, dbg_file);
512
      symbuf->n_desc = bfd_get_16 (abfd, (unsigned char *) &si);
513
      cmplrid = symbuf->n_desc & 0xff;
514
      break;
515
    case N_SYM_SLINE:
516
      fread (&li, sizeof (li), 1, dbg_file);
517
      symbuf->n_value = bfd_get_32 (abfd, (unsigned char *) &li);
518
      fread (&li, sizeof (li), 1, dbg_file);
519
      li = bfd_get_32 (abfd, (unsigned char *) &li);
520
      symbuf->n_strx = (char *) (li >> 12);
521
      symbuf->n_desc = li & 0xfff;
522
      break;
523
    case N_SYM_SYM:
524
      fread (&li, sizeof (li), 1, dbg_file);
525
      symbuf->n_value = bfd_get_32 (abfd, (unsigned char *) &li);
526
      si = 0;
527
      do
528
        {
529
          ii = getc (dbg_file);
530
          strbuf[si++] = (char) ii;
531
        }
532
      while (ii != 0 || si % 2 != 0);
533
      symbuf->n_strx = strbuf;
534
      p = (char *) strchr (strbuf, ':');
535
      if (!p)
536
        break;
537
      if ((p[1] == 'F' || p[1] == 'f') && cmplrid == VER_PRE_ULTRAC)
538
        {
539
          fread (&si, sizeof (si), 1, dbg_file);
540
          nmask = bfd_get_16 (abfd, (unsigned char *) &si);
541
          for (ii = 0; ii < nmask; ii++)
542
            fread (&si, sizeof (si), 1, dbg_file);
543
        }
544
      break;
545
    case N_SYM_LBRAC:
546
      fread (&li, sizeof (li), 1, dbg_file);
547
      symbuf->n_value = bfd_get_32 (abfd, (unsigned char *) &li);
548
      break;
549
    case N_SYM_RBRAC:
550
      fread (&li, sizeof (li), 1, dbg_file);
551
      symbuf->n_value = bfd_get_32 (abfd, (unsigned char *) &li);
552
      break;
553
    case N_SYM_SE:
554
      break;
555
    }
556
  return 1;
557
}
558
 
559
/* Given pointers to an a.out symbol table in core containing dbx
560
   style data, setup partial_symtab's describing each source file for
561
   which debugging information is available.
562
   SYMFILE_NAME is the name of the file we are reading from. */
563
 
564
static void
565
read_os9k_psymtab (objfile, text_addr, text_size)
566
     struct objfile *objfile;
567
     CORE_ADDR text_addr;
568
     int text_size;
569
{
570
  register struct internal_symstruct *bufp = 0;          /* =0 avoids gcc -Wall glitch */
571
  register char *namestring;
572
  int past_first_source_file = 0;
573
  CORE_ADDR last_o_file_start = 0;
574
#if 0
575
  struct cleanup *back_to;
576
#endif
577
  bfd *abfd;
578
  FILE *fp;
579
 
580
  /* End of the text segment of the executable file.  */
581
  static CORE_ADDR end_of_text_addr;
582
 
583
  /* Current partial symtab */
584
  static struct partial_symtab *pst = 0;
585
 
586
  /* List of current psymtab's include files */
587
  char **psymtab_include_list;
588
  int includes_allocated;
589
  int includes_used;
590
 
591
  /* Index within current psymtab dependency list */
592
  struct partial_symtab **dependency_list;
593
  int dependencies_used, dependencies_allocated;
594
 
595
  includes_allocated = 30;
596
  includes_used = 0;
597
  psymtab_include_list = (char **) alloca (includes_allocated *
598
                                           sizeof (char *));
599
 
600
  dependencies_allocated = 30;
601
  dependencies_used = 0;
602
  dependency_list =
603
    (struct partial_symtab **) alloca (dependencies_allocated *
604
                                       sizeof (struct partial_symtab *));
605
 
606
  last_source_file = NULL;
607
 
608
#ifdef END_OF_TEXT_DEFAULT
609
  end_of_text_addr = END_OF_TEXT_DEFAULT;
610
#else
611
  end_of_text_addr = text_addr + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT)
612
    + text_size;                /* Relocate */
613
#endif
614
 
615
  abfd = objfile->obfd;
616
  fp = objfile->auxf2;
617
  if (!fp)
618
    return;
619
 
620
  fread (&dbghdr.sync, sizeof (dbghdr.sync), 1, fp);
621
  fread (&dbghdr.rev, sizeof (dbghdr.rev), 1, fp);
622
  fread (&dbghdr.crc, sizeof (dbghdr.crc), 1, fp);
623
  fread (&dbghdr.os, sizeof (dbghdr.os), 1, fp);
624
  fread (&dbghdr.cpu, sizeof (dbghdr.cpu), 1, fp);
625
  SWAP_DBGHDR (&dbghdr, abfd);
626
 
627
  symnum = 0;
628
  while (1)
629
    {
630
      int ret;
631
      long cursymoffset;
632
 
633
      /* Get the symbol for this run and pull out some info */
634
      QUIT;                     /* allow this to be interruptable */
635
      cursymoffset = ftell (objfile->auxf2);
636
      ret = fill_sym (objfile->auxf2, abfd);
637
      if (ret <= 0)
638
        break;
639
      else
640
        symnum++;
641
      bufp = symbuf;
642
 
643
      /* Special case to speed up readin. */
644
      if (bufp->n_type == (short) N_SYM_SLINE)
645
        continue;
646
 
647
#define CUR_SYMBOL_VALUE bufp->n_value
648
      /* partial-stab.h */
649
 
650
      switch (bufp->n_type)
651
        {
652
          char *p;
653
 
654
        case N_SYM_CMPLR:
655
          continue;
656
 
657
        case N_SYM_SE:
658
          CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
659
          if (psymfile_depth == 1 && pst)
660
            {
661
              os9k_end_psymtab (pst, psymtab_include_list, includes_used,
662
                                symnum, CUR_SYMBOL_VALUE,
663
                                dependency_list, dependencies_used);
664
              pst = (struct partial_symtab *) 0;
665
              includes_used = 0;
666
              dependencies_used = 0;
667
            }
668
          psymfile_depth--;
669
          continue;
670
 
671
        case N_SYM_SYM: /* Typedef or automatic variable. */
672
          namestring = bufp->n_strx;
673
          p = (char *) strchr (namestring, ':');
674
          if (!p)
675
            continue;           /* Not a debugging symbol.   */
676
 
677
          /* Main processing section for debugging symbols which
678
             the initial read through the symbol tables needs to worry
679
             about.  If we reach this point, the symbol which we are
680
             considering is definitely one we are interested in.
681
             p must also contain the (valid) index into the namestring
682
             which indicates the debugging type symbol.  */
683
 
684
          switch (p[1])
685
            {
686
            case 'S':
687
              {
688
                unsigned long valu;
689
                enum language tmp_language;
690
                char *str, *p;
691
                int n;
692
 
693
                valu = CUR_SYMBOL_VALUE;
694
                if (valu)
695
                  valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
696
                past_first_source_file = 1;
697
 
698
                p = strchr (namestring, ':');
699
                if (p)
700
                  n = p - namestring;
701
                else
702
                  n = strlen (namestring);
703
                str = alloca (n + 1);
704
                strncpy (str, namestring, n);
705
                str[n] = '\0';
706
 
707
                if (psymfile_depth == 0)
708
                  {
709
                    if (!pst)
710
                      pst = os9k_start_psymtab (objfile,
711
                                                str, valu,
712
                                                cursymoffset,
713
                                                symnum - 1,
714
                                              objfile->global_psymbols.next,
715
                                             objfile->static_psymbols.next);
716
                  }
717
                else
718
                  {             /* this is a include file */
719
                    tmp_language = deduce_language_from_filename (str);
720
                    if (tmp_language != language_unknown
721
                        && (tmp_language != language_c
722
                            || psymtab_language != language_cplus))
723
                      psymtab_language = tmp_language;
724
 
725
/*
726
   if (pst && STREQ (str, pst->filename))
727
   continue;
728
   {
729
   register int i;
730
   for (i = 0; i < includes_used; i++)
731
   if (STREQ (str, psymtab_include_list[i]))
732
   {
733
   i = -1;
734
   break;
735
   }
736
   if (i == -1)
737
   continue;
738
   }
739
 */
740
 
741
                    psymtab_include_list[includes_used++] = str;
742
                    if (includes_used >= includes_allocated)
743
                      {
744
                        char **orig = psymtab_include_list;
745
 
746
                        psymtab_include_list = (char **)
747
                          alloca ((includes_allocated *= 2) * sizeof (char *));
748
                        memcpy ((PTR) psymtab_include_list, (PTR) orig,
749
                                includes_used * sizeof (char *));
750
                      }
751
 
752
                  }
753
                psymfile_depth++;
754
                continue;
755
              }
756
 
757
            case 'v':
758
              add_psymbol_to_list (namestring, p - namestring,
759
                                   VAR_NAMESPACE, LOC_STATIC,
760
                                   &objfile->static_psymbols,
761
                                   0, CUR_SYMBOL_VALUE,
762
                                   psymtab_language, objfile);
763
              continue;
764
            case 'V':
765
              add_psymbol_to_list (namestring, p - namestring,
766
                                   VAR_NAMESPACE, LOC_STATIC,
767
                                   &objfile->global_psymbols,
768
                                   0, CUR_SYMBOL_VALUE,
769
                                   psymtab_language, objfile);
770
              continue;
771
 
772
            case 'T':
773
              if (p != namestring)      /* a name is there, not just :T... */
774
                {
775
                  add_psymbol_to_list (namestring, p - namestring,
776
                                       STRUCT_NAMESPACE, LOC_TYPEDEF,
777
                                       &objfile->static_psymbols,
778
                                       CUR_SYMBOL_VALUE, 0,
779
                                       psymtab_language, objfile);
780
                  if (p[2] == 't')
781
                    {
782
                      /* Also a typedef with the same name.  */
783
                      add_psymbol_to_list (namestring, p - namestring,
784
                                           VAR_NAMESPACE, LOC_TYPEDEF,
785
                                           &objfile->static_psymbols,
786
                                      CUR_SYMBOL_VALUE, 0, psymtab_language,
787
                                           objfile);
788
                      p += 1;
789
                    }
790
                  /* The semantics of C++ state that "struct foo { ... }"
791
                     also defines a typedef for "foo".  Unfortuantely, cfront
792
                     never makes the typedef when translating from C++ to C.
793
                     We make the typedef here so that "ptype foo" works as
794
                     expected for cfront translated code.  */
795
                  else if (psymtab_language == language_cplus)
796
                    {
797
                      /* Also a typedef with the same name.  */
798
                      add_psymbol_to_list (namestring, p - namestring,
799
                                           VAR_NAMESPACE, LOC_TYPEDEF,
800
                                           &objfile->static_psymbols,
801
                                      CUR_SYMBOL_VALUE, 0, psymtab_language,
802
                                           objfile);
803
                    }
804
                }
805
              goto check_enum;
806
            case 't':
807
              if (p != namestring)      /* a name is there, not just :T... */
808
                {
809
                  add_psymbol_to_list (namestring, p - namestring,
810
                                       VAR_NAMESPACE, LOC_TYPEDEF,
811
                                       &objfile->static_psymbols,
812
                                       CUR_SYMBOL_VALUE, 0,
813
                                       psymtab_language, objfile);
814
                }
815
            check_enum:
816
              /* If this is an enumerated type, we need to
817
                 add all the enum constants to the partial symbol
818
                 table.  This does not cover enums without names, e.g.
819
                 "enum {a, b} c;" in C, but fortunately those are
820
                 rare.  There is no way for GDB to find those from the
821
                 enum type without spending too much time on it.  Thus
822
                 to solve this problem, the compiler needs to put out the
823
                 enum in a nameless type.  GCC2 does this.  */
824
 
825
              /* We are looking for something of the form
826
                 <name> ":" ("t" | "T") [<number> "="] "e" <size>
827
                 {<constant> ":" <value> ","} ";".  */
828
 
829
              /* Skip over the colon and the 't' or 'T'.  */
830
              p += 2;
831
              /* This type may be given a number.  Also, numbers can come
832
                 in pairs like (0,26).  Skip over it.  */
833
              while ((*p >= '0' && *p <= '9')
834
                     || *p == '(' || *p == ',' || *p == ')'
835
                     || *p == '=')
836
                p++;
837
 
838
              if (*p++ == 'e')
839
                {
840
                  /* We have found an enumerated type. skip size */
841
                  while (*p >= '0' && *p <= '9')
842
                    p++;
843
                  /* According to comments in read_enum_type
844
                     a comma could end it instead of a semicolon.
845
                     I don't know where that happens.
846
                     Accept either.  */
847
                  while (*p && *p != ';' && *p != ',')
848
                    {
849
                      char *q;
850
 
851
                      /* Check for and handle cretinous dbx symbol name
852
                         continuation!
853
                         if (*p == '\\')
854
                         p = next_symbol_text (objfile);
855
                       */
856
 
857
                      /* Point to the character after the name
858
                         of the enum constant.  */
859
                      for (q = p; *q && *q != ':'; q++)
860
                        ;
861
                      /* Note that the value doesn't matter for
862
                         enum constants in psymtabs, just in symtabs.  */
863
                      add_psymbol_to_list (p, q - p,
864
                                           VAR_NAMESPACE, LOC_CONST,
865
                                           &objfile->static_psymbols, 0,
866
                                           0, psymtab_language, objfile);
867
                      /* Point past the name.  */
868
                      p = q;
869
                      /* Skip over the value.  */
870
                      while (*p && *p != ',')
871
                        p++;
872
                      /* Advance past the comma.  */
873
                      if (*p)
874
                        p++;
875
                    }
876
                }
877
              continue;
878
            case 'c':
879
              /* Constant, e.g. from "const" in Pascal.  */
880
              add_psymbol_to_list (namestring, p - namestring,
881
                                   VAR_NAMESPACE, LOC_CONST,
882
                                &objfile->static_psymbols, CUR_SYMBOL_VALUE,
883
                                   0, psymtab_language, objfile);
884
              continue;
885
 
886
            case 'f':
887
              CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
888
              if (pst && pst->textlow == 0)
889
                pst->textlow = CUR_SYMBOL_VALUE;
890
 
891
              add_psymbol_to_list (namestring, p - namestring,
892
                                   VAR_NAMESPACE, LOC_BLOCK,
893
                                &objfile->static_psymbols, CUR_SYMBOL_VALUE,
894
                                   0, psymtab_language, objfile);
895
              continue;
896
 
897
            case 'F':
898
              CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
899
              if (pst && pst->textlow == 0)
900
                pst->textlow = CUR_SYMBOL_VALUE;
901
 
902
              add_psymbol_to_list (namestring, p - namestring,
903
                                   VAR_NAMESPACE, LOC_BLOCK,
904
                                &objfile->global_psymbols, CUR_SYMBOL_VALUE,
905
                                   0, psymtab_language, objfile);
906
              continue;
907
 
908
            case 'p':
909
            case 'l':
910
            case 's':
911
              continue;
912
 
913
            case ':':
914
              /* It is a C++ nested symbol.  We don't need to record it
915
                 (I don't think); if we try to look up foo::bar::baz,
916
                 then symbols for the symtab containing foo should get
917
                 read in, I think.  */
918
              /* Someone says sun cc puts out symbols like
919
                 /foo/baz/maclib::/usr/local/bin/maclib,
920
                 which would get here with a symbol type of ':'.  */
921
              continue;
922
 
923
            default:
924
              /* Unexpected symbol descriptor.  The second and subsequent stabs
925
                 of a continued stab can show up here.  The question is
926
                 whether they ever can mimic a normal stab--it would be
927
                 nice if not, since we certainly don't want to spend the
928
                 time searching to the end of every string looking for
929
                 a backslash.  */
930
 
931
              complain (&unknown_symchar_complaint, p[1]);
932
              continue;
933
            }
934
 
935
        case N_SYM_RBRAC:
936
          CUR_SYMBOL_VALUE += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
937
#ifdef HANDLE_RBRAC
938
          HANDLE_RBRAC (CUR_SYMBOL_VALUE);
939
          continue;
940
#endif
941
        case N_SYM_LBRAC:
942
          continue;
943
 
944
        default:
945
          /* If we haven't found it yet, ignore it.  It's probably some
946
             new type we don't know about yet.  */
947
          complain (&unknown_symtype_complaint,
948
                    local_hex_string ((unsigned long) bufp->n_type));
949
          continue;
950
        }
951
    }
952
 
953
  DBX_SYMCOUNT (objfile) = symnum;
954
 
955
  /* If there's stuff to be cleaned up, clean it up.  */
956
  if (DBX_SYMCOUNT (objfile) > 0
957
/*FIXME, does this have a bug at start address 0? */
958
      && last_o_file_start
959
      && objfile->ei.entry_point < bufp->n_value
960
      && objfile->ei.entry_point >= last_o_file_start)
961
    {
962
      objfile->ei.entry_file_lowpc = last_o_file_start;
963
      objfile->ei.entry_file_highpc = bufp->n_value;
964
    }
965
 
966
  if (pst)
967
    {
968
      os9k_end_psymtab (pst, psymtab_include_list, includes_used,
969
                        symnum, end_of_text_addr,
970
                        dependency_list, dependencies_used);
971
    }
972
/*
973
   do_cleanups (back_to);
974
 */
975
}
976
 
977
/* Allocate and partially fill a partial symtab.  It will be
978
   completely filled at the end of the symbol list.
979
 
980
   SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
981
   is the address relative to which its symbols are (incremental) or 0
982
   (normal). */
983
 
984
 
985
static struct partial_symtab *
986
os9k_start_psymtab (objfile,
987
            filename, textlow, ldsymoff, ldsymcnt, global_syms, static_syms)
988
     struct objfile *objfile;
989
     char *filename;
990
     CORE_ADDR textlow;
991
     int ldsymoff;
992
     int ldsymcnt;
993
     struct partial_symbol **global_syms;
994
     struct partial_symbol **static_syms;
995
{
996
  struct partial_symtab *result =
997
  start_psymtab_common (objfile, objfile->section_offsets,
998
                        filename, textlow, global_syms, static_syms);
999
 
1000
  result->read_symtab_private = (char *)
1001
    obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
1002
 
1003
  LDSYMOFF (result) = ldsymoff;
1004
  LDSYMCNT (result) = ldsymcnt;
1005
  result->read_symtab = os9k_psymtab_to_symtab;
1006
 
1007
  /* Deduce the source language from the filename for this psymtab. */
1008
  psymtab_language = deduce_language_from_filename (filename);
1009
  return result;
1010
}
1011
 
1012
/* Close off the current usage of PST.
1013
   Returns PST or NULL if the partial symtab was empty and thrown away.
1014
   FIXME:  List variables and peculiarities of same.  */
1015
 
1016
static struct partial_symtab *
1017
os9k_end_psymtab (pst, include_list, num_includes, capping_symbol_cnt,
1018
                  capping_text, dependency_list, number_dependencies)
1019
     struct partial_symtab *pst;
1020
     char **include_list;
1021
     int num_includes;
1022
     int capping_symbol_cnt;
1023
     CORE_ADDR capping_text;
1024
     struct partial_symtab **dependency_list;
1025
     int number_dependencies;
1026
     /* struct partial_symbol *capping_global, *capping_static; */
1027
{
1028
  int i;
1029
  struct partial_symtab *p1;
1030
  struct objfile *objfile = pst->objfile;
1031
 
1032
  if (capping_symbol_cnt != -1)
1033
    LDSYMCNT (pst) = capping_symbol_cnt - LDSYMCNT (pst);
1034
 
1035
  /* Under Solaris, the N_SO symbols always have a value of 0,
1036
     instead of the usual address of the .o file.  Therefore,
1037
     we have to do some tricks to fill in texthigh and textlow.
1038
     The first trick is in partial-stab.h: if we see a static
1039
     or global function, and the textlow for the current pst
1040
     is still 0, then we use that function's address for
1041
     the textlow of the pst.
1042
 
1043
     Now, to fill in texthigh, we remember the last function seen
1044
     in the .o file (also in partial-stab.h).  Also, there's a hack in
1045
     bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
1046
     to here via the misc_info field.  Therefore, we can fill in
1047
     a reliable texthigh by taking the address plus size of the
1048
     last function in the file.
1049
 
1050
     Unfortunately, that does not cover the case where the last function
1051
     in the file is static.  See the paragraph below for more comments
1052
     on this situation.
1053
 
1054
     Finally, if we have a valid textlow for the current file, we run
1055
     down the partial_symtab_list filling in previous texthighs that
1056
     are still unknown.  */
1057
 
1058
  if (pst->texthigh == 0 && last_function_name)
1059
    {
1060
      char *p;
1061
      int n;
1062
      struct minimal_symbol *minsym;
1063
 
1064
      p = strchr (last_function_name, ':');
1065
      if (p == NULL)
1066
        p = last_function_name;
1067
      n = p - last_function_name;
1068
      p = alloca (n + 1);
1069
      strncpy (p, last_function_name, n);
1070
      p[n] = 0;
1071
 
1072
      minsym = lookup_minimal_symbol (p, NULL, objfile);
1073
 
1074
      if (minsym)
1075
        {
1076
          pst->texthigh = SYMBOL_VALUE_ADDRESS (minsym) + (long) MSYMBOL_INFO (minsym);
1077
        }
1078
      else
1079
        {
1080
          /* This file ends with a static function, and it's
1081
             difficult to imagine how hard it would be to track down
1082
             the elf symbol.  Luckily, most of the time no one will notice,
1083
             since the next file will likely be compiled with -g, so
1084
             the code below will copy the first fuction's start address
1085
             back to our texthigh variable.  (Also, if this file is the
1086
             last one in a dynamically linked program, texthigh already
1087
             has the right value.)  If the next file isn't compiled
1088
             with -g, then the last function in this file winds up owning
1089
             all of the text space up to the next -g file, or the end (minus
1090
             shared libraries).  This only matters for single stepping,
1091
             and even then it will still work, except that it will single
1092
             step through all of the covered functions, instead of setting
1093
             breakpoints around them as it usualy does.  This makes it
1094
             pretty slow, but at least it doesn't fail.
1095
 
1096
             We can fix this with a fairly big change to bfd, but we need
1097
             to coordinate better with Cygnus if we want to do that.  FIXME.  */
1098
        }
1099
      last_function_name = NULL;
1100
    }
1101
 
1102
  /* this test will be true if the last .o file is only data */
1103
  if (pst->textlow == 0)
1104
    pst->textlow = pst->texthigh;
1105
 
1106
  /* If we know our own starting text address, then walk through all other
1107
     psymtabs for this objfile, and if any didn't know their ending text
1108
     address, set it to our starting address.  Take care to not set our
1109
     own ending address to our starting address, nor to set addresses on
1110
     `dependency' files that have both textlow and texthigh zero.  */
1111
  if (pst->textlow)
1112
    {
1113
      ALL_OBJFILE_PSYMTABS (objfile, p1)
1114
      {
1115
        if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst)
1116
          {
1117
            p1->texthigh = pst->textlow;
1118
            /* if this file has only data, then make textlow match texthigh */
1119
            if (p1->textlow == 0)
1120
              p1->textlow = p1->texthigh;
1121
          }
1122
      }
1123
    }
1124
 
1125
  /* End of kludge for patching Solaris textlow and texthigh.  */
1126
 
1127
  pst->n_global_syms =
1128
    objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
1129
  pst->n_static_syms =
1130
    objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
1131
 
1132
  pst->number_of_dependencies = number_dependencies;
1133
  if (number_dependencies)
1134
    {
1135
      pst->dependencies = (struct partial_symtab **)
1136
        obstack_alloc (&objfile->psymbol_obstack,
1137
                    number_dependencies * sizeof (struct partial_symtab *));
1138
      memcpy (pst->dependencies, dependency_list,
1139
              number_dependencies * sizeof (struct partial_symtab *));
1140
    }
1141
  else
1142
    pst->dependencies = 0;
1143
 
1144
  for (i = 0; i < num_includes; i++)
1145
    {
1146
      struct partial_symtab *subpst =
1147
      allocate_psymtab (include_list[i], objfile);
1148
 
1149
      subpst->section_offsets = pst->section_offsets;
1150
      subpst->read_symtab_private =
1151
        (char *) obstack_alloc (&objfile->psymbol_obstack,
1152
                                sizeof (struct symloc));
1153
      LDSYMOFF (subpst) =
1154
        LDSYMCNT (subpst) =
1155
        subpst->textlow =
1156
        subpst->texthigh = 0;
1157
 
1158
      /* We could save slight bits of space by only making one of these,
1159
         shared by the entire set of include files.  FIXME-someday.  */
1160
      subpst->dependencies = (struct partial_symtab **)
1161
        obstack_alloc (&objfile->psymbol_obstack,
1162
                       sizeof (struct partial_symtab *));
1163
      subpst->dependencies[0] = pst;
1164
      subpst->number_of_dependencies = 1;
1165
 
1166
      subpst->globals_offset =
1167
        subpst->n_global_syms =
1168
        subpst->statics_offset =
1169
        subpst->n_static_syms = 0;
1170
 
1171
      subpst->readin = 0;
1172
      subpst->symtab = 0;
1173
      subpst->read_symtab = pst->read_symtab;
1174
    }
1175
 
1176
  sort_pst_symbols (pst);
1177
 
1178
  /* If there is already a psymtab or symtab for a file of this name,
1179
     remove it.
1180
     (If there is a symtab, more drastic things also happen.)
1181
     This happens in VxWorks.  */
1182
  free_named_symtabs (pst->filename);
1183
 
1184
  if (num_includes == 0
1185
      && number_dependencies == 0
1186
      && pst->n_global_syms == 0
1187
      && pst->n_static_syms == 0)
1188
    {
1189
      /* Throw away this psymtab, it's empty.  We can't deallocate it, since
1190
         it is on the obstack, but we can forget to chain it on the list.  */
1191
      /* Indicate that psymtab was thrown away.  */
1192
 
1193
      discard_psymtab (pst);
1194
 
1195
      pst = (struct partial_symtab *) NULL;
1196
    }
1197
  return pst;
1198
}
1199
 
1200
static void
1201
os9k_psymtab_to_symtab_1 (pst)
1202
     struct partial_symtab *pst;
1203
{
1204
  struct cleanup *old_chain;
1205
  int i;
1206
 
1207
  if (!pst)
1208
    return;
1209
 
1210
  if (pst->readin)
1211
    {
1212
      fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in.  Shouldn't happen.\n",
1213
                          pst->filename);
1214
      return;
1215
    }
1216
 
1217
  /* Read in all partial symtabs on which this one is dependent */
1218
  for (i = 0; i < pst->number_of_dependencies; i++)
1219
    if (!pst->dependencies[i]->readin)
1220
      {
1221
        /* Inform about additional files that need to be read in.  */
1222
        if (info_verbose)
1223
          {
1224
            fputs_filtered (" ", gdb_stdout);
1225
            wrap_here ("");
1226
            fputs_filtered ("and ", gdb_stdout);
1227
            wrap_here ("");
1228
            printf_filtered ("%s...", pst->dependencies[i]->filename);
1229
            wrap_here ("");     /* Flush output */
1230
            gdb_flush (gdb_stdout);
1231
          }
1232
        os9k_psymtab_to_symtab_1 (pst->dependencies[i]);
1233
      }
1234
 
1235
  if (LDSYMCNT (pst))           /* Otherwise it's a dummy */
1236
    {
1237
      /* Init stuff necessary for reading in symbols */
1238
      stabsread_init ();
1239
      buildsym_init ();
1240
      old_chain = make_cleanup (really_free_pendings, 0);
1241
 
1242
      /* Read in this file's symbols */
1243
      os9k_read_ofile_symtab (pst);
1244
      sort_symtab_syms (pst->symtab);
1245
      do_cleanups (old_chain);
1246
    }
1247
 
1248
  pst->readin = 1;
1249
}
1250
 
1251
/* Read in all of the symbols for a given psymtab for real.
1252
   Be verbose about it if the user wants that.  */
1253
 
1254
static void
1255
os9k_psymtab_to_symtab (pst)
1256
     struct partial_symtab *pst;
1257
{
1258
  bfd *sym_bfd;
1259
 
1260
  if (!pst)
1261
    return;
1262
 
1263
  if (pst->readin)
1264
    {
1265
      fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in.  Shouldn't happen.\n",
1266
                          pst->filename);
1267
      return;
1268
    }
1269
 
1270
  if (LDSYMCNT (pst) || pst->number_of_dependencies)
1271
    {
1272
      /* Print the message now, before reading the string table,
1273
         to avoid disconcerting pauses.  */
1274
      if (info_verbose)
1275
        {
1276
          printf_filtered ("Reading in symbols for %s...", pst->filename);
1277
          gdb_flush (gdb_stdout);
1278
        }
1279
 
1280
      sym_bfd = pst->objfile->obfd;
1281
      os9k_psymtab_to_symtab_1 (pst);
1282
 
1283
      /* Match with global symbols.  This only needs to be done once,
1284
         after all of the symtabs and dependencies have been read in.   */
1285
      scan_file_globals (pst->objfile);
1286
 
1287
      /* Finish up the debug error message.  */
1288
      if (info_verbose)
1289
        printf_filtered ("done.\n");
1290
    }
1291
}
1292
 
1293
/* Read in a defined section of a specific object file's symbols. */
1294
static void
1295
os9k_read_ofile_symtab (pst)
1296
     struct partial_symtab *pst;
1297
{
1298
  register struct internal_symstruct *bufp;
1299
  unsigned char type;
1300
  unsigned max_symnum;
1301
  register bfd *abfd;
1302
  struct objfile *objfile;
1303
  int sym_offset;               /* Offset to start of symbols to read */
1304
  CORE_ADDR text_offset;        /* Start of text segment for symbols */
1305
  int text_size;                /* Size of text segment for symbols */
1306
  FILE *dbg_file;
1307
 
1308
  objfile = pst->objfile;
1309
  sym_offset = LDSYMOFF (pst);
1310
  max_symnum = LDSYMCNT (pst);
1311
  text_offset = pst->textlow;
1312
  text_size = pst->texthigh - pst->textlow;
1313
 
1314
  current_objfile = objfile;
1315
  subfile_stack = NULL;
1316
  last_source_file = NULL;
1317
 
1318
  abfd = objfile->obfd;
1319
  dbg_file = objfile->auxf2;
1320
 
1321
#if 0
1322
  /* It is necessary to actually read one symbol *before* the start
1323
     of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
1324
     occurs before the N_SO symbol.
1325
     Detecting this in read_dbx_symtab
1326
     would slow down initial readin, so we look for it here instead. */
1327
  if (!processing_acc_compilation && sym_offset >= (int) symbol_size)
1328
    {
1329
      fseek (objefile->auxf2, sym_offset, SEEK_CUR);
1330
      fill_sym (objfile->auxf2, abfd);
1331
      bufp = symbuf;
1332
 
1333
      processing_gcc_compilation = 0;
1334
      if (bufp->n_type == N_TEXT)
1335
        {
1336
          if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
1337
            processing_gcc_compilation = 1;
1338
          else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
1339
            processing_gcc_compilation = 2;
1340
        }
1341
 
1342
      /* Try to select a C++ demangling based on the compilation unit
1343
         producer. */
1344
 
1345
      if (processing_gcc_compilation)
1346
        {
1347
          if (AUTO_DEMANGLING)
1348
            {
1349
              set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1350
            }
1351
        }
1352
    }
1353
  else
1354
    {
1355
      /* The N_SO starting this symtab is the first symbol, so we
1356
         better not check the symbol before it.  I'm not this can
1357
         happen, but it doesn't hurt to check for it.  */
1358
      bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
1359
      processing_gcc_compilation = 0;
1360
    }
1361
#endif /* 0 */
1362
 
1363
  fseek (dbg_file, (long) sym_offset, 0);
1364
/*
1365
   if (bufp->n_type != (unsigned char)N_SYM_SYM)
1366
   error("First symbol in segment of executable not a source symbol");
1367
 */
1368
 
1369
  for (symnum = 0; symnum < max_symnum; symnum++)
1370
    {
1371
      QUIT;                     /* Allow this to be interruptable */
1372
      fill_sym (dbg_file, abfd);
1373
      bufp = symbuf;
1374
      type = bufp->n_type;
1375
 
1376
      os9k_process_one_symbol ((int) type, (int) bufp->n_desc,
1377
         (CORE_ADDR) bufp->n_value, bufp->n_strx, pst->section_offsets, objfile);
1378
 
1379
      /* We skip checking for a new .o or -l file; that should never
1380
         happen in this routine. */
1381
#if 0
1382
      else
1383
      if (type == N_TEXT)
1384
        {
1385
          /* I don't think this code will ever be executed, because
1386
             the GCC_COMPILED_FLAG_SYMBOL usually is right before
1387
             the N_SO symbol which starts this source file.
1388
             However, there is no reason not to accept
1389
             the GCC_COMPILED_FLAG_SYMBOL anywhere.  */
1390
 
1391
          if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
1392
            processing_gcc_compilation = 1;
1393
          else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
1394
            processing_gcc_compilation = 2;
1395
 
1396
          if (AUTO_DEMANGLING)
1397
            {
1398
              set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
1399
            }
1400
        }
1401
      else if (type & N_EXT || type == (unsigned char) N_TEXT
1402
               || type == (unsigned char) N_NBTEXT
1403
        )
1404
        {
1405
          /* Global symbol: see if we came across a dbx defintion for
1406
             a corresponding symbol.  If so, store the value.  Remove
1407
             syms from the chain when their values are stored, but
1408
             search the whole chain, as there may be several syms from
1409
             different files with the same name. */
1410
          /* This is probably not true.  Since the files will be read
1411
             in one at a time, each reference to a global symbol will
1412
             be satisfied in each file as it appears. So we skip this
1413
             section. */
1414
          ;
1415
        }
1416
#endif /* 0 */
1417
    }
1418
 
1419
  current_objfile = NULL;
1420
 
1421
  /* In a Solaris elf file, this variable, which comes from the
1422
     value of the N_SO symbol, will still be 0.  Luckily, text_offset,
1423
     which comes from pst->textlow is correct. */
1424
  if (last_source_start_addr == 0)
1425
    last_source_start_addr = text_offset;
1426
  pst->symtab = end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT);
1427
  end_stabs ();
1428
}
1429
 
1430
 
1431
/* This handles a single symbol from the symbol-file, building symbols
1432
   into a GDB symtab.  It takes these arguments and an implicit argument.
1433
 
1434
   TYPE is the type field of the ".stab" symbol entry.
1435
   DESC is the desc field of the ".stab" entry.
1436
   VALU is the value field of the ".stab" entry.
1437
   NAME is the symbol name, in our address space.
1438
   SECTION_OFFSETS is a set of amounts by which the sections of this object
1439
   file were relocated when it was loaded into memory.
1440
   All symbols that refer
1441
   to memory locations need to be offset by these amounts.
1442
   OBJFILE is the object file from which we are reading symbols.
1443
   It is used in end_symtab.  */
1444
 
1445
static void
1446
os9k_process_one_symbol (type, desc, valu, name, section_offsets, objfile)
1447
     int type, desc;
1448
     CORE_ADDR valu;
1449
     char *name;
1450
     struct section_offsets *section_offsets;
1451
     struct objfile *objfile;
1452
{
1453
  register struct context_stack *new;
1454
  /* The stab type used for the definition of the last function.
1455
     N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers.  */
1456
  static int function_stab_type = 0;
1457
 
1458
#if 0
1459
  /* Something is wrong if we see real data before
1460
     seeing a source file name.  */
1461
  if (last_source_file == NULL && type != (unsigned char) N_SO)
1462
    {
1463
      /* Ignore any symbols which appear before an N_SO symbol.
1464
         Currently no one puts symbols there, but we should deal
1465
         gracefully with the case.  A complain()t might be in order,
1466
         but this should not be an error ().  */
1467
      return;
1468
    }
1469
#endif /* 0 */
1470
 
1471
  switch (type)
1472
    {
1473
    case N_SYM_LBRAC:
1474
      /* On most machines, the block addresses are relative to the
1475
         N_SO, the linker did not relocate them (sigh).  */
1476
      valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1477
      new = push_context (desc, valu);
1478
      break;
1479
 
1480
    case N_SYM_RBRAC:
1481
      valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1482
      new = pop_context ();
1483
 
1484
#if !defined (OS9K_VARIABLES_INSIDE_BLOCK)
1485
#define OS9K_VARIABLES_INSIDE_BLOCK(desc, gcc_p) 1
1486
#endif
1487
 
1488
      if (!OS9K_VARIABLES_INSIDE_BLOCK (desc, processing_gcc_compilation))
1489
        local_symbols = new->locals;
1490
 
1491
      if (context_stack_depth > 1)
1492
        {
1493
          /* This is not the outermost LBRAC...RBRAC pair in the function,
1494
             its local symbols preceded it, and are the ones just recovered
1495
             from the context stack.  Define the block for them (but don't
1496
             bother if the block contains no symbols.  Should we complain
1497
             on blocks without symbols?  I can't think of any useful purpose
1498
             for them).  */
1499
          if (local_symbols != NULL)
1500
            {
1501
              /* Muzzle a compiler bug that makes end < start.  (which
1502
                 compilers?  Is this ever harmful?).  */
1503
              if (new->start_addr > valu)
1504
                {
1505
                  complain (&lbrac_rbrac_complaint);
1506
                  new->start_addr = valu;
1507
                }
1508
              /* Make a block for the local symbols within.  */
1509
              finish_block (0, &local_symbols, new->old_blocks,
1510
                            new->start_addr, valu, objfile);
1511
            }
1512
        }
1513
      else
1514
        {
1515
          if (context_stack_depth == 0)
1516
            {
1517
              within_function = 0;
1518
              /* Make a block for the local symbols within.  */
1519
              finish_block (new->name, &local_symbols, new->old_blocks,
1520
                            new->start_addr, valu, objfile);
1521
            }
1522
          else
1523
            {
1524
              /* attach local_symbols to the end of new->locals */
1525
              if (!new->locals)
1526
                new->locals = local_symbols;
1527
              else
1528
                {
1529
                  struct pending *p;
1530
 
1531
                  p = new->locals;
1532
                  while (p->next)
1533
                    p = p->next;
1534
                  p->next = local_symbols;
1535
                }
1536
            }
1537
        }
1538
 
1539
      if (OS9K_VARIABLES_INSIDE_BLOCK (desc, processing_gcc_compilation))
1540
        /* Now pop locals of block just finished.  */
1541
        local_symbols = new->locals;
1542
      break;
1543
 
1544
 
1545
    case N_SYM_SLINE:
1546
      /* This type of "symbol" really just records
1547
         one line-number -- core-address correspondence.
1548
         Enter it in the line list for this symbol table. */
1549
      /* Relocate for dynamic loading and for ELF acc fn-relative syms.  */
1550
      valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1551
      /* FIXME: loses if sizeof (char *) > sizeof (int) */
1552
      record_line (current_subfile, (int) name, valu);
1553
      break;
1554
 
1555
      /* The following symbol types need to have the appropriate offset added
1556
         to their value; then we process symbol definitions in the name.  */
1557
    case N_SYM_SYM:
1558
 
1559
      if (name)
1560
        {
1561
          char deftype;
1562
          char *dirn, *n;
1563
          char *p = strchr (name, ':');
1564
          if (p == NULL)
1565
            deftype = '\0';
1566
          else
1567
            deftype = p[1];
1568
 
1569
 
1570
          switch (deftype)
1571
            {
1572
            case 'S':
1573
              valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1574
              n = strrchr (name, '/');
1575
              if (n != NULL)
1576
                {
1577
                  *n = '\0';
1578
                  n++;
1579
                  dirn = name;
1580
                }
1581
              else
1582
                {
1583
                  n = name;
1584
                  dirn = NULL;
1585
                }
1586
              *p = '\0';
1587
              if (symfile_depth++ == 0)
1588
                {
1589
                  if (last_source_file)
1590
                    {
1591
                      end_symtab (valu, objfile, SECT_OFF_TEXT);
1592
                      end_stabs ();
1593
                    }
1594
                  start_stabs ();
1595
                  os9k_stabs = 1;
1596
                  start_symtab (n, dirn, valu);
1597
                  record_debugformat ("OS9");
1598
                }
1599
              else
1600
                {
1601
                  push_subfile ();
1602
                  start_subfile (n, dirn != NULL ? dirn : current_subfile->dirname);
1603
                }
1604
              break;
1605
 
1606
            case 'f':
1607
            case 'F':
1608
              valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1609
              function_stab_type = type;
1610
 
1611
              within_function = 1;
1612
              new = push_context (0, valu);
1613
              new->name = define_symbol (valu, name, desc, type, objfile);
1614
              break;
1615
 
1616
            case 'V':
1617
            case 'v':
1618
              valu += ANOFFSET (section_offsets, SECT_OFF_DATA);
1619
              define_symbol (valu, name, desc, type, objfile);
1620
              break;
1621
 
1622
            default:
1623
              define_symbol (valu, name, desc, type, objfile);
1624
              break;
1625
            }
1626
        }
1627
      break;
1628
 
1629
    case N_SYM_SE:
1630
      if (--symfile_depth != 0)
1631
        start_subfile (pop_subfile (), current_subfile->dirname);
1632
      break;
1633
 
1634
    default:
1635
      complain (&unknown_symtype_complaint,
1636
                local_hex_string ((unsigned long) type));
1637
      /* FALLTHROUGH */
1638
      break;
1639
 
1640
    case N_SYM_CMPLR:
1641
      break;
1642
    }
1643
  previous_stab_code = type;
1644
}
1645
 
1646
static struct sym_fns os9k_sym_fns =
1647
{
1648
  bfd_target_os9k_flavour,
1649
  os9k_new_init,                /* sym_new_init: init anything gbl to entire symtab */
1650
  os9k_symfile_init,            /* sym_init: read initial info, setup for sym_read() */
1651
  os9k_symfile_read,            /* sym_read: read a symbol file into symtab */
1652
  os9k_symfile_finish,          /* sym_finish: finished with file, cleanup */
1653
  default_symfile_offsets,      /* sym_offsets: parse user's offsets to internal form */
1654
  NULL                          /* next: pointer to next struct sym_fns */
1655
};
1656
 
1657
void
1658
_initialize_os9kread ()
1659
{
1660
  add_symtab_fns (&os9k_sym_fns);
1661
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.