* ldmain.c (main): Use full sentences to ease translation.
[deliverable/binutils-gdb.git] / gprof / corefile.c
CommitLineData
ef368dac
NC
1/* corefile.c
2
0eee5820 3 Copyright 2000, 2001 Free Software Foundation, Inc.
ef368dac
NC
4
5 This file is part of GNU Binutils.
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, Boston, MA
20 02111-1307, USA. */
21\f
252b5132
RH
22#include "libiberty.h"
23#include "gprof.h"
24#include "corefile.h"
25#include "symtab.h"
26
27bfd *core_bfd;
28int core_num_syms;
29asymbol **core_syms;
30asection *core_text_sect;
31PTR core_text_space;
32
33int min_insn_size;
34int offset_to_code;
35
36/* For mapping symbols to specific .o files during file ordering. */
ef368dac
NC
37struct function_map
38{
252b5132
RH
39 char *function_name;
40 char *file_name;
41};
42
43struct function_map *symbol_map;
44unsigned int symbol_map_count;
45
ef368dac 46extern void i386_find_call PARAMS ((Sym *, bfd_vma, bfd_vma));
252b5132 47extern void alpha_find_call PARAMS ((Sym *, bfd_vma, bfd_vma));
ef368dac 48extern void vax_find_call PARAMS ((Sym *, bfd_vma, bfd_vma));
252b5132
RH
49extern void tahoe_find_call PARAMS ((Sym *, bfd_vma, bfd_vma));
50extern void sparc_find_call PARAMS ((Sym *, bfd_vma, bfd_vma));
51
52static void
53DEFUN (read_function_mappings, (filename), const char *filename)
54{
55 FILE *file = fopen (filename, "r");
56 char dummy[1024];
57 int count = 0;
58
59 if (!file)
60 {
61 fprintf (stderr, _("%s: could not open %s.\n"), whoami, filename);
62 done (1);
63 }
64
65 /* First parse the mapping file so we know how big we need to
66 make our tables. We also do some sanity checks at this
67 time. */
68 while (!feof (file))
69 {
70 int matches;
71
72 matches = fscanf (file, "%[^\n:]", dummy);
73 if (!matches)
74 {
75 fprintf (stderr, _("%s: unable to parse mapping file %s.\n"),
76 whoami, filename);
77 done (1);
78 }
79
80 /* Just skip messages about files with no symbols. */
81 if (!strncmp (dummy, "No symbols in ", 14))
82 {
83 fscanf (file, "\n");
84 continue;
85 }
86
87 /* Don't care what else is on this line at this point. */
88 fscanf (file, "%[^\n]\n", dummy);
89 count++;
90 }
91
92 /* Now we know how big we need to make our table. */
93 symbol_map = ((struct function_map *)
94 xmalloc (count * sizeof (struct function_map)));
95
96 /* Rewind the input file so we can read it again. */
97 rewind (file);
98
99 /* Read each entry and put it into the table. */
100 count = 0;
101 while (!feof (file))
102 {
103 int matches;
104 char *tmp;
105
106 matches = fscanf (file, "%[^\n:]", dummy);
107 if (!matches)
108 {
109 fprintf (stderr, _("%s: unable to parse mapping file %s.\n"),
110 whoami, filename);
111 done (1);
112 }
113
114 /* Just skip messages about files with no symbols. */
115 if (!strncmp (dummy, "No symbols in ", 14))
116 {
117 fscanf (file, "\n");
118 continue;
119 }
120
121 /* dummy has the filename, go ahead and copy it. */
122 symbol_map[count].file_name = xmalloc (strlen (dummy) + 1);
123 strcpy (symbol_map[count].file_name, dummy);
124
125 /* Now we need the function name. */
126 fscanf (file, "%[^\n]\n", dummy);
127 tmp = strrchr (dummy, ' ') + 1;
128 symbol_map[count].function_name = xmalloc (strlen (tmp) + 1);
129 strcpy (symbol_map[count].function_name, tmp);
130 count++;
131 }
132
133 /* Record the size of the map table for future reference. */
134 symbol_map_count = count;
135}
136
ef368dac 137
252b5132
RH
138void
139DEFUN (core_init, (a_out_name), const char *a_out_name)
140{
141 core_bfd = bfd_openr (a_out_name, 0);
142
143 if (!core_bfd)
144 {
145 perror (a_out_name);
146 done (1);
147 }
148
149 if (!bfd_check_format (core_bfd, bfd_object))
150 {
151 fprintf (stderr, _("%s: %s: not in a.out format\n"), whoami, a_out_name);
152 done (1);
153 }
154
ef368dac 155 /* Get core's text section. */
252b5132
RH
156 core_text_sect = bfd_get_section_by_name (core_bfd, ".text");
157 if (!core_text_sect)
158 {
159 core_text_sect = bfd_get_section_by_name (core_bfd, "$CODE$");
160 if (!core_text_sect)
161 {
162 fprintf (stderr, _("%s: can't find .text section in %s\n"),
163 whoami, a_out_name);
164 done (1);
165 }
166 }
167
ef368dac 168 /* Read core's symbol table. */
252b5132 169
ef368dac 170 /* This will probably give us more than we need, but that's ok. */
252b5132
RH
171 core_num_syms = bfd_get_symtab_upper_bound (core_bfd);
172 if (core_num_syms < 0)
173 {
174 fprintf (stderr, "%s: %s: %s\n", whoami, a_out_name,
175 bfd_errmsg (bfd_get_error ()));
176 done (1);
177 }
178
179 core_syms = (asymbol **) xmalloc (core_num_syms);
180 core_num_syms = bfd_canonicalize_symtab (core_bfd, core_syms);
0eee5820 181
252b5132
RH
182 if (core_num_syms < 0)
183 {
184 fprintf (stderr, "%s: %s: %s\n", whoami, a_out_name,
185 bfd_errmsg (bfd_get_error ()));
186 done (1);
187 }
188
189 min_insn_size = 1;
190 offset_to_code = 0;
191
192 switch (bfd_get_arch (core_bfd))
193 {
194 case bfd_arch_vax:
195 case bfd_arch_tahoe:
196 offset_to_code = 2;
197 break;
198
199 case bfd_arch_alpha:
200 min_insn_size = 4;
201 break;
202
203 default:
204 break;
205 }
206
207 if (function_mapping_file)
208 read_function_mappings (function_mapping_file);
209}
210
ef368dac 211/* Read in the text space of an a.out file. */
252b5132 212
252b5132
RH
213void
214DEFUN (core_get_text_space, (core_bfd), bfd * core_bfd)
215{
216 core_text_space = (PTR) malloc (core_text_sect->_raw_size);
217
218 if (!core_text_space)
219 {
fdcf7d43
ILT
220 fprintf (stderr, _("%s: ran out room for %lu bytes of text space\n"),
221 whoami, (unsigned long) core_text_sect->_raw_size);
252b5132
RH
222 done (1);
223 }
0eee5820 224
252b5132
RH
225 if (!bfd_get_section_contents (core_bfd, core_text_sect, core_text_space,
226 0, core_text_sect->_raw_size))
227 {
228 bfd_perror ("bfd_get_section_contents");
229 free (core_text_space);
230 core_text_space = 0;
231 }
0eee5820 232
252b5132 233 if (!core_text_space)
ef368dac 234 fprintf (stderr, _("%s: can't do -c\n"), whoami);
252b5132
RH
235}
236
237
238void
239DEFUN (find_call, (parent, p_lowpc, p_highpc),
240 Sym * parent AND bfd_vma p_lowpc AND bfd_vma p_highpc)
241{
242 switch (bfd_get_arch (core_bfd))
243 {
244 case bfd_arch_i386:
245 i386_find_call (parent, p_lowpc, p_highpc);
246 break;
247
248 case bfd_arch_alpha:
249 alpha_find_call (parent, p_lowpc, p_highpc);
250 break;
251
252 case bfd_arch_vax:
253 vax_find_call (parent, p_lowpc, p_highpc);
254 break;
255
256 case bfd_arch_sparc:
257 sparc_find_call (parent, p_lowpc, p_highpc);
258 break;
259
260 case bfd_arch_tahoe:
261 tahoe_find_call (parent, p_lowpc, p_highpc);
262 break;
263
264 default:
265 fprintf (stderr, _("%s: -c not supported on architecture %s\n"),
266 whoami, bfd_printable_name(core_bfd));
267
268 /* Don't give the error more than once. */
269 ignore_direct_calls = FALSE;
270 }
271}
272
ef368dac 273/* Return class of symbol SYM. The returned class can be any of:
0eee5820
AM
274 0 -> symbol is not interesting to us
275 'T' -> symbol is a global name
276 't' -> symbol is a local (static) name. */
ef368dac 277
252b5132
RH
278static int
279DEFUN (core_sym_class, (sym), asymbol * sym)
280{
281 symbol_info syminfo;
282 const char *name;
283 char sym_prefix;
284 int i;
285
286 if (sym->section == NULL || (sym->flags & BSF_DEBUGGING) != 0)
ef368dac 287 return 0;
252b5132 288
ef368dac
NC
289 /* Must be a text symbol, and static text symbols
290 don't qualify if ignore_static_funcs set. */
252b5132
RH
291 if (ignore_static_funcs && (sym->flags & BSF_LOCAL))
292 {
293 DBG (AOUTDEBUG, printf ("[core_sym_class] %s: not a function\n",
294 sym->name));
295 return 0;
296 }
297
298 bfd_get_symbol_info (core_bfd, sym, &syminfo);
299 i = syminfo.type;
300
301 if (i == 'T')
ef368dac 302 return i; /* It's a global symbol. */
252b5132
RH
303
304 if (i == 'W')
ef368dac
NC
305 /* Treat weak symbols as text symbols. FIXME: a weak symbol may
306 also be a data symbol. */
307 return 'T';
252b5132
RH
308
309 if (i != 't')
310 {
ef368dac 311 /* Not a static text symbol. */
252b5132
RH
312 DBG (AOUTDEBUG, printf ("[core_sym_class] %s is of class %c\n",
313 sym->name, i));
314 return 0;
315 }
316
ef368dac 317 /* Do some more filtering on static function-names. */
252b5132 318 if (ignore_static_funcs)
ef368dac
NC
319 return 0;
320
321 /* Can't zero-length name or funny characters in name, where
322 `funny' includes: `.' (.o file names) and `$' (Pascal labels). */
252b5132 323 if (!sym->name || sym->name[0] == '\0')
ef368dac 324 return 0;
252b5132
RH
325
326 for (name = sym->name; *name; ++name)
327 {
328 if (*name == '.' || *name == '$')
ef368dac
NC
329 return 0;
330 }
0eee5820 331
ef368dac
NC
332 /* On systems where the C compiler adds an underscore to all
333 names, static names without underscores seem usually to be
334 labels in hand written assembler in the library. We don't want
335 these names. This is certainly necessary on a Sparc running
336 SunOS 4.1 (try profiling a program that does a lot of
337 division). I don't know whether it has harmful side effects on
338 other systems. Perhaps it should be made configurable. */
252b5132 339 sym_prefix = bfd_get_symbol_leading_char (core_bfd);
0eee5820 340
252b5132 341 if ((sym_prefix && sym_prefix != sym->name[0])
ef368dac 342 /* GCC may add special symbols to help gdb figure out the file
0eee5820 343 language. We want to ignore these, since sometimes they mask
ef368dac 344 the real function. (dj@ctron) */
252b5132
RH
345 || !strncmp (sym->name, "__gnu_compiled", 14)
346 || !strncmp (sym->name, "___gnu_compiled", 15))
347 {
348 return 0;
349 }
350
ef368dac
NC
351 /* If the object file supports marking of function symbols, then
352 we can zap anything that doesn't have BSF_FUNCTION set. */
252b5132
RH
353 if (ignore_non_functions && (sym->flags & BSF_FUNCTION) == 0)
354 return 0;
355
ef368dac 356 return 't'; /* It's a static text symbol. */
252b5132
RH
357}
358
ef368dac 359/* Get whatever source info we can get regarding address ADDR. */
252b5132 360
252b5132
RH
361static bool
362DEFUN (get_src_info, (addr, filename, name, line_num),
363 bfd_vma addr AND const char **filename AND const char **name
364 AND int *line_num)
365{
366 const char *fname = 0, *func_name = 0;
367 int l = 0;
368
369 if (bfd_find_nearest_line (core_bfd, core_text_sect, core_syms,
370 addr - core_text_sect->vma,
371 &fname, &func_name, (unsigned int *) &l)
372 && fname && func_name && l)
373 {
374 DBG (AOUTDEBUG, printf ("[get_src_info] 0x%lx -> %s:%d (%s)\n",
fdcf7d43 375 (unsigned long) addr, fname, l, func_name));
252b5132
RH
376 *filename = fname;
377 *name = func_name;
378 *line_num = l;
379 return TRUE;
380 }
381 else
382 {
383 DBG (AOUTDEBUG, printf ("[get_src_info] no info for 0x%lx (%s:%d,%s)\n",
384 (long) addr, fname ? fname : "<unknown>", l,
385 func_name ? func_name : "<unknown>"));
386 return FALSE;
387 }
388}
389
ef368dac
NC
390/* Read in symbol table from core.
391 One symbol per function is entered. */
252b5132 392
252b5132 393void
8622e41b
ILT
394core_create_function_syms (core_bfd)
395 bfd *core_bfd ATTRIBUTE_UNUSED;
252b5132
RH
396{
397 bfd_vma min_vma = ~0, max_vma = 0;
398 int class;
399 long i, found, skip;
400 unsigned int j;
401
ef368dac 402 /* Pass 1 - determine upper bound on number of function names. */
252b5132 403 symtab.len = 0;
0eee5820 404
252b5132
RH
405 for (i = 0; i < core_num_syms; ++i)
406 {
407 if (!core_sym_class (core_syms[i]))
ef368dac 408 continue;
252b5132
RH
409
410 /* This should be replaced with a binary search or hashed
0eee5820 411 search. Gross.
252b5132
RH
412
413 Don't create a symtab entry for a function that has
414 a mapping to a file, unless it's the first function
415 in the file. */
416 skip = 0;
417 for (j = 0; j < symbol_map_count; j++)
418 if (!strcmp (core_syms[i]->name, symbol_map[j].function_name))
419 {
420 if (j > 0 && ! strcmp (symbol_map [j].file_name,
0eee5820 421 symbol_map [j - 1].file_name))
252b5132
RH
422 skip = 1;
423 break;
424 }
0eee5820 425
252b5132 426 if (!skip)
0eee5820 427 ++symtab.len;
252b5132
RH
428 }
429
430 if (symtab.len == 0)
431 {
432 fprintf (stderr, _("%s: file `%s' has no symbols\n"), whoami, a_out_name);
433 done (1);
434 }
435
ef368dac 436 /* The "+ 2" is for the sentinels. */
252b5132
RH
437 symtab.base = (Sym *) xmalloc ((symtab.len + 2) * sizeof (Sym));
438
ef368dac 439 /* Pass 2 - create symbols. */
252b5132 440 symtab.limit = symtab.base;
0eee5820 441
252b5132
RH
442 for (i = 0; i < core_num_syms; ++i)
443 {
444 class = core_sym_class (core_syms[i]);
0eee5820 445
252b5132
RH
446 if (!class)
447 {
448 DBG (AOUTDEBUG,
449 printf ("[core_create_function_syms] rejecting: 0x%lx %s\n",
fdcf7d43
ILT
450 (unsigned long) core_syms[i]->value,
451 core_syms[i]->name));
252b5132
RH
452 continue;
453 }
0eee5820 454
252b5132
RH
455 /* This should be replaced with a binary search or hashed
456 search. Gross. */
252b5132
RH
457 skip = 0;
458 found = 0;
0eee5820 459
252b5132
RH
460 for (j = 0; j < symbol_map_count; j++)
461 if (!strcmp (core_syms[i]->name, symbol_map[j].function_name))
462 {
463 if (j > 0 && ! strcmp (symbol_map [j].file_name,
0eee5820 464 symbol_map [j - 1].file_name))
252b5132
RH
465 skip = 1;
466 else
467 found = j;
468 break;
469 }
470
471 if (skip)
472 continue;
473
474 sym_init (symtab.limit);
475
ef368dac 476 /* Symbol offsets are always section-relative. */
252b5132 477 symtab.limit->addr = core_syms[i]->value + core_syms[i]->section->vma;
0eee5820 478
252b5132
RH
479 if (symbol_map_count
480 && !strcmp (core_syms[i]->name, symbol_map[found].function_name))
481 {
482 symtab.limit->name = symbol_map[found].file_name;
483 symtab.limit->mapped = 1;
484 }
485 else
486 {
487 symtab.limit->name = core_syms[i]->name;
488 symtab.limit->mapped = 0;
489 }
490
ef368dac 491 /* Lookup filename and line number, if we can. */
252b5132
RH
492 {
493 const char *filename, *func_name;
0eee5820 494
252b5132
RH
495 if (get_src_info (symtab.limit->addr, &filename, &func_name,
496 &symtab.limit->line_num))
497 {
498 symtab.limit->file = source_file_lookup_path (filename);
499
500 /* FIXME: Checking __osf__ here does not work with a cross
0eee5820 501 gprof. */
252b5132 502#ifdef __osf__
ef368dac
NC
503 /* Suppress symbols that are not function names. This is
504 useful to suppress code-labels and aliases.
0eee5820 505
ef368dac
NC
506 This is known to be useful under DEC's OSF/1. Under SunOS 4.x,
507 labels do not appear in the symbol table info, so this isn't
508 necessary. */
252b5132
RH
509
510 if (strcmp (symtab.limit->name, func_name) != 0)
511 {
ef368dac
NC
512 /* The symbol's address maps to a different name, so
513 it can't be a function-entry point. This happens
514 for labels, for example. */
252b5132
RH
515 DBG (AOUTDEBUG,
516 printf ("[core_create_function_syms: rej %s (maps to %s)\n",
517 symtab.limit->name, func_name));
518 continue;
519 }
520#endif
521 }
522 }
523
524 symtab.limit->is_func = TRUE;
525 symtab.limit->is_bb_head = TRUE;
0eee5820 526
252b5132 527 if (class == 't')
ef368dac 528 symtab.limit->is_static = TRUE;
252b5132
RH
529
530 min_vma = MIN (symtab.limit->addr, min_vma);
531 max_vma = MAX (symtab.limit->addr, max_vma);
532
ef368dac 533 /* If we see "main" without an initial '_', we assume names
0eee5820 534 are *not* prefixed by '_'. */
252b5132
RH
535 if (symtab.limit->name[0] == 'm' && discard_underscores
536 && strcmp (symtab.limit->name, "main") == 0)
ef368dac 537 discard_underscores = 0;
252b5132
RH
538
539 DBG (AOUTDEBUG, printf ("[core_create_function_syms] %ld %s 0x%lx\n",
540 (long) (symtab.limit - symtab.base),
fdcf7d43
ILT
541 symtab.limit->name,
542 (unsigned long) symtab.limit->addr));
252b5132
RH
543 ++symtab.limit;
544 }
545
ef368dac 546 /* Create sentinels. */
252b5132
RH
547 sym_init (symtab.limit);
548 symtab.limit->name = "<locore>";
549 symtab.limit->addr = 0;
550 symtab.limit->end_addr = min_vma - 1;
551 ++symtab.limit;
552
553 sym_init (symtab.limit);
554 symtab.limit->name = "<hicore>";
555 symtab.limit->addr = max_vma + 1;
556 symtab.limit->end_addr = ~0;
557 ++symtab.limit;
558
559 symtab.len = symtab.limit - symtab.base;
560 symtab_finalize (&symtab);
561}
562
ef368dac
NC
563/* Read in symbol table from core.
564 One symbol per line of source code is entered. */
252b5132 565
252b5132
RH
566void
567DEFUN (core_create_line_syms, (core_bfd), bfd * core_bfd)
568{
569 char *prev_name, *prev_filename;
570 int prev_name_len, prev_filename_len;
571 bfd_vma vma, min_vma = ~0, max_vma = 0;
572 bfd_vma offset;
573 Sym *prev, dummy, *sentinel, *sym;
574 const char *filename;
575 int prev_line_num;
576 Sym_Table ltab;
0eee5820 577
ef368dac
NC
578 /* Create symbols for functions as usual. This is necessary in
579 cases where parts of a program were not compiled with -g. For
580 those parts we still want to get info at the function level. */
252b5132
RH
581 core_create_function_syms (core_bfd);
582
ef368dac
NC
583 /* Pass 1 - counter number of symbols. */
584
585 /* To find all line information, walk through all possible
586 text-space addresses (one by one!) and get the debugging
587 info for each address. When the debugging info changes,
588 it is time to create a new symbol.
0eee5820 589
ef368dac
NC
590 Of course, this is rather slow and it would be better if
591 bfd would provide an iterator for enumerating all line infos. */
252b5132
RH
592 prev_name_len = PATH_MAX;
593 prev_filename_len = PATH_MAX;
594 prev_name = xmalloc (prev_name_len);
595 prev_filename = xmalloc (prev_filename_len);
596 ltab.len = 0;
597 prev_line_num = 0;
0eee5820 598
252b5132
RH
599 for (offset = 0; offset < core_text_sect->_raw_size; offset += min_insn_size)
600 {
601 int len;
602
603 vma = core_text_sect->vma + offset;
0eee5820 604
252b5132
RH
605 if (!get_src_info (vma, &filename, &dummy.name, &dummy.line_num)
606 || (prev_line_num == dummy.line_num
607 && prev_name != NULL
608 && strcmp (prev_name, dummy.name) == 0
609 && strcmp (prev_filename, filename) == 0))
ef368dac 610 continue;
252b5132
RH
611
612 ++ltab.len;
613 prev_line_num = dummy.line_num;
614
615 len = strlen (dummy.name);
616 if (len >= prev_name_len)
617 {
618 prev_name_len = len + 1024;
619 free (prev_name);
620 prev_name = xmalloc (prev_name_len);
621 }
0eee5820 622
252b5132 623 strcpy (prev_name, dummy.name);
252b5132 624 len = strlen (filename);
0eee5820 625
252b5132
RH
626 if (len >= prev_filename_len)
627 {
628 prev_filename_len = len + 1024;
629 free (prev_filename);
630 prev_filename = xmalloc (prev_filename_len);
631 }
0eee5820 632
252b5132
RH
633 strcpy (prev_filename, filename);
634
635 min_vma = MIN (vma, min_vma);
636 max_vma = MAX (vma, max_vma);
637 }
638
639 free (prev_name);
640 free (prev_filename);
641
ef368dac 642 /* Make room for function symbols, too. */
252b5132
RH
643 ltab.len += symtab.len;
644 ltab.base = (Sym *) xmalloc (ltab.len * sizeof (Sym));
645 ltab.limit = ltab.base;
646
ef368dac 647 /* Pass 2 - create symbols. */
252b5132
RH
648
649 /* We now set is_static as we go along, rather than by running
650 through the symbol table at the end.
651
652 The old way called symtab_finalize before the is_static pass,
653 causing a problem since symtab_finalize uses is_static as part of
654 its address conflict resolution algorithm. Since global symbols
655 were prefered over static symbols, and all line symbols were
656 global at that point, static function names that conflicted with
657 their own line numbers (static, but labeled as global) were
658 rejected in favor of the line num.
659
660 This was not the desired functionality. We always want to keep
661 our function symbols and discard any conflicting line symbols.
662 Perhaps symtab_finalize should be modified to make this
663 distinction as well, but the current fix works and the code is a
664 lot cleaner now. */
252b5132 665 prev = 0;
0eee5820 666
252b5132
RH
667 for (offset = 0; offset < core_text_sect->_raw_size; offset += min_insn_size)
668 {
669 sym_init (ltab.limit);
0eee5820 670
252b5132
RH
671 if (!get_src_info (core_text_sect->vma + offset, &filename,
672 &ltab.limit->name, &ltab.limit->line_num)
673 || (prev && prev->line_num == ltab.limit->line_num
674 && strcmp (prev->name, ltab.limit->name) == 0
675 && strcmp (prev->file->name, filename) == 0))
ef368dac 676 continue;
252b5132 677
ef368dac 678 /* Make name pointer a malloc'ed string. */
252b5132
RH
679 ltab.limit->name = xstrdup (ltab.limit->name);
680 ltab.limit->file = source_file_lookup_path (filename);
681
682 ltab.limit->addr = core_text_sect->vma + offset;
683
684 /* Set is_static based on the enclosing function, using either:
0eee5820
AM
685 1) the previous symbol, if it's from the same function, or
686 2) a symtab lookup. */
252b5132
RH
687 if (prev && ltab.limit->file == prev->file &&
688 strcmp (ltab.limit->name, prev->name) == 0)
689 {
690 ltab.limit->is_static = prev->is_static;
691 }
692 else
693 {
694 sym = sym_lookup(&symtab, ltab.limit->addr);
695 ltab.limit->is_static = sym->is_static;
696 }
697
698 prev = ltab.limit;
699
ef368dac 700 /* If we see "main" without an initial '_', we assume names
0eee5820 701 are *not* prefixed by '_'. */
252b5132
RH
702 if (ltab.limit->name[0] == 'm' && discard_underscores
703 && strcmp (ltab.limit->name, "main") == 0)
ef368dac 704 discard_underscores = 0;
252b5132 705
4a607dcc
ILT
706 DBG (AOUTDEBUG, printf ("[core_create_line_syms] %lu %s 0x%lx\n",
707 (unsigned long) (ltab.limit - ltab.base),
708 ltab.limit->name,
fdcf7d43 709 (unsigned long) ltab.limit->addr));
252b5132
RH
710 ++ltab.limit;
711 }
712
ef368dac 713 /* Update sentinels. */
252b5132 714 sentinel = sym_lookup (&symtab, 0);
0eee5820 715
252b5132
RH
716 if (strcmp (sentinel->name, "<locore>") == 0
717 && min_vma <= sentinel->end_addr)
ef368dac 718 sentinel->end_addr = min_vma - 1;
252b5132
RH
719
720 sentinel = sym_lookup (&symtab, ~0);
0eee5820 721
252b5132 722 if (strcmp (sentinel->name, "<hicore>") == 0 && max_vma >= sentinel->addr)
ef368dac 723 sentinel->addr = max_vma + 1;
252b5132 724
ef368dac 725 /* Copy in function symbols. */
252b5132
RH
726 memcpy (ltab.limit, symtab.base, symtab.len * sizeof (Sym));
727 ltab.limit += symtab.len;
728
729 if ((unsigned int) (ltab.limit - ltab.base) != ltab.len)
730 {
731 fprintf (stderr,
732 _("%s: somebody miscounted: ltab.len=%d instead of %ld\n"),
733 whoami, ltab.len, (long) (ltab.limit - ltab.base));
734 done (1);
735 }
736
ef368dac 737 /* Finalize ltab and make it symbol table. */
252b5132
RH
738 symtab_finalize (&ltab);
739 free (symtab.base);
740 symtab = ltab;
252b5132 741}
This page took 0.124466 seconds and 4 git commands to generate.