xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_sections.c (revision deb6f0161a9109e7de9b519dc8dfb9478668dcdd)
1 /*	$NetBSD: dwarf_sections.c,v 1.2 2016/02/20 02:43:41 christos Exp $	*/
2 /*-
3  * Copyright (c) 2014 Kai Wang
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include "_libdwarf.h"
29 
30 __RCSID("$NetBSD: dwarf_sections.c,v 1.2 2016/02/20 02:43:41 christos Exp $");
31 ELFTC_VCSID("Id: dwarf_sections.c 3226 2015-06-23 13:00:16Z emaste ");
32 
33 #define	SET(N, V)				\
34 	do {					\
35 		if ((N) != NULL)		\
36 			*(N) = (V);		\
37 	} while (0)
38 
39 int
40 dwarf_get_section_max_offsets_b(Dwarf_Debug dbg, Dwarf_Unsigned *debug_info,
41     Dwarf_Unsigned *debug_abbrev, Dwarf_Unsigned *debug_line,
42     Dwarf_Unsigned *debug_loc, Dwarf_Unsigned *debug_aranges,
43     Dwarf_Unsigned *debug_macinfo, Dwarf_Unsigned *debug_pubnames,
44     Dwarf_Unsigned *debug_str, Dwarf_Unsigned *debug_frame,
45     Dwarf_Unsigned *debug_ranges, Dwarf_Unsigned *debug_pubtypes,
46     Dwarf_Unsigned *debug_types)
47 {
48 	const char *n;
49 	Dwarf_Unsigned sz;
50 	int i;
51 
52 	if (dbg == NULL)
53 		return (DW_DLV_ERROR);
54 
55 	SET(debug_info, 0);
56 	SET(debug_abbrev, 0);
57 	SET(debug_line, 0);
58 	SET(debug_loc, 0);
59 	SET(debug_aranges, 0);
60 	SET(debug_macinfo, 0);
61 	SET(debug_pubnames, 0);
62 	SET(debug_str, 0);
63 	SET(debug_frame, 0);
64 	SET(debug_ranges, 0);
65 	SET(debug_pubtypes, 0);
66 	SET(debug_types, 0);
67 
68 	for (i = 0; (Dwarf_Unsigned) i < dbg->dbg_seccnt; i++) {
69 		n = dbg->dbg_section[i].ds_name;
70 		sz = dbg->dbg_section[i].ds_size;
71 		if (!strcmp(n, ".debug_info"))
72 			SET(debug_info, sz);
73 		else if (!strcmp(n, ".debug_abbrev"))
74 			SET(debug_abbrev, sz);
75 		else if (!strcmp(n, ".debug_line"))
76 			SET(debug_line, sz);
77 		else if (!strcmp(n, ".debug_loc"))
78 			SET(debug_loc, sz);
79 		else if (!strcmp(n, ".debug_aranges"))
80 			SET(debug_aranges, sz);
81 		else if (!strcmp(n, ".debug_macinfo"))
82 			SET(debug_macinfo, sz);
83 		else if (!strcmp(n, ".debug_pubnames"))
84 			SET(debug_pubnames, sz);
85 		else if (!strcmp(n, ".debug_str"))
86 			SET(debug_str, sz);
87 		else if (!strcmp(n, ".debug_frame"))
88 			SET(debug_frame, sz);
89 		else if (!strcmp(n, ".debug_ranges"))
90 			SET(debug_ranges, sz);
91 		else if (!strcmp(n, ".debug_pubtypes"))
92 			SET(debug_pubtypes, sz);
93 		else if (!strcmp(n, ".debug_types"))
94 			SET(debug_types, sz);
95 	}
96 
97 	return (DW_DLV_OK);
98 }
99 
100 int
101 dwarf_get_section_max_offsets(Dwarf_Debug dbg, Dwarf_Unsigned *debug_info,
102     Dwarf_Unsigned *debug_abbrev, Dwarf_Unsigned *debug_line,
103     Dwarf_Unsigned *debug_loc, Dwarf_Unsigned *debug_aranges,
104     Dwarf_Unsigned *debug_macinfo, Dwarf_Unsigned *debug_pubnames,
105     Dwarf_Unsigned *debug_str, Dwarf_Unsigned *debug_frame,
106     Dwarf_Unsigned *debug_ranges, Dwarf_Unsigned *debug_pubtypes)
107 {
108 
109 	return (dwarf_get_section_max_offsets_b(dbg, debug_info, debug_abbrev,
110 	    debug_line, debug_loc, debug_aranges, debug_macinfo,
111 	    debug_pubnames, debug_str, debug_frame, debug_ranges,
112 	    debug_pubtypes, NULL));
113 }
114