1/* $NetBSD: dwarf_nametbl.m4,v 1.2 2014/03/09 16:58:04 christos Exp $ */ 2 3/*- 4 * Copyright (c) 2009,2011 Kai Wang 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * Id: dwarf_nametbl.m4 2074 2011-10-27 03:34:33Z jkoshy 29 */ 30 31define(`MAKE_NAMETBL_API',` 32int 33dwarf_get_$1s(Dwarf_Debug dbg, Dwarf_$2 **$1s, 34 Dwarf_Signed *ret_count, Dwarf_Error *error) 35{ 36 Dwarf_Section *ds; 37 int ret; 38 39 if (dbg == NULL || $1s == NULL || ret_count == NULL) { 40 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 41 return (DW_DLV_ERROR); 42 } 43 44 if (dbg->dbg_$1s == NULL) { 45 if ((ds = _dwarf_find_section(dbg, ".debug_$4")) != NULL) { 46 ret = _dwarf_nametbl_init(dbg, &dbg->dbg_$1s, ds, 47 error); 48 if (ret != DW_DLE_NONE) 49 return (DW_DLV_ERROR); 50 } 51 if (dbg->dbg_$1s == NULL) { 52 DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY); 53 return (DW_DLV_NO_ENTRY); 54 } 55 } 56 57 *$1s = dbg->dbg_$1s->ns_array; 58 *ret_count = dbg->dbg_$1s->ns_len; 59 60 return (DW_DLV_OK); 61} 62 63int 64dwarf_$3name(Dwarf_$2 $1, char **ret_name, Dwarf_Error *error) 65{ 66 Dwarf_Debug dbg; 67 68 dbg = $1 != NULL ? $1->np_nt->nt_cu->cu_dbg : NULL; 69 70 if ($1 == NULL || ret_name == NULL) { 71 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 72 return (DW_DLV_ERROR); 73 } 74 75 *ret_name = $1->np_name; 76 77 return (DW_DLV_OK); 78} 79 80int 81dwarf_$1_die_offset(Dwarf_$2 $1, Dwarf_Off *ret_offset, 82 Dwarf_Error *error) 83{ 84 Dwarf_NameTbl nt; 85 Dwarf_Debug dbg; 86 87 dbg = $1 != NULL ? $1->np_nt->nt_cu->cu_dbg : NULL; 88 89 if ($1 == NULL || ret_offset == NULL) { 90 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 91 return (DW_DLV_ERROR); 92 } 93 94 nt = $1->np_nt; 95 assert(nt != NULL); 96 97 *ret_offset = nt->nt_cu_offset + $1->np_offset; 98 99 return (DW_DLV_OK); 100} 101 102int 103dwarf_$1_cu_offset(Dwarf_$2 $1, Dwarf_Off *ret_offset, 104 Dwarf_Error *error) 105{ 106 Dwarf_NameTbl nt; 107 Dwarf_Debug dbg; 108 109 dbg = $1 != NULL ? $1->np_nt->nt_cu->cu_dbg : NULL; 110 111 if ($1 == NULL || ret_offset == NULL) { 112 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 113 return (DW_DLV_ERROR); 114 } 115 116 nt = $1->np_nt; 117 assert(nt != NULL); 118 119 *ret_offset = nt->nt_cu_offset; 120 121 return (DW_DLV_OK); 122} 123 124int 125dwarf_$1_name_offsets(Dwarf_$2 $1, char **ret_name, Dwarf_Off *die_offset, 126 Dwarf_Off *cu_offset, Dwarf_Error *error) 127{ 128 Dwarf_CU cu; 129 Dwarf_Debug dbg; 130 Dwarf_NameTbl nt; 131 132 dbg = $1 != NULL ? $1->np_nt->nt_cu->cu_dbg : NULL; 133 134 if ($1 == NULL || ret_name == NULL || die_offset == NULL || 135 cu_offset == NULL) { 136 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 137 return (DW_DLV_ERROR); 138 } 139 140 nt = $1->np_nt; 141 assert(nt != NULL); 142 143 cu = nt->nt_cu; 144 assert(cu != NULL); 145 146 *ret_name = $1->np_name; 147 *die_offset = nt->nt_cu_offset + $1->np_offset; 148 *cu_offset = cu->cu_1st_offset; 149 150 return (DW_DLV_OK); 151} 152 153void 154dwarf_$1s_dealloc(Dwarf_Debug dbg, Dwarf_$2 *$1s, Dwarf_Signed count) 155{ 156 157 (void) dbg; 158 (void) $1s; 159 (void) count; 160} 161') 162