| 1 |
/* |
| 2 |
Copyright (C) 2000-2006 Silicon Graphics, Inc. All Rights Reserved. |
| 3 |
Portions Copyright 2007-2010 Sun Microsystems, Inc. All rights reserved. |
| 4 |
Portions Copyright 2009-2012 SN Systems Ltd. All rights reserved. |
| 5 |
Portions Copyright 2008-2012 David Anderson. All rights reserved. |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or |
| 8 |
modify it under the terms of version 2 of the GNU General |
| 9 |
Public License as published by the Free Software Foundation. |
| 10 |
|
| 11 |
This program is distributed in the hope that it would be |
| 12 |
useful, but WITHOUT ANY WARRANTY; without even the implied |
| 13 |
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
PURPOSE. |
| 15 |
|
| 16 |
Further, this software is distributed without any warranty |
| 17 |
that it is free of the rightful claim of any third person |
| 18 |
regarding infringement or the like. Any license provided |
| 19 |
herein, whether implied or otherwise, applies only to this |
| 20 |
software file. Patent licenses, if any, provided herein |
| 21 |
do not apply to combinations of this program with other |
| 22 |
software, or any other product whatsoever. |
| 23 |
|
| 24 |
You should have received a copy of the GNU General Public |
| 25 |
License along with this program; if not, write the Free |
| 26 |
Software Foundation, Inc., 51 Franklin Street - Fifth Floor, |
| 27 |
Boston MA 02110-1301, USA. |
| 28 |
|
| 29 |
*/ |
| 30 |
|
| 31 |
#include <config.h> |
| 32 |
#include <stdio.h> /* FILE decl for dd_esb.h, printf etc */ |
| 33 |
|
| 34 |
#include "dwarf.h" |
| 35 |
#include "libdwarf.h" |
| 36 |
#include "libdwarf_private.h" |
| 37 |
#include "dd_defined_types.h" |
| 38 |
#include "dd_checkutil.h" |
| 39 |
#include "dd_glflags.h" |
| 40 |
#include "dd_globals.h" |
| 41 |
#include "dd_naming.h" |
| 42 |
#include "dd_esb.h" |
| 43 |
#include "dd_esb_using_functions.h" |
| 44 |
#include "dd_sanitized.h" |
| 45 |
|
| 46 |
#include "print_sections.h" |
| 47 |
|
| 48 |
static void |
| 49 |
print_sec_name(Dwarf_Debug dbg) |
| 50 |
{ |
| 51 |
struct esb_s truename; |
| 52 |
char buf[DWARF_SECNAME_BUFFER_SIZE]; |
| 53 |
|
| 54 |
esb_constructor_fixed(&truename,buf,sizeof(buf)); |
| 55 |
get_true_section_name(dbg,".debug_str", |
| 56 |
&truename,TRUE); |
| 57 |
printf("\n%s\n",sanitized(esb_get_string(&truename))); |
| 58 |
esb_destructor(&truename); |
| 59 |
} |
| 60 |
|
| 61 |
/* print data in .debug_str */ |
| 62 |
int |
| 63 |
print_strings(Dwarf_Debug dbg,Dwarf_Error *err) |
| 64 |
{ |
| 65 |
Dwarf_Signed length = 0; |
| 66 |
char* name = 0; |
| 67 |
Dwarf_Off offset = 0; |
| 68 |
int sres = 0; |
| 69 |
unsigned loopct = 0; |
| 70 |
|
| 71 |
glflags.current_section_id = DEBUG_STR; |
| 72 |
for (loopct = 0; |
| 73 |
(sres = dwarf_get_str(dbg, offset, &name, &length, err)) |
| 74 |
== DW_DLV_OK; |
| 75 |
++loopct) { |
| 76 |
if (!loopct) { |
| 77 |
print_sec_name(dbg); |
| 78 |
} |
| 79 |
if (glflags.gf_display_offsets) { |
| 80 |
printf("name at offset 0x%" DW_PR_XZEROS DW_PR_DUx |
| 81 |
", length %4" DW_PR_DSd " is '%s'\n", |
| 82 |
(Dwarf_Unsigned)offset, length, sanitized(name)); |
| 83 |
} else { |
| 84 |
printf("name: length %4" DW_PR_DSd " is '%s'\n", |
| 85 |
length, sanitized(name)); |
| 86 |
} |
| 87 |
offset += length + 1; |
| 88 |
} |
| 89 |
if (!loopct) { |
| 90 |
print_sec_name(dbg); |
| 91 |
} |
| 92 |
/* An inability to find the section is not necessarily |
| 93 |
a real error, so do not report error unless we've |
| 94 |
seen a real record. */ |
| 95 |
if (sres == DW_DLV_ERROR) { |
| 96 |
struct esb_s m; |
| 97 |
|
| 98 |
esb_constructor(&m); |
| 99 |
esb_append_printf_u(&m, |
| 100 |
"\nERROR: Getting a .debug_str section string failed " |
| 101 |
" at string number %u",loopct); |
| 102 |
esb_append_printf_u(&m,",section offset 0x%." DW_PR_DUx |
| 103 |
".",offset); |
| 104 |
simple_err_only_return_action(sres,esb_get_string(&m)); |
| 105 |
esb_destructor(&m); |
| 106 |
} |
| 107 |
return sres; |
| 108 |
} |