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