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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [symmisc.c] - Blame information for rev 1775

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 markom
/* Do various things to symbol tables (other than lookup), for GDB.
2
   Copyright 1986, 1987, 1989, 1991-1996, 1998, 2000 Free Software Foundation, Inc.
3
 
4
   This file is part of GDB.
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 2 of the License, or
9
   (at your option) any later version.
10
 
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
 
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 59 Temple Place - Suite 330,
19
   Boston, MA 02111-1307, USA.  */
20
 
21
#include "defs.h"
22
#include "symtab.h"
23
#include "gdbtypes.h"
24
#include "bfd.h"
25
#include "symfile.h"
26
#include "objfiles.h"
27
#include "breakpoint.h"
28
#include "command.h"
29
#include "obstack.h"
30
#include "language.h"
31
#include "bcache.h"
32
 
33
#include "gdb_string.h"
34
 
35
#ifndef DEV_TTY
36
#define DEV_TTY "/dev/tty"
37
#endif
38
 
39
/* Unfortunately for debugging, stderr is usually a macro.  This is painful
40
   when calling functions that take FILE *'s from the debugger.
41
   So we make a variable which has the same value and which is accessible when
42
   debugging GDB with itself.  Because stdin et al need not be constants,
43
   we initialize them in the _initialize_symmisc function at the bottom
44
   of the file.  */
45
FILE *std_in;
46
FILE *std_out;
47
FILE *std_err;
48
 
49
/* Prototypes for local functions */
50
 
51
static void dump_symtab (struct objfile *, struct symtab *,
52
                         struct ui_file *);
53
 
54
static void dump_psymtab (struct objfile *, struct partial_symtab *,
55
                          struct ui_file *);
56
 
57
static void dump_msymbols (struct objfile *, struct ui_file *);
58
 
59
static void dump_objfile PARAMS ((struct objfile *));
60
 
61
static int block_depth PARAMS ((struct block *));
62
 
63
static void print_partial_symbols (struct partial_symbol **, int,
64
                                   char *, struct ui_file *);
65
 
66
static void free_symtab_block PARAMS ((struct objfile *, struct block *));
67
 
68
void _initialize_symmisc PARAMS ((void));
69
 
70
struct print_symbol_args
71
  {
72
    struct symbol *symbol;
73
    int depth;
74
    struct ui_file *outfile;
75
  };
76
 
77
static int print_symbol PARAMS ((PTR));
78
 
79
static void
80
free_symtab_block PARAMS ((struct objfile *, struct block *));
81
 
82
 
83
/* Free a struct block <- B and all the symbols defined in that block.  */
84
 
85
static void
86
free_symtab_block (objfile, b)
87
     struct objfile *objfile;
88
     struct block *b;
89
{
90
  register int i, n;
91
  n = BLOCK_NSYMS (b);
92
  for (i = 0; i < n; i++)
93
    {
94
      mfree (objfile->md, SYMBOL_NAME (BLOCK_SYM (b, i)));
95
      mfree (objfile->md, (PTR) BLOCK_SYM (b, i));
96
    }
97
  mfree (objfile->md, (PTR) b);
98
}
99
 
100
/* Free all the storage associated with the struct symtab <- S.
101
   Note that some symtabs have contents malloc'ed structure by structure,
102
   while some have contents that all live inside one big block of memory,
103
   and some share the contents of another symbol table and so you should
104
   not free the contents on their behalf (except sometimes the linetable,
105
   which maybe per symtab even when the rest is not).
106
   It is s->free_code that says which alternative to use.  */
107
 
108
void
109
free_symtab (s)
110
     register struct symtab *s;
111
{
112
  register int i, n;
113
  register struct blockvector *bv;
114
 
115
  switch (s->free_code)
116
    {
117
    case free_nothing:
118
      /* All the contents are part of a big block of memory (an obstack),
119
         and some other symtab is in charge of freeing that block.
120
         Therefore, do nothing.  */
121
      break;
122
 
123
    case free_contents:
124
      /* Here all the contents were malloc'ed structure by structure
125
         and must be freed that way.  */
126
      /* First free the blocks (and their symbols.  */
127
      bv = BLOCKVECTOR (s);
128
      n = BLOCKVECTOR_NBLOCKS (bv);
129
      for (i = 0; i < n; i++)
130
        free_symtab_block (s->objfile, BLOCKVECTOR_BLOCK (bv, i));
131
      /* Free the blockvector itself.  */
132
      mfree (s->objfile->md, (PTR) bv);
133
      /* Also free the linetable.  */
134
 
135
    case free_linetable:
136
      /* Everything will be freed either by our `free_ptr'
137
         or by some other symtab, except for our linetable.
138
         Free that now.  */
139
      if (LINETABLE (s))
140
        mfree (s->objfile->md, (PTR) LINETABLE (s));
141
      break;
142
    }
143
 
144
  /* If there is a single block of memory to free, free it.  */
145
  if (s->free_ptr != NULL)
146
    mfree (s->objfile->md, s->free_ptr);
147
 
148
  /* Free source-related stuff */
149
  if (s->line_charpos != NULL)
150
    mfree (s->objfile->md, (PTR) s->line_charpos);
151
  if (s->fullname != NULL)
152
    mfree (s->objfile->md, s->fullname);
153
  if (s->debugformat != NULL)
154
    mfree (s->objfile->md, s->debugformat);
155
  mfree (s->objfile->md, (PTR) s);
156
}
157
 
158
void
159
print_symbol_bcache_statistics ()
160
{
161
  struct objfile *objfile;
162
 
163
  immediate_quit++;
164
  ALL_OBJFILES (objfile)
165
  {
166
    printf_filtered ("Byte cache statistics for '%s':\n", objfile->name);
167
    print_bcache_statistics (&objfile->psymbol_cache, "partial symbol cache");
168
  }
169
  immediate_quit--;
170
}
171
 
172
void
173
print_objfile_statistics ()
174
{
175
  struct objfile *objfile;
176
 
177
  immediate_quit++;
178
  ALL_OBJFILES (objfile)
179
  {
180
    printf_filtered ("Statistics for '%s':\n", objfile->name);
181
    if (OBJSTAT (objfile, n_stabs) > 0)
182
      printf_filtered ("  Number of \"stab\" symbols read: %d\n",
183
                       OBJSTAT (objfile, n_stabs));
184
    if (OBJSTAT (objfile, n_minsyms) > 0)
185
      printf_filtered ("  Number of \"minimal\" symbols read: %d\n",
186
                       OBJSTAT (objfile, n_minsyms));
187
    if (OBJSTAT (objfile, n_psyms) > 0)
188
      printf_filtered ("  Number of \"partial\" symbols read: %d\n",
189
                       OBJSTAT (objfile, n_psyms));
190
    if (OBJSTAT (objfile, n_syms) > 0)
191
      printf_filtered ("  Number of \"full\" symbols read: %d\n",
192
                       OBJSTAT (objfile, n_syms));
193
    if (OBJSTAT (objfile, n_types) > 0)
194
      printf_filtered ("  Number of \"types\" defined: %d\n",
195
                       OBJSTAT (objfile, n_types));
196
    if (OBJSTAT (objfile, sz_strtab) > 0)
197
      printf_filtered ("  Space used by a.out string tables: %d\n",
198
                       OBJSTAT (objfile, sz_strtab));
199
    printf_filtered ("  Total memory used for psymbol obstack: %d\n",
200
                     obstack_memory_used (&objfile->psymbol_obstack));
201
    printf_filtered ("  Total memory used for psymbol cache: %d\n",
202
                     obstack_memory_used (&objfile->psymbol_cache.cache));
203
    printf_filtered ("  Total memory used for symbol obstack: %d\n",
204
                     obstack_memory_used (&objfile->symbol_obstack));
205
    printf_filtered ("  Total memory used for type obstack: %d\n",
206
                     obstack_memory_used (&objfile->type_obstack));
207
  }
208
  immediate_quit--;
209
}
210
 
211
static void
212
dump_objfile (objfile)
213
     struct objfile *objfile;
214
{
215
  struct symtab *symtab;
216
  struct partial_symtab *psymtab;
217
 
218
  printf_filtered ("\nObject file %s:  ", objfile->name);
219
  printf_filtered ("Objfile at ");
220
  gdb_print_host_address (objfile, gdb_stdout);
221
  printf_filtered (", bfd at ");
222
  gdb_print_host_address (objfile->obfd, gdb_stdout);
223
  printf_filtered (", %d minsyms\n\n",
224
                   objfile->minimal_symbol_count);
225
 
226
  if (objfile->psymtabs)
227
    {
228
      printf_filtered ("Psymtabs:\n");
229
      for (psymtab = objfile->psymtabs;
230
           psymtab != NULL;
231
           psymtab = psymtab->next)
232
        {
233
          printf_filtered ("%s at ",
234
                           psymtab->filename);
235
          gdb_print_host_address (psymtab, gdb_stdout);
236
          printf_filtered (", ");
237
          if (psymtab->objfile != objfile)
238
            {
239
              printf_filtered ("NOT ON CHAIN!  ");
240
            }
241
          wrap_here ("  ");
242
        }
243
      printf_filtered ("\n\n");
244
    }
245
 
246
  if (objfile->symtabs)
247
    {
248
      printf_filtered ("Symtabs:\n");
249
      for (symtab = objfile->symtabs;
250
           symtab != NULL;
251
           symtab = symtab->next)
252
        {
253
          printf_filtered ("%s at ", symtab->filename);
254
          gdb_print_host_address (symtab, gdb_stdout);
255
          printf_filtered (", ");
256
          if (symtab->objfile != objfile)
257
            {
258
              printf_filtered ("NOT ON CHAIN!  ");
259
            }
260
          wrap_here ("  ");
261
        }
262
      printf_filtered ("\n\n");
263
    }
264
}
265
 
266
/* Print minimal symbols from this objfile.  */
267
 
268
static void
269
dump_msymbols (objfile, outfile)
270
     struct objfile *objfile;
271
     struct ui_file *outfile;
272
{
273
  struct minimal_symbol *msymbol;
274
  int index;
275
  char ms_type;
276
 
277
  fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile->name);
278
  if (objfile->minimal_symbol_count == 0)
279
    {
280
      fprintf_filtered (outfile, "No minimal symbols found.\n");
281
      return;
282
    }
283
  for (index = 0, msymbol = objfile->msymbols;
284
       SYMBOL_NAME (msymbol) != NULL; msymbol++, index++)
285
    {
286
      switch (msymbol->type)
287
        {
288
        case mst_unknown:
289
          ms_type = 'u';
290
          break;
291
        case mst_text:
292
          ms_type = 'T';
293
          break;
294
        case mst_solib_trampoline:
295
          ms_type = 'S';
296
          break;
297
        case mst_data:
298
          ms_type = 'D';
299
          break;
300
        case mst_bss:
301
          ms_type = 'B';
302
          break;
303
        case mst_abs:
304
          ms_type = 'A';
305
          break;
306
        case mst_file_text:
307
          ms_type = 't';
308
          break;
309
        case mst_file_data:
310
          ms_type = 'd';
311
          break;
312
        case mst_file_bss:
313
          ms_type = 'b';
314
          break;
315
        default:
316
          ms_type = '?';
317
          break;
318
        }
319
      fprintf_filtered (outfile, "[%2d] %c ", index, ms_type);
320
      print_address_numeric (SYMBOL_VALUE_ADDRESS (msymbol), 1, outfile);
321
      fprintf_filtered (outfile, " %s", SYMBOL_NAME (msymbol));
322
      if (SYMBOL_BFD_SECTION (msymbol))
323
        fprintf_filtered (outfile, " section %s",
324
                          bfd_section_name (objfile->obfd,
325
                                            SYMBOL_BFD_SECTION (msymbol)));
326
      if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
327
        {
328
          fprintf_filtered (outfile, "  %s", SYMBOL_DEMANGLED_NAME (msymbol));
329
        }
330
#ifdef SOFUN_ADDRESS_MAYBE_MISSING
331
      if (msymbol->filename)
332
        fprintf_filtered (outfile, "  %s", msymbol->filename);
333
#endif
334
      fputs_filtered ("\n", outfile);
335
    }
336
  if (objfile->minimal_symbol_count != index)
337
    {
338
      warning ("internal error:  minimal symbol count %d != %d",
339
               objfile->minimal_symbol_count, index);
340
    }
341
  fprintf_filtered (outfile, "\n");
342
}
343
 
344
static void
345
dump_psymtab (objfile, psymtab, outfile)
346
     struct objfile *objfile;
347
     struct partial_symtab *psymtab;
348
     struct ui_file *outfile;
349
{
350
  int i;
351
 
352
  fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
353
                    psymtab->filename);
354
  fprintf_filtered (outfile, "(object ");
355
  gdb_print_host_address (psymtab, outfile);
356
  fprintf_filtered (outfile, ")\n\n");
357
  fprintf_unfiltered (outfile, "  Read from object file %s (",
358
                      objfile->name);
359
  gdb_print_host_address (objfile, outfile);
360
  fprintf_unfiltered (outfile, ")\n");
361
 
362
  if (psymtab->readin)
363
    {
364
      fprintf_filtered (outfile,
365
                        "  Full symtab was read (at ");
366
      gdb_print_host_address (psymtab->symtab, outfile);
367
      fprintf_filtered (outfile, " by function at ");
368
      gdb_print_host_address ((PTR) psymtab->read_symtab, outfile);
369
      fprintf_filtered (outfile, ")\n");
370
    }
371
 
372
  fprintf_filtered (outfile, "  Relocate symbols by ");
373
  for (i = 0; i < psymtab->objfile->num_sections; ++i)
374
    {
375
      if (i != 0)
376
        fprintf_filtered (outfile, ", ");
377
      wrap_here ("    ");
378
      print_address_numeric (ANOFFSET (psymtab->section_offsets, i),
379
                             1,
380
                             outfile);
381
    }
382
  fprintf_filtered (outfile, "\n");
383
 
384
  fprintf_filtered (outfile, "  Symbols cover text addresses ");
385
  print_address_numeric (psymtab->textlow, 1, outfile);
386
  fprintf_filtered (outfile, "-");
387
  print_address_numeric (psymtab->texthigh, 1, outfile);
388
  fprintf_filtered (outfile, "\n");
389
  fprintf_filtered (outfile, "  Depends on %d other partial symtabs.\n",
390
                    psymtab->number_of_dependencies);
391
  for (i = 0; i < psymtab->number_of_dependencies; i++)
392
    {
393
      fprintf_filtered (outfile, "    %d ", i);
394
      gdb_print_host_address (psymtab->dependencies[i], outfile);
395
      fprintf_filtered (outfile, " %s\n",
396
                        psymtab->dependencies[i]->filename);
397
    }
398
  if (psymtab->n_global_syms > 0)
399
    {
400
      print_partial_symbols (objfile->global_psymbols.list
401
                             + psymtab->globals_offset,
402
                             psymtab->n_global_syms, "Global", outfile);
403
    }
404
  if (psymtab->n_static_syms > 0)
405
    {
406
      print_partial_symbols (objfile->static_psymbols.list
407
                             + psymtab->statics_offset,
408
                             psymtab->n_static_syms, "Static", outfile);
409
    }
410
  fprintf_filtered (outfile, "\n");
411
}
412
 
413
static void
414
dump_symtab (objfile, symtab, outfile)
415
     struct objfile *objfile;
416
     struct symtab *symtab;
417
     struct ui_file *outfile;
418
{
419
  register int i, j;
420
  int len, blen;
421
  register struct linetable *l;
422
  struct blockvector *bv;
423
  register struct block *b;
424
  int depth;
425
 
426
  fprintf_filtered (outfile, "\nSymtab for file %s\n", symtab->filename);
427
  if (symtab->dirname)
428
    fprintf_filtered (outfile, "Compilation directory is %s\n",
429
                      symtab->dirname);
430
  fprintf_filtered (outfile, "Read from object file %s (", objfile->name);
431
  gdb_print_host_address (objfile, outfile);
432
  fprintf_filtered (outfile, ")\n");
433
  fprintf_filtered (outfile, "Language: %s\n", language_str (symtab->language));
434
 
435
  /* First print the line table.  */
436
  l = LINETABLE (symtab);
437
  if (l)
438
    {
439
      fprintf_filtered (outfile, "\nLine table:\n\n");
440
      len = l->nitems;
441
      for (i = 0; i < len; i++)
442
        {
443
          fprintf_filtered (outfile, " line %d at ", l->item[i].line);
444
          print_address_numeric (l->item[i].pc, 1, outfile);
445
          fprintf_filtered (outfile, "\n");
446
        }
447
    }
448
  /* Now print the block info, but only for primary symtabs since we will
449
     print lots of duplicate info otherwise. */
450
  if (symtab->primary)
451
    {
452
      fprintf_filtered (outfile, "\nBlockvector:\n\n");
453
      bv = BLOCKVECTOR (symtab);
454
      len = BLOCKVECTOR_NBLOCKS (bv);
455
      for (i = 0; i < len; i++)
456
        {
457
          b = BLOCKVECTOR_BLOCK (bv, i);
458
          depth = block_depth (b) * 2;
459
          print_spaces (depth, outfile);
460
          fprintf_filtered (outfile, "block #%03d, object at ", i);
461
          gdb_print_host_address (b, outfile);
462
          if (BLOCK_SUPERBLOCK (b))
463
            {
464
              fprintf_filtered (outfile, " under ");
465
              gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile);
466
            }
467
          blen = BLOCK_NSYMS (b);
468
          fprintf_filtered (outfile, ", %d syms in ", blen);
469
          print_address_numeric (BLOCK_START (b), 1, outfile);
470
          fprintf_filtered (outfile, "..");
471
          print_address_numeric (BLOCK_END (b), 1, outfile);
472
          if (BLOCK_FUNCTION (b))
473
            {
474
              fprintf_filtered (outfile, ", function %s", SYMBOL_NAME (BLOCK_FUNCTION (b)));
475
              if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
476
                {
477
                  fprintf_filtered (outfile, ", %s",
478
                                SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
479
                }
480
            }
481
          if (BLOCK_GCC_COMPILED (b))
482
            fprintf_filtered (outfile, ", compiled with gcc%d", BLOCK_GCC_COMPILED (b));
483
          fprintf_filtered (outfile, "\n");
484
          /* Now print each symbol in this block */
485
          for (j = 0; j < blen; j++)
486
            {
487
              struct print_symbol_args s;
488
              s.symbol = BLOCK_SYM (b, j);
489
              s.depth = depth + 1;
490
              s.outfile = outfile;
491
              catch_errors (print_symbol, &s, "Error printing symbol:\n",
492
                            RETURN_MASK_ALL);
493
            }
494
        }
495
      fprintf_filtered (outfile, "\n");
496
    }
497
  else
498
    {
499
      fprintf_filtered (outfile, "\nBlockvector same as previous symtab\n\n");
500
    }
501
}
502
 
503
void
504
maintenance_print_symbols (args, from_tty)
505
     char *args;
506
     int from_tty;
507
{
508
  char **argv;
509
  struct ui_file *outfile;
510
  struct cleanup *cleanups;
511
  char *symname = NULL;
512
  char *filename = DEV_TTY;
513
  struct objfile *objfile;
514
  struct symtab *s;
515
 
516
  dont_repeat ();
517
 
518
  if (args == NULL)
519
    {
520
      error ("\
521
Arguments missing: an output file name and an optional symbol file name");
522
    }
523
  else if ((argv = buildargv (args)) == NULL)
524
    {
525
      nomem (0);
526
    }
527
  cleanups = make_cleanup_freeargv (argv);
528
 
529
  if (argv[0] != NULL)
530
    {
531
      filename = argv[0];
532
      /* If a second arg is supplied, it is a source file name to match on */
533
      if (argv[1] != NULL)
534
        {
535
          symname = argv[1];
536
        }
537
    }
538
 
539
  filename = tilde_expand (filename);
540
  make_cleanup (free, filename);
541
 
542
  outfile = gdb_fopen (filename, FOPEN_WT);
543
  if (outfile == 0)
544
    perror_with_name (filename);
545
  make_cleanup_ui_file_delete (outfile);
546
 
547
  immediate_quit++;
548
  ALL_SYMTABS (objfile, s)
549
    if (symname == NULL || (STREQ (symname, s->filename)))
550
    dump_symtab (objfile, s, outfile);
551
  immediate_quit--;
552
  do_cleanups (cleanups);
553
}
554
 
555
/* Print symbol ARGS->SYMBOL on ARGS->OUTFILE.  ARGS->DEPTH says how
556
   far to indent.  ARGS is really a struct print_symbol_args *, but is
557
   declared as char * to get it past catch_errors.  Returns 0 for error,
558
   1 for success.  */
559
 
560
static int
561
print_symbol (args)
562
     PTR args;
563
{
564
  struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
565
  int depth = ((struct print_symbol_args *) args)->depth;
566
  struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
567
 
568
  print_spaces (depth, outfile);
569
  if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
570
    {
571
      fprintf_filtered (outfile, "label %s at ", SYMBOL_SOURCE_NAME (symbol));
572
      print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
573
      if (SYMBOL_BFD_SECTION (symbol))
574
        fprintf_filtered (outfile, " section %s\n",
575
                       bfd_section_name (SYMBOL_BFD_SECTION (symbol)->owner,
576
                                         SYMBOL_BFD_SECTION (symbol)));
577
      else
578
        fprintf_filtered (outfile, "\n");
579
      return 1;
580
    }
581
  if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
582
    {
583
      if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
584
        {
585
          LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
586
        }
587
      else
588
        {
589
          fprintf_filtered (outfile, "%s %s = ",
590
                         (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
591
                          ? "enum"
592
                     : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
593
                        ? "struct" : "union")),
594
                            SYMBOL_NAME (symbol));
595
          LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
596
        }
597
      fprintf_filtered (outfile, ";\n");
598
    }
599
  else
600
    {
601
      if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
602
        fprintf_filtered (outfile, "typedef ");
603
      if (SYMBOL_TYPE (symbol))
604
        {
605
          /* Print details of types, except for enums where it's clutter.  */
606
          LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_SOURCE_NAME (symbol),
607
                         outfile,
608
                         TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
609
                         depth);
610
          fprintf_filtered (outfile, "; ");
611
        }
612
      else
613
        fprintf_filtered (outfile, "%s ", SYMBOL_SOURCE_NAME (symbol));
614
 
615
      switch (SYMBOL_CLASS (symbol))
616
        {
617
        case LOC_CONST:
618
          fprintf_filtered (outfile, "const %ld (0x%lx)",
619
                            SYMBOL_VALUE (symbol),
620
                            SYMBOL_VALUE (symbol));
621
          break;
622
 
623
        case LOC_CONST_BYTES:
624
          {
625
            unsigned i;
626
            struct type *type = check_typedef (SYMBOL_TYPE (symbol));
627
            fprintf_filtered (outfile, "const %u hex bytes:",
628
                              TYPE_LENGTH (type));
629
            for (i = 0; i < TYPE_LENGTH (type); i++)
630
              fprintf_filtered (outfile, " %02x",
631
                                (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
632
          }
633
          break;
634
 
635
        case LOC_STATIC:
636
          fprintf_filtered (outfile, "static at ");
637
          print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
638
          if (SYMBOL_BFD_SECTION (symbol))
639
            fprintf_filtered (outfile, " section %s",
640
                              bfd_section_name
641
                              (SYMBOL_BFD_SECTION (symbol)->owner,
642
                               SYMBOL_BFD_SECTION (symbol)));
643
          break;
644
 
645
        case LOC_INDIRECT:
646
          fprintf_filtered (outfile, "extern global at *(");
647
          print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
648
          fprintf_filtered (outfile, "),");
649
          break;
650
 
651
        case LOC_REGISTER:
652
          fprintf_filtered (outfile, "register %ld", SYMBOL_VALUE (symbol));
653
          break;
654
 
655
        case LOC_ARG:
656
          fprintf_filtered (outfile, "arg at offset 0x%lx",
657
                            SYMBOL_VALUE (symbol));
658
          break;
659
 
660
        case LOC_LOCAL_ARG:
661
          fprintf_filtered (outfile, "arg at offset 0x%lx from fp",
662
                            SYMBOL_VALUE (symbol));
663
          break;
664
 
665
        case LOC_REF_ARG:
666
          fprintf_filtered (outfile, "reference arg at 0x%lx", SYMBOL_VALUE (symbol));
667
          break;
668
 
669
        case LOC_REGPARM:
670
          fprintf_filtered (outfile, "parameter register %ld", SYMBOL_VALUE (symbol));
671
          break;
672
 
673
        case LOC_REGPARM_ADDR:
674
          fprintf_filtered (outfile, "address parameter register %ld", SYMBOL_VALUE (symbol));
675
          break;
676
 
677
        case LOC_LOCAL:
678
          fprintf_filtered (outfile, "local at offset 0x%lx",
679
                            SYMBOL_VALUE (symbol));
680
          break;
681
 
682
        case LOC_BASEREG:
683
          fprintf_filtered (outfile, "local at 0x%lx from register %d",
684
                            SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
685
          break;
686
 
687
        case LOC_BASEREG_ARG:
688
          fprintf_filtered (outfile, "arg at 0x%lx from register %d",
689
                            SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
690
          break;
691
 
692
        case LOC_TYPEDEF:
693
          break;
694
 
695
        case LOC_LABEL:
696
          fprintf_filtered (outfile, "label at ");
697
          print_address_numeric (SYMBOL_VALUE_ADDRESS (symbol), 1, outfile);
698
          if (SYMBOL_BFD_SECTION (symbol))
699
            fprintf_filtered (outfile, " section %s",
700
                              bfd_section_name
701
                              (SYMBOL_BFD_SECTION (symbol)->owner,
702
                               SYMBOL_BFD_SECTION (symbol)));
703
          break;
704
 
705
        case LOC_BLOCK:
706
          fprintf_filtered (outfile, "block object ");
707
          gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile);
708
          fprintf_filtered (outfile, ", ");
709
          print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)),
710
                                 1,
711
                                 outfile);
712
          fprintf_filtered (outfile, "..");
713
          print_address_numeric (BLOCK_END (SYMBOL_BLOCK_VALUE (symbol)),
714
                                 1,
715
                                 outfile);
716
          if (SYMBOL_BFD_SECTION (symbol))
717
            fprintf_filtered (outfile, " section %s",
718
                              bfd_section_name
719
                              (SYMBOL_BFD_SECTION (symbol)->owner,
720
                               SYMBOL_BFD_SECTION (symbol)));
721
          break;
722
 
723
        case LOC_UNRESOLVED:
724
          fprintf_filtered (outfile, "unresolved");
725
          break;
726
 
727
        case LOC_OPTIMIZED_OUT:
728
          fprintf_filtered (outfile, "optimized out");
729
          break;
730
 
731
        default:
732
          fprintf_filtered (outfile, "botched symbol class %x",
733
                            SYMBOL_CLASS (symbol));
734
          break;
735
        }
736
    }
737
  fprintf_filtered (outfile, "\n");
738
  return 1;
739
}
740
 
741
void
742
maintenance_print_psymbols (args, from_tty)
743
     char *args;
744
     int from_tty;
745
{
746
  char **argv;
747
  struct ui_file *outfile;
748
  struct cleanup *cleanups;
749
  char *symname = NULL;
750
  char *filename = DEV_TTY;
751
  struct objfile *objfile;
752
  struct partial_symtab *ps;
753
 
754
  dont_repeat ();
755
 
756
  if (args == NULL)
757
    {
758
      error ("print-psymbols takes an output file name and optional symbol file name");
759
    }
760
  else if ((argv = buildargv (args)) == NULL)
761
    {
762
      nomem (0);
763
    }
764
  cleanups = make_cleanup_freeargv (argv);
765
 
766
  if (argv[0] != NULL)
767
    {
768
      filename = argv[0];
769
      /* If a second arg is supplied, it is a source file name to match on */
770
      if (argv[1] != NULL)
771
        {
772
          symname = argv[1];
773
        }
774
    }
775
 
776
  filename = tilde_expand (filename);
777
  make_cleanup (free, filename);
778
 
779
  outfile = gdb_fopen (filename, FOPEN_WT);
780
  if (outfile == 0)
781
    perror_with_name (filename);
782
  make_cleanup_ui_file_delete (outfile);
783
 
784
  immediate_quit++;
785
  ALL_PSYMTABS (objfile, ps)
786
    if (symname == NULL || (STREQ (symname, ps->filename)))
787
    dump_psymtab (objfile, ps, outfile);
788
  immediate_quit--;
789
  do_cleanups (cleanups);
790
}
791
 
792
static void
793
print_partial_symbols (p, count, what, outfile)
794
     struct partial_symbol **p;
795
     int count;
796
     char *what;
797
     struct ui_file *outfile;
798
{
799
  fprintf_filtered (outfile, "  %s partial symbols:\n", what);
800
  while (count-- > 0)
801
    {
802
      fprintf_filtered (outfile, "    `%s'", SYMBOL_NAME (*p));
803
      if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
804
        {
805
          fprintf_filtered (outfile, "  `%s'", SYMBOL_DEMANGLED_NAME (*p));
806
        }
807
      fputs_filtered (", ", outfile);
808
      switch (SYMBOL_NAMESPACE (*p))
809
        {
810
        case UNDEF_NAMESPACE:
811
          fputs_filtered ("undefined namespace, ", outfile);
812
          break;
813
        case VAR_NAMESPACE:
814
          /* This is the usual thing -- don't print it */
815
          break;
816
        case STRUCT_NAMESPACE:
817
          fputs_filtered ("struct namespace, ", outfile);
818
          break;
819
        case LABEL_NAMESPACE:
820
          fputs_filtered ("label namespace, ", outfile);
821
          break;
822
        default:
823
          fputs_filtered ("<invalid namespace>, ", outfile);
824
          break;
825
        }
826
      switch (SYMBOL_CLASS (*p))
827
        {
828
        case LOC_UNDEF:
829
          fputs_filtered ("undefined", outfile);
830
          break;
831
        case LOC_CONST:
832
          fputs_filtered ("constant int", outfile);
833
          break;
834
        case LOC_STATIC:
835
          fputs_filtered ("static", outfile);
836
          break;
837
        case LOC_INDIRECT:
838
          fputs_filtered ("extern global", outfile);
839
          break;
840
        case LOC_REGISTER:
841
          fputs_filtered ("register", outfile);
842
          break;
843
        case LOC_ARG:
844
          fputs_filtered ("pass by value", outfile);
845
          break;
846
        case LOC_REF_ARG:
847
          fputs_filtered ("pass by reference", outfile);
848
          break;
849
        case LOC_REGPARM:
850
          fputs_filtered ("register parameter", outfile);
851
          break;
852
        case LOC_REGPARM_ADDR:
853
          fputs_filtered ("register address parameter", outfile);
854
          break;
855
        case LOC_LOCAL:
856
          fputs_filtered ("stack parameter", outfile);
857
          break;
858
        case LOC_TYPEDEF:
859
          fputs_filtered ("type", outfile);
860
          break;
861
        case LOC_LABEL:
862
          fputs_filtered ("label", outfile);
863
          break;
864
        case LOC_BLOCK:
865
          fputs_filtered ("function", outfile);
866
          break;
867
        case LOC_CONST_BYTES:
868
          fputs_filtered ("constant bytes", outfile);
869
          break;
870
        case LOC_LOCAL_ARG:
871
          fputs_filtered ("shuffled arg", outfile);
872
          break;
873
        case LOC_UNRESOLVED:
874
          fputs_filtered ("unresolved", outfile);
875
          break;
876
        case LOC_OPTIMIZED_OUT:
877
          fputs_filtered ("optimized out", outfile);
878
          break;
879
        default:
880
          fputs_filtered ("<invalid location>", outfile);
881
          break;
882
        }
883
      fputs_filtered (", ", outfile);
884
      print_address_numeric (SYMBOL_VALUE_ADDRESS (*p), 1, outfile);
885
      fprintf_filtered (outfile, "\n");
886
      p++;
887
    }
888
}
889
 
890
void
891
maintenance_print_msymbols (args, from_tty)
892
     char *args;
893
     int from_tty;
894
{
895
  char **argv;
896
  struct ui_file *outfile;
897
  struct cleanup *cleanups;
898
  char *filename = DEV_TTY;
899
  char *symname = NULL;
900
  struct objfile *objfile;
901
 
902
  dont_repeat ();
903
 
904
  if (args == NULL)
905
    {
906
      error ("print-msymbols takes an output file name and optional symbol file name");
907
    }
908
  else if ((argv = buildargv (args)) == NULL)
909
    {
910
      nomem (0);
911
    }
912
  cleanups = make_cleanup_freeargv (argv);
913
 
914
  if (argv[0] != NULL)
915
    {
916
      filename = argv[0];
917
      /* If a second arg is supplied, it is a source file name to match on */
918
      if (argv[1] != NULL)
919
        {
920
          symname = argv[1];
921
        }
922
    }
923
 
924
  filename = tilde_expand (filename);
925
  make_cleanup (free, filename);
926
 
927
  outfile = gdb_fopen (filename, FOPEN_WT);
928
  if (outfile == 0)
929
    perror_with_name (filename);
930
  make_cleanup_ui_file_delete (outfile);
931
 
932
  immediate_quit++;
933
  ALL_OBJFILES (objfile)
934
    if (symname == NULL || (STREQ (symname, objfile->name)))
935
    dump_msymbols (objfile, outfile);
936
  immediate_quit--;
937
  fprintf_filtered (outfile, "\n\n");
938
  do_cleanups (cleanups);
939
}
940
 
941
void
942
maintenance_print_objfiles (ignore, from_tty)
943
     char *ignore;
944
     int from_tty;
945
{
946
  struct objfile *objfile;
947
 
948
  dont_repeat ();
949
 
950
  immediate_quit++;
951
  ALL_OBJFILES (objfile)
952
    dump_objfile (objfile);
953
  immediate_quit--;
954
}
955
 
956
/* Check consistency of psymtabs and symtabs.  */
957
 
958
void
959
maintenance_check_symtabs (ignore, from_tty)
960
     char *ignore;
961
     int from_tty;
962
{
963
  register struct symbol *sym;
964
  register struct partial_symbol **psym;
965
  register struct symtab *s = NULL;
966
  register struct partial_symtab *ps;
967
  struct blockvector *bv;
968
  register struct objfile *objfile;
969
  register struct block *b;
970
  int length;
971
 
972
  ALL_PSYMTABS (objfile, ps)
973
  {
974
    s = PSYMTAB_TO_SYMTAB (ps);
975
    if (s == NULL)
976
      continue;
977
    bv = BLOCKVECTOR (s);
978
    b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
979
    psym = ps->objfile->static_psymbols.list + ps->statics_offset;
980
    length = ps->n_static_syms;
981
    while (length--)
982
      {
983
        sym = lookup_block_symbol (b, SYMBOL_NAME (*psym),
984
                                   SYMBOL_NAMESPACE (*psym));
985
        if (!sym)
986
          {
987
            printf_filtered ("Static symbol `");
988
            puts_filtered (SYMBOL_NAME (*psym));
989
            printf_filtered ("' only found in ");
990
            puts_filtered (ps->filename);
991
            printf_filtered (" psymtab\n");
992
          }
993
        psym++;
994
      }
995
    b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
996
    psym = ps->objfile->global_psymbols.list + ps->globals_offset;
997
    length = ps->n_global_syms;
998
    while (length--)
999
      {
1000
        sym = lookup_block_symbol (b, SYMBOL_NAME (*psym),
1001
                                   SYMBOL_NAMESPACE (*psym));
1002
        if (!sym)
1003
          {
1004
            printf_filtered ("Global symbol `");
1005
            puts_filtered (SYMBOL_NAME (*psym));
1006
            printf_filtered ("' only found in ");
1007
            puts_filtered (ps->filename);
1008
            printf_filtered (" psymtab\n");
1009
          }
1010
        psym++;
1011
      }
1012
    if (ps->texthigh < ps->textlow)
1013
      {
1014
        printf_filtered ("Psymtab ");
1015
        puts_filtered (ps->filename);
1016
        printf_filtered (" covers bad range ");
1017
        print_address_numeric (ps->textlow, 1, gdb_stdout);
1018
        printf_filtered (" - ");
1019
        print_address_numeric (ps->texthigh, 1, gdb_stdout);
1020
        printf_filtered ("\n");
1021
        continue;
1022
      }
1023
    if (ps->texthigh == 0)
1024
      continue;
1025
    if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1026
      {
1027
        printf_filtered ("Psymtab ");
1028
        puts_filtered (ps->filename);
1029
        printf_filtered (" covers ");
1030
        print_address_numeric (ps->textlow, 1, gdb_stdout);
1031
        printf_filtered (" - ");
1032
        print_address_numeric (ps->texthigh, 1, gdb_stdout);
1033
        printf_filtered (" but symtab covers only ");
1034
        print_address_numeric (BLOCK_START (b), 1, gdb_stdout);
1035
        printf_filtered (" - ");
1036
        print_address_numeric (BLOCK_END (b), 1, gdb_stdout);
1037
        printf_filtered ("\n");
1038
      }
1039
  }
1040
}
1041
 
1042
 
1043
/* Return the nexting depth of a block within other blocks in its symtab.  */
1044
 
1045
static int
1046
block_depth (block)
1047
     struct block *block;
1048
{
1049
  register int i = 0;
1050
  while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
1051
    {
1052
      i++;
1053
    }
1054
  return i;
1055
}
1056
 
1057
 
1058
/* Increase the space allocated for LISTP, which is probably
1059
   global_psymbols or static_psymbols. This space will eventually
1060
   be freed in free_objfile().  */
1061
 
1062
void
1063
extend_psymbol_list (listp, objfile)
1064
     register struct psymbol_allocation_list *listp;
1065
     struct objfile *objfile;
1066
{
1067
  int new_size;
1068
  if (listp->size == 0)
1069
    {
1070
      new_size = 255;
1071
      listp->list = (struct partial_symbol **)
1072
        xmmalloc (objfile->md, new_size * sizeof (struct partial_symbol *));
1073
    }
1074
  else
1075
    {
1076
      new_size = listp->size * 2;
1077
      listp->list = (struct partial_symbol **)
1078
        xmrealloc (objfile->md, (char *) listp->list,
1079
                   new_size * sizeof (struct partial_symbol *));
1080
    }
1081
  /* Next assumes we only went one over.  Should be good if
1082
     program works correctly */
1083
  listp->next = listp->list + listp->size;
1084
  listp->size = new_size;
1085
}
1086
 
1087
 
1088
/* Do early runtime initializations. */
1089
void
1090
_initialize_symmisc ()
1091
{
1092
  std_in = stdin;
1093
  std_out = stdout;
1094
  std_err = stderr;
1095
}

powered by: WebSVN 2.1.0

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