560eb887c84c56f413357f71d4f90a81fd16299a
[deliverable/binutils-gdb.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 2004 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, "L0\001", 3) == 0)
223 || (strncmp (symname, "$PIC", 4) == 0))
224 continue;
225 break;
226
227 case ST_PRI_PROG:
228 case ST_SEC_PROG:
229 case ST_MILLICODE:
230 symname = bufp->name.n_strx + stringtab;
231 ms_type = mst_file_text;
232 bufp->symbol_value += text_offset;
233 bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
234 break;
235
236 case ST_ENTRY:
237 symname = bufp->name.n_strx + stringtab;
238 /* SS_LOCAL symbols in a shared library do not have
239 export stubs, so we do not have to worry about
240 using mst_file_text vs mst_solib_trampoline here like
241 we do for SS_UNIVERSAL and SS_EXTERNAL symbols above. */
242 ms_type = mst_file_text;
243 bufp->symbol_value += text_offset;
244 bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
245 break;
246
247 case ST_STUB:
248 symname = bufp->name.n_strx + stringtab;
249 ms_type = mst_solib_trampoline;
250 bufp->symbol_value += text_offset;
251 bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
252 break;
253
254
255 case ST_DATA:
256 symname = bufp->name.n_strx + stringtab;
257 bufp->symbol_value += data_offset;
258 ms_type = mst_file_data;
259 goto check_strange_names;
260
261 default:
262 continue;
263 }
264 break;
265
266 /* This can happen for common symbols when -E is passed to the
267 final link. No idea _why_ that would make the linker force
268 common symbols to have an SS_UNSAT scope, but it does.
269
270 This also happens for weak symbols, but their type is
271 ST_DATA. */
272 case SS_UNSAT:
273 switch (bufp->symbol_type)
274 {
275 case ST_STORAGE:
276 case ST_DATA:
277 symname = bufp->name.n_strx + stringtab;
278 bufp->symbol_value += data_offset;
279 ms_type = mst_data;
280 break;
281
282 default:
283 continue;
284 }
285 break;
286
287 default:
288 continue;
289 }
290
291 if (bufp->name.n_strx > obj_som_stringtab_size (abfd))
292 error ("Invalid symbol data; bad HP string table offset: %d",
293 bufp->name.n_strx);
294
295 prim_record_minimal_symbol (symname, bufp->symbol_value, ms_type,
296 objfile);
297 }
298 }
299
300 /* Scan and build partial symbols for a symbol file.
301 We have been initialized by a call to som_symfile_init, which
302 currently does nothing.
303
304 SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
305 in each section. This is ignored, as it isn't needed for SOM.
306
307 MAINLINE is true if we are reading the main symbol
308 table (as opposed to a shared lib or dynamically loaded file).
309
310 This function only does the minimum work necessary for letting the
311 user "name" things symbolically; it does not read the entire symtab.
312 Instead, it reads the external and static symbols and puts them in partial
313 symbol tables. When more extensive information is requested of a
314 file, the corresponding partial symbol table is mutated into a full
315 fledged symbol table by going back and reading the symbols
316 for real.
317
318 We look for sections with specific names, to tell us what debug
319 format to look for: FIXME!!!
320
321 somstab_build_psymtabs() handles STABS symbols.
322
323 Note that SOM files have a "minimal" symbol table, which is vaguely
324 reminiscent of a COFF symbol table, but has only the minimal information
325 necessary for linking. We process this also, and use the information to
326 build gdb's minimal symbol table. This gives us some minimal debugging
327 capability even for files compiled without -g. */
328
329 static void
330 som_symfile_read (struct objfile *objfile, int mainline)
331 {
332 bfd *abfd = objfile->obfd;
333 struct cleanup *back_to;
334
335 do_pxdb (symfile_bfd_open (objfile->name));
336
337 init_minimal_symbol_collection ();
338 back_to = make_cleanup_discard_minimal_symbols ();
339
340 /* Read in the import list and the export list. Currently
341 the export list isn't used; the import list is used in
342 hp-symtab-read.c to handle static vars declared in other
343 shared libraries. */
344 init_import_symbols (objfile);
345 #if 0 /* Export symbols not used today 1997-08-05 */
346 init_export_symbols (objfile);
347 #else
348 objfile->export_list = NULL;
349 objfile->export_list_size = 0;
350 #endif
351
352 /* Process the normal SOM symbol table first.
353 This reads in the DNTT and string table, but doesn't
354 actually scan the DNTT. It does scan the linker symbol
355 table and thus build up a "minimal symbol table". */
356
357 som_symtab_read (abfd, objfile, objfile->section_offsets);
358
359 /* Install any minimal symbols that have been collected as the current
360 minimal symbols for this objfile.
361 Further symbol-reading is done incrementally, file-by-file,
362 in a step known as "psymtab-to-symtab" expansion. hp-symtab-read.c
363 contains the code to do the actual DNTT scanning and symtab building. */
364 install_minimal_symbols (objfile);
365 do_cleanups (back_to);
366
367 /* Now read information from the stabs debug sections.
368 This is a no-op for SOM.
369 Perhaps it is intended for some kind of mixed STABS/SOM
370 situation? */
371 stabsect_build_psymtabs (objfile, mainline,
372 "$GDB_SYMBOLS$", "$GDB_STRINGS$", "$TEXT$");
373
374 /* Now read the native debug information.
375 This builds the psymtab. This used to be done via a scan of
376 the DNTT, but is now done via the PXDB-built quick-lookup tables
377 together with a scan of the GNTT. See hp-psymtab-read.c. */
378 hpread_build_psymtabs (objfile, mainline);
379
380 /* Force hppa-tdep.c to re-read the unwind descriptors. */
381 objfile->obj_private = NULL;
382 }
383
384 /* Initialize anything that needs initializing when a completely new symbol
385 file is specified (not just adding some symbols from another file, e.g. a
386 shared library).
387
388 We reinitialize buildsym, since we may be reading stabs from a SOM file. */
389
390 static void
391 som_new_init (struct objfile *ignore)
392 {
393 stabsread_new_init ();
394 buildsym_new_init ();
395 }
396
397 /* Perform any local cleanups required when we are done with a particular
398 objfile. I.E, we are in the process of discarding all symbol information
399 for an objfile, freeing up all memory held for it, and unlinking the
400 objfile struct from the global list of known objfiles. */
401
402 static void
403 som_symfile_finish (struct objfile *objfile)
404 {
405 if (objfile->sym_stab_info != NULL)
406 {
407 xfree (objfile->sym_stab_info);
408 }
409 hpread_symfile_finish (objfile);
410 }
411
412 /* SOM specific initialization routine for reading symbols. */
413
414 static void
415 som_symfile_init (struct objfile *objfile)
416 {
417 /* SOM objects may be reordered, so set OBJF_REORDERED. If we
418 find this causes a significant slowdown in gdb then we could
419 set it in the debug symbol readers only when necessary. */
420 objfile->flags |= OBJF_REORDERED;
421 hpread_symfile_init (objfile);
422 }
423
424 /* SOM specific parsing routine for section offsets.
425
426 Plain and simple for now. */
427
428 static void
429 som_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
430 {
431 int i;
432 CORE_ADDR text_addr;
433
434 objfile->num_sections = bfd_count_sections (objfile->obfd);
435 objfile->section_offsets = (struct section_offsets *)
436 obstack_alloc (&objfile->objfile_obstack,
437 SIZEOF_N_SECTION_OFFSETS (objfile->num_sections));
438
439 /* FIXME: ezannoni 2000-04-20 The section names in SOM are not
440 .text, .data, etc, but $TEXT$, $DATA$,... We should initialize
441 SET_OFF_* from bfd. (See default_symfile_offsets()). But I don't
442 know the correspondence between SOM sections and GDB's idea of
443 section names. So for now we default to what is was before these
444 changes.*/
445 objfile->sect_index_text = 0;
446 objfile->sect_index_data = 1;
447 objfile->sect_index_bss = 2;
448 objfile->sect_index_rodata = 3;
449
450 /* First see if we're a shared library. If so, get the section
451 offsets from the library, else get them from addrs. */
452 if (!som_solib_section_offsets (objfile, objfile->section_offsets))
453 {
454 /* Note: Here is OK to compare with ".text" because this is the
455 name that gdb itself gives to that section, not the SOM
456 name. */
457 for (i = 0; i < objfile->num_sections && addrs->other[i].name; i++)
458 if (strcmp (addrs->other[i].name, ".text") == 0)
459 break;
460 text_addr = addrs->other[i].addr;
461
462 for (i = 0; i < objfile->num_sections; i++)
463 (objfile->section_offsets)->offsets[i] = text_addr;
464 }
465 }
466
467 /* Read in and initialize the SOM import list which is present
468 for all executables and shared libraries. The import list
469 consists of the symbols that are referenced in OBJFILE but
470 not defined there. (Variables that are imported are dealt
471 with as "loc_indirect" vars.)
472 Return value = number of import symbols read in. */
473 static int
474 init_import_symbols (struct objfile *objfile)
475 {
476 unsigned int import_list;
477 unsigned int import_list_size;
478 unsigned int string_table;
479 unsigned int string_table_size;
480 char *string_buffer;
481 int i;
482 int j;
483 int k;
484 asection *text_section; /* section handle */
485 unsigned int dl_header[12]; /* SOM executable header */
486
487 /* A struct for an entry in the SOM import list */
488 typedef struct
489 {
490 int name; /* index into the string table */
491 short dont_care1; /* we don't use this */
492 unsigned char type; /* 0 = NULL, 2 = Data, 3 = Code, 7 = Storage, 13 = Plabel */
493 unsigned int reserved2:8; /* not used */
494 }
495 SomImportEntry;
496
497 /* We read 100 entries in at a time from the disk file. */
498 #define SOM_READ_IMPORTS_NUM 100
499 #define SOM_READ_IMPORTS_CHUNK_SIZE (sizeof (SomImportEntry) * SOM_READ_IMPORTS_NUM)
500 SomImportEntry buffer[SOM_READ_IMPORTS_NUM];
501
502 /* Initialize in case we error out */
503 objfile->import_list = NULL;
504 objfile->import_list_size = 0;
505
506 /* It doesn't work, for some reason, to read in space $TEXT$;
507 the subspace $SHLIB_INFO$ has to be used. Some BFD quirk? pai/1997-08-05 */
508 text_section = bfd_get_section_by_name (objfile->obfd, "$SHLIB_INFO$");
509 if (!text_section)
510 return 0;
511 /* Get the SOM executable header */
512 bfd_get_section_contents (objfile->obfd, text_section, dl_header, 0, 12 * sizeof (int));
513
514 /* Check header version number for 10.x HP-UX */
515 /* Currently we deal only with 10.x systems; on 9.x the version # is 89060912.
516 FIXME: Change for future HP-UX releases and mods to the SOM executable format */
517 if (dl_header[0] != 93092112)
518 return 0;
519
520 import_list = dl_header[4];
521 import_list_size = dl_header[5];
522 if (!import_list_size)
523 return 0;
524 string_table = dl_header[10];
525 string_table_size = dl_header[11];
526 if (!string_table_size)
527 return 0;
528
529 /* Suck in SOM string table */
530 string_buffer = (char *) xmalloc (string_table_size);
531 bfd_get_section_contents (objfile->obfd, text_section, string_buffer,
532 string_table, string_table_size);
533
534 /* Allocate import list in the psymbol obstack; this has nothing
535 to do with psymbols, just a matter of convenience. We want the
536 import list to be freed when the objfile is deallocated */
537 objfile->import_list
538 = (ImportEntry *) obstack_alloc (&objfile->objfile_obstack,
539 import_list_size * sizeof (ImportEntry));
540
541 /* Read in the import entries, a bunch at a time */
542 for (j = 0, k = 0;
543 j < (import_list_size / SOM_READ_IMPORTS_NUM);
544 j++)
545 {
546 bfd_get_section_contents (objfile->obfd, text_section, buffer,
547 import_list + j * SOM_READ_IMPORTS_CHUNK_SIZE,
548 SOM_READ_IMPORTS_CHUNK_SIZE);
549 for (i = 0; i < SOM_READ_IMPORTS_NUM; i++, k++)
550 {
551 if (buffer[i].type != (unsigned char) 0)
552 {
553 objfile->import_list[k]
554 = (char *) obstack_alloc (&objfile->objfile_obstack, strlen (string_buffer + buffer[i].name) + 1);
555 strcpy (objfile->import_list[k], string_buffer + buffer[i].name);
556 /* Some day we might want to record the type and other information too */
557 }
558 else /* null type */
559 objfile->import_list[k] = NULL;
560
561 }
562 }
563
564 /* Get the leftovers */
565 if (k < import_list_size)
566 bfd_get_section_contents (objfile->obfd, text_section, buffer,
567 import_list + k * sizeof (SomImportEntry),
568 (import_list_size - k) * sizeof (SomImportEntry));
569 for (i = 0; k < import_list_size; i++, k++)
570 {
571 if (buffer[i].type != (unsigned char) 0)
572 {
573 objfile->import_list[k]
574 = (char *) obstack_alloc (&objfile->objfile_obstack, strlen (string_buffer + buffer[i].name) + 1);
575 strcpy (objfile->import_list[k], string_buffer + buffer[i].name);
576 /* Some day we might want to record the type and other information too */
577 }
578 else
579 objfile->import_list[k] = NULL;
580 }
581
582 objfile->import_list_size = import_list_size;
583 xfree (string_buffer);
584 return import_list_size;
585 }
586
587 /* Read in and initialize the SOM export list which is present
588 for all executables and shared libraries. The import list
589 consists of the symbols that are referenced in OBJFILE but
590 not defined there. (Variables that are imported are dealt
591 with as "loc_indirect" vars.)
592 Return value = number of import symbols read in. */
593 int
594 init_export_symbols (struct objfile *objfile)
595 {
596 unsigned int export_list;
597 unsigned int export_list_size;
598 unsigned int string_table;
599 unsigned int string_table_size;
600 char *string_buffer;
601 int i;
602 int j;
603 int k;
604 asection *text_section; /* section handle */
605 unsigned int dl_header[12]; /* SOM executable header */
606
607 /* A struct for an entry in the SOM export list */
608 typedef struct
609 {
610 int next; /* for hash table use -- we don't use this */
611 int name; /* index into string table */
612 int value; /* offset or plabel */
613 int dont_care1; /* not used */
614 unsigned char type; /* 0 = NULL, 2 = Data, 3 = Code, 7 = Storage, 13 = Plabel */
615 char dont_care2; /* not used */
616 short dont_care3; /* not used */
617 }
618 SomExportEntry;
619
620 /* We read 100 entries in at a time from the disk file. */
621 #define SOM_READ_EXPORTS_NUM 100
622 #define SOM_READ_EXPORTS_CHUNK_SIZE (sizeof (SomExportEntry) * SOM_READ_EXPORTS_NUM)
623 SomExportEntry buffer[SOM_READ_EXPORTS_NUM];
624
625 /* Initialize in case we error out */
626 objfile->export_list = NULL;
627 objfile->export_list_size = 0;
628
629 /* It doesn't work, for some reason, to read in space $TEXT$;
630 the subspace $SHLIB_INFO$ has to be used. Some BFD quirk? pai/1997-08-05 */
631 text_section = bfd_get_section_by_name (objfile->obfd, "$SHLIB_INFO$");
632 if (!text_section)
633 return 0;
634 /* Get the SOM executable header */
635 bfd_get_section_contents (objfile->obfd, text_section, dl_header, 0, 12 * sizeof (int));
636
637 /* Check header version number for 10.x HP-UX */
638 /* Currently we deal only with 10.x systems; on 9.x the version # is 89060912.
639 FIXME: Change for future HP-UX releases and mods to the SOM executable format */
640 if (dl_header[0] != 93092112)
641 return 0;
642
643 export_list = dl_header[8];
644 export_list_size = dl_header[9];
645 if (!export_list_size)
646 return 0;
647 string_table = dl_header[10];
648 string_table_size = dl_header[11];
649 if (!string_table_size)
650 return 0;
651
652 /* Suck in SOM string table */
653 string_buffer = (char *) xmalloc (string_table_size);
654 bfd_get_section_contents (objfile->obfd, text_section, string_buffer,
655 string_table, string_table_size);
656
657 /* Allocate export list in the psymbol obstack; this has nothing
658 to do with psymbols, just a matter of convenience. We want the
659 export list to be freed when the objfile is deallocated */
660 objfile->export_list
661 = (ExportEntry *) obstack_alloc (&objfile->objfile_obstack,
662 export_list_size * sizeof (ExportEntry));
663
664 /* Read in the export entries, a bunch at a time */
665 for (j = 0, k = 0;
666 j < (export_list_size / SOM_READ_EXPORTS_NUM);
667 j++)
668 {
669 bfd_get_section_contents (objfile->obfd, text_section, buffer,
670 export_list + j * SOM_READ_EXPORTS_CHUNK_SIZE,
671 SOM_READ_EXPORTS_CHUNK_SIZE);
672 for (i = 0; i < SOM_READ_EXPORTS_NUM; i++, k++)
673 {
674 if (buffer[i].type != (unsigned char) 0)
675 {
676 objfile->export_list[k].name
677 = (char *) obstack_alloc (&objfile->objfile_obstack, strlen (string_buffer + buffer[i].name) + 1);
678 strcpy (objfile->export_list[k].name, string_buffer + buffer[i].name);
679 objfile->export_list[k].address = buffer[i].value;
680 /* Some day we might want to record the type and other information too */
681 }
682 else
683 /* null type */
684 {
685 objfile->export_list[k].name = NULL;
686 objfile->export_list[k].address = 0;
687 }
688 }
689 }
690
691 /* Get the leftovers */
692 if (k < export_list_size)
693 bfd_get_section_contents (objfile->obfd, text_section, buffer,
694 export_list + k * sizeof (SomExportEntry),
695 (export_list_size - k) * sizeof (SomExportEntry));
696 for (i = 0; k < export_list_size; i++, k++)
697 {
698 if (buffer[i].type != (unsigned char) 0)
699 {
700 objfile->export_list[k].name
701 = (char *) obstack_alloc (&objfile->objfile_obstack, strlen (string_buffer + buffer[i].name) + 1);
702 strcpy (objfile->export_list[k].name, string_buffer + buffer[i].name);
703 /* Some day we might want to record the type and other information too */
704 objfile->export_list[k].address = buffer[i].value;
705 }
706 else
707 {
708 objfile->export_list[k].name = NULL;
709 objfile->export_list[k].address = 0;
710 }
711 }
712
713 objfile->export_list_size = export_list_size;
714 xfree (string_buffer);
715 return export_list_size;
716 }
717 \f
718
719
720 /* Register that we are able to handle SOM object file formats. */
721
722 static struct sym_fns som_sym_fns =
723 {
724 bfd_target_som_flavour,
725 som_new_init, /* sym_new_init: init anything gbl to entire symtab */
726 som_symfile_init, /* sym_init: read initial info, setup for sym_read() */
727 som_symfile_read, /* sym_read: read a symbol file into symtab */
728 som_symfile_finish, /* sym_finish: finished with file, cleanup */
729 som_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */
730 NULL /* next: pointer to next struct sym_fns */
731 };
732
733 void
734 _initialize_somread (void)
735 {
736 add_symtab_fns (&som_sym_fns);
737 }
This page took 0.055184 seconds and 3 git commands to generate.