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
|
/*
Copyright (C) 2000,2002,2003,2004,2005 Silicon Graphics, Inc. All Rights Reserved.
Portions Copyright (C) 2008-2010 Arxan Technologies, Inc. All Rights Reserved.
Portions Copyright (C) 2009-2011 David Anderson. All Rights Reserved.
Portions Copyright (C) 2010 SN Systems Ltd. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it
under the terms of version 2.1 of the GNU Lesser General Public License
as published by the Free Software Foundation.
This program is distributed in the hope that it would be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Further, this software is distributed without any warranty that it is
free of the rightful claim of any third person regarding infringement
or the like. Any license provided herein, whether implied or
otherwise, applies only to this software file. Patent licenses, if
any, provided herein do not apply to combinations of this program with
other software, or any other product whatsoever.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
USA.
Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
Mountain View, CA 94043, or:
http://www.sgi.com
For further information regarding this notice, see:
http://oss.sgi.com/projects/GenInfo/NoticeExplan
*/
#include "config.h"
#include "dwarf_incl.h"
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include "dwarf_incl.h"
#include "dwarf_harmless.h"
#include "malloc_check.h"
#define DWARF_DBG_ERROR(dbg,errval,retval) \
_dwarf_error(dbg, error, errval); return(retval);
#define FALSE 0
#define TRUE 1
/* This static is copied to the dbg on dbg init
so that the static need not be referenced at
run time, preserving better locality of
reference.
Value is 0 means do the string check.
Value non-zero means do not do the check.
*/
static Dwarf_Small _dwarf_assume_string_bad;
static Dwarf_Small _dwarf_apply_relocs = 1;
/* Call this after calling dwarf_init but before doing anything else.
It applies to all objects, not just the current object. */
int
dwarf_set_reloc_application(int apply)
{
int oldval = _dwarf_apply_relocs;
_dwarf_apply_relocs = apply;
return oldval;
}
int
dwarf_set_stringcheck(int newval)
{
int oldval = _dwarf_assume_string_bad;
_dwarf_assume_string_bad = newval;
return oldval;
}
/* Unifies the basic duplicate/empty testing and section
data setting to one place. */
static int
get_basic_section_data(Dwarf_Debug dbg,
struct Dwarf_Section_s *secdata,
struct Dwarf_Obj_Access_Section_s *doas,
Dwarf_Half section_index,
Dwarf_Error* error,
int duperr, int emptyerr )
{
/* There is an elf convention that section index 0 is reserved,
and that section is always empty.
Non-elf object formats must honor that by ensuring that
(when they assign numbers to 'sections' or 'section-like-things')
they never assign a real section section-number 0 to dss_index. */
if (secdata->dss_index != 0) {
DWARF_DBG_ERROR(dbg, duperr, DW_DLV_ERROR);
}
if (doas->size == 0) {
if (emptyerr == 0 ) {
/* Allow empty section. */
return DW_DLV_OK;
}
/* Know no reason to allow section */
DWARF_DBG_ERROR(dbg, emptyerr, DW_DLV_ERROR);
}
secdata->dss_index = section_index;
secdata->dss_size = doas->size;
secdata->dss_addr = doas->addr;
secdata->dss_link = doas->link;
secdata->dss_entrysize = doas->entrysize;
return DW_DLV_OK;
}
static void
add_rela_data( struct Dwarf_Section_s *secdata,
struct Dwarf_Obj_Access_Section_s *doas,
Dwarf_Half section_index)
{
secdata->dss_reloc_index = section_index;
secdata->dss_reloc_size = doas->size;
secdata->dss_reloc_entrysize = doas->entrysize;
secdata->dss_reloc_addr = doas->addr;
secdata->dss_reloc_symtab = doas->link;
secdata->dss_reloc_link = doas->link;
}
/* Given an Elf ptr, set up dbg with pointers
to all the Dwarf data sections.
Return NULL on error.
This function is also responsible for determining
whether the given object contains Dwarf information
or not. The test currently used is that it contains
either a .debug_info or a .debug_frame section. If
not, it returns DW_DLV_NO_ENTRY causing dwarf_init() also to
return DW_DLV_NO_ENTRY. Earlier, we had thought of using only
the presence/absence of .debug_info to test, but we
added .debug_frame since there could be stripped objects
that have only a .debug_frame section for exception
processing.
DW_DLV_NO_ENTRY or DW_DLV_OK or DW_DLV_ERROR */
static int
_dwarf_setup(Dwarf_Debug dbg, Dwarf_Error * error)
{
const char *scn_name = 0;
int foundDwarf = 0;
struct Dwarf_Obj_Access_Interface_s * obj = 0;
Dwarf_Endianness endianness;
Dwarf_Unsigned section_size = 0;
Dwarf_Unsigned section_count = 0;
Dwarf_Half section_index = 0;
Dwarf_Addr section_addr = 0;
foundDwarf = FALSE;
dbg->de_assume_string_in_bounds = _dwarf_assume_string_bad;
dbg->de_same_endian = 1;
dbg->de_copy_word = memcpy;
obj = dbg->de_obj_file;
endianness = obj->methods->get_byte_order(obj->object);
#ifdef WORDS_BIGENDIAN
dbg->de_big_endian_object = 1;
if (endianness == DW_OBJECT_LSB ) {
dbg->de_same_endian = 0;
dbg->de_big_endian_object = 0;
dbg->de_copy_word = _dwarf_memcpy_swap_bytes;
}
#else /* little endian */
dbg->de_big_endian_object = 0;
if (endianness == DW_OBJECT_MSB ) {
dbg->de_same_endian = 0;
dbg->de_big_endian_object = 1;
dbg->de_copy_word = _dwarf_memcpy_swap_bytes;
}
#endif /* !WORDS_BIGENDIAN */
/* The following de_length_size is Not Too Significant. Only used
one calculation, and an approximate one at that. */
dbg->de_length_size = obj->methods->get_length_size(obj->object);
dbg->de_pointer_size = obj->methods->get_pointer_size(obj->object);
/* For windows always is 4 ? */
#ifdef WIN32
dbg->de_pointer_size = 4;
#endif /* WIN32 */
section_count = obj->methods->get_section_count(obj->object);
/* We can skip index 0 when considering ELF files, but not other
object types. Indeed regardless of the object type we should
skip section 0 here.
This is a convention. We depend on it.
Non-elf object access code should
(in itself) understand we will index beginning at 1 and adjust
itself to deal with this Elf convention. Without this
convention various parts of the code in this file won't work correctly.
A dss_index of 0 must not be used, even though we start at 0
here. So the get_section_info() must adapt to the situation
(the elf version does automatically as a result of Elf having
a section zero with zero length and an empty name). */
for (section_index = 0; section_index < section_count;
++section_index) {
struct Dwarf_Obj_Access_Section_s doas;
int res = DW_DLV_ERROR;
int err = 0;
memset(&doas,0,sizeof(doas));
res = obj->methods->get_section_info(obj->object,
section_index,
&doas, &err);
if(res == DW_DLV_ERROR){
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
}
section_addr = doas.addr;
section_size = doas.size;
scn_name = doas.name;
if (strncmp(scn_name, ".debug_", 7)
&& strcmp(scn_name, ".eh_frame")
&& strcmp(scn_name, ".symtab")
&& strcmp(scn_name, ".strtab")
&& strncmp(scn_name, ".rela.",6)) {
continue;
}
else if (strcmp(scn_name, ".debug_info") == 0) {
res = get_basic_section_data(dbg,&dbg->de_debug_info, &doas,
section_index,error,
DW_DLE_DEBUG_INFO_DUPLICATE,DW_DLE_DEBUG_INFO_NULL);
if(res != DW_DLV_OK) {
return res;
}
foundDwarf = TRUE;
}
else if (strcmp(scn_name, ".debug_types") == 0) {
res = get_basic_section_data(dbg,&dbg->de_debug_types, &doas,
section_index,error,
DW_DLE_DEBUG_TYPES_DUPLICATE,DW_DLE_DEBUG_TYPES_NULL);
if(res != DW_DLV_OK) {
return res;
}
foundDwarf = TRUE;
}
else if (strcmp(scn_name, ".debug_abbrev") == 0) {
res = get_basic_section_data(dbg,&dbg->de_debug_abbrev, &doas,
section_index,error,
DW_DLE_DEBUG_ABBREV_DUPLICATE,DW_DLE_DEBUG_ABBREV_NULL);
if(res != DW_DLV_OK) {
return res;
}
}
else if (strcmp(scn_name, ".debug_aranges") == 0) {
res = get_basic_section_data(dbg,&dbg->de_debug_aranges, &doas,
section_index,error, DW_DLE_DEBUG_ARANGES_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
}
else if (strcmp(scn_name, ".debug_line") == 0) {
res = get_basic_section_data(dbg,&dbg->de_debug_line, &doas,
section_index,error, DW_DLE_DEBUG_LINE_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
}
else if (strcmp(scn_name, ".debug_frame") == 0) {
res = get_basic_section_data(dbg,&dbg->de_debug_frame, &doas,
section_index,error, DW_DLE_DEBUG_FRAME_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
foundDwarf = TRUE;
} else if (strcmp(scn_name, ".eh_frame") == 0) {
/* gnu egcs-1.1.2 data */
res = get_basic_section_data(dbg,&dbg->de_debug_frame_eh_gnu,
&doas,
section_index,error, DW_DLE_DEBUG_FRAME_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
foundDwarf = TRUE;
}
else if (strcmp(scn_name, ".debug_loc") == 0) {
res = get_basic_section_data(dbg,&dbg->de_debug_loc, &doas,
section_index,error, DW_DLE_DEBUG_LOC_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
}
else if (strcmp(scn_name, ".debug_pubnames") == 0) {
res = get_basic_section_data(dbg,&dbg->de_debug_pubnames, &doas,
section_index,error, DW_DLE_DEBUG_PUBNAMES_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
}
else if (strcmp(scn_name, ".debug_str") == 0) {
res = get_basic_section_data(dbg,&dbg->de_debug_str, &doas,
section_index,error, DW_DLE_DEBUG_STR_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
}
else if (strcmp(scn_name, ".debug_funcnames") == 0) {
/* SGI IRIX-only. */
res = get_basic_section_data(dbg,&dbg->de_debug_funcnames,
&doas,
section_index,error, DW_DLE_DEBUG_FUNCNAMES_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
}
else if (strcmp(scn_name, ".debug_typenames") == 0) {
/* SGI IRIX-only, created years before DWARF3. Content
essentially identical to .debug_pubtypes. */
res = get_basic_section_data(dbg,&dbg->de_debug_typenames,
&doas,
section_index,error, DW_DLE_DEBUG_TYPENAMES_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
} else if (strcmp(scn_name, ".debug_pubtypes") == 0) {
/* Section new in DWARF3. */
res = get_basic_section_data(dbg,&dbg->de_debug_pubtypes, &doas,
section_index,error, DW_DLE_DEBUG_PUBTYPES_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
}
else if (strcmp(scn_name, ".debug_varnames") == 0) {
/* SGI IRIX-only. */
res = get_basic_section_data(dbg,&dbg->de_debug_varnames, &doas,
section_index,error, DW_DLE_DEBUG_VARNAMES_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
}
else if (strcmp(scn_name, ".debug_weaknames") == 0) {
/* SGI IRIX-only. */
res = get_basic_section_data(dbg,&dbg->de_debug_weaknames,
&doas, section_index,error,
DW_DLE_DEBUG_WEAKNAMES_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
} else if (strcmp(scn_name, ".debug_macinfo") == 0) {
res = get_basic_section_data(dbg,&dbg->de_debug_macinfo, &doas,
section_index,error, DW_DLE_DEBUG_MACINFO_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
}
else if (strcmp(scn_name, ".debug_ranges") == 0) {
res = get_basic_section_data(dbg,&dbg->de_debug_ranges, &doas,
section_index,error, DW_DLE_DEBUG_RANGES_DUPLICATE,0);
if(res != DW_DLV_OK) {
return res;
}
foundDwarf = TRUE;
}
else if (strcmp(scn_name, ".symtab") == 0) {
res = get_basic_section_data(dbg,&dbg->de_elf_symtab, &doas,
section_index,error, DW_DLE_DEBUG_SYMTAB_ERR,0);
if(res != DW_DLV_OK) {
return res;
}
}
else if (strcmp(scn_name, ".strtab") == 0) {
res = get_basic_section_data(dbg,&dbg->de_elf_strtab, &doas,
section_index,error, DW_DLE_DEBUG_STRTAB_ERR,0);
if(res != DW_DLV_OK) {
return res;
}
}
else if (strncmp(scn_name, ".rela.debug_",12) == 0) {
const char *rcn_name = scn_name + 5;
if (strcmp(rcn_name, ".debug_info") == 0) {
add_rela_data(&dbg->de_debug_info,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_abbrev") == 0) {
add_rela_data(&dbg->de_debug_abbrev,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_aranges") == 0) {
add_rela_data(&dbg->de_debug_aranges,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_line") == 0) {
add_rela_data(&dbg->de_debug_line,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_frame") == 0) {
add_rela_data(&dbg->de_debug_frame,&doas,section_index);
} else if (strcmp(rcn_name, ".eh_frame") == 0) {
add_rela_data(&dbg->de_debug_frame_eh_gnu,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_loc") == 0) {
add_rela_data(&dbg->de_debug_loc,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_pubnames") == 0) {
add_rela_data(&dbg->de_debug_pubnames,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_str") == 0) {
add_rela_data(&dbg->de_debug_str,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_funcnames") == 0) {
add_rela_data(&dbg->de_debug_funcnames,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_typenames") == 0) {
add_rela_data(&dbg->de_debug_typenames,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_pubtypes") == 0) {
add_rela_data(&dbg->de_debug_pubtypes,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_varnames") == 0) {
add_rela_data(&dbg->de_debug_varnames,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_weaknames") == 0) {
add_rela_data(&dbg->de_debug_weaknames,&doas,section_index);
} else if (strcmp(rcn_name, ".debug_macinfo") == 0) {
add_rela_data(&dbg->de_debug_macinfo,&doas,section_index);
}
}
}
if (foundDwarf) {
return DW_DLV_OK;
}
return DW_DLV_NO_ENTRY;
}
/*
Use a Dwarf_Obj_Access_Interface to kick things off. All other
init routines eventually use this one.
The returned Dwarf_Debug contains a copy of *obj
the callers copy of *obj may be freed whenever the caller
wishes.
*/
int
dwarf_object_init(Dwarf_Obj_Access_Interface* obj, Dwarf_Handler errhand,
Dwarf_Ptr errarg, Dwarf_Debug* ret_dbg,
Dwarf_Error* error)
{
Dwarf_Debug dbg = 0;
int setup_result = DW_DLV_OK;
dbg = _dwarf_get_debug();
if (dbg == NULL) {
DWARF_DBG_ERROR(dbg, DW_DLE_DBG_ALLOC, DW_DLV_ERROR);
}
dbg->de_errhand = errhand;
dbg->de_errarg = errarg;
dbg->de_frame_rule_initial_value = DW_FRAME_REG_INITIAL_VALUE;
dbg->de_frame_reg_rules_entry_count = DW_FRAME_LAST_REG_NUM;
#ifdef HAVE_OLD_FRAME_CFA_COL
/* DW_FRAME_CFA_COL is really only suitable for old libdwarf frame
interfaces and its value of 0 there is only usable where
(as in MIPS) register 0 has no value other than 0 so
we can use the frame table column 0 for the CFA value
(and rely on client software to know when 'register 0'
is the cfa and when to just use a value 0 for register 0).
*/
dbg->de_frame_cfa_col_number = DW_FRAME_CFA_COL;
#else
dbg->de_frame_cfa_col_number = DW_FRAME_CFA_COL3;
#endif
dbg->de_frame_same_value_number = DW_FRAME_SAME_VAL;
dbg->de_frame_undefined_value_number = DW_FRAME_UNDEFINED_VAL;
dbg->de_obj_file = obj;
setup_result = _dwarf_setup(dbg, error);
if (setup_result != DW_DLV_OK) {
/* The status we want to return here is of _dwarf_setup,
not of the _dwarf_free_all_of_one_debug(dbg) call.
So use a local status variable for the free. */
int freeresult = _dwarf_free_all_of_one_debug(dbg);
if (freeresult == DW_DLV_ERROR) {
DWARF_DBG_ERROR(dbg, DW_DLE_DBG_ALLOC, DW_DLV_ERROR);
}
dwarf_malloc_check_complete("After Final free");
return setup_result;
}
dwarf_harmless_init(&dbg->de_harmless_errors,
DW_HARMLESS_ERROR_CIRCULAR_LIST_DEFAULT_SIZE);
/* This call cannot fail: allocates nothing, releases nothing */
_dwarf_setup_debug(dbg);
*ret_dbg = dbg;
return DW_DLV_OK;
}
/* A finish routine that is completely unaware of ELF.
Frees all memory that was not previously freed by
dwarf_dealloc.
Aside frmo certain categories. */
int
dwarf_object_finish(Dwarf_Debug dbg, Dwarf_Error * error)
{
int res = DW_DLV_OK;
res = _dwarf_free_all_of_one_debug(dbg);
if (res == DW_DLV_ERROR) {
DWARF_DBG_ERROR(dbg, DW_DLE_DBG_ALLOC, DW_DLV_ERROR);
}
dwarf_malloc_check_complete("After Final free");
return res;
}
/* Load the ELF section with the specified index and set the
pointer pointed to by section_data to the memory where it
was loaded. */
int
_dwarf_load_section(Dwarf_Debug dbg,
struct Dwarf_Section_s *section,
Dwarf_Error * error)
{
int res = DW_DLV_ERROR;
int err = 0;
struct Dwarf_Obj_Access_Interface_s *o = 0;
/* check to see if the section is already loaded */
if (section->dss_data != NULL) {
return DW_DLV_OK;
}
o = dbg->de_obj_file;
/* There is an elf convention that section index 0 is reserved,
and that section is always empty.
Non-elf object formats must honor that by ensuring that
(when they assign numbers to 'sections' or 'section-like-things')
they never assign a real section section-number 0 to dss_index. */
res = o->methods->load_section(
o->object, section->dss_index,
§ion->dss_data, &err);
if(res == DW_DLV_ERROR){
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
}
if(_dwarf_apply_relocs == 0) {
return res;
}
if(section->dss_reloc_size == 0) {
return res;
}
if(!o->methods->relocate_a_section) {
return res;
}
/*apply relocations */
res = o->methods->relocate_a_section( o->object, section->dss_index,
dbg, &err);
if(res == DW_DLV_ERROR) {
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
}
return res;
}
/* This is a hack so clients can verify offsets.
Added April 2005 so that debugger can detect broken offsets
(which happened in an IRIX -64 executable larger than 2GB
using MIPSpro 7.3.1.3 compilers. A couple .debug_pubnames
offsets were wrong.).
*/
int
dwarf_get_section_max_offsets(Dwarf_Debug dbg,
Dwarf_Unsigned * debug_info_size,
Dwarf_Unsigned * debug_abbrev_size,
Dwarf_Unsigned * debug_line_size,
Dwarf_Unsigned * debug_loc_size,
Dwarf_Unsigned * debug_aranges_size,
Dwarf_Unsigned * debug_macinfo_size,
Dwarf_Unsigned * debug_pubnames_size,
Dwarf_Unsigned * debug_str_size,
Dwarf_Unsigned * debug_frame_size,
Dwarf_Unsigned * debug_ranges_size,
Dwarf_Unsigned * debug_typenames_size)
{
*debug_info_size = dbg->de_debug_info.dss_size;
*debug_abbrev_size = dbg->de_debug_abbrev.dss_size;
*debug_line_size = dbg->de_debug_line.dss_size;
*debug_loc_size = dbg->de_debug_loc.dss_size;
*debug_aranges_size = dbg->de_debug_aranges.dss_size;
*debug_macinfo_size = dbg->de_debug_macinfo.dss_size;
*debug_pubnames_size = dbg->de_debug_pubnames.dss_size;
*debug_str_size = dbg->de_debug_str.dss_size;
*debug_frame_size = dbg->de_debug_frame.dss_size;
*debug_ranges_size = dbg->de_debug_ranges.dss_size;
*debug_typenames_size = dbg->de_debug_typenames.dss_size;
return DW_DLV_OK;
}
/* This adds the new types size (new section) to the output data.
Oct 27, 2011. */
int
dwarf_get_section_max_offsets_b(Dwarf_Debug dbg,
Dwarf_Unsigned * debug_info_size,
Dwarf_Unsigned * debug_abbrev_size,
Dwarf_Unsigned * debug_line_size,
Dwarf_Unsigned * debug_loc_size,
Dwarf_Unsigned * debug_aranges_size,
Dwarf_Unsigned * debug_macinfo_size,
Dwarf_Unsigned * debug_pubnames_size,
Dwarf_Unsigned * debug_str_size,
Dwarf_Unsigned * debug_frame_size,
Dwarf_Unsigned * debug_ranges_size,
Dwarf_Unsigned * debug_typenames_size,
Dwarf_Unsigned * debug_types_size)
{
*debug_info_size = dbg->de_debug_info.dss_size;
*debug_abbrev_size = dbg->de_debug_abbrev.dss_size;
*debug_line_size = dbg->de_debug_line.dss_size;
*debug_loc_size = dbg->de_debug_loc.dss_size;
*debug_aranges_size = dbg->de_debug_aranges.dss_size;
*debug_macinfo_size = dbg->de_debug_macinfo.dss_size;
*debug_pubnames_size = dbg->de_debug_pubnames.dss_size;
*debug_str_size = dbg->de_debug_str.dss_size;
*debug_frame_size = dbg->de_debug_frame.dss_size;
*debug_ranges_size = dbg->de_debug_ranges.dss_size;
*debug_typenames_size = dbg->de_debug_typenames.dss_size;
*debug_types_size = dbg->de_debug_types.dss_size;
return DW_DLV_OK;
}
/* Given a section name, get its size and address */
int
dwarf_get_section_info_by_name(Dwarf_Debug dbg,
const char *section_name,
Dwarf_Addr *section_addr,
Dwarf_Unsigned *section_size,
Dwarf_Error * error)
{
struct Dwarf_Obj_Access_Section_s doas;
struct Dwarf_Obj_Access_Interface_s * obj = 0;
Dwarf_Unsigned section_count = 0;
Dwarf_Half section_index = 0;
*section_addr = 0;
*section_size = 0;
obj = dbg->de_obj_file;
if (NULL == obj) {
return DW_DLV_NO_ENTRY;
}
section_count = obj->methods->get_section_count(obj->object);
/* We can skip index 0 when considering ELF files, but not other
object types. */
for (section_index = 0; section_index < section_count;
++section_index) {
int err = 0;
int res = obj->methods->get_section_info(obj->object,
section_index, &doas, &err);
if (res == DW_DLV_ERROR) {
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
}
if (!strcmp(section_name,doas.name)) {
*section_addr = doas.addr;
*section_size = doas.size;
return DW_DLV_OK;
}
}
return DW_DLV_NO_ENTRY;
}
/* Given a section index, get its size and address */
int
dwarf_get_section_info_by_index(Dwarf_Debug dbg,
int section_index,
const char **section_name,
Dwarf_Addr *section_addr,
Dwarf_Unsigned *section_size,
Dwarf_Error * error)
{
*section_addr = 0;
*section_size = 0;
*section_name = NULL;
/* Check if we have a valid section index */
if (section_index >= 0 && section_index < dwarf_get_section_count(dbg)) {
int res = 0;
int err = 0;
struct Dwarf_Obj_Access_Section_s doas;
struct Dwarf_Obj_Access_Interface_s * obj = dbg->de_obj_file;
if (NULL == obj) {
return DW_DLV_NO_ENTRY;
}
res = obj->methods->get_section_info(obj->object,
section_index, &doas, &err);
if (res == DW_DLV_ERROR){
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
}
*section_addr = doas.addr;
*section_size = doas.size;
*section_name = doas.name;
return DW_DLV_OK;
}
return DW_DLV_NO_ENTRY;
}
/* Get section count */
int
dwarf_get_section_count(Dwarf_Debug dbg)
{
struct Dwarf_Obj_Access_Interface_s * obj = dbg->de_obj_file;
if (NULL == obj) {
return DW_DLV_NO_ENTRY;
}
return obj->methods->get_section_count(obj->object);
}
Dwarf_Cmdline_Options dwarf_cmdline_options = {
FALSE /* Use quiet mode by default. */
};
/* Lets libdwarf reflect a command line option, so we can get details
of some errors printed using libdwarf-internal information. */
void
dwarf_record_cmdline_options(Dwarf_Cmdline_Options options)
{
dwarf_cmdline_options = options;
}
|