Skip to content

Commit 3e75142

Browse files
committed
Refining the formatting of the printf output.
modified: src/bin/dwarfdump/print_debug_names.c modified: src/lib/libdwarf/dwarf_debugnames.c A comment noting that specialized access functions are missing, but full access to the section is provided. modified: src/lib/libdwarf/libdwarf.h
1 parent 0965889 commit 3e75142

File tree

3 files changed

+65
-35
lines changed

3 files changed

+65
-35
lines changed

src/bin/dwarfdump/print_debug_names.c

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Copyright 2017-2018 David Anderson. All rights reserved.
3737
#include "dd_esb.h"
3838
#include "dd_esb_using_functions.h"
3939

40-
#define ATTR_ARRAY_SIZE 60
40+
#define ATTR_ARRAY_SIZE 10
4141

4242
#if 0
4343
static void
@@ -247,11 +247,12 @@ print_dnames_abbrevtable(unsigned int indent,Dwarf_Dnames_Head dn,
247247
DW_PR_DUu " bytes.\n", table_length);
248248
printindent(indent);
249249
printf("[] offset code"
250-
" tag idxattr/form count\n");
250+
" count idxattr\n");
251251
res = DW_DLV_OK;
252252
for ( ; res == DW_DLV_OK; ++i) {
253253
Dwarf_Unsigned limit = 0;
254254
Dwarf_Unsigned k = 0;
255+
const char *tagname = "<TAGunknown>";
255256

256257
/* Never returns DW_DLV_ERROR */
257258
res = dwarf_dnames_abbrevtable(dn,i,
@@ -263,12 +264,14 @@ print_dnames_abbrevtable(unsigned int indent,Dwarf_Dnames_Head dn,
263264
if (res == DW_DLV_NO_ENTRY) {
264265
break;
265266
}
266-
printindent(indent);
267+
dwarf_get_TAG_name(abbrev_tag,&tagname);
268+
printindent(indent+2);
267269
printf("[%4" DW_PR_DUu "] ",i);
268270
printf(" 0x%" DW_PR_XZEROS DW_PR_DUx " ",abbrev_offset);
269-
printf(" 0x%05" DW_PR_DUx " ",abbrev_code);
270-
printf(" 0x%04" DW_PR_DUx " ",abbrev_tag);
271+
printf(" 0x%05" DW_PR_DUx "\n",abbrev_code);
271272
printf(" %3" DW_PR_DUu " ",actual_attr_count);
273+
printindent(indent+12);
274+
printf(" 0x%04" DW_PR_DUx " %-16s",abbrev_tag,tagname);
272275
printf("\n");
273276
limit = actual_attr_count;
274277
if (limit > ATTR_ARRAY_SIZE) {
@@ -383,6 +386,7 @@ print_name_values(unsigned int indent,Dwarf_Dnames_Head dn ,
383386
Dwarf_Unsigned offset_next_entry_pool = 0;
384387
const char *idname = 0;
385388
Dwarf_Unsigned i = 0;
389+
const char *tagname = "<TAGunknown";
386390

387391
res = dwarf_dnames_entrypool(dn,
388392
offset_in_entrypool,
@@ -393,16 +397,22 @@ print_name_values(unsigned int indent,Dwarf_Dnames_Head dn ,
393397
return res;
394398
}
395399
printindent(indent);
400+
dwarf_get_TAG_name(tag,&tagname);
396401
printf(
397-
"nameindex %6" DW_PR_DUu
398-
" tag 0x%04x"
402+
"Nameindex %6" DW_PR_DUu
399403
" abbrevcode %4" DW_PR_DUu
400404
" abbrevindex %4" DW_PR_DUu
401405
"\n",
402-
name_index,tag,abbrev_code,index_of_abbrev);
406+
name_index,
407+
abbrev_code,
408+
index_of_abbrev);
409+
printindent(indent);
410+
printf(
411+
"Tag 0x%04x %-16s\n",
412+
tag,tagname);
403413
printindent(indent);
404414
printf(
405-
"valuecount %4" DW_PR_DUu
415+
"Valuecount %4" DW_PR_DUu
406416
" valuesoffset 0x%04" DW_PR_DUx
407417
"\n",
408418
value_count, offset_of_initial_value);
@@ -438,12 +448,12 @@ print_name_values(unsigned int indent,Dwarf_Dnames_Head dn ,
438448
single_cu_offset);
439449
}
440450
printindent(indent);
441-
printf("[ ] idxattr idxname value\n");
451+
printf("[ ] idxattr idxname value\n");
442452
for (i = 0; i < value_count; ++i) {
443453
Dwarf_Half idx = idx_array[i];
444454

445455
printindent(indent);
446-
printf("[%" DW_PR_DUu "] ",i);
456+
printf("[%2" DW_PR_DUu "] ",i);
447457

448458
if (!idx) {
449459
if (i == (value_count-1)) {
@@ -459,7 +469,7 @@ print_name_values(unsigned int indent,Dwarf_Dnames_Head dn ,
459469
}
460470
}
461471
dwarf_get_IDX_name(idx,&idname);
462-
printf("%2u %-19s ",idx,idname);
472+
printf(" %2u %-19s ",idx,idname);
463473
switch(idx) {
464474
case DW_IDX_compile_unit:
465475
printf(" CUindex= %" DW_PR_DUu ,offsets_array[i]);
@@ -527,6 +537,7 @@ print_names_table(unsigned int indent,Dwarf_Dnames_Head dn,
527537
}
528538
printf(" StrOffset Name\n");
529539
for ( ; i <= name_count;++i) {
540+
const char *tagname = "<TAGunknown>";
530541
printindent(indent);
531542
res = dwarf_dnames_name(dn,i,
532543
&bucketnum, &hashval,
@@ -555,24 +566,26 @@ print_names_table(unsigned int indent,Dwarf_Dnames_Head dn,
555566
printf("0x%06" DW_PR_DUx , offset_to_debug_str);
556567
printf(" %s",ptrtostr?sanitized(ptrtostr):"<null>");
557568
printf("\n");
558-
printindent(indent);
559-
printf(" entrypool= 0x%06" DW_PR_DUx ,
569+
printindent(indent+4);
570+
dwarf_get_TAG_name(abbrev_tag,&tagname);
571+
printf("entrypool= 0x%06" DW_PR_DUx ,
560572
offset_in_entrypool);
561573
printf(" abbrev#= %4" DW_PR_DUu,
562574
abbrev_number);
563-
printf(" tag= 0x%04x",
564-
abbrev_tag);
565575
printf(" attrcount= %4" DW_PR_DUu,
566576
attr_count);
567-
printf(" arraysz= %4" DW_PR_DUu,
577+
printf(" arraysz= %4" DW_PR_DUu "\n",
568578
array_size);
579+
printindent(indent+4);
580+
printf("tag= 0x%04x %-16s",
581+
abbrev_tag,tagname);
569582
printf("\n");
570583
if (glflags.verbose) {
571584
print_attr_array(indent+2,
572585
attr_count,array_size,
573586
nt_idxattr_array, nt_form_array);
574587
}
575-
res = print_name_values(indent+2,dn,i,offset_in_entrypool,
588+
res = print_name_values(indent+6,dn,i,offset_in_entrypool,
576589
error);
577590
if (res != DW_DLV_OK) {
578591
return res;

src/lib/libdwarf/dwarf_debugnames.c

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ read_uword_ab(Dwarf_Small **lp,
132132
return DW_DLV_OK;
133133
}
134134

135+
static void
136+
free_temp_abbrevs( struct Dwarf_D_Abbrev_s * firstab)
137+
{
138+
struct Dwarf_D_Abbrev_s *curab = firstab;
139+
140+
while (curab) {
141+
struct Dwarf_D_Abbrev_s *nxtab = 0;
142+
143+
nxtab = curab->da_next;
144+
curab->da_next = 0;
145+
free(curab);
146+
curab = nxtab;
147+
}
148+
}
149+
135150
static int
136151
fill_in_abbrevs_table(Dwarf_Dnames_Head dn,
137152
Dwarf_Error * error)
@@ -144,9 +159,9 @@ fill_in_abbrevs_table(Dwarf_Dnames_Head dn,
144159
Dwarf_Unsigned tag = 0;
145160
int foundabend = FALSE;
146161
Dwarf_Unsigned abcount = 0;
147-
struct Dwarf_D_Abbrev_s *firstdab = 0;
148-
struct Dwarf_D_Abbrev_s *lastdab = 0;
149162
struct Dwarf_D_Abbrev_s *curdab = 0;
163+
struct Dwarf_D_Abbrev_s *firstdab = 0;
164+
struct Dwarf_D_Abbrev_s **lastabp = &firstdab;
150165
Dwarf_Debug dbg = dn->dn_dbg;
151166

152167
for (abcur = abdata; abcur < tabend; ) {
@@ -159,6 +174,7 @@ fill_in_abbrevs_table(Dwarf_Dnames_Head dn,
159174
inroffset = abcur - abdata;
160175
res = read_uword_ab(&abcur,&code,dbg,error,tabend);
161176
if (res != DW_DLV_OK) {
177+
free_temp_abbrevs(firstdab);
162178
return res;
163179
}
164180
if (code == 0) {
@@ -168,12 +184,14 @@ fill_in_abbrevs_table(Dwarf_Dnames_Head dn,
168184

169185
res = read_uword_ab(&abcur,&tag,dbg,error,tabend);
170186
if (res != DW_DLV_OK) {
187+
free_temp_abbrevs(firstdab);
171188
return res;
172189
}
173190
inner = abcur;
174191
curdab = (struct Dwarf_D_Abbrev_s *)calloc(1,
175192
sizeof(struct Dwarf_D_Abbrev_s));
176193
if (!curdab) {
194+
free_temp_abbrevs(firstdab);
177195
firstdab = 0;
178196
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
179197
return DW_DLV_ERROR;
@@ -185,18 +203,22 @@ fill_in_abbrevs_table(Dwarf_Dnames_Head dn,
185203
for (;;) {
186204
res = read_uword_ab(&inner,&attr,dbg,error,tabend);
187205
if (res != DW_DLV_OK) {
188-
free(curdab);
206+
free_temp_abbrevs(curdab);
207+
free_temp_abbrevs(firstdab);
189208
firstdab = 0;
190209
return res;
191210
}
192211
res = read_uword_ab(&inner,&form,dbg,error,tabend);
193212
if (res != DW_DLV_OK) {
194-
free(curdab);
213+
free_temp_abbrevs(curdab);
214+
free_temp_abbrevs(firstdab);
195215
firstdab = 0;
196216
return res;
197217
}
198218
if ( curdab->da_pairs_count ==
199219
ABB_PAIRS_MAX) {
220+
free_temp_abbrevs(curdab);
221+
free_temp_abbrevs(firstdab);
200222
_dwarf_error_string(dbg,error,
201223
DW_DLE_DEBUG_NAMES_ABBREV_CORRUPTION,
202224
"DW_DLE_DEBUG_NAMES_ABBREV_CORRUPTION: "
@@ -214,17 +236,13 @@ fill_in_abbrevs_table(Dwarf_Dnames_Head dn,
214236
}
215237
}
216238

239+
/* Building singly linked list. without if stmt. */
217240
abcur = inner;
218-
if (!firstdab) {
219-
firstdab = curdab;
220-
lastdab = curdab;
221-
} else {
222-
/* Add new on the end, last */
223-
lastdab->da_next = curdab;
224-
lastdab = curdab;
225-
}
241+
*lastabp = curdab;
242+
lastabp = &curdab->da_next;
226243
}
227244
if (!foundabend) {
245+
free_temp_abbrevs(firstdab);
228246
_dwarf_error_string(dbg, error,
229247
DW_DLE_DEBUG_NAMES_ABBREV_CORRUPTION,
230248
"DW_DLE_DEBUG_NAMES_ABBREV_CORRUPTION: Never found"
@@ -261,6 +279,7 @@ fill_in_abbrevs_table(Dwarf_Dnames_Head dn,
261279
(struct Dwarf_D_Abbrev_s *)calloc(
262280
abcount,sizeof(struct Dwarf_D_Abbrev_s));
263281
if (!dn->dn_abbrev_instances) {
282+
free_temp_abbrevs(firstdab);
264283
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
265284
return DW_DLV_ERROR;
266285
}
@@ -271,12 +290,13 @@ fill_in_abbrevs_table(Dwarf_Dnames_Head dn,
271290
/* da_next no longer means anything */
272291
dn->dn_abbrev_instances[ct] = *tmpa;
273292
dn->dn_abbrev_instances[ct].da_next = 0;
293+
free(tmpa);
274294
tmpa = tmpb;
275295
}
276296
tmpa = 0;
277297
firstdab = 0;
278-
lastdab = 0;
279-
/* Now the list has turned into an array. We can ignore
298+
/* Now the list has turned into an
299+
array. We can ignore
280300
the list aspect. */
281301
}
282302
return DW_DLV_OK;

src/lib/libdwarf/libdwarf.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5978,9 +5978,6 @@ DW_API int dwarf_get_debug_sup(Dwarf_Debug dw_dbg,
59785978
The section is new in DWARF5 supersedes .debug_pubnames and
59795979
.debug_pubtypes in DWARF2, DWARF3, and DWARF4.
59805980
5981-
The code is incomplete . We have no examples
5982-
produced by a compiler as yet.
5983-
59845981
The existing functions provide a detailed reporting
59855982
of the content and structure of the table, they
59865983
are not intended to be used to search the table.

0 commit comments

Comments
 (0)