Debian Codegraph @

src/bin/dwarfdump/print_debug_sup.c

raw
1 /*
2 Copyright (C) 2020 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_sup */
33
34 #include <config.h>
35 #include <stdio.h> /* FILE decl for dd_esb.h, printf etc */
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 int
50 print_debug_sup(Dwarf_Debug dbg,
51 Dwarf_Error *error)
52 {
53 int res = 0;
54 const char *stdname = 0;
55 char buf[DWARF_SECNAME_BUFFER_SIZE];
56 struct esb_s truename;
57 Dwarf_Half version = 0;
58 Dwarf_Small is_supplementary = 0;
59 char * filename = 0;
60 Dwarf_Unsigned checksum_len = 0;
61 Dwarf_Unsigned i =0;
62 Dwarf_Small *checksum_ptr = 0;
63 Dwarf_Small *curptr = 0;
64
65 esb_constructor_fixed(&truename,buf,
66 DWARF_SECNAME_BUFFER_SIZE);
67 glflags.current_section_id = DEBUG_SUP;
68 stdname = ".debug_sup";
69 get_true_section_name(dbg,stdname, &truename,TRUE);
70 res = dwarf_get_debug_sup(dbg,
71 &version,&is_supplementary,
72 &filename,&checksum_len,
73 &checksum_ptr,error);
74 if (res == DW_DLV_ERROR) {
75 glflags.gf_count_major_errors++;
76 printf("ERROR: problem reading %s. %s\n",
77 sanitized(esb_get_string(&truename)),
78 dwarf_errmsg(*error));
79 dwarf_dealloc_error(dbg,*error);
80 *error = 0;
81 esb_destructor(&truename);
82 return DW_DLV_OK;
83 }
84 if (res == DW_DLV_NO_ENTRY) {
85 esb_destructor(&truename);
86 return res;
87 }
88 printf("\n%s\n",sanitized(esb_get_string(&truename)));
89 printf(" Version : %u\n",version);
90 if (version != 2) {
91 glflags.gf_count_major_errors++;
92 printf("ERROR: the %s version is %u but "
93 "only 2 is currently valid\n",
94 sanitized(esb_get_string(&truename)),
95 version);
96 }
97 printf(" Supplementary file : %u (%s}\n",is_supplementary,
98 is_supplementary?"yes":"no");
99 if (is_supplementary > 1) {
100 glflags.gf_count_major_errors++;
101 printf("ERROR: the %s is_supplementary field is %u but "
102 "only 0 or 1 is currently valid\n",
103 sanitized(esb_get_string(&truename)),
104 is_supplementary);
105 }
106 printf(" Filename : %s\n",sanitized(filename));
107 printf(" Checksum Length : %" DW_PR_DUu "\n",checksum_len);
108 printf(" Checksum bytes in hex:\n");
109 curptr = checksum_ptr;
110 if (checksum_len > 0) {
111 printf(" ");
112 }
113 for (i = 0 ; i < checksum_len; ++i,++curptr) {
114 if (i > 0 && (i%16) == 0) {
115 printf("\n ");
116 }
117 printf("%02x",*curptr);
118 }
119 printf("\n");
120 esb_destructor(&truename);
121 return DW_DLV_OK;
122 }