Skip to content

Commit

Permalink
Altered indents to multiples of 4 spaces, no tabs,
Browse files Browse the repository at this point in the history
in the dwarfexample directory.
  • Loading branch information
David Anderson committed Jun 5, 2011
1 parent d545ab2 commit 6b989c1
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 75 deletions.
3 changes: 3 additions & 0 deletions dwarfexample/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
2011-06-04 DavidAnderson <[email protected]>
* frame1.c, simplereader.c: Altered indentation to
multiples of 4 spaces, no tabs. No substantive change.
2011-01-13 DavidAnderson <[email protected]>
* New year starts.
82 changes: 41 additions & 41 deletions dwarfexample/frame1.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* simplereader.c
This is an example of code reading dwarf .debug_frame.
It is kept as simple as possible to expose essential features.
It does not do all possible error reporting or error handling.
/* simplereader.c
This is an example of code reading dwarf .debug_frame.
It is kept as simple as possible to expose essential features.
It does not do all possible error reporting or error handling.
It specifically calls dwarf_expand_frame_instructions()
to verify that works without crashing!
It specifically calls dwarf_expand_frame_instructions()
to verify that works without crashing!
To use, try
make
./frame1 frame1
To use, try
make
./frame1 frame1
*/
#include <sys/types.h> /* For open() */
#include <sys/stat.h> /* For open() */
Expand Down Expand Up @@ -90,16 +90,16 @@ main(int argc, char **argv)
printf("Giving up, dwarf_init failed, cannot do DWARF processing\n");
exit(1);
}
/* Do this setting after init before any real operations.
These return the old values, but here we do not
need to know the old values. The sizes and
values here are higher than most ABIs and entirely
arbitrary.
The setting of initial_value to
the same as undefined-value (the other possible choice being
same-value) is arbitrary, different ABIs do differ, and
you have to know which is right. */
/* Do this setting after init before any real operations.
These return the old values, but here we do not
need to know the old values. The sizes and
values here are higher than most ABIs and entirely
arbitrary.
The setting of initial_value to
the same as undefined-value (the other possible choice being
same-value) is arbitrary, different ABIs do differ, and
you have to know which is right. */
regtabrulecount=1999;
dwarf_set_frame_undefined_value(dbg, UNDEF_VAL);
dwarf_set_frame_rule_initial_value(dbg, UNDEF_VAL);
Expand Down Expand Up @@ -131,8 +131,8 @@ read_frame_data(Dwarf_Debug dbg)
res = dwarf_get_fde_list(dbg,&cie_data,&cie_element_count,
&fde_data,&fde_element_count,&error);
if(res == DW_DLV_NO_ENTRY) {
printf("No frame data present ");
exit(0);
printf("No frame data present ");
exit(0);
}
if( res == DW_DLV_ERROR) {
printf("Error reading frame data ");
Expand Down Expand Up @@ -237,13 +237,13 @@ print_fde_instrs(Dwarf_Debug dbg,

arbitrary_addr = lowpc + (func_length/2);
printf("function low pc 0x%" DW_PR_DUx
" and length 0x%" DW_PR_DUx
" and addr we choose 0x%" DW_PR_DUx
"\n",
lowpc,func_length,arbitrary_addr);
" and length 0x%" DW_PR_DUx
" and addr we choose 0x%" DW_PR_DUx
"\n",
lowpc,func_length,arbitrary_addr);

/* 1 is arbitrary. We are winding up getting the
rule count here while leaving things unchanged. */
/* 1 is arbitrary. We are winding up getting the
rule count here while leaving things unchanged. */
oldrulecount = dwarf_set_frame_rule_table_size(dbg,1);
dwarf_set_frame_rule_table_size(dbg,oldrulecount);

Expand Down Expand Up @@ -271,8 +271,8 @@ print_fde_instrs(Dwarf_Debug dbg,
}
res = dwarf_get_cie_of_fde(fde,&cie,error);
if(res != DW_DLV_OK) {
printf("Error getting cie from fde\n");
exit(1);
printf("Error getting cie from fde\n");
exit(1);
}

res = dwarf_expand_frame_instructions(cie,
Expand Down Expand Up @@ -321,8 +321,8 @@ print_one_regentry(const char *prefix,Dwarf_Fde fde,Dwarf_Debug dbg,
(entry->dw_value_type == DW_EXPR_VAL_OFFSET)? "DW_EXPR_VAL_OFFSET":
(entry->dw_value_type == DW_EXPR_EXPRESSION)? "DW_EXPR_EXPRESSION":
(entry->dw_value_type == DW_EXPR_VAL_EXPRESSION)?
"DW_EXPR_VAL_EXPRESSION":
"Unknown");
"DW_EXPR_VAL_EXPRESSION":
"Unknown");
switch(entry->dw_value_type) {
case DW_EXPR_OFFSET:
print_reg(entry->dw_regnum);
Expand All @@ -336,7 +336,7 @@ print_one_regentry(const char *prefix,Dwarf_Fde fde,Dwarf_Debug dbg,
printf("address of value is CFA plus signed offset");
}
if(!is_cfa && entry->dw_regnum != CFA_VAL) {
printf(" compiler botch, regnum != CFA_VAL");
printf(" compiler botch, regnum != CFA_VAL");
}
} else {
printf("value in register");
Expand All @@ -345,14 +345,14 @@ print_one_regentry(const char *prefix,Dwarf_Fde fde,Dwarf_Debug dbg,
case DW_EXPR_VAL_OFFSET:
print_reg(entry->dw_regnum);
printf(" offset %" DW_PR_DSd " " ,
entry->dw_offset_or_block_len);
entry->dw_offset_or_block_len);
if(is_cfa) {
printf("does this make sense? No?");
} else {
printf("value at CFA plus signed offset");
}
if(!is_cfa && entry->dw_regnum != CFA_VAL) {
printf(" compiler botch, regnum != CFA_VAL");
printf(" compiler botch, regnum != CFA_VAL");
}
break;
case DW_EXPR_EXPRESSION:
Expand Down Expand Up @@ -391,14 +391,14 @@ print_regtable(Dwarf_Fde fde,Dwarf_Regtable3 *tab3,int oldrulecount,
max = tab3->rt3_reg_table_size;
}
print_one_regentry("cfa",fde,dbg,oldrulecount,&tab3->rt3_cfa_rule,
error);
error);

for(r = 0; r < max; r++) {
char rn[30];
snprintf(rn,sizeof(rn),"reg %d",r);
print_one_regentry(rn, fde,dbg,oldrulecount,tab3->rt3_rules+r,
error);
}
for(r = 0; r < max; r++) {
char rn[30];
snprintf(rn,sizeof(rn),"reg %d",r);
print_one_regentry(rn, fde,dbg,oldrulecount,tab3->rt3_rules+r,
error);
}


}
Expand Down
70 changes: 36 additions & 34 deletions dwarfexample/simplereader.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* simplereader.c
This is an example of code reading dwarf .debug_info.
It is kept as simple as possible to expose essential features.
It does not do all possible error reporting or error handling.
/* simplereader.c
This is an example of code reading dwarf .debug_info.
It is kept as simple as possible to expose essential features.
It does not do all possible error reporting or error handling.
The --names
option adds some extra printing.
The --names
option adds some extra printing.
To use, try
make
./simplereader simplereader
To use, try
make
./simplereader simplereader
*/
#include <sys/types.h> /* For open() */
#include <sys/stat.h> /* For open() */
Expand Down Expand Up @@ -80,9 +80,9 @@ main(int argc, char **argv)
int i = 0;
for(i = 1; i < (argc-1) ; ++i) {
if(strcmp(argv[i],"--names") == 0) {
namesoptionon=1;
namesoptionon=1;
} else {
printf("Unknown argument \"%s\" ignored\n",argv[i]);
printf("Unknown argument \"%s\" ignored\n",argv[i]);
}
}
filepath = argv[i];
Expand Down Expand Up @@ -250,26 +250,26 @@ print_subprog(Dwarf_Debug dbg,Dwarf_Die die, int level,
res = dwarf_whatattr(attrbuf[i],&aform,&error);
if(res == DW_DLV_OK) {
if(aform == DW_AT_decl_file) {
get_number(attrbuf[i],&filenum);
if((filenum > 0) && (sf->srcfilescount > (filenum-1))) {
filename = sf->srcfiles[filenum-1];
}
get_number(attrbuf[i],&filenum);
if((filenum > 0) && (sf->srcfilescount > (filenum-1))) {
filename = sf->srcfiles[filenum-1];
}
}
if(aform == DW_AT_decl_line) {
get_number(attrbuf[i],&linenum);
get_number(attrbuf[i],&linenum);
}
if(aform == DW_AT_low_pc) {
get_addr(attrbuf[i],&lowpc);
get_addr(attrbuf[i],&lowpc);
}
if(aform == DW_AT_high_pc) {
get_addr(attrbuf[i],&highpc);
get_addr(attrbuf[i],&highpc);
}
}
dwarf_dealloc(dbg,attrbuf[i],DW_DLA_ATTR);
}
if(filenum || linenum) {
printf("<%3d> file: %" DW_PR_DUu " %s line %"
DW_PR_DUu "\n",level,filenum,filename?filename:"",linenum);
DW_PR_DUu "\n",level,filenum,filename?filename:"",linenum);
}
if(lowpc) {
printf("<%3d> low_pc : 0x%" DW_PR_DUx "\n",
Expand Down Expand Up @@ -301,11 +301,12 @@ print_comp_dir(Dwarf_Debug dbg,Dwarf_Die die,int level, struct srcfilesdata *sf)
res = dwarf_whatattr(attrbuf[i],&aform,&error);
if(res == DW_DLV_OK) {
if(aform == DW_AT_comp_dir) {
char *name = 0;
res = dwarf_formstring(attrbuf[i],&name,&error);
if(res == DW_DLV_OK) {
printf( "<%3d> compilation directory : \"%s\"\n",level,name);
}
char *name = 0;
res = dwarf_formstring(attrbuf[i],&name,&error);
if(res == DW_DLV_OK) {
printf( "<%3d> compilation directory : \"%s\"\n",
level,name);
}
}
if(aform == DW_AT_stmt_list) {
/* Offset of stmt list for this CU in .debug_line */
Expand All @@ -319,14 +320,14 @@ print_comp_dir(Dwarf_Debug dbg,Dwarf_Die die,int level, struct srcfilesdata *sf)
static void
resetsrcfiles(Dwarf_Debug dbg,struct srcfilesdata *sf)
{
Dwarf_Signed sri = 0;
for (sri = 0; sri < sf->srcfilescount; ++sri) {
dwarf_dealloc(dbg, sf->srcfiles[sri], DW_DLA_STRING);
}
dwarf_dealloc(dbg, sf->srcfiles, DW_DLA_LIST);
sf->srcfilesres = DW_DLV_ERROR;
sf->srcfiles = 0;
sf->srcfilescount = 0;
Dwarf_Signed sri = 0;
for (sri = 0; sri < sf->srcfilescount; ++sri) {
dwarf_dealloc(dbg, sf->srcfiles[sri], DW_DLA_STRING);
}
dwarf_dealloc(dbg, sf->srcfiles, DW_DLA_LIST);
sf->srcfilesres = DW_DLV_ERROR;
sf->srcfiles = 0;
sf->srcfilescount = 0;
}

static void
Expand Down Expand Up @@ -364,8 +365,9 @@ print_die_data(Dwarf_Debug dbg, Dwarf_Die print_me,int level,
printf( "<%3d> subprogram : \"%s\"\n",level,name);
print_subprog(dbg,print_me,level,sf);
} else if (tag == DW_TAG_compile_unit ||
tag == DW_TAG_partial_unit ||
tag == DW_TAG_type_unit) {
tag == DW_TAG_partial_unit ||
tag == DW_TAG_type_unit) {

resetsrcfiles(dbg,sf);
printf( "<%3d> source file : \"%s\"\n",level,name);
print_comp_dir(dbg,print_me,level,sf);
Expand Down

0 comments on commit 6b989c1

Please sign in to comment.