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