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