Skip to content

Commit e75cc02

Browse files
committed
Now has example of dwarf_validate_die_sibling()
even though that is not something one needs to use. This is all essentially documentation changes. Ready for release. modified: doc/checkexamples.c modified: doc/libdwarf.dox modified: doc/libdwarf.pdf modified: src/lib/libdwarf/libdwarf.h
1 parent 59b57ab commit e75cc02

File tree

4 files changed

+136
-17
lines changed

4 files changed

+136
-17
lines changed

doc/checkexamples.c

Lines changed: 112 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,109 @@ void example5(Dwarf_Die in_die)
384384
}
385385
/*! @endcode */
386386

387+
/*! @defgroup example_sibvalid using dwarf_validate_die_sibling
388+
@brief A DIE tree validation.
389+
390+
Here we show how one uses
391+
dwarf_validate_die_sibling().
392+
Dwarfdump uses this function as a part of its
393+
valdation of DIE trees.
394+
395+
It is not something you need to use.
396+
But one must use it in a specific pattern
397+
for it to work properly.
398+
399+
dwarf_validate_die_sibling() depends on data set
400+
by dwarf_child() preceeding dwarf_siblingof_b() .
401+
dwarf_child() records a little bit
402+
of information invisibly in the Dwarf_Debug data.
403+
404+
@code
405+
*/
406+
407+
int example_sibvalid(Dwarf_Debug dbg,
408+
Dwarf_Die in_die,
409+
Dwarf_Error*error)
410+
{
411+
int cres = DW_DLV_OK;
412+
int sibres = DW_DLV_OK;
413+
Dwarf_Die die = 0;
414+
Dwarf_Die sibdie = 0;
415+
Dwarf_Die child = 0;
416+
Dwarf_Bool is_info = dwarf_get_die_infotypes_flag(die);
417+
418+
die = in_die;
419+
for ( ; die ; die = sibdie) {
420+
int vres = 0;
421+
Dwarf_Unsigned offset = 0;
422+
423+
/* Maybe print something you extract from the DIE */
424+
cres = dwarf_child(die,&child,error);
425+
if (cres == DW_DLV_ERROR) {
426+
if (die != in_die) {
427+
dwarf_dealloc_die(die);
428+
}
429+
printf("dwarf_child ERROR\n");
430+
return DW_DLV_ERROR;
431+
}
432+
if (cres == DW_DLV_OK) {
433+
int lres = 0;
434+
435+
child = 0;
436+
lres = example_sibvalid(dbg,child,error);
437+
if (lres == DW_DLV_ERROR) {
438+
if (die != in_die) {
439+
dwarf_dealloc_die(die);
440+
}
441+
dwarf_dealloc_die(child);
442+
printf("example_sibvalid ERROR\n");
443+
return lres;
444+
}
445+
}
446+
sibdie = 0;
447+
sibres = dwarf_siblingof_b(dbg,die,is_info,
448+
&sibdie,error);
449+
if (sibres == DW_DLV_ERROR) {
450+
if (die != in_die) {
451+
dwarf_dealloc_die(die);
452+
}
453+
if (child) {
454+
dwarf_dealloc_die(child);
455+
}
456+
printf("dwarf_siblinof_b ERROR\n");
457+
return DW_DLV_ERROR;
458+
}
459+
if (sibres == DW_DLV_NO_ENTRY) {
460+
if (die != in_die) {
461+
dwarf_dealloc_die(die);
462+
}
463+
if (child) {
464+
dwarf_dealloc_die(child);
465+
}
466+
return DW_DLV_OK;
467+
}
468+
vres = dwarf_validate_die_sibling(sibdie,&offset);
469+
if (vres == DW_DLV_ERROR) {
470+
if (die != in_die) {
471+
dwarf_dealloc_die(die);
472+
}
473+
if (child) {
474+
dwarf_dealloc_die(child);
475+
}
476+
dwarf_dealloc_die(sibdie);
477+
printf("Invalid sibling DIE\n");
478+
return DW_DLV_ERROR;
479+
}
480+
/* loop again */
481+
if (die != in_die) {
482+
dwarf_dealloc_die(die);
483+
}
484+
die = 0;
485+
}
486+
return DW_DLV_OK;
487+
}
488+
/*! @endcode */
489+
387490
/*! @defgroup examplecuhdr Example walking CUs
388491
389492
@brief Accessing all CUs looking for specific items.
@@ -824,7 +927,7 @@ int example_discr_list(Dwarf_Debug dbg,
824927
This example simply *assumes* the attribute
825928
has a form which relates to location lists
826929
or location expressions. Use dwarf_get_form_class()
827-
to determine if this attribute fits.
930+
to determine if this attribute fits.
828931
Use dwarf_get_version_of_die() to help get the
829932
data you need.
830933
@see dwarf_get_form_class
@@ -1293,7 +1396,7 @@ int exampleg(Dwarf_Debug dbg, Dwarf_Error *error)
12931396
12941397
This section is an SGI/MIPS extension, not created
12951398
by modern compilers.
1296-
You
1399+
You
12971400
12981401
@code
12991402
*/
@@ -1305,7 +1408,7 @@ int exampleh(Dwarf_Debug dbg,Dwarf_Error *error)
13051408
int res = 0;
13061409

13071410
res = dwarf_globals_by_type(dbg,DW_GL_WEAKS,
1308-
&weaks,&count,error);
1411+
&weaks,&count,error);
13091412
if (res != DW_DLV_OK) {
13101413
return res;
13111414
}
@@ -1333,7 +1436,7 @@ int examplej(Dwarf_Debug dbg, Dwarf_Error*error)
13331436
int fres = 0;
13341437

13351438
fres = dwarf_globals_by_type(dbg,DW_GL_FUNCS,
1336-
&funcs,&count,error);
1439+
&funcs,&count,error);
13371440
if (fres != DW_DLV_OK) {
13381441
return fres;
13391442
}
@@ -1361,7 +1464,7 @@ int examplel(Dwarf_Debug dbg, Dwarf_Error *error)
13611464
int res = 0;
13621465

13631466
res = dwarf_globals_by_type(dbg,DW_GL_TYPES,
1364-
&types,&count,error);
1467+
&types,&count,error);
13651468
if (res != DW_DLV_OK) {
13661469
return res;
13671470
}
@@ -1389,7 +1492,7 @@ int examplen(Dwarf_Debug dbg,Dwarf_Error *error)
13891492
int res = 0;
13901493

13911494
res = dwarf_globals_by_type(dbg,DW_GL_VARS,
1392-
&vars,&count,error);
1495+
&vars,&count,error);
13931496
if (res != DW_DLV_OK) {
13941497
return res;
13951498
}
@@ -2448,9 +2551,9 @@ int examplehighpc(Dwarf_Die die,
24482551
enum Dwarf_Form_Class formclass = DW_FORM_CLASS_UNKNOWN;
24492552

24502553
res = dwarf_highpc_b(die,&localhighpc,
2451-
&form,&formclass, error);
2554+
&form,&formclass, error);
24522555
if (res != DW_DLV_OK) {
2453-
return res;
2556+
return res;
24542557
}
24552558
if (form != DW_FORM_addr &&
24562559
!dwarf_addr_form_is_indexed(form)) {
@@ -2460,7 +2563,7 @@ int examplehighpc(Dwarf_Die die,
24602563
DW_AT_low_pc. */
24612564
res = dwarf_lowpc(die,&low_pc,error);
24622565
if (res != DW_DLV_OK) {
2463-
return res;
2566+
return res;
24642567
} else {
24652568
localhighpc += low_pc;
24662569
}
@@ -2470,7 +2573,6 @@ int examplehighpc(Dwarf_Die die,
24702573
}
24712574
/*! @endcode */
24722575

2473-
24742576
/*! @defgroup exampleza Reading Split Dwarf (Debug Fission) data
24752577
@brief Example getting cu/tu name, offset
24762578

doc/libdwarf.dox

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@tableofcontents{HTML:3,LaTeX:3}
44
@author David Anderson
55
@copyright This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
6-
@date 2023-04-27 v0.7.0
6+
@date 2023-05-20 v0.7.0
77

88
@section draft Suggestions for improvement are welcome.
99

@@ -907,6 +907,8 @@
907907

908908
<b>Changes 0.6.0 to 0.7.0</b>
909909

910+
v0.7.0 released 2023-05-20
911+
910912
Elf section counts can exceed 16 bits
911913
(on linux see <b>man 5 elf</b>)
912914
so some function prototype members
@@ -919,7 +921,10 @@
919921
instead of Dwarf_Half.
920922
Without this change executables/objects
921923
with more than 64K sections cannot
922-
be read by libdwarf.
924+
be read by libdwarf. This is unlikely
925+
to affect your code since for most users
926+
libdwarf takes care of this and dwarfdump
927+
is aware of this change.
923928

924929
Two functions have been removed from libdwarf.h
925930
and the library: dwarf_dnames_abbrev_by_code()

doc/libdwarf.pdf

3.25 KB
Binary file not shown.

src/lib/libdwarf/libdwarf.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,13 +2227,25 @@ DW_API int dwarf_die_abbrev_code(Dwarf_Die dw_die);
22272227
DW_API int dwarf_die_abbrev_children_flag(Dwarf_Die dw_die,
22282228
Dwarf_Half * dw_ab_has_child);
22292229

2230-
/*! @brief Validate a sibling DIE.
2230+
/*! @brief Validate a sibling DIE.
22312231
22322232
This is used by dwarfdump (when
2233-
dwarfdump is checking for valid DWARF but
2234-
it depends on the caller to have done
2235-
precise setup. Ignore it or read the comments
2236-
for this function in dwarf_die_deliv.c.
2233+
dwarfdump is checking for valid DWARF)
2234+
to try to catch a corrupt DIE tree.
2235+
2236+
@see example_sibvalid
2237+
2238+
@param dw_sibling
2239+
Pass in a DIE returned by dwarf_siblingof_b().
2240+
@param dw_offset
2241+
Set to zero through the pointer.
2242+
@return
2243+
Returns DW_DLV_OK if the sibling is
2244+
at an appropriate place in the section.
2245+
Otherwise it returns DW_DLV_ERROR indicating
2246+
the DIE tree is corrupt.
2247+
2248+
22372249
*/
22382250
DW_API int dwarf_validate_die_sibling(Dwarf_Die dw_sibling,
22392251
Dwarf_Off* dw_offset);

0 commit comments

Comments
 (0)