]> Git Repo - binutils.git/blob - gdb/somread.c
2003-04-28 Andrew Cagney <[email protected]>
[binutils.git] / gdb / somread.c
1 /* Read HP PA/Risc object files for GDB.
2    Copyright 1991, 1992, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002
3    Free Software Foundation, Inc.
4    Written by Fred Fish at Cygnus Support.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22
23 #include "defs.h"
24 #include "bfd.h"
25 #include <syms.h>
26 #include "symtab.h"
27 #include "symfile.h"
28 #include "objfiles.h"
29 #include "buildsym.h"
30 #include "stabsread.h"
31 #include "gdb-stabs.h"
32 #include "complaints.h"
33 #include "gdb_string.h"
34 #include "demangle.h"
35 #include "som.h"
36 #include "libhppa.h"
37
38 /* Various things we might complain about... */
39
40 static int init_import_symbols (struct objfile *objfile);
41
42 static void som_symfile_init (struct objfile *);
43
44 static void som_new_init (struct objfile *);
45
46 static void som_symfile_read (struct objfile *, int);
47
48 static void som_symfile_finish (struct objfile *);
49
50 static void som_symtab_read (bfd *, struct objfile *,
51                              struct section_offsets *);
52
53 static void som_symfile_offsets (struct objfile *, struct section_addr_info *);
54
55 /* FIXME: These should really be in a common header somewhere */
56
57 extern void hpread_build_psymtabs (struct objfile *, int);
58
59 extern void hpread_symfile_finish (struct objfile *);
60
61 extern void hpread_symfile_init (struct objfile *);
62
63 extern void do_pxdb (bfd *);
64
65 /*
66
67    LOCAL FUNCTION
68
69    som_symtab_read -- read the symbol table of a SOM file
70
71    SYNOPSIS
72
73    void som_symtab_read (bfd *abfd, struct objfile *objfile,
74    struct section_offsets *section_offsets)
75
76    DESCRIPTION
77
78    Given an open bfd, a base address to relocate symbols to, and a
79    flag that specifies whether or not this bfd is for an executable
80    or not (may be shared library for example), add all the global
81    function and data symbols to the minimal symbol table.
82  */
83
84 static void
85 som_symtab_read (bfd *abfd, struct objfile *objfile,
86                  struct section_offsets *section_offsets)
87 {
88   unsigned int number_of_symbols;
89   int val, dynamic;
90   char *stringtab;
91   asection *shlib_info;
92   struct symbol_dictionary_record *buf, *bufp, *endbufp;
93   char *symname;
94   CONST int symsize = sizeof (struct symbol_dictionary_record);
95   CORE_ADDR text_offset, data_offset;
96
97
98   text_offset = ANOFFSET (section_offsets, 0);
99   data_offset = ANOFFSET (section_offsets, 1);
100
101   number_of_symbols = bfd_get_symcount (abfd);
102
103   /* FIXME (alloca): could be quite large. */
104   buf = alloca (symsize * number_of_symbols);
105   bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET);
106   val = bfd_bread (buf, symsize * number_of_symbols, abfd);
107   if (val != symsize * number_of_symbols)
108     error ("Couldn't read symbol dictionary!");
109
110   /* FIXME (alloca): could be quite large. */
111   stringtab = alloca (obj_som_stringtab_size (abfd));
112   bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET);
113   val = bfd_bread (stringtab, obj_som_stringtab_size (abfd), abfd);
114   if (val != obj_som_stringtab_size (abfd))
115     error ("Can't read in HP string table.");
116
117   /* We need to determine if objfile is a dynamic executable (so we
118      can do the right thing for ST_ENTRY vs ST_CODE symbols).
119
120      There's nothing in the header which easily allows us to do
121      this.
122
123      This code used to rely upon the existence of a $SHLIB_INFO$
124      section to make this determination.  HP claims that it is
125      more accurate to check for a nonzero text offset, but they
126      have not provided any information about why that test is
127      more accurate.  */
128   dynamic = (text_offset != 0);
129
130   endbufp = buf + number_of_symbols;
131   for (bufp = buf; bufp < endbufp; ++bufp)
132     {
133       enum minimal_symbol_type ms_type;
134
135       QUIT;
136
137       switch (bufp->symbol_scope)
138         {
139         case SS_UNIVERSAL:
140         case SS_EXTERNAL:
141           switch (bufp->symbol_type)
142             {
143             case ST_SYM_EXT:
144             case ST_ARG_EXT:
145               continue;
146
147             case ST_CODE:
148             case ST_PRI_PROG:
149             case ST_SEC_PROG:
150             case ST_MILLICODE:
151               symname = bufp->name.n_strx + stringtab;
152               ms_type = mst_text;
153               bufp->symbol_value += text_offset;
154               bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
155               break;
156
157             case ST_ENTRY:
158               symname = bufp->name.n_strx + stringtab;
159               /* For a dynamic executable, ST_ENTRY symbols are
160                  the stubs, while the ST_CODE symbol is the real
161                  function.  */
162               if (dynamic)
163                 ms_type = mst_solib_trampoline;
164               else
165                 ms_type = mst_text;
166               bufp->symbol_value += text_offset;
167               bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
168               break;
169
170             case ST_STUB:
171               symname = bufp->name.n_strx + stringtab;
172               ms_type = mst_solib_trampoline;
173               bufp->symbol_value += text_offset;
174               bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
175               break;
176
177             case ST_DATA:
178               symname = bufp->name.n_strx + stringtab;
179               bufp->symbol_value += data_offset;
180               ms_type = mst_data;
181               break;
182             default:
183               continue;
184             }
185           break;
186
187 #if 0
188           /* SS_GLOBAL and SS_LOCAL are two names for the same thing (!).  */
189         case SS_GLOBAL:
190 #endif
191         case SS_LOCAL:
192           switch (bufp->symbol_type)
193             {
194             case ST_SYM_EXT:
195             case ST_ARG_EXT:
196               continue;
197
198             case ST_CODE:
199               symname = bufp->name.n_strx + stringtab;
200               ms_type = mst_file_text;
201               bufp->symbol_value += text_offset;
202               bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
203
204             check_strange_names:
205               /* Utah GCC 2.5, FSF GCC 2.6 and later generate correct local
206                  label prefixes for stabs, constant data, etc.  So we need
207                  only filter out L$ symbols which are left in due to
208                  limitations in how GAS generates SOM relocations.
209
210                  When linking in the HPUX C-library the HP linker has
211                  the nasty habit of placing section symbols from the literal
212                  subspaces in the middle of the program's text.  Filter
213                  those out as best we can.  Check for first and last character
214                  being '$'. 
215
216                  And finally, the newer HP compilers emit crud like $PIC_foo$N
217                  in some circumstance (PIC code I guess).  It's also claimed
218                  that they emit D$ symbols too.  What stupidity.  */
219               if ((symname[0] == 'L' && symname[1] == '$')
220               || (symname[0] == '$' && symname[strlen (symname) - 1] == '$')
221                   || (symname[0] == 'D' && symname[1] == '$')
222                   || (strncmp (symname, "$PIC", 4) == 0))
223                 continue;
224               break;
225
226             case ST_PRI_PROG:
227             case ST_SEC_PROG:
228             case ST_MILLICODE:
229               symname = bufp->name.n_strx + stringtab;
230               ms_type = mst_file_text;
231               bufp->symbol_value += text_offset;
232               bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
233               break;
234
235             case ST_ENTRY:
236               symname = bufp->name.n_strx + stringtab;
237               /* SS_LOCAL symbols in a shared library do not have
238                  export stubs, so we do not have to worry about
239                  using mst_file_text vs mst_solib_trampoline here like
240                  we do for SS_UNIVERSAL and SS_EXTERNAL symbols above.  */
241               ms_type = mst_file_text;
242               bufp->symbol_value += text_offset;
243               bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
244               break;
245
246             case ST_STUB:
247               symname = bufp->name.n_strx + stringtab;
248               ms_type = mst_solib_trampoline;
249               bufp->symbol_value += text_offset;
250               bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
251               break;
252
253
254             case ST_DATA:
255               symname = bufp->name.n_strx + stringtab;
256               bufp->symbol_value += data_offset;
257               ms_type = mst_file_data;
258               goto check_strange_names;
259
260             default:
261               continue;
262             }
263           break;
264
265           /* This can happen for common symbols when -E is passed to the
266              final link.  No idea _why_ that would make the linker force
267              common symbols to have an SS_UNSAT scope, but it does.
268
269              This also happens for weak symbols, but their type is
270              ST_DATA.  */
271         case SS_UNSAT:
272           switch (bufp->symbol_type)
273             {
274             case ST_STORAGE:
275             case ST_DATA:
276               symname = bufp->name.n_strx + stringtab;
277               bufp->symbol_value += data_offset;
278               ms_type = mst_data;
279               break;
280
281             default:
282               continue;
283             }
284           break;
285
286         default:
287           continue;
288         }
289
290       if (bufp->name.n_strx > obj_som_stringtab_size (abfd))
291         error ("Invalid symbol data; bad HP string table offset: %d",
292                bufp->name.n_strx);
293
294       prim_record_minimal_symbol (symname, bufp->symbol_value, ms_type,
295                                   objfile);
296     }
297 }
298
299 /* Scan and build partial symbols for a symbol file.
300    We have been initialized by a call to som_symfile_init, which 
301    currently does nothing.
302
303    SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
304    in each section.  This is ignored, as it isn't needed for SOM.
305
306    MAINLINE is true if we are reading the main symbol
307    table (as opposed to a shared lib or dynamically loaded file).
308
309    This function only does the minimum work necessary for letting the
310    user "name" things symbolically; it does not read the entire symtab.
311    Instead, it reads the external and static symbols and puts them in partial
312    symbol tables.  When more extensive information is requested of a
313    file, the corresponding partial symbol table is mutated into a full
314    fledged symbol table by going back and reading the symbols
315    for real.
316
317    We look for sections with specific names, to tell us what debug
318    format to look for:  FIXME!!!
319
320    somstab_build_psymtabs() handles STABS symbols.
321
322    Note that SOM files have a "minimal" symbol table, which is vaguely
323    reminiscent of a COFF symbol table, but has only the minimal information
324    necessary for linking.  We process this also, and use the information to
325    build gdb's minimal symbol table.  This gives us some minimal debugging
326    capability even for files compiled without -g.  */
327
328 static void
329 som_symfile_read (struct objfile *objfile, int mainline)
330 {
331   bfd *abfd = objfile->obfd;
332   struct cleanup *back_to;
333
334   do_pxdb (symfile_bfd_open (objfile->name));
335
336   init_minimal_symbol_collection ();
337   back_to = make_cleanup_discard_minimal_symbols ();
338
339   /* Read in the import list and the export list.  Currently
340      the export list isn't used; the import list is used in
341      hp-symtab-read.c to handle static vars declared in other
342      shared libraries. */
343   init_import_symbols (objfile);
344 #if 0                           /* Export symbols not used today 1997-08-05 */
345   init_export_symbols (objfile);
346 #else
347   objfile->export_list = NULL;
348   objfile->export_list_size = 0;
349 #endif
350
351   /* Process the normal SOM symbol table first. 
352      This reads in the DNTT and string table, but doesn't
353      actually scan the DNTT. It does scan the linker symbol
354      table and thus build up a "minimal symbol table". */
355
356   som_symtab_read (abfd, objfile, objfile->section_offsets);
357
358   /* Install any minimal symbols that have been collected as the current
359      minimal symbols for this objfile. 
360      Further symbol-reading is done incrementally, file-by-file,
361      in a step known as "psymtab-to-symtab" expansion. hp-symtab-read.c
362      contains the code to do the actual DNTT scanning and symtab building. */
363   install_minimal_symbols (objfile);
364   do_cleanups (back_to);
365
366   /* Now read information from the stabs debug sections.
367      This is a no-op for SOM.
368      Perhaps it is intended for some kind of mixed STABS/SOM
369      situation? */
370   stabsect_build_psymtabs (objfile, mainline,
371                            "$GDB_SYMBOLS$", "$GDB_STRINGS$", "$TEXT$");
372
373   /* Now read the native debug information. 
374      This builds the psymtab. This used to be done via a scan of
375      the DNTT, but is now done via the PXDB-built quick-lookup tables
376      together with a scan of the GNTT. See hp-psymtab-read.c. */
377   hpread_build_psymtabs (objfile, mainline);
378
379   /* Force hppa-tdep.c to re-read the unwind descriptors.  */
380   objfile->obj_private = NULL;
381 }
382
383 /* Initialize anything that needs initializing when a completely new symbol
384    file is specified (not just adding some symbols from another file, e.g. a
385    shared library).
386
387    We reinitialize buildsym, since we may be reading stabs from a SOM file.  */
388
389 static void
390 som_new_init (struct objfile *ignore)
391 {
392   stabsread_new_init ();
393   buildsym_new_init ();
394 }
395
396 /* Perform any local cleanups required when we are done with a particular
397    objfile.  I.E, we are in the process of discarding all symbol information
398    for an objfile, freeing up all memory held for it, and unlinking the
399    objfile struct from the global list of known objfiles. */
400
401 static void
402 som_symfile_finish (struct objfile *objfile)
403 {
404   if (objfile->sym_stab_info != NULL)
405     {
406       xmfree (objfile->md, objfile->sym_stab_info);
407     }
408   hpread_symfile_finish (objfile);
409 }
410
411 /* SOM specific initialization routine for reading symbols.  */
412
413 static void
414 som_symfile_init (struct objfile *objfile)
415 {
416   /* SOM objects may be reordered, so set OBJF_REORDERED.  If we
417      find this causes a significant slowdown in gdb then we could
418      set it in the debug symbol readers only when necessary.  */
419   objfile->flags |= OBJF_REORDERED;
420   hpread_symfile_init (objfile);
421 }
422
423 /* SOM specific parsing routine for section offsets.
424
425    Plain and simple for now.  */
426
427 static void
428 som_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
429 {
430   int i;
431   CORE_ADDR text_addr;
432
433   objfile->num_sections = SECT_OFF_MAX;
434   objfile->section_offsets = (struct section_offsets *)
435     obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
436
437   /* FIXME: ezannoni 2000-04-20 The section names in SOM are not
438      .text, .data, etc, but $TEXT$, $DATA$,... We should initialize
439      SET_OFF_* from bfd. (See default_symfile_offsets()). But I don't
440      know the correspondence between SOM sections and GDB's idea of
441      section names. So for now we default to what is was before these
442      changes.*/
443   objfile->sect_index_text = 0;
444   objfile->sect_index_data = 1;
445   objfile->sect_index_bss = 2;
446   objfile->sect_index_rodata = 3;
447
448   /* First see if we're a shared library.  If so, get the section
449      offsets from the library, else get them from addrs.  */
450   if (!som_solib_section_offsets (objfile, objfile->section_offsets))
451     {
452       /* Note: Here is OK to compare with ".text" because this is the
453          name that gdb itself gives to that section, not the SOM
454          name. */
455       for (i = 0; i < SECT_OFF_MAX && addrs->other[i].name; i++)
456         if (strcmp (addrs->other[i].name, ".text") == 0)
457           break;
458       text_addr = addrs->other[i].addr;
459
460       for (i = 0; i < SECT_OFF_MAX; i++)
461         (objfile->section_offsets)->offsets[i] = text_addr;
462     }
463 }
464
465 /* Read in and initialize the SOM import list which is present
466    for all executables and shared libraries.  The import list
467    consists of the symbols that are referenced in OBJFILE but
468    not defined there.  (Variables that are imported are dealt
469    with as "loc_indirect" vars.)
470    Return value = number of import symbols read in. */
471 static int
472 init_import_symbols (struct objfile *objfile)
473 {
474   unsigned int import_list;
475   unsigned int import_list_size;
476   unsigned int string_table;
477   unsigned int string_table_size;
478   char *string_buffer;
479   register int i;
480   register int j;
481   register int k;
482   asection *text_section;       /* section handle */
483   unsigned int dl_header[12];   /* SOM executable header */
484
485   /* A struct for an entry in the SOM import list */
486   typedef struct
487     {
488       int name;                 /* index into the string table */
489       short dont_care1;         /* we don't use this */
490       unsigned char type;       /* 0 = NULL, 2 = Data, 3 = Code, 7 = Storage, 13 = Plabel */
491       unsigned int reserved2:8; /* not used */
492     }
493   SomImportEntry;
494
495   /* We read 100 entries in at a time from the disk file. */
496 #define SOM_READ_IMPORTS_NUM         100
497 #define SOM_READ_IMPORTS_CHUNK_SIZE  (sizeof (SomImportEntry) * SOM_READ_IMPORTS_NUM)
498   SomImportEntry buffer[SOM_READ_IMPORTS_NUM];
499
500   /* Initialize in case we error out */
501   objfile->import_list = NULL;
502   objfile->import_list_size = 0;
503
504   /* It doesn't work, for some reason, to read in space $TEXT$;
505      the subspace $SHLIB_INFO$ has to be used.  Some BFD quirk? pai/1997-08-05 */
506   text_section = bfd_get_section_by_name (objfile->obfd, "$SHLIB_INFO$");
507   if (!text_section)
508     return 0;
509   /* Get the SOM executable header */
510   bfd_get_section_contents (objfile->obfd, text_section, dl_header, 0, 12 * sizeof (int));
511
512   /* Check header version number for 10.x HP-UX */
513   /* Currently we deal only with 10.x systems; on 9.x the version # is 89060912.
514      FIXME: Change for future HP-UX releases and mods to the SOM executable format */
515   if (dl_header[0] != 93092112)
516     return 0;
517
518   import_list = dl_header[4];
519   import_list_size = dl_header[5];
520   if (!import_list_size)
521     return 0;
522   string_table = dl_header[10];
523   string_table_size = dl_header[11];
524   if (!string_table_size)
525     return 0;
526
527   /* Suck in SOM string table */
528   string_buffer = (char *) xmalloc (string_table_size);
529   bfd_get_section_contents (objfile->obfd, text_section, string_buffer,
530                             string_table, string_table_size);
531
532   /* Allocate import list in the psymbol obstack; this has nothing
533      to do with psymbols, just a matter of convenience.  We want the
534      import list to be freed when the objfile is deallocated */
535   objfile->import_list
536     = (ImportEntry *) obstack_alloc (&objfile->psymbol_obstack,
537                                    import_list_size * sizeof (ImportEntry));
538
539   /* Read in the import entries, a bunch at a time */
540   for (j = 0, k = 0;
541        j < (import_list_size / SOM_READ_IMPORTS_NUM);
542        j++)
543     {
544       bfd_get_section_contents (objfile->obfd, text_section, buffer,
545                               import_list + j * SOM_READ_IMPORTS_CHUNK_SIZE,
546                                 SOM_READ_IMPORTS_CHUNK_SIZE);
547       for (i = 0; i < SOM_READ_IMPORTS_NUM; i++, k++)
548         {
549           if (buffer[i].type != (unsigned char) 0)
550             {
551               objfile->import_list[k]
552                 = (char *) obstack_alloc (&objfile->psymbol_obstack, strlen (string_buffer + buffer[i].name) + 1);
553               strcpy (objfile->import_list[k], string_buffer + buffer[i].name);
554               /* Some day we might want to record the type and other information too */
555             }
556           else                  /* null type */
557             objfile->import_list[k] = NULL;
558
559         }
560     }
561
562   /* Get the leftovers */
563   if (k < import_list_size)
564     bfd_get_section_contents (objfile->obfd, text_section, buffer,
565                               import_list + k * sizeof (SomImportEntry),
566                           (import_list_size - k) * sizeof (SomImportEntry));
567   for (i = 0; k < import_list_size; i++, k++)
568     {
569       if (buffer[i].type != (unsigned char) 0)
570         {
571           objfile->import_list[k]
572             = (char *) obstack_alloc (&objfile->psymbol_obstack, strlen (string_buffer + buffer[i].name) + 1);
573           strcpy (objfile->import_list[k], string_buffer + buffer[i].name);
574           /* Some day we might want to record the type and other information too */
575         }
576       else
577         objfile->import_list[k] = NULL;
578     }
579
580   objfile->import_list_size = import_list_size;
581   xfree (string_buffer);
582   return import_list_size;
583 }
584
585 /* Read in and initialize the SOM export list which is present
586    for all executables and shared libraries.  The import list
587    consists of the symbols that are referenced in OBJFILE but
588    not defined there.  (Variables that are imported are dealt
589    with as "loc_indirect" vars.)
590    Return value = number of import symbols read in. */
591 int
592 init_export_symbols (struct objfile *objfile)
593 {
594   unsigned int export_list;
595   unsigned int export_list_size;
596   unsigned int string_table;
597   unsigned int string_table_size;
598   char *string_buffer;
599   register int i;
600   register int j;
601   register int k;
602   asection *text_section;       /* section handle */
603   unsigned int dl_header[12];   /* SOM executable header */
604
605   /* A struct for an entry in the SOM export list */
606   typedef struct
607     {
608       int next;                 /* for hash table use -- we don't use this */
609       int name;                 /* index into string table */
610       int value;                /* offset or plabel */
611       int dont_care1;           /* not used */
612       unsigned char type;       /* 0 = NULL, 2 = Data, 3 = Code, 7 = Storage, 13 = Plabel */
613       char dont_care2;          /* not used */
614       short dont_care3;         /* not used */
615     }
616   SomExportEntry;
617
618   /* We read 100 entries in at a time from the disk file. */
619 #define SOM_READ_EXPORTS_NUM         100
620 #define SOM_READ_EXPORTS_CHUNK_SIZE  (sizeof (SomExportEntry) * SOM_READ_EXPORTS_NUM)
621   SomExportEntry buffer[SOM_READ_EXPORTS_NUM];
622
623   /* Initialize in case we error out */
624   objfile->export_list = NULL;
625   objfile->export_list_size = 0;
626
627   /* It doesn't work, for some reason, to read in space $TEXT$;
628      the subspace $SHLIB_INFO$ has to be used.  Some BFD quirk? pai/1997-08-05 */
629   text_section = bfd_get_section_by_name (objfile->obfd, "$SHLIB_INFO$");
630   if (!text_section)
631     return 0;
632   /* Get the SOM executable header */
633   bfd_get_section_contents (objfile->obfd, text_section, dl_header, 0, 12 * sizeof (int));
634
635   /* Check header version number for 10.x HP-UX */
636   /* Currently we deal only with 10.x systems; on 9.x the version # is 89060912.
637      FIXME: Change for future HP-UX releases and mods to the SOM executable format */
638   if (dl_header[0] != 93092112)
639     return 0;
640
641   export_list = dl_header[8];
642   export_list_size = dl_header[9];
643   if (!export_list_size)
644     return 0;
645   string_table = dl_header[10];
646   string_table_size = dl_header[11];
647   if (!string_table_size)
648     return 0;
649
650   /* Suck in SOM string table */
651   string_buffer = (char *) xmalloc (string_table_size);
652   bfd_get_section_contents (objfile->obfd, text_section, string_buffer,
653                             string_table, string_table_size);
654
655   /* Allocate export list in the psymbol obstack; this has nothing
656      to do with psymbols, just a matter of convenience.  We want the
657      export list to be freed when the objfile is deallocated */
658   objfile->export_list
659     = (ExportEntry *) obstack_alloc (&objfile->psymbol_obstack,
660                                    export_list_size * sizeof (ExportEntry));
661
662   /* Read in the export entries, a bunch at a time */
663   for (j = 0, k = 0;
664        j < (export_list_size / SOM_READ_EXPORTS_NUM);
665        j++)
666     {
667       bfd_get_section_contents (objfile->obfd, text_section, buffer,
668                               export_list + j * SOM_READ_EXPORTS_CHUNK_SIZE,
669                                 SOM_READ_EXPORTS_CHUNK_SIZE);
670       for (i = 0; i < SOM_READ_EXPORTS_NUM; i++, k++)
671         {
672           if (buffer[i].type != (unsigned char) 0)
673             {
674               objfile->export_list[k].name
675                 = (char *) obstack_alloc (&objfile->psymbol_obstack, strlen (string_buffer + buffer[i].name) + 1);
676               strcpy (objfile->export_list[k].name, string_buffer + buffer[i].name);
677               objfile->export_list[k].address = buffer[i].value;
678               /* Some day we might want to record the type and other information too */
679             }
680           else
681             /* null type */
682             {
683               objfile->export_list[k].name = NULL;
684               objfile->export_list[k].address = 0;
685             }
686         }
687     }
688
689   /* Get the leftovers */
690   if (k < export_list_size)
691     bfd_get_section_contents (objfile->obfd, text_section, buffer,
692                               export_list + k * sizeof (SomExportEntry),
693                           (export_list_size - k) * sizeof (SomExportEntry));
694   for (i = 0; k < export_list_size; i++, k++)
695     {
696       if (buffer[i].type != (unsigned char) 0)
697         {
698           objfile->export_list[k].name
699             = (char *) obstack_alloc (&objfile->psymbol_obstack, strlen (string_buffer + buffer[i].name) + 1);
700           strcpy (objfile->export_list[k].name, string_buffer + buffer[i].name);
701           /* Some day we might want to record the type and other information too */
702           objfile->export_list[k].address = buffer[i].value;
703         }
704       else
705         {
706           objfile->export_list[k].name = NULL;
707           objfile->export_list[k].address = 0;
708         }
709     }
710
711   objfile->export_list_size = export_list_size;
712   xfree (string_buffer);
713   return export_list_size;
714 }
715 \f
716
717
718 /* Register that we are able to handle SOM object file formats.  */
719
720 static struct sym_fns som_sym_fns =
721 {
722   bfd_target_som_flavour,
723   som_new_init,                 /* sym_new_init: init anything gbl to entire symtab */
724   som_symfile_init,             /* sym_init: read initial info, setup for sym_read() */
725   som_symfile_read,             /* sym_read: read a symbol file into symtab */
726   som_symfile_finish,           /* sym_finish: finished with file, cleanup */
727   som_symfile_offsets,          /* sym_offsets:  Translate ext. to int. relocation */
728   NULL                          /* next: pointer to next struct sym_fns */
729 };
730
731 void
732 _initialize_somread (void)
733 {
734   add_symtab_fns (&som_sym_fns);
735 }
This page took 0.068212 seconds and 4 git commands to generate.