1*5ac3bc71Schristos /* $NetBSD: dwarf_sections.c,v 1.4 2024/03/03 17:37:32 christos Exp $ */
2*5ac3bc71Schristos
339a6cffcSchristos /*-
439a6cffcSchristos * Copyright (c) 2014 Kai Wang
539a6cffcSchristos * All rights reserved.
639a6cffcSchristos *
739a6cffcSchristos * Redistribution and use in source and binary forms, with or without
839a6cffcSchristos * modification, are permitted provided that the following conditions
939a6cffcSchristos * are met:
1039a6cffcSchristos * 1. Redistributions of source code must retain the above copyright
1139a6cffcSchristos * notice, this list of conditions and the following disclaimer.
1239a6cffcSchristos * 2. Redistributions in binary form must reproduce the above copyright
1339a6cffcSchristos * notice, this list of conditions and the following disclaimer in the
1439a6cffcSchristos * documentation and/or other materials provided with the distribution.
1539a6cffcSchristos *
1639a6cffcSchristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1739a6cffcSchristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1839a6cffcSchristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1939a6cffcSchristos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2039a6cffcSchristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2139a6cffcSchristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2239a6cffcSchristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2339a6cffcSchristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2439a6cffcSchristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2539a6cffcSchristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2639a6cffcSchristos * SUCH DAMAGE.
2739a6cffcSchristos */
2839a6cffcSchristos
2939a6cffcSchristos #include "_libdwarf.h"
3039a6cffcSchristos
31*5ac3bc71Schristos __RCSID("$NetBSD: dwarf_sections.c,v 1.4 2024/03/03 17:37:32 christos Exp $");
32*5ac3bc71Schristos ELFTC_VCSID("Id: dwarf_sections.c 3902 2020-11-24 21:17:41Z jkoshy");
3339a6cffcSchristos
3439a6cffcSchristos #define SET(N, V) \
3539a6cffcSchristos do { \
3639a6cffcSchristos if ((N) != NULL) \
3739a6cffcSchristos *(N) = (V); \
38*5ac3bc71Schristos } while (/* CONSTCOND */ 0)
3939a6cffcSchristos
4039a6cffcSchristos 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)4139a6cffcSchristos dwarf_get_section_max_offsets_b(Dwarf_Debug dbg, Dwarf_Unsigned *debug_info,
4239a6cffcSchristos Dwarf_Unsigned *debug_abbrev, Dwarf_Unsigned *debug_line,
4339a6cffcSchristos Dwarf_Unsigned *debug_loc, Dwarf_Unsigned *debug_aranges,
4439a6cffcSchristos Dwarf_Unsigned *debug_macinfo, Dwarf_Unsigned *debug_pubnames,
4539a6cffcSchristos Dwarf_Unsigned *debug_str, Dwarf_Unsigned *debug_frame,
4639a6cffcSchristos Dwarf_Unsigned *debug_ranges, Dwarf_Unsigned *debug_pubtypes,
4739a6cffcSchristos Dwarf_Unsigned *debug_types)
4839a6cffcSchristos {
4939a6cffcSchristos const char *n;
5039a6cffcSchristos Dwarf_Unsigned sz;
5139a6cffcSchristos int i;
5239a6cffcSchristos
5339a6cffcSchristos if (dbg == NULL)
5439a6cffcSchristos return (DW_DLV_ERROR);
5539a6cffcSchristos
5639a6cffcSchristos SET(debug_info, 0);
5739a6cffcSchristos SET(debug_abbrev, 0);
5839a6cffcSchristos SET(debug_line, 0);
5939a6cffcSchristos SET(debug_loc, 0);
6039a6cffcSchristos SET(debug_aranges, 0);
6139a6cffcSchristos SET(debug_macinfo, 0);
6239a6cffcSchristos SET(debug_pubnames, 0);
6339a6cffcSchristos SET(debug_str, 0);
6439a6cffcSchristos SET(debug_frame, 0);
6539a6cffcSchristos SET(debug_ranges, 0);
6639a6cffcSchristos SET(debug_pubtypes, 0);
6739a6cffcSchristos SET(debug_types, 0);
6839a6cffcSchristos
6939a6cffcSchristos for (i = 0; (Dwarf_Unsigned) i < dbg->dbg_seccnt; i++) {
7039a6cffcSchristos n = dbg->dbg_section[i].ds_name;
7139a6cffcSchristos sz = dbg->dbg_section[i].ds_size;
7239a6cffcSchristos if (!strcmp(n, ".debug_info"))
7339a6cffcSchristos SET(debug_info, sz);
7439a6cffcSchristos else if (!strcmp(n, ".debug_abbrev"))
7539a6cffcSchristos SET(debug_abbrev, sz);
7639a6cffcSchristos else if (!strcmp(n, ".debug_line"))
7739a6cffcSchristos SET(debug_line, sz);
7839a6cffcSchristos else if (!strcmp(n, ".debug_loc"))
7939a6cffcSchristos SET(debug_loc, sz);
8039a6cffcSchristos else if (!strcmp(n, ".debug_aranges"))
8139a6cffcSchristos SET(debug_aranges, sz);
8239a6cffcSchristos else if (!strcmp(n, ".debug_macinfo"))
8339a6cffcSchristos SET(debug_macinfo, sz);
8439a6cffcSchristos else if (!strcmp(n, ".debug_pubnames"))
8539a6cffcSchristos SET(debug_pubnames, sz);
8639a6cffcSchristos else if (!strcmp(n, ".debug_str"))
8739a6cffcSchristos SET(debug_str, sz);
8839a6cffcSchristos else if (!strcmp(n, ".debug_frame"))
8939a6cffcSchristos SET(debug_frame, sz);
9039a6cffcSchristos else if (!strcmp(n, ".debug_ranges"))
9139a6cffcSchristos SET(debug_ranges, sz);
9239a6cffcSchristos else if (!strcmp(n, ".debug_pubtypes"))
9339a6cffcSchristos SET(debug_pubtypes, sz);
9439a6cffcSchristos else if (!strcmp(n, ".debug_types"))
9539a6cffcSchristos SET(debug_types, sz);
9639a6cffcSchristos }
9739a6cffcSchristos
9839a6cffcSchristos return (DW_DLV_OK);
9939a6cffcSchristos }
10039a6cffcSchristos
10139a6cffcSchristos 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)10239a6cffcSchristos dwarf_get_section_max_offsets(Dwarf_Debug dbg, Dwarf_Unsigned *debug_info,
10339a6cffcSchristos Dwarf_Unsigned *debug_abbrev, Dwarf_Unsigned *debug_line,
10439a6cffcSchristos Dwarf_Unsigned *debug_loc, Dwarf_Unsigned *debug_aranges,
10539a6cffcSchristos Dwarf_Unsigned *debug_macinfo, Dwarf_Unsigned *debug_pubnames,
10639a6cffcSchristos Dwarf_Unsigned *debug_str, Dwarf_Unsigned *debug_frame,
10739a6cffcSchristos Dwarf_Unsigned *debug_ranges, Dwarf_Unsigned *debug_pubtypes)
10839a6cffcSchristos {
10939a6cffcSchristos
11039a6cffcSchristos return (dwarf_get_section_max_offsets_b(dbg, debug_info, debug_abbrev,
11139a6cffcSchristos debug_line, debug_loc, debug_aranges, debug_macinfo,
11239a6cffcSchristos debug_pubnames, debug_str, debug_frame, debug_ranges,
11339a6cffcSchristos debug_pubtypes, NULL));
11439a6cffcSchristos }
115