xref: /minix3/external/bsd/elftoolchain/dist/libdwarf/libdwarf_info.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: libdwarf_info.c,v 1.2 2014/03/09 16:58:04 christos Exp $	*/
2*0a6a1f1dSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc /*-
4*0a6a1f1dSLionel Sambuc  * Copyright (c) 2007 John Birrell (jb@freebsd.org)
5*0a6a1f1dSLionel Sambuc  * Copyright (c) 2010,2011 Kai Wang
6*0a6a1f1dSLionel Sambuc  * All rights reserved.
7*0a6a1f1dSLionel Sambuc  *
8*0a6a1f1dSLionel Sambuc  * Redistribution and use in source and binary forms, with or without
9*0a6a1f1dSLionel Sambuc  * modification, are permitted provided that the following conditions
10*0a6a1f1dSLionel Sambuc  * are met:
11*0a6a1f1dSLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
12*0a6a1f1dSLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
13*0a6a1f1dSLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
14*0a6a1f1dSLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
15*0a6a1f1dSLionel Sambuc  *    documentation and/or other materials provided with the distribution.
16*0a6a1f1dSLionel Sambuc  *
17*0a6a1f1dSLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18*0a6a1f1dSLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*0a6a1f1dSLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*0a6a1f1dSLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21*0a6a1f1dSLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*0a6a1f1dSLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*0a6a1f1dSLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*0a6a1f1dSLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*0a6a1f1dSLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*0a6a1f1dSLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*0a6a1f1dSLionel Sambuc  * SUCH DAMAGE.
28*0a6a1f1dSLionel Sambuc  */
29*0a6a1f1dSLionel Sambuc 
30*0a6a1f1dSLionel Sambuc #include "_libdwarf.h"
31*0a6a1f1dSLionel Sambuc 
32*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: libdwarf_info.c,v 1.2 2014/03/09 16:58:04 christos Exp $");
33*0a6a1f1dSLionel Sambuc ELFTC_VCSID("Id: libdwarf_info.c 2942 2013-05-04 23:03:54Z kaiwang27 ");
34*0a6a1f1dSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc int
_dwarf_info_first_cu(Dwarf_Debug dbg,Dwarf_Error * error)36*0a6a1f1dSLionel Sambuc _dwarf_info_first_cu(Dwarf_Debug dbg, Dwarf_Error *error)
37*0a6a1f1dSLionel Sambuc {
38*0a6a1f1dSLionel Sambuc 	Dwarf_CU cu;
39*0a6a1f1dSLionel Sambuc 	int ret;
40*0a6a1f1dSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc 	assert(dbg->dbg_cu_current == NULL);
42*0a6a1f1dSLionel Sambuc 	cu = STAILQ_FIRST(&dbg->dbg_cu);
43*0a6a1f1dSLionel Sambuc 	if (cu != NULL) {
44*0a6a1f1dSLionel Sambuc 		dbg->dbg_cu_current = cu;
45*0a6a1f1dSLionel Sambuc 		return (DW_DLE_NONE);
46*0a6a1f1dSLionel Sambuc 	}
47*0a6a1f1dSLionel Sambuc 
48*0a6a1f1dSLionel Sambuc 	if (dbg->dbg_info_loaded)
49*0a6a1f1dSLionel Sambuc 		return (DW_DLE_NO_ENTRY);
50*0a6a1f1dSLionel Sambuc 
51*0a6a1f1dSLionel Sambuc 	dbg->dbg_info_off = 0;
52*0a6a1f1dSLionel Sambuc 	ret = _dwarf_info_load(dbg, 0, error);
53*0a6a1f1dSLionel Sambuc 	if (ret != DW_DLE_NONE)
54*0a6a1f1dSLionel Sambuc 		return (ret);
55*0a6a1f1dSLionel Sambuc 
56*0a6a1f1dSLionel Sambuc 	dbg->dbg_cu_current = STAILQ_FIRST(&dbg->dbg_cu);
57*0a6a1f1dSLionel Sambuc 
58*0a6a1f1dSLionel Sambuc 	return (DW_DLE_NONE);
59*0a6a1f1dSLionel Sambuc }
60*0a6a1f1dSLionel Sambuc 
61*0a6a1f1dSLionel Sambuc int
_dwarf_info_next_cu(Dwarf_Debug dbg,Dwarf_Error * error)62*0a6a1f1dSLionel Sambuc _dwarf_info_next_cu(Dwarf_Debug dbg, Dwarf_Error *error)
63*0a6a1f1dSLionel Sambuc {
64*0a6a1f1dSLionel Sambuc 	Dwarf_CU cu;
65*0a6a1f1dSLionel Sambuc 	int ret;
66*0a6a1f1dSLionel Sambuc 
67*0a6a1f1dSLionel Sambuc 	assert(dbg->dbg_cu_current != NULL);
68*0a6a1f1dSLionel Sambuc 	cu = STAILQ_NEXT(dbg->dbg_cu_current, cu_next);
69*0a6a1f1dSLionel Sambuc 	if (cu != NULL) {
70*0a6a1f1dSLionel Sambuc 		dbg->dbg_cu_current = cu;
71*0a6a1f1dSLionel Sambuc 		return (DW_DLE_NONE);
72*0a6a1f1dSLionel Sambuc 	}
73*0a6a1f1dSLionel Sambuc 
74*0a6a1f1dSLionel Sambuc 	if (dbg->dbg_info_loaded) {
75*0a6a1f1dSLionel Sambuc 		dbg->dbg_cu_current = NULL;
76*0a6a1f1dSLionel Sambuc 		return (DW_DLE_NO_ENTRY);
77*0a6a1f1dSLionel Sambuc 	}
78*0a6a1f1dSLionel Sambuc 
79*0a6a1f1dSLionel Sambuc 	ret = _dwarf_info_load(dbg, 0, error);
80*0a6a1f1dSLionel Sambuc 	if (ret != DW_DLE_NONE)
81*0a6a1f1dSLionel Sambuc 		return (ret);
82*0a6a1f1dSLionel Sambuc 
83*0a6a1f1dSLionel Sambuc 	dbg->dbg_cu_current = STAILQ_NEXT(dbg->dbg_cu_current, cu_next);
84*0a6a1f1dSLionel Sambuc 
85*0a6a1f1dSLionel Sambuc 	return (DW_DLE_NONE);
86*0a6a1f1dSLionel Sambuc }
87*0a6a1f1dSLionel Sambuc 
88*0a6a1f1dSLionel Sambuc int
_dwarf_info_load(Dwarf_Debug dbg,int load_all,Dwarf_Error * error)89*0a6a1f1dSLionel Sambuc _dwarf_info_load(Dwarf_Debug dbg, int load_all, Dwarf_Error *error)
90*0a6a1f1dSLionel Sambuc {
91*0a6a1f1dSLionel Sambuc 	Dwarf_CU cu;
92*0a6a1f1dSLionel Sambuc 	Dwarf_Section *ds;
93*0a6a1f1dSLionel Sambuc 	int dwarf_size, ret;
94*0a6a1f1dSLionel Sambuc 	uint64_t length;
95*0a6a1f1dSLionel Sambuc 	uint64_t next_offset;
96*0a6a1f1dSLionel Sambuc 	uint64_t offset;
97*0a6a1f1dSLionel Sambuc 
98*0a6a1f1dSLionel Sambuc 	ret = DW_DLE_NONE;
99*0a6a1f1dSLionel Sambuc 	if (dbg->dbg_info_loaded)
100*0a6a1f1dSLionel Sambuc 		return (DW_DLE_NONE);
101*0a6a1f1dSLionel Sambuc 
102*0a6a1f1dSLionel Sambuc 	offset = dbg->dbg_info_off;
103*0a6a1f1dSLionel Sambuc 	ds = dbg->dbg_info_sec;
104*0a6a1f1dSLionel Sambuc 	assert(ds != NULL);
105*0a6a1f1dSLionel Sambuc 	while (offset < ds->ds_size) {
106*0a6a1f1dSLionel Sambuc 		if ((cu = calloc(1, sizeof(struct _Dwarf_CU))) == NULL) {
107*0a6a1f1dSLionel Sambuc 			DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
108*0a6a1f1dSLionel Sambuc 			return (DW_DLE_MEMORY);
109*0a6a1f1dSLionel Sambuc 		}
110*0a6a1f1dSLionel Sambuc 
111*0a6a1f1dSLionel Sambuc 		cu->cu_dbg = dbg;
112*0a6a1f1dSLionel Sambuc 		cu->cu_offset = offset;
113*0a6a1f1dSLionel Sambuc 
114*0a6a1f1dSLionel Sambuc 		length = dbg->read(ds->ds_data, &offset, 4);
115*0a6a1f1dSLionel Sambuc 		if (length == 0xffffffff) {
116*0a6a1f1dSLionel Sambuc 			length = dbg->read(ds->ds_data, &offset, 8);
117*0a6a1f1dSLionel Sambuc 			dwarf_size = 8;
118*0a6a1f1dSLionel Sambuc 		} else
119*0a6a1f1dSLionel Sambuc 			dwarf_size = 4;
120*0a6a1f1dSLionel Sambuc 		cu->cu_dwarf_size = dwarf_size;
121*0a6a1f1dSLionel Sambuc 
122*0a6a1f1dSLionel Sambuc 		/*
123*0a6a1f1dSLionel Sambuc 		 * Check if there is enough ELF data for this CU. This assumes
124*0a6a1f1dSLionel Sambuc 		 * that libelf gives us the entire section in one Elf_Data
125*0a6a1f1dSLionel Sambuc 		 * object.
126*0a6a1f1dSLionel Sambuc 		 */
127*0a6a1f1dSLionel Sambuc 		if (length > ds->ds_size - offset) {
128*0a6a1f1dSLionel Sambuc 			free(cu);
129*0a6a1f1dSLionel Sambuc 			DWARF_SET_ERROR(dbg, error, DW_DLE_CU_LENGTH_ERROR);
130*0a6a1f1dSLionel Sambuc 			return (DW_DLE_CU_LENGTH_ERROR);
131*0a6a1f1dSLionel Sambuc 		}
132*0a6a1f1dSLionel Sambuc 
133*0a6a1f1dSLionel Sambuc 		/* Compute the offset to the next compilation unit: */
134*0a6a1f1dSLionel Sambuc 		next_offset = offset + length;
135*0a6a1f1dSLionel Sambuc 		dbg->dbg_info_off = next_offset;
136*0a6a1f1dSLionel Sambuc 
137*0a6a1f1dSLionel Sambuc 		/* Initialise the compilation unit. */
138*0a6a1f1dSLionel Sambuc 		cu->cu_length		 = length;
139*0a6a1f1dSLionel Sambuc 		cu->cu_length_size	 = (dwarf_size == 4 ? 4 : 12);
140*0a6a1f1dSLionel Sambuc 		cu->cu_version		 = dbg->read(ds->ds_data, &offset, 2);
141*0a6a1f1dSLionel Sambuc 		cu->cu_abbrev_offset	 = dbg->read(ds->ds_data, &offset,
142*0a6a1f1dSLionel Sambuc 		    dwarf_size);
143*0a6a1f1dSLionel Sambuc 		cu->cu_abbrev_offset_cur = cu->cu_abbrev_offset;
144*0a6a1f1dSLionel Sambuc 		cu->cu_pointer_size	 = dbg->read(ds->ds_data, &offset, 1);
145*0a6a1f1dSLionel Sambuc 		cu->cu_next_offset	 = next_offset;
146*0a6a1f1dSLionel Sambuc 
147*0a6a1f1dSLionel Sambuc 		/* Add the compilation unit to the list. */
148*0a6a1f1dSLionel Sambuc 		STAILQ_INSERT_TAIL(&dbg->dbg_cu, cu, cu_next);
149*0a6a1f1dSLionel Sambuc 
150*0a6a1f1dSLionel Sambuc 		if (cu->cu_version < 2 || cu->cu_version > 4) {
151*0a6a1f1dSLionel Sambuc 			DWARF_SET_ERROR(dbg, error, DW_DLE_VERSION_STAMP_ERROR);
152*0a6a1f1dSLionel Sambuc 			ret = DW_DLE_VERSION_STAMP_ERROR;
153*0a6a1f1dSLionel Sambuc 			break;
154*0a6a1f1dSLionel Sambuc 		}
155*0a6a1f1dSLionel Sambuc 
156*0a6a1f1dSLionel Sambuc 		cu->cu_1st_offset = offset;
157*0a6a1f1dSLionel Sambuc 
158*0a6a1f1dSLionel Sambuc 		offset = next_offset;
159*0a6a1f1dSLionel Sambuc 
160*0a6a1f1dSLionel Sambuc 		if (!load_all)
161*0a6a1f1dSLionel Sambuc 			break;
162*0a6a1f1dSLionel Sambuc 	}
163*0a6a1f1dSLionel Sambuc 
164*0a6a1f1dSLionel Sambuc 	if ((Dwarf_Unsigned) dbg->dbg_info_off >= ds->ds_size)
165*0a6a1f1dSLionel Sambuc 		dbg->dbg_info_loaded = 1;
166*0a6a1f1dSLionel Sambuc 
167*0a6a1f1dSLionel Sambuc 	return (ret);
168*0a6a1f1dSLionel Sambuc }
169*0a6a1f1dSLionel Sambuc 
170*0a6a1f1dSLionel Sambuc void
_dwarf_info_cleanup(Dwarf_Debug dbg)171*0a6a1f1dSLionel Sambuc _dwarf_info_cleanup(Dwarf_Debug dbg)
172*0a6a1f1dSLionel Sambuc {
173*0a6a1f1dSLionel Sambuc 	Dwarf_CU cu, tcu;
174*0a6a1f1dSLionel Sambuc 
175*0a6a1f1dSLionel Sambuc 	assert(dbg != NULL && dbg->dbg_mode == DW_DLC_READ);
176*0a6a1f1dSLionel Sambuc 
177*0a6a1f1dSLionel Sambuc 	STAILQ_FOREACH_SAFE(cu, &dbg->dbg_cu, cu_next, tcu) {
178*0a6a1f1dSLionel Sambuc 		STAILQ_REMOVE(&dbg->dbg_cu, cu, _Dwarf_CU, cu_next);
179*0a6a1f1dSLionel Sambuc 		_dwarf_abbrev_cleanup(cu);
180*0a6a1f1dSLionel Sambuc 		if (cu->cu_lineinfo != NULL) {
181*0a6a1f1dSLionel Sambuc 			_dwarf_lineno_cleanup(cu->cu_lineinfo);
182*0a6a1f1dSLionel Sambuc 			cu->cu_lineinfo = NULL;
183*0a6a1f1dSLionel Sambuc 		}
184*0a6a1f1dSLionel Sambuc 		free(cu);
185*0a6a1f1dSLionel Sambuc 	}
186*0a6a1f1dSLionel Sambuc }
187*0a6a1f1dSLionel Sambuc 
188*0a6a1f1dSLionel Sambuc int
_dwarf_info_gen(Dwarf_P_Debug dbg,Dwarf_Error * error)189*0a6a1f1dSLionel Sambuc _dwarf_info_gen(Dwarf_P_Debug dbg, Dwarf_Error *error)
190*0a6a1f1dSLionel Sambuc {
191*0a6a1f1dSLionel Sambuc 	Dwarf_P_Section ds;
192*0a6a1f1dSLionel Sambuc 	Dwarf_Rel_Section drs;
193*0a6a1f1dSLionel Sambuc 	Dwarf_Unsigned offset;
194*0a6a1f1dSLionel Sambuc 	Dwarf_CU cu;
195*0a6a1f1dSLionel Sambuc 	int ret;
196*0a6a1f1dSLionel Sambuc 
197*0a6a1f1dSLionel Sambuc 	assert(dbg != NULL && dbg->write_alloc != NULL);
198*0a6a1f1dSLionel Sambuc 
199*0a6a1f1dSLionel Sambuc 	if (dbg->dbgp_root_die == NULL)
200*0a6a1f1dSLionel Sambuc 		return (DW_DLE_NONE);
201*0a6a1f1dSLionel Sambuc 
202*0a6a1f1dSLionel Sambuc 	/* Create the single CU for this debugging object. */
203*0a6a1f1dSLionel Sambuc 	if ((cu = calloc(1, sizeof(struct _Dwarf_CU))) == NULL) {
204*0a6a1f1dSLionel Sambuc 		DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
205*0a6a1f1dSLionel Sambuc 		return (DW_DLE_MEMORY);
206*0a6a1f1dSLionel Sambuc 	}
207*0a6a1f1dSLionel Sambuc 	cu->cu_dbg = dbg;
208*0a6a1f1dSLionel Sambuc 	cu->cu_version = 2;	/* DWARF2 */
209*0a6a1f1dSLionel Sambuc 	cu->cu_pointer_size = dbg->dbg_pointer_size;
210*0a6a1f1dSLionel Sambuc 	STAILQ_INSERT_TAIL(&dbg->dbg_cu, cu, cu_next);
211*0a6a1f1dSLionel Sambuc 
212*0a6a1f1dSLionel Sambuc 	/* Create .debug_info section. */
213*0a6a1f1dSLionel Sambuc 	if ((ret = _dwarf_section_init(dbg, &dbg->dbgp_info, ".debug_info", 0,
214*0a6a1f1dSLionel Sambuc 	    error)) != DW_DLE_NONE)
215*0a6a1f1dSLionel Sambuc 		goto gen_fail1;
216*0a6a1f1dSLionel Sambuc 	ds = dbg->dbgp_info;
217*0a6a1f1dSLionel Sambuc 
218*0a6a1f1dSLionel Sambuc 	/* Create relocation section for .debug_init */
219*0a6a1f1dSLionel Sambuc 	if ((ret = _dwarf_reloc_section_init(dbg, &drs, ds, error)) !=
220*0a6a1f1dSLionel Sambuc 	    DW_DLE_NONE)
221*0a6a1f1dSLionel Sambuc 		goto gen_fail0;
222*0a6a1f1dSLionel Sambuc 
223*0a6a1f1dSLionel Sambuc 	/* Length placeholder. (We only use 32-bit DWARF format) */
224*0a6a1f1dSLionel Sambuc 	RCHECK(WRITE_VALUE(cu->cu_length, 4));
225*0a6a1f1dSLionel Sambuc 
226*0a6a1f1dSLionel Sambuc 	/* Write CU version */
227*0a6a1f1dSLionel Sambuc 	RCHECK(WRITE_VALUE(cu->cu_version, 2));
228*0a6a1f1dSLionel Sambuc 
229*0a6a1f1dSLionel Sambuc 	/*
230*0a6a1f1dSLionel Sambuc 	 * Write abbrev offset. (always 0, we only support single CU)
231*0a6a1f1dSLionel Sambuc 	 * Also generate a relocation entry for this offset.
232*0a6a1f1dSLionel Sambuc 	 */
233*0a6a1f1dSLionel Sambuc 	RCHECK(_dwarf_reloc_entry_add(dbg, drs, ds, dwarf_drt_data_reloc, 4,
234*0a6a1f1dSLionel Sambuc 	    ds->ds_size, 0, cu->cu_abbrev_offset, ".debug_abbrev", error));
235*0a6a1f1dSLionel Sambuc 
236*0a6a1f1dSLionel Sambuc 	/* Pointer size. */
237*0a6a1f1dSLionel Sambuc 	RCHECK(WRITE_VALUE(cu->cu_pointer_size, 1));
238*0a6a1f1dSLionel Sambuc 
239*0a6a1f1dSLionel Sambuc 	/* Transform the DIE(s) of this CU. */
240*0a6a1f1dSLionel Sambuc 	RCHECK(_dwarf_die_gen(dbg, cu, drs, error));
241*0a6a1f1dSLionel Sambuc 
242*0a6a1f1dSLionel Sambuc 	/* Now we can fill in the length of this CU. */
243*0a6a1f1dSLionel Sambuc 	cu->cu_length = ds->ds_size - 4;
244*0a6a1f1dSLionel Sambuc 	offset = 0;
245*0a6a1f1dSLionel Sambuc 	dbg->write(ds->ds_data, &offset, cu->cu_length, 4);
246*0a6a1f1dSLionel Sambuc 
247*0a6a1f1dSLionel Sambuc 	/* Inform application the creation of .debug_info ELF section. */
248*0a6a1f1dSLionel Sambuc 	RCHECK(_dwarf_section_callback(dbg, ds, SHT_PROGBITS, 0, 0, 0, error));
249*0a6a1f1dSLionel Sambuc 
250*0a6a1f1dSLionel Sambuc 	/*
251*0a6a1f1dSLionel Sambuc 	 * Inform application the creation of relocation section for
252*0a6a1f1dSLionel Sambuc 	 * .debug_info.
253*0a6a1f1dSLionel Sambuc 	 */
254*0a6a1f1dSLionel Sambuc 	RCHECK(_dwarf_reloc_section_finalize(dbg, drs, error));
255*0a6a1f1dSLionel Sambuc 
256*0a6a1f1dSLionel Sambuc 	return (DW_DLE_NONE);
257*0a6a1f1dSLionel Sambuc 
258*0a6a1f1dSLionel Sambuc gen_fail:
259*0a6a1f1dSLionel Sambuc 	_dwarf_reloc_section_free(dbg, &drs);
260*0a6a1f1dSLionel Sambuc 
261*0a6a1f1dSLionel Sambuc gen_fail0:
262*0a6a1f1dSLionel Sambuc 	_dwarf_section_free(dbg, &dbg->dbgp_info);
263*0a6a1f1dSLionel Sambuc 
264*0a6a1f1dSLionel Sambuc gen_fail1:
265*0a6a1f1dSLionel Sambuc 	STAILQ_REMOVE(&dbg->dbg_cu, cu, _Dwarf_CU, cu_next);
266*0a6a1f1dSLionel Sambuc 	free(cu);
267*0a6a1f1dSLionel Sambuc 
268*0a6a1f1dSLionel Sambuc 	return (ret);
269*0a6a1f1dSLionel Sambuc }
270*0a6a1f1dSLionel Sambuc 
271*0a6a1f1dSLionel Sambuc void
_dwarf_info_pro_cleanup(Dwarf_P_Debug dbg)272*0a6a1f1dSLionel Sambuc _dwarf_info_pro_cleanup(Dwarf_P_Debug dbg)
273*0a6a1f1dSLionel Sambuc {
274*0a6a1f1dSLionel Sambuc 	Dwarf_CU cu;
275*0a6a1f1dSLionel Sambuc 
276*0a6a1f1dSLionel Sambuc 	assert(dbg != NULL && dbg->dbg_mode == DW_DLC_WRITE);
277*0a6a1f1dSLionel Sambuc 
278*0a6a1f1dSLionel Sambuc 	cu = STAILQ_FIRST(&dbg->dbg_cu);
279*0a6a1f1dSLionel Sambuc 	if (cu != NULL) {
280*0a6a1f1dSLionel Sambuc 		STAILQ_REMOVE(&dbg->dbg_cu, cu, _Dwarf_CU, cu_next);
281*0a6a1f1dSLionel Sambuc 		_dwarf_abbrev_cleanup(cu);
282*0a6a1f1dSLionel Sambuc 		free(cu);
283*0a6a1f1dSLionel Sambuc 	}
284*0a6a1f1dSLionel Sambuc }
285