xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_pro_nametbl.m4 (revision 5ac3bc719ce6e70593039505b491894133237d12)
1*5ac3bc71Schristosdnl 	$NetBSD: dwarf_pro_nametbl.m4,v 1.4 2024/03/03 17:37:32 christos Exp $
29dd9d0cfSchristos/*-
39dd9d0cfSchristos * Copyright (c) 2010 Kai Wang
49dd9d0cfSchristos * All rights reserved.
59dd9d0cfSchristos *
69dd9d0cfSchristos * Redistribution and use in source and binary forms, with or without
79dd9d0cfSchristos * modification, are permitted provided that the following conditions
89dd9d0cfSchristos * are met:
99dd9d0cfSchristos * 1. Redistributions of source code must retain the above copyright
109dd9d0cfSchristos *    notice, this list of conditions and the following disclaimer.
119dd9d0cfSchristos * 2. Redistributions in binary form must reproduce the above copyright
129dd9d0cfSchristos *    notice, this list of conditions and the following disclaimer in the
139dd9d0cfSchristos *    documentation and/or other materials provided with the distribution.
149dd9d0cfSchristos *
159dd9d0cfSchristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
169dd9d0cfSchristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
179dd9d0cfSchristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
189dd9d0cfSchristos * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199dd9d0cfSchristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209dd9d0cfSchristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
219dd9d0cfSchristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
229dd9d0cfSchristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
239dd9d0cfSchristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
249dd9d0cfSchristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
259dd9d0cfSchristos * SUCH DAMAGE.
269dd9d0cfSchristos *
279dd9d0cfSchristos * Id: dwarf_pro_nametbl.m4 2074 2011-10-27 03:34:33Z jkoshy
289dd9d0cfSchristos */
299dd9d0cfSchristos
309dd9d0cfSchristosdefine(`MAKE_NAMETBL_PRO_API',`
319dd9d0cfSchristosDwarf_Unsigned
329dd9d0cfSchristosdwarf_add_$1name(Dwarf_P_Debug dbg, Dwarf_P_Die die, char *$1_name,
339dd9d0cfSchristos    Dwarf_Error *error)
349dd9d0cfSchristos{
359dd9d0cfSchristos	Dwarf_NameTbl nt;
369dd9d0cfSchristos	Dwarf_NamePair np;
379dd9d0cfSchristos
389dd9d0cfSchristos	if (dbg == NULL || die == NULL || $1_name == NULL) {
399dd9d0cfSchristos		DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
409dd9d0cfSchristos		return (0);
419dd9d0cfSchristos	}
429dd9d0cfSchristos
439dd9d0cfSchristos	if (dbg->dbgp_$1s == NULL) {
449dd9d0cfSchristos		dbg->dbgp_$1s = calloc(1, sizeof(struct _Dwarf_NameTbl));
459dd9d0cfSchristos		if (dbg->dbgp_$1s == NULL) {
469dd9d0cfSchristos			DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
479dd9d0cfSchristos			return (0);
489dd9d0cfSchristos		}
499dd9d0cfSchristos		STAILQ_INIT(&dbg->dbgp_$1s->nt_nplist);
509dd9d0cfSchristos	}
519dd9d0cfSchristos
529dd9d0cfSchristos	nt = dbg->dbgp_$1s;
539dd9d0cfSchristos
549dd9d0cfSchristos	if ((np = calloc(1, sizeof(struct _Dwarf_NamePair))) == NULL) {
559dd9d0cfSchristos		DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
569dd9d0cfSchristos		return (0);
579dd9d0cfSchristos	}
589dd9d0cfSchristos
599dd9d0cfSchristos	np->np_nt = nt;
609dd9d0cfSchristos	np->np_die = die;
619dd9d0cfSchristos	if ((np->np_name = strdup($1_name)) == NULL) {
629dd9d0cfSchristos		free(np);
639dd9d0cfSchristos		DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
649dd9d0cfSchristos		return (0);
659dd9d0cfSchristos	}
669dd9d0cfSchristos
679dd9d0cfSchristos	STAILQ_INSERT_TAIL(&nt->nt_nplist, np, np_next);
689dd9d0cfSchristos
699dd9d0cfSchristos	return (1);
709dd9d0cfSchristos}
719dd9d0cfSchristos')
72