@@ -31,15 +31,21 @@ cc -c -Wall -O0 -Wpointer-arith \
3131#define FALSE 0
3232
3333/*! @defgroup exampleinit Using dwarf_init_path()
34+
3435 @brief Example of a libdwarf initialization call.
3536
3637 An example calling dwarf_init_path() and dwarf_finish()
3738 @param path
3839 Path to an object we wish to open.
3940 @param groupnumber
41+ Desired groupnumber. Use DW_DW_GROUPNUMBER_ANY
42+ unless you have reason to do otherwise.
43+ @return
44+ Returns the applicable result. DW_DLV_OK etc.
45+
4046 @code
4147*/
42- void exampleinit (const char * path , unsigned groupnumber )
48+ int exampleinit (const char * path , unsigned groupnumber )
4349{
4450 static char true_pathbuf [FILENAME_MAX ];
4551 unsigned tpathlen = FILENAME_MAX ;
@@ -56,54 +62,67 @@ void exampleinit(const char *path, unsigned groupnumber)
5662 /* Necessary call even though dbg is null!
5763 This avoids a memory leak. */
5864 dwarf_dealloc_error (dbg ,error );
59- return ;
65+ return res ;
6066 }
6167 if (res == DW_DLV_NO_ENTRY ) {
6268 /* Nothing we can do */
63- return ;
69+ return res ;
6470 }
6571 printf ("The file we actually opened is %s\n" ,
6672 true_pathbuf );
6773 /* Call libdwarf functions here */
6874 dwarf_finish (dbg );
75+ return DW_DLV_OK ;
6976}
7077/*! @endcode */
7178
7279/*! @defgroup exampleinit_dl Using dwarf_init_path_dl()
80+
7381 @brief Example focused on GNU debuglink data
7482
7583 In case GNU debuglink data is followed the true_pathbuf
7684 content will not match path.
7785 The path actually used is copied to true_path_out.
86+
7887 In the case of MacOS dSYM the true_path_out
7988 may not match path.
80- If debuglink missing from the Elf executable
89+
90+ If debuglink data is missing from the Elf executable
8191 or shared-object (ie, it is a normal
8292 object!) or unusable by libdwarf or
8393 true_path_buffer len is zero or true_path_out_buffer
8494 is zero libdwarf accepts the path given as the object
8595 to report on, no debuglink or dSYM processing will be used.
8696
87- @sa https://sourceware.org/gdb/onlinedocs/\
88- gdb/Separate-Debug-Files.html
97+ @see https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html
8998
9099 An example calling dwarf_init_path_dl() and dwarf_finish()
100+
101+ @param path
102+ Path to an object we wish to open.
103+ @param groupnumber
104+ Desired groupnumber. Use DW_DW_GROUPNUMBER_ANY
105+ unless you have reason to do otherwise.
106+ @param error
107+ A pointer we can use to record error details.
108+ @return
109+ Returns the applicable result. DW_DLV_OK etc.
110+
91111 @code
92112*/
93- int exampleinit_dl (const char * path , unsigned groupnumber ,
94- Dwarf_Error * error )
113+ int exampleinit_dl (const char * path , unsigned groupnumber , Dwarf_Error * error )
95114{
96115 static char true_pathbuf [FILENAME_MAX ];
97116 static const char * glpath [3 ] = {
98117 "/usr/local/debug" ,
99118 "/usr/local/private/debug" ,
100119 "/usr/local/libdwarf/debug"
101120 };
102- unsigned tpathlen = FILENAME_MAX ;
121+ unsigned tpathlen = FILENAME_MAX ;
103122 Dwarf_Handler errhand = 0 ;
104- Dwarf_Ptr errarg = 0 ;
105- Dwarf_Debug dbg = 0 ;
106- int res = 0 ;
123+ Dwarf_Ptr errarg = 0 ;
124+ Dwarf_Debug dbg = 0 ;
125+ int res = 0 ;
107126 unsigned char path_source = 0 ;
108127
109128 res = dwarf_init_path_dl (path ,true_pathbuf ,
@@ -114,11 +133,12 @@ int exampleinit_dl(const char *path, unsigned groupnumber,
114133 & path_source ,
115134 error );
116135 if (res == DW_DLV_ERROR ) {
117- /* Necessary call even though dbg is null!
118- This avoids a memory leak. */
136+ /* We are not returning dbg, so we must do:
137+ dwarf_dealloc_error(dbg,*error);
138+ here to free the error details. */
119139 dwarf_dealloc_error (dbg ,* error );
120140 * error = 0 ;
121- return DW_DLV_NO_ENTRY ;
141+ return res ;
122142 }
123143 if (res == DW_DLV_NO_ENTRY ) {
124144 return res ;
@@ -127,13 +147,21 @@ int exampleinit_dl(const char *path, unsigned groupnumber,
127147 true_pathbuf );
128148 /* Call libdwarf functions here */
129149 dwarf_finish (dbg );
130- return DW_DLV_OK ;
150+ return res ;
131151}
132152/*! @endcode */
133153
134154/*! @defgroup example1 Using dwarf_attrlist()
155+
135156 @brief Example showing dwarf_attrlist()
136157
158+ @param somedie
159+ Pass in any valid relevant DIE pointer.
160+ @param error
161+ An error pointer we can use.
162+ @return
163+ Return DW_DLV_OK (etc).
164+
137165 @code
138166*/
139167int example1 (Dwarf_Die somedie ,Dwarf_Error * error )
@@ -201,10 +229,10 @@ int example1(Dwarf_Die somedie,Dwarf_Error *error)
201229 @return
202230 Returns DW_DLV_OK or DW_DLV_ERROR or
203231 DW_DLV_NO_ENTRY to the caller.
232+
204233 @code
205234*/
206- int example2 (Dwarf_Debug split_dbg , Dwarf_Debug tied_dbg ,
207- Dwarf_Error * error )
235+ int example2 (Dwarf_Debug split_dbg , Dwarf_Debug tied_dbg , Dwarf_Error * error )
208236{
209237 int res = 0 ;
210238
@@ -219,7 +247,6 @@ int example2(Dwarf_Debug split_dbg, Dwarf_Debug tied_dbg,
219247 values) deal with doing dwarf_finish()
220248 */
221249 return res ;
222-
223250}
224251/*! @endcode */
225252
@@ -2129,7 +2156,8 @@ int examplep5(Dwarf_Die cu_die,Dwarf_Error *error)
21292156/*! @defgroup examplep2 Reading .debug_macinfo (DWARF2-4)
21302157 @brief Example reading .debug_macinfo, DWARF2-4
21312158
2132- @code */
2159+ @code
2160+ */
21332161
21342162void functionusingsigned (Dwarf_Signed s );
21352163
@@ -2183,7 +2211,8 @@ int examplep2(Dwarf_Debug dbg, Dwarf_Off cur_off,
21832211/*! @defgroup exampleq Extracting fde, cie lists.
21842212 @brief Example Opening FDE and CIE lists
21852213
2186- @code */
2214+ @code
2215+ */
21872216int exampleq (Dwarf_Debug dbg ,Dwarf_Error * error )
21882217{
21892218 Dwarf_Cie * cie_data = 0 ;
@@ -2209,8 +2238,7 @@ int exampleq(Dwarf_Debug dbg,Dwarf_Error *error)
22092238
22102239 @code
22112240*/
2212- int exampler (Dwarf_Debug dbg ,Dwarf_Addr mypcval ,
2213- Dwarf_Error * error )
2241+ int exampler (Dwarf_Debug dbg ,Dwarf_Addr mypcval ,Dwarf_Error * error )
22142242{
22152243 /* Given a pc value
22162244 for a function find the FDE and CIE data for
@@ -2220,18 +2248,19 @@ int exampler(Dwarf_Debug dbg,Dwarf_Addr mypcval,
22202248 dwarf_get_fde_n() allows accessing all FDE/CIE
22212249 data so one could build up an application-specific
22222250 table of information if that is more useful. */
2223- Dwarf_Cie * cie_data = 0 ;
2251+ Dwarf_Cie * cie_data = 0 ;
22242252 Dwarf_Signed cie_count = 0 ;
2225- Dwarf_Fde * fde_data = 0 ;
2253+ Dwarf_Fde * fde_data = 0 ;
22262254 Dwarf_Signed fde_count = 0 ;
2227- int fres = 0 ;
2255+ int fres = 0 ;
22282256
22292257 fres = dwarf_get_fde_list_eh (dbg ,& cie_data ,& cie_count ,
22302258 & fde_data ,& fde_count ,error );
22312259 if (fres == DW_DLV_OK ) {
22322260 Dwarf_Fde myfde = 0 ;
22332261 Dwarf_Addr low_pc = 0 ;
22342262 Dwarf_Addr high_pc = 0 ;
2263+
22352264 fres = dwarf_get_fde_at_pc (fde_data ,mypcval ,
22362265 & myfde ,& low_pc ,& high_pc ,
22372266 error );
@@ -2850,8 +2879,8 @@ int exampleza(Dwarf_Xu_Index_Header xuhdr,
28502879*/
28512880void examplezb (void )
28522881{
2853- const char * out = "unknown something" ;;
2854- int res = 0 ;
2882+ const char * out = "unknown something" ;
2883+ int res = 0 ;
28552884
28562885 /* The following is wrong, do not do it!
28572886 Confusing TAG with ACCESS! */
@@ -2862,12 +2891,12 @@ void examplezb(void)
28622891 out = "<unknown TAG>" ; /* Not a malloc'd string! */
28632892 /* The following is meaningful.*/
28642893 res = dwarf_get_TAG_name (DW_TAG_entry_point ,& out );
2894+ (void )res ; /* avoids unused var compiler warning */
28652895 /* If res == DW_DLV_ERROR or DW_DLV_NO_ENTRY
28662896 out will be the locally assigned static string.
28672897 If res == DW_DLV_OK it will be a usable
28682898 TAG name string.
2869- In no case should a returned string be free()d.
2870- */
2899+ In no case should a returned string be free()d. */
28712900}
28722901/*! @endcode */
28732902
0 commit comments