| 1 |
/* |
| 2 |
Copyright 2018-2018 David Anderson. All rights reserved. |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of version 2 of the GNU General |
| 6 |
Public License as published by the Free Software Foundation. |
| 7 |
|
| 8 |
This program is distributed in the hope that it would be |
| 9 |
useful, but WITHOUT ANY WARRANTY; without even the implied |
| 10 |
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 11 |
PURPOSE. |
| 12 |
|
| 13 |
Further, this software is distributed without any warranty |
| 14 |
that it is free of the rightful claim of any third person |
| 15 |
regarding infringement or the like. Any license provided |
| 16 |
herein, whether implied or otherwise, applies only to this |
| 17 |
software file. Patent licenses, if any, provided herein |
| 18 |
do not apply to combinations of this program with other |
| 19 |
software, or any other product whatsoever. |
| 20 |
|
| 21 |
You should have received a copy of the GNU General Public |
| 22 |
License along with this program; if not, write the Free |
| 23 |
Software Foundation, Inc., 51 Franklin Street - Fifth Floor, |
| 24 |
Boston MA 02110-1301, USA. |
| 25 |
*/ |
| 26 |
|
| 27 |
/* SGI has moved from the Crittenden Lane address. */ |
| 28 |
|
| 29 |
#include <config.h> |
| 30 |
/* We've tried stick to C90, but a newish clang on |
| 31 |
MacOS deprecates sprintf. So we use snprintf as |
| 32 |
of 2024 v0.11.1 */ |
| 33 |
#include <stdio.h> /* FILE decl for dd_esb.h,snprintf */ |
| 34 |
|
| 35 |
#include "dwarf.h" |
| 36 |
#include "libdwarf.h" |
| 37 |
#include "libdwarf_private.h" |
| 38 |
#include "dd_defined_types.h" |
| 39 |
#include "dd_checkutil.h" |
| 40 |
#include "dd_glflags.h" |
| 41 |
#include "dd_globals.h" |
| 42 |
#include "dd_esb.h" |
| 43 |
#include "dd_esb_using_functions.h" |
| 44 |
|
| 45 |
int get_true_section_name(Dwarf_Debug dbg, |
| 46 |
const char *standard_name, |
| 47 |
struct esb_s *name_out, |
| 48 |
Dwarf_Bool add_compr) |
| 49 |
{ |
| 50 |
Dwarf_Small marked_compressed = 0; |
| 51 |
Dwarf_Small marked_zlib_compressed = 0; |
| 52 |
Dwarf_Small marked_shf_compressed = 0; |
| 53 |
Dwarf_Unsigned compressed_length = 0; |
| 54 |
Dwarf_Unsigned uncompressed_length = 0; |
| 55 |
const char *stdname = standard_name; |
| 56 |
const char *actualname = 0; |
| 57 |
int cres = 0; |
| 58 |
Dwarf_Error tnameerr = 0; |
| 59 |
|
| 60 |
cres = dwarf_get_real_section_name(dbg, |
| 61 |
stdname, &actualname, &marked_compressed, |
| 62 |
&marked_zlib_compressed, |
| 63 |
&marked_shf_compressed, |
| 64 |
&compressed_length,&uncompressed_length, |
| 65 |
&tnameerr); |
| 66 |
if (cres == DW_DLV_OK) { |
| 67 |
esb_append(name_out,actualname); |
| 68 |
if (add_compr) { |
| 69 |
Dwarf_Bool compr = FALSE; |
| 70 |
if (marked_compressed) { |
| 71 |
esb_append(name_out," .zdebug"); |
| 72 |
compr = TRUE; |
| 73 |
} |
| 74 |
if (marked_zlib_compressed) { |
| 75 |
esb_append(name_out," ZLIB-initial-bytes"); |
| 76 |
compr = TRUE; |
| 77 |
} |
| 78 |
if (marked_shf_compressed) { |
| 79 |
esb_append(name_out," SHF_COMPRESSED"); |
| 80 |
compr = TRUE; |
| 81 |
} |
| 82 |
if (compr) { |
| 83 |
char floatbuf[40]; |
| 84 |
double comprfactor = 0.0; |
| 85 |
if (compressed_length > 0) { |
| 86 |
comprfactor = (double)uncompressed_length / |
| 87 |
(double)compressed_length; |
| 88 |
} |
| 89 |
esb_append_printf_u(name_out," CompLen=%" |
| 90 |
DW_PR_DUu, compressed_length); |
| 91 |
esb_append_printf_u(name_out," Uncomp=%" |
| 92 |
DW_PR_DUu, uncompressed_length); |
| 93 |
snprintf(floatbuf,sizeof(floatbuf), |
| 94 |
" compression=%.1f",comprfactor); |
| 95 |
esb_append(name_out, floatbuf); |
| 96 |
} |
| 97 |
} |
| 98 |
return DW_DLV_OK; |
| 99 |
} |
| 100 |
if (cres == DW_DLV_NO_ENTRY) { |
| 101 |
esb_append(name_out,stdname); |
| 102 |
return cres; |
| 103 |
} |
| 104 |
/* DW_DLV_ERROR */ |
| 105 |
esb_append(name_out,stdname); |
| 106 |
/* avoid error leak */ |
| 107 |
dwarf_dealloc(dbg,tnameerr,DW_DLA_ERROR); |
| 108 |
tnameerr = 0; |
| 109 |
esb_append(name_out," (Error accessing section name)"); |
| 110 |
return DW_DLV_OK; |
| 111 |
} |