| 1 |
/* |
| 2 |
Copyright (C) 2022 David Anderson. All Rights Reserved. |
| 3 |
|
| 4 |
Redistribution and use in source and binary forms, with |
| 5 |
or without modification, are permitted provided that the |
| 6 |
following conditions are met: |
| 7 |
|
| 8 |
Redistributions of source code must retain the above |
| 9 |
copyright notice, this list of conditions and the following |
| 10 |
disclaimer. |
| 11 |
|
| 12 |
Redistributions in binary form must reproduce the above |
| 13 |
copyright notice, this list of conditions and the following |
| 14 |
disclaimer in the documentation and/or other materials |
| 15 |
provided with the distribution. |
| 16 |
|
| 17 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
| 18 |
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 19 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 |
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 22 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 |
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 24 |
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 25 |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 26 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 28 |
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 29 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 |
*/ |
| 31 |
|
| 32 |
/* To print .debug_gnu_pubnames, .debug_gnu_typenames */ |
| 33 |
|
| 34 |
#include <config.h> |
| 35 |
#include <stdio.h> /* FILE decl for dd_esb.h */ |
| 36 |
|
| 37 |
#include "dwarf.h" |
| 38 |
#include "libdwarf.h" |
| 39 |
#include "libdwarf_private.h" |
| 40 |
#include "dd_defined_types.h" |
| 41 |
#include "dd_checkutil.h" |
| 42 |
#include "dd_glflags.h" |
| 43 |
#include "dd_globals.h" |
| 44 |
#include "dd_naming.h" |
| 45 |
#include "dd_esb.h" /* For flexible string buffer. */ |
| 46 |
#include "dd_esb_using_functions.h" |
| 47 |
#include "dd_sanitized.h" |
| 48 |
|
| 49 |
static void |
| 50 |
print_sec_name(Dwarf_Debug dbg) |
| 51 |
{ |
| 52 |
struct esb_s truename; |
| 53 |
char buf[DWARF_SECNAME_BUFFER_SIZE]; |
| 54 |
|
| 55 |
esb_constructor_fixed(&truename,buf,sizeof(buf)); |
| 56 |
get_true_section_name(dbg,".debug_addr", |
| 57 |
&truename,TRUE); |
| 58 |
printf("\n%s\n\n",sanitized(esb_get_string(&truename))); |
| 59 |
esb_destructor(&truename); |
| 60 |
} |
| 61 |
|
| 62 |
static void |
| 63 |
print_table_header(Dwarf_Unsigned tabnum, |
| 64 |
Dwarf_Unsigned cur_secoff, |
| 65 |
Dwarf_Unsigned length, |
| 66 |
Dwarf_Half version, |
| 67 |
Dwarf_Small address_size, |
| 68 |
Dwarf_Unsigned at_addr_base, |
| 69 |
Dwarf_Unsigned entry_count, |
| 70 |
Dwarf_Unsigned next_table_offset) |
| 71 |
{ |
| 72 |
printf("Debug Addr table : %" DW_PR_DUu "\n",tabnum); |
| 73 |
printf(" table length : %" DW_PR_DUu "\n",length); |
| 74 |
printf(" table version : %u\n",version); |
| 75 |
printf(" address size : %u\n",address_size); |
| 76 |
printf(" segment selector size : 0\n"); |
| 77 |
printf(" table entry count : %" DW_PR_DUu "\n",entry_count); |
| 78 |
printf(" table section offset : 0x%" DW_PR_XZEROS DW_PR_DUx "\n", |
| 79 |
cur_secoff); |
| 80 |
printf(" addr base : 0x%" DW_PR_XZEROS DW_PR_DUx "\n", |
| 81 |
at_addr_base); |
| 82 |
printf(" addr base will match some " |
| 83 |
"DW_AT_addr_base attribute\n"); |
| 84 |
printf(" next table offset : 0x%" DW_PR_XZEROS DW_PR_DUx "\n", |
| 85 |
next_table_offset); |
| 86 |
} |
| 87 |
|
| 88 |
int |
| 89 |
print_debug_addr(Dwarf_Debug dbg, |
| 90 |
Dwarf_Error *error) |
| 91 |
{ |
| 92 |
int res = DW_DLV_OK; |
| 93 |
Dwarf_Unsigned tabnum = 0; |
| 94 |
Dwarf_Unsigned cur_secoff = 0; |
| 95 |
Dwarf_Debug_Addr_Table tab = 0; |
| 96 |
Dwarf_Unsigned length = 0; |
| 97 |
Dwarf_Half version = 0; |
| 98 |
Dwarf_Small address_size = 0; |
| 99 |
Dwarf_Unsigned at_addr_base = 0; |
| 100 |
Dwarf_Unsigned entry_count = 0; |
| 101 |
Dwarf_Unsigned next_table_offset = 0; |
| 102 |
|
| 103 |
print_sec_name(dbg); |
| 104 |
for ( ;; tabnum++,cur_secoff = next_table_offset) { |
| 105 |
Dwarf_Unsigned curindex = 0; |
| 106 |
|
| 107 |
res = dwarf_debug_addr_table(dbg,cur_secoff, |
| 108 |
&tab,&length,&version,&address_size, |
| 109 |
&at_addr_base,&entry_count,&next_table_offset, |
| 110 |
error); |
| 111 |
if (res == DW_DLV_ERROR) { |
| 112 |
return res; |
| 113 |
} |
| 114 |
if (res == DW_DLV_NO_ENTRY) { |
| 115 |
/* End of section. */ |
| 116 |
break; |
| 117 |
} |
| 118 |
print_table_header(tabnum,cur_secoff,length,version, |
| 119 |
address_size, at_addr_base,entry_count, |
| 120 |
next_table_offset); |
| 121 |
for ( ;curindex < entry_count;++curindex) { |
| 122 |
int eres = 0; |
| 123 |
Dwarf_Unsigned addr = 0; |
| 124 |
eres = dwarf_debug_addr_by_index(tab,curindex, |
| 125 |
&addr,error); |
| 126 |
if (eres == DW_DLV_ERROR) { |
| 127 |
dwarf_dealloc_debug_addr_table(tab); |
| 128 |
return eres; |
| 129 |
} |
| 130 |
if (eres == DW_DLV_NO_ENTRY) { |
| 131 |
printf("ERROR: Unexpected NO entry on " |
| 132 |
".debug_addr table %" DW_PR_DUu |
| 133 |
" offset 0x" DW_PR_XZEROS DW_PR_DUx |
| 134 |
" entry index %" DW_PR_DUu "\n", |
| 135 |
tabnum,curindex); |
| 136 |
glflags.gf_count_major_errors++; |
| 137 |
break; |
| 138 |
} |
| 139 |
if (!curindex) { |
| 140 |
printf(" [index] address\n"); |
| 141 |
} |
| 142 |
|
| 143 |
printf(" [%3" DW_PR_DUu "]" |
| 144 |
" 0x%" DW_PR_XZEROS DW_PR_DUx "\n", |
| 145 |
curindex,addr); |
| 146 |
} |
| 147 |
dwarf_dealloc_debug_addr_table(tab); |
| 148 |
} |
| 149 |
printf("\n"); |
| 150 |
return DW_DLV_OK; |
| 151 |
} |