1dnl $NetBSD: dwarf_nametbl.m4,v 1.4 2024/03/03 17:37:31 christos Exp $ 2/*- 3 * Copyright (c) 2009,2011 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 * Id: dwarf_nametbl.m4 2074 2011-10-27 03:34:33Z jkoshy 28 */ 29 30define(`MAKE_NAMETBL_API',` 31int 32dwarf_get_$1s(Dwarf_Debug dbg, Dwarf_$2 **$1s, 33 Dwarf_Signed *ret_count, Dwarf_Error *error) 34{ 35 Dwarf_Section *ds; 36 int ret; 37 38 if (dbg == NULL || $1s == NULL || ret_count == NULL) { 39 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 40 return (DW_DLV_ERROR); 41 } 42 43 if (dbg->dbg_$1s == NULL) { 44 if ((ds = _dwarf_find_section(dbg, ".debug_$4")) != NULL) { 45 ret = _dwarf_nametbl_init(dbg, &dbg->dbg_$1s, ds, 46 error); 47 if (ret != DW_DLE_NONE) 48 return (DW_DLV_ERROR); 49 } 50 if (dbg->dbg_$1s == NULL) { 51 DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY); 52 return (DW_DLV_NO_ENTRY); 53 } 54 } 55 56 *$1s = dbg->dbg_$1s->ns_array; 57 *ret_count = dbg->dbg_$1s->ns_len; 58 59 return (DW_DLV_OK); 60} 61 62int 63dwarf_$3name(Dwarf_$2 $1, char **ret_name, Dwarf_Error *error) 64{ 65 Dwarf_Debug dbg; 66 67 dbg = $1 != NULL ? $1->np_nt->nt_cu->cu_dbg : NULL; 68 69 if ($1 == NULL || ret_name == NULL) { 70 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 71 return (DW_DLV_ERROR); 72 } 73 74 *ret_name = $1->np_name; 75 76 return (DW_DLV_OK); 77} 78 79int 80dwarf_$1_die_offset(Dwarf_$2 $1, Dwarf_Off *ret_offset, 81 Dwarf_Error *error) 82{ 83 Dwarf_NameTbl nt; 84 Dwarf_Debug dbg; 85 86 dbg = $1 != NULL ? $1->np_nt->nt_cu->cu_dbg : NULL; 87 88 if ($1 == NULL || ret_offset == NULL) { 89 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 90 return (DW_DLV_ERROR); 91 } 92 93 nt = $1->np_nt; 94 assert(nt != NULL); 95 96 *ret_offset = nt->nt_cu_offset + $1->np_offset; 97 98 return (DW_DLV_OK); 99} 100 101int 102dwarf_$1_cu_offset(Dwarf_$2 $1, Dwarf_Off *ret_offset, 103 Dwarf_Error *error) 104{ 105 Dwarf_NameTbl nt; 106 Dwarf_Debug dbg; 107 108 dbg = $1 != NULL ? $1->np_nt->nt_cu->cu_dbg : NULL; 109 110 if ($1 == NULL || ret_offset == NULL) { 111 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 112 return (DW_DLV_ERROR); 113 } 114 115 nt = $1->np_nt; 116 assert(nt != NULL); 117 118 *ret_offset = nt->nt_cu_offset; 119 120 return (DW_DLV_OK); 121} 122 123int 124dwarf_$1_name_offsets(Dwarf_$2 $1, char **ret_name, Dwarf_Off *die_offset, 125 Dwarf_Off *cu_offset, Dwarf_Error *error) 126{ 127 Dwarf_CU cu; 128 Dwarf_Debug dbg; 129 Dwarf_NameTbl nt; 130 131 dbg = $1 != NULL ? $1->np_nt->nt_cu->cu_dbg : NULL; 132 133 if ($1 == NULL || ret_name == NULL || die_offset == NULL || 134 cu_offset == NULL) { 135 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 136 return (DW_DLV_ERROR); 137 } 138 139 nt = $1->np_nt; 140 assert(nt != NULL); 141 142 cu = nt->nt_cu; 143 assert(cu != NULL); 144 145 *ret_name = $1->np_name; 146 *die_offset = nt->nt_cu_offset + $1->np_offset; 147 *cu_offset = cu->cu_1st_offset; 148 149 return (DW_DLV_OK); 150} 151 152void 153dwarf_$1s_dealloc(Dwarf_Debug dbg, Dwarf_$2 *$1s, Dwarf_Signed count) 154{ 155 156 (void) dbg; 157 (void) $1s; 158 (void) count; 159} 160') 161