-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdwarf.c
10449 lines (9162 loc) · 290 KB
/
dwarf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* dwarf.c -- display DWARF contents of a BFD binary file
Copyright (C) 2005-2019 Free Software Foundation, Inc.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
#include "sysdep.h"
#include "libiberty.h"
#include "bfd.h"
#include "bfd_stdint.h"
#include "bucomm.h"
#include "elfcomm.h"
#include "elf/common.h"
#include "dwarf2.h"
#include "dwarf.h"
#include "gdb/gdb-index.h"
#include "filenames.h"
#include <assert.h>
#undef MAX
#undef MIN
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
static const char *regname (unsigned int regno, int row);
static int have_frame_base;
static int need_base_address;
static unsigned int num_debug_info_entries = 0;
static unsigned int alloc_num_debug_info_entries = 0;
static debug_info *debug_information = NULL;
/* Special value for num_debug_info_entries to indicate
that the .debug_info section could not be loaded/parsed. */
#define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
/* A .debug_info section can contain multiple links to separate
DWO object files. We use these structures to record these links. */
typedef enum dwo_type
{
DWO_NAME,
DWO_DIR,
DWO_ID
} dwo_type;
typedef struct dwo_info
{
dwo_type type;
const char * value;
struct dwo_info * next;
} dwo_info;
static dwo_info * first_dwo_info = NULL;
static bfd_boolean need_dwo_info;
separate_info * first_separate_info = NULL;
unsigned int eh_addr_size;
int do_debug_info;
int do_debug_abbrevs;
int do_debug_lines;
int do_debug_pubnames;
int do_debug_pubtypes;
int do_debug_aranges;
int do_debug_ranges;
int do_debug_frames;
int do_debug_frames_interp;
int do_debug_macinfo;
int do_debug_str;
int do_debug_loc;
int do_gdb_index;
int do_trace_info;
int do_trace_abbrevs;
int do_trace_aranges;
int do_debug_addr;
int do_debug_cu_index;
int do_wide;
int do_debug_links;
int do_follow_links;
int dwarf_cutoff_level = -1;
unsigned long dwarf_start_die;
int dwarf_check = 0;
/* Convenient constant, to avoid having to cast -1 to dwarf_vma when
testing whether e.g. a locview list is present. */
static const dwarf_vma vm1 = -1;
/* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
sections. For version 1 package files, each set is stored in SHNDX_POOL
as a zero-terminated list of section indexes comprising one set of debug
sections from a .dwo file. */
static unsigned int *shndx_pool = NULL;
static unsigned int shndx_pool_size = 0;
static unsigned int shndx_pool_used = 0;
/* For version 2 package files, each set contains an array of section offsets
and an array of section sizes, giving the offset and size of the
contribution from a CU or TU within one of the debug sections.
When displaying debug info from a package file, we need to use these
tables to locate the corresponding contributions to each section. */
struct cu_tu_set
{
uint64_t signature;
dwarf_vma section_offsets[DW_SECT_MAX];
size_t section_sizes[DW_SECT_MAX];
};
static int cu_count = 0;
static int tu_count = 0;
static struct cu_tu_set *cu_sets = NULL;
static struct cu_tu_set *tu_sets = NULL;
static bfd_boolean load_cu_tu_indexes (void *);
/* Values for do_debug_lines. */
#define FLAG_DEBUG_LINES_RAW 1
#define FLAG_DEBUG_LINES_DECODED 2
static unsigned int
size_of_encoded_value (int encoding)
{
switch (encoding & 0x7)
{
default: /* ??? */
case 0: return eh_addr_size;
case 2: return 2;
case 3: return 4;
case 4: return 8;
}
}
static dwarf_vma
get_encoded_value (unsigned char **pdata,
int encoding,
struct dwarf_section *section,
unsigned char * end)
{
unsigned char * data = * pdata;
unsigned int size = size_of_encoded_value (encoding);
dwarf_vma val;
if (data + size >= end)
{
warn (_("Encoded value extends past end of section\n"));
* pdata = end;
return 0;
}
/* PR 17512: file: 002-829853-0.004. */
if (size > 8)
{
warn (_("Encoded size of %d is too large to read\n"), size);
* pdata = end;
return 0;
}
/* PR 17512: file: 1085-5603-0.004. */
if (size == 0)
{
warn (_("Encoded size of 0 is too small to read\n"));
* pdata = end;
return 0;
}
if (encoding & DW_EH_PE_signed)
val = byte_get_signed (data, size);
else
val = byte_get (data, size);
if ((encoding & 0x70) == DW_EH_PE_pcrel)
val += section->address + (data - section->start);
* pdata = data + size;
return val;
}
#if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
# ifndef __MINGW32__
# define DWARF_VMA_FMT "ll"
# define DWARF_VMA_FMT_LONG "%16.16llx"
# else
# define DWARF_VMA_FMT "I64"
# define DWARF_VMA_FMT_LONG "%016I64x"
# endif
#else
# define DWARF_VMA_FMT "l"
# define DWARF_VMA_FMT_LONG "%16.16lx"
#endif
/* Convert a dwarf vma value into a string. Returns a pointer to a static
buffer containing the converted VALUE. The value is converted according
to the printf formating character FMTCH. If NUM_BYTES is non-zero then
it specifies the maximum number of bytes to be displayed in the converted
value and FMTCH is ignored - hex is always used. */
static const char *
dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
{
/* As dwarf_vmatoa is used more then once in a printf call
for output, we are cycling through an fixed array of pointers
for return address. */
static int buf_pos = 0;
static struct dwarf_vmatoa_buf
{
char place[64];
} buf[16];
char *ret;
ret = buf[buf_pos++].place;
buf_pos %= ARRAY_SIZE (buf);
if (num_bytes)
{
/* Printf does not have a way of specifying a maximum field width for an
integer value, so we print the full value into a buffer and then select
the precision we need. */
snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
if (num_bytes > 8)
num_bytes = 8;
return ret + (16 - 2 * num_bytes);
}
else
{
char fmt[32];
if (fmtch)
sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
else
sprintf (fmt, "%%%s", DWARF_VMA_FMT);
snprintf (ret, sizeof (buf[0].place), fmt, value);
return ret;
}
}
static inline const char *
dwarf_vmatoa (const char * fmtch, dwarf_vma value)
{
return dwarf_vmatoa_1 (fmtch, value, 0);
}
/* Print a dwarf_vma value (typically an address, offset or length) in
hexadecimal format, followed by a space. The length of the VALUE (and
hence the precision displayed) is determined by the NUM_BYTES parameter. */
static void
print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
{
printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
}
/* Print a view number in hexadecimal value, with the same width
print_dwarf_vma would have printed it with the same num_bytes.
Print blanks for zero view, unless force is nonzero. */
static void
print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force)
{
int len;
if (!num_bytes)
len = 4;
else
len = num_bytes * 2;
assert (value == (unsigned long) value);
if (value || force)
printf ("v%0*lx ", len - 1, (unsigned long) value);
else
printf ("%*s", len + 1, "");
}
/* Format a 64-bit value, given as two 32-bit values, in hex.
For reentrancy, this uses a buffer provided by the caller. */
static const char *
dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
unsigned int buf_len)
{
int len = 0;
if (hvalue == 0)
snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
else
{
len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
snprintf (buf + len, buf_len - len,
"%08" DWARF_VMA_FMT "x", lvalue);
}
return buf;
}
/* Read in a LEB128 encoded value starting at address DATA.
If SIGN is true, return a signed LEB128 value.
If LENGTH_RETURN is not NULL, return in it the number of bytes read.
No bytes will be read at address END or beyond. */
dwarf_vma
read_leb128 (unsigned char *data,
unsigned int *length_return,
bfd_boolean sign,
const unsigned char * const end)
{
dwarf_vma result = 0;
unsigned int num_read = 0;
unsigned int shift = 0;
unsigned char byte = 0;
while (data < end)
{
byte = *data++;
num_read++;
result |= ((dwarf_vma) (byte & 0x7f)) << shift;
shift += 7;
if ((byte & 0x80) == 0)
break;
/* PR 17512: file: 0ca183b8.
FIXME: Should we signal this error somehow ? */
if (shift >= sizeof (result) * 8)
break;
}
if (length_return != NULL)
*length_return = num_read;
if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
result |= -((dwarf_vma) 1 << shift);
return result;
}
/* Create a signed version to avoid painful typecasts. */
static inline dwarf_signed_vma
read_sleb128 (unsigned char * data,
unsigned int * length_return,
const unsigned char * const end)
{
return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
}
static inline dwarf_vma
read_uleb128 (unsigned char * data,
unsigned int * length_return,
const unsigned char * const end)
{
return read_leb128 (data, length_return, FALSE, end);
}
#define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
#define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
#define READ_ULEB(var) \
do \
{ \
dwarf_vma _val; \
\
(var) = _val = read_uleb128 (start, &length_return, end); \
if ((var) != _val) \
error (_("Internal error: %s:%d: LEB value (%s) " \
"too large for containing variable\n"), \
__FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \
start += length_return; \
} \
while (0)
#define READ_SLEB(var) \
do \
{ \
dwarf_signed_vma _val; \
\
(var) = _val = read_sleb128 (start, &length_return, end); \
if ((var) != _val) \
error (_("Internal error: %s:%d: LEB value (%s) " \
"too large for containing variable\n"), \
__FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \
start += length_return; \
} \
while (0)
/* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
Checks to make sure that the read will not reach or pass END
and that VAL is big enough to hold AMOUNT bytes. */
#define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
do \
{ \
unsigned int amount = (AMOUNT); \
if (sizeof (VAL) < amount) \
{ \
error (ngettext ("internal error: attempt to read %d byte " \
"of data in to %d sized variable", \
"internal error: attempt to read %d bytes " \
"of data in to %d sized variable", \
amount), \
amount, (int) sizeof (VAL)); \
amount = sizeof (VAL); \
} \
if (((PTR) + amount) >= (END)) \
{ \
if ((PTR) < (END)) \
amount = (END) - (PTR); \
else \
amount = 0; \
} \
if (amount == 0 || amount > 8) \
VAL = 0; \
else \
VAL = byte_get ((PTR), amount); \
} \
while (0)
/* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
#define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
do \
{ \
SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
PTR += AMOUNT; \
} \
while (0)
/* Like SAFE_BYTE_GET, but reads a signed value. */
#define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
do \
{ \
unsigned int amount = (AMOUNT); \
if (((PTR) + amount) >= (END)) \
{ \
if ((PTR) < (END)) \
amount = (END) - (PTR); \
else \
amount = 0; \
} \
if (amount) \
VAL = byte_get_signed ((PTR), amount); \
else \
VAL = 0; \
} \
while (0)
/* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
#define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
do \
{ \
SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
PTR += AMOUNT; \
} \
while (0)
#define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
do \
{ \
if (((PTR) + 8) <= (END)) \
{ \
byte_get_64 ((PTR), (HIGH), (LOW)); \
} \
else \
{ \
* (LOW) = * (HIGH) = 0; \
} \
} \
while (0)
typedef struct State_Machine_Registers
{
dwarf_vma address;
unsigned int view;
unsigned int file;
unsigned int line;
unsigned int column;
int is_stmt;
int basic_block;
unsigned char op_index;
unsigned char end_sequence;
/* This variable hold the number of the last entry seen
in the File Table. */
unsigned int last_file_entry;
} SMR;
static SMR state_machine_regs;
static void
reset_state_machine (int is_stmt)
{
state_machine_regs.address = 0;
state_machine_regs.view = 0;
state_machine_regs.op_index = 0;
state_machine_regs.file = 1;
state_machine_regs.line = 1;
state_machine_regs.column = 0;
state_machine_regs.is_stmt = is_stmt;
state_machine_regs.basic_block = 0;
state_machine_regs.end_sequence = 0;
state_machine_regs.last_file_entry = 0;
}
/* Handled an extend line op.
Returns the number of bytes read. */
static int
process_extended_line_op (unsigned char * data,
int is_stmt,
unsigned char * end)
{
unsigned char op_code;
unsigned int bytes_read;
unsigned int len;
unsigned char *name;
unsigned char *orig_data = data;
dwarf_vma adr;
len = read_uleb128 (data, & bytes_read, end);
data += bytes_read;
if (len == 0 || data == end || len > (uintptr_t) (end - data))
{
warn (_("Badly formed extended line op encountered!\n"));
return bytes_read;
}
len += bytes_read;
op_code = *data++;
printf (_(" Extended opcode %d: "), op_code);
switch (op_code)
{
case DW_LNE_end_sequence:
printf (_("End of Sequence\n\n"));
reset_state_machine (is_stmt);
break;
case DW_LNE_set_address:
/* PR 17512: file: 002-100480-0.004. */
if (len - bytes_read - 1 > 8)
{
warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
len - bytes_read - 1);
adr = 0;
}
else
SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
state_machine_regs.address = adr;
state_machine_regs.view = 0;
state_machine_regs.op_index = 0;
break;
case DW_LNE_define_file:
printf (_("define new File Table entry\n"));
printf (_(" Entry\tDir\tTime\tSize\tName\n"));
printf (" %d\t", ++state_machine_regs.last_file_entry);
{
size_t l;
name = data;
l = strnlen ((char *) data, end - data);
data += len + 1;
printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
data += bytes_read;
printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
data += bytes_read;
printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
data += bytes_read;
printf ("%.*s\n\n", (int) l, name);
}
if (((unsigned int) (data - orig_data) != len) || data == end)
warn (_("DW_LNE_define_file: Bad opcode length\n"));
break;
case DW_LNE_set_discriminator:
printf (_("set Discriminator to %s\n"),
dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
break;
/* HP extensions. */
case DW_LNE_HP_negate_is_UV_update:
printf ("DW_LNE_HP_negate_is_UV_update\n");
break;
case DW_LNE_HP_push_context:
printf ("DW_LNE_HP_push_context\n");
break;
case DW_LNE_HP_pop_context:
printf ("DW_LNE_HP_pop_context\n");
break;
case DW_LNE_HP_set_file_line_column:
printf ("DW_LNE_HP_set_file_line_column\n");
break;
case DW_LNE_HP_set_routine_name:
printf ("DW_LNE_HP_set_routine_name\n");
break;
case DW_LNE_HP_set_sequence:
printf ("DW_LNE_HP_set_sequence\n");
break;
case DW_LNE_HP_negate_post_semantics:
printf ("DW_LNE_HP_negate_post_semantics\n");
break;
case DW_LNE_HP_negate_function_exit:
printf ("DW_LNE_HP_negate_function_exit\n");
break;
case DW_LNE_HP_negate_front_end_logical:
printf ("DW_LNE_HP_negate_front_end_logical\n");
break;
case DW_LNE_HP_define_proc:
printf ("DW_LNE_HP_define_proc\n");
break;
case DW_LNE_HP_source_file_correlation:
{
unsigned char *edata = data + len - bytes_read - 1;
printf ("DW_LNE_HP_source_file_correlation\n");
while (data < edata)
{
unsigned int opc;
opc = read_uleb128 (data, & bytes_read, edata);
data += bytes_read;
switch (opc)
{
case DW_LNE_HP_SFC_formfeed:
printf (" DW_LNE_HP_SFC_formfeed\n");
break;
case DW_LNE_HP_SFC_set_listing_line:
printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
dwarf_vmatoa ("u",
read_uleb128 (data, & bytes_read, edata)));
data += bytes_read;
break;
case DW_LNE_HP_SFC_associate:
printf (" DW_LNE_HP_SFC_associate ");
printf ("(%s",
dwarf_vmatoa ("u",
read_uleb128 (data, & bytes_read, edata)));
data += bytes_read;
printf (",%s",
dwarf_vmatoa ("u",
read_uleb128 (data, & bytes_read, edata)));
data += bytes_read;
printf (",%s)\n",
dwarf_vmatoa ("u",
read_uleb128 (data, & bytes_read, edata)));
data += bytes_read;
break;
default:
printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
data = edata;
break;
}
}
}
break;
default:
{
unsigned int rlen = len - bytes_read - 1;
if (op_code >= DW_LNE_lo_user
/* The test against DW_LNW_hi_user is redundant due to
the limited range of the unsigned char data type used
for op_code. */
/*&& op_code <= DW_LNE_hi_user*/)
printf (_("user defined: "));
else
printf (_("UNKNOWN: "));
printf (_("length %d ["), rlen);
for (; rlen; rlen--)
printf (" %02x", *data++);
printf ("]\n");
}
break;
}
return len;
}
static const unsigned char *
fetch_indirect_string (dwarf_vma offset)
{
struct dwarf_section *section = &debug_displays [str].section;
const unsigned char * ret;
if (section->start == NULL)
return (const unsigned char *) _("<no .debug_str section>");
if (offset >= section->size)
{
warn (_("DW_FORM_strp offset too big: %s\n"),
dwarf_vmatoa ("x", offset));
return (const unsigned char *) _("<offset is too big>");
}
ret = section->start + offset;
/* Unfortunately we cannot rely upon the .debug_str section ending with a
NUL byte. Since our caller is expecting to receive a well formed C
string we test for the lack of a terminating byte here. */
if (strnlen ((const char *) ret, section->size - offset)
== section->size - offset)
ret = (const unsigned char *)
_("<no NUL byte at end of .debug_str section>");
return ret;
}
static const unsigned char *
fetch_indirect_line_string (dwarf_vma offset)
{
struct dwarf_section *section = &debug_displays [line_str].section;
const unsigned char * ret;
if (section->start == NULL)
return (const unsigned char *) _("<no .debug_line_str section>");
if (offset >= section->size)
{
warn (_("DW_FORM_line_strp offset too big: %s\n"),
dwarf_vmatoa ("x", offset));
return (const unsigned char *) _("<offset is too big>");
}
ret = section->start + offset;
/* Unfortunately we cannot rely upon the .debug_line_str section ending
with a NUL byte. Since our caller is expecting to receive a well formed
C string we test for the lack of a terminating byte here. */
if (strnlen ((const char *) ret, section->size - offset)
== section->size - offset)
ret = (const unsigned char *)
_("<no NUL byte at end of .debug_line_str section>");
return ret;
}
static const char *
fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
dwarf_vma offset_size, bfd_boolean dwo)
{
enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
dwarf_vma index_offset = idx * offset_size;
dwarf_vma str_offset;
const char * ret;
if (index_section->start == NULL)
return (dwo ? _("<no .debug_str_offsets.dwo section>")
: _("<no .debug_str_offsets section>"));
if (this_set != NULL)
index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
if (index_offset >= index_section->size)
{
warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
dwarf_vmatoa ("x", index_offset));
return _("<index offset is too big>");
}
if (str_section->start == NULL)
return (dwo ? _("<no .debug_str.dwo section>")
: _("<no .debug_str section>"));
str_offset = byte_get (index_section->start + index_offset, offset_size);
str_offset -= str_section->address;
if (str_offset >= str_section->size)
{
warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
dwarf_vmatoa ("x", str_offset));
return _("<indirect index offset is too big>");
}
ret = (const char *) str_section->start + str_offset;
/* Unfortunately we cannot rely upon str_section ending with a NUL byte.
Since our caller is expecting to receive a well formed C string we test
for the lack of a terminating byte here. */
if (strnlen (ret, str_section->size - str_offset)
== str_section->size - str_offset)
ret = (const char *) _("<no NUL byte at end of section>");
return ret;
}
static const char *
fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
{
struct dwarf_section *section = &debug_displays [debug_addr].section;
if (section->start == NULL)
return (_("<no .debug_addr section>"));
if (offset + bytes > section->size)
{
warn (_("Offset into section %s too big: %s\n"),
section->name, dwarf_vmatoa ("x", offset));
return "<offset too big>";
}
return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
}
/* FIXME: There are better and more efficient ways to handle
these structures. For now though, I just want something that
is simple to implement. */
typedef struct abbrev_attr
{
unsigned long attribute;
unsigned long form;
bfd_signed_vma implicit_const;
struct abbrev_attr *next;
}
abbrev_attr;
typedef struct abbrev_entry
{
unsigned long entry;
unsigned long tag;
int children;
struct abbrev_attr *first_attr;
struct abbrev_attr *last_attr;
struct abbrev_entry *next;
}
abbrev_entry;
static abbrev_entry *first_abbrev = NULL;
static abbrev_entry *last_abbrev = NULL;
static void
free_abbrevs (void)
{
abbrev_entry *abbrv;
for (abbrv = first_abbrev; abbrv;)
{
abbrev_entry *next_abbrev = abbrv->next;
abbrev_attr *attr;
for (attr = abbrv->first_attr; attr;)
{
abbrev_attr *next_attr = attr->next;
free (attr);
attr = next_attr;
}
free (abbrv);
abbrv = next_abbrev;
}
last_abbrev = first_abbrev = NULL;
}
static void
add_abbrev (unsigned long number, unsigned long tag, int children)
{
abbrev_entry *entry;
entry = (abbrev_entry *) malloc (sizeof (*entry));
if (entry == NULL)
/* ugg */
return;
entry->entry = number;
entry->tag = tag;
entry->children = children;
entry->first_attr = NULL;
entry->last_attr = NULL;
entry->next = NULL;
if (first_abbrev == NULL)
first_abbrev = entry;
else
last_abbrev->next = entry;
last_abbrev = entry;
}
static void
add_abbrev_attr (unsigned long attribute, unsigned long form,
bfd_signed_vma implicit_const)
{
abbrev_attr *attr;
attr = (abbrev_attr *) malloc (sizeof (*attr));
if (attr == NULL)
/* ugg */
return;
attr->attribute = attribute;
attr->form = form;
attr->implicit_const = implicit_const;
attr->next = NULL;
if (last_abbrev->first_attr == NULL)
last_abbrev->first_attr = attr;
else
last_abbrev->last_attr->next = attr;
last_abbrev->last_attr = attr;
}
/* Processes the (partial) contents of a .debug_abbrev section.
Returns NULL if the end of the section was encountered.
Returns the address after the last byte read if the end of
an abbreviation set was found. */
static unsigned char *
process_abbrev_section (unsigned char *start, unsigned char *end)
{
if (first_abbrev != NULL)
return NULL;
while (start < end)
{
unsigned int bytes_read;
unsigned long entry;
unsigned long tag;
unsigned long attribute;
int children;
entry = read_uleb128 (start, & bytes_read, end);
start += bytes_read;
/* A single zero is supposed to end the section according
to the standard. If there's more, then signal that to
the caller. */
if (start == end)
return NULL;
if (entry == 0)
return start;
tag = read_uleb128 (start, & bytes_read, end);
start += bytes_read;
if (start == end)
return NULL;
children = *start++;
add_abbrev (entry, tag, children);
do
{
unsigned long form;
/* Initialize it due to a false compiler warning. */
bfd_signed_vma implicit_const = -1;
attribute = read_uleb128 (start, & bytes_read, end);
start += bytes_read;
if (start == end)
break;
form = read_uleb128 (start, & bytes_read, end);
start += bytes_read;
if (start == end)
break;
if (form == DW_FORM_implicit_const)
{
implicit_const = read_sleb128 (start, & bytes_read, end);
start += bytes_read;
if (start == end)
break;
}
add_abbrev_attr (attribute, form, implicit_const);
}
while (attribute != 0);
}
/* Report the missing single zero which ends the section. */
error (_(".debug_abbrev section not zero terminated\n"));
return NULL;
}
static const char *
get_TAG_name (unsigned long tag)
{
const char *name = get_DW_TAG_name ((unsigned int) tag);