2 * Copyright (c) 2009-2011,2014 Kai Wang
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
27 #include "_libdwarf.h"
29 ELFTC_VCSID("$Id: libdwarf_frame.c 3106 2014-12-19 16:00:58Z kaiwang27 $");
32 _dwarf_frame_find_cie(Dwarf_FrameSec fs, Dwarf_Unsigned offset,
37 STAILQ_FOREACH(cie, &fs->fs_cielist, cie_next) {
38 if (cie->cie_offset == offset)
43 return (DW_DLE_NO_ENTRY);
52 _dwarf_frame_read_lsb_encoded(Dwarf_Debug dbg, Dwarf_Cie cie, uint64_t *val,
53 uint8_t *data, uint64_t *offsetp, uint8_t encode, Dwarf_Addr pc,
58 if (encode == DW_EH_PE_omit)
61 application = encode & 0xf0;
66 *val = dbg->read(data, offsetp, cie->cie_addrsize);
68 case DW_EH_PE_uleb128:
69 *val = _dwarf_read_uleb128(data, offsetp);
72 *val = dbg->read(data, offsetp, 2);
75 *val = dbg->read(data, offsetp, 4);
78 *val = dbg->read(data, offsetp, 8);
80 case DW_EH_PE_sleb128:
81 *val = _dwarf_read_sleb128(data, offsetp);
84 *val = (int16_t) dbg->read(data, offsetp, 2);
87 *val = (int32_t) dbg->read(data, offsetp, 4);
90 *val = dbg->read(data, offsetp, 8);
93 DWARF_SET_ERROR(dbg, error, DW_DLE_FRAME_AUGMENTATION_UNKNOWN);
94 return (DW_DLE_FRAME_AUGMENTATION_UNKNOWN);
97 if (application == DW_EH_PE_pcrel) {
99 * Value is relative to .eh_frame section virtual addr.
102 case DW_EH_PE_uleb128:
103 case DW_EH_PE_udata2:
104 case DW_EH_PE_udata4:
105 case DW_EH_PE_udata8:
108 case DW_EH_PE_sleb128:
109 case DW_EH_PE_sdata2:
110 case DW_EH_PE_sdata4:
111 case DW_EH_PE_sdata8:
112 *val = pc + (int64_t) *val;
115 /* DW_EH_PE_absptr is absolute value. */
120 /* XXX Applications other than DW_EH_PE_pcrel are not handled. */
122 return (DW_DLE_NONE);
126 _dwarf_frame_parse_lsb_cie_augment(Dwarf_Debug dbg, Dwarf_Cie cie,
129 uint8_t *aug_p, *augdata_p;
130 uint64_t val, offset;
134 assert(cie->cie_augment != NULL && *cie->cie_augment == 'z');
137 * Here we're only interested in the presence of augment 'R'
138 * and associated CIE augment data, which describes the
139 * encoding scheme of FDE PC begin and range.
141 aug_p = &cie->cie_augment[1];
142 augdata_p = cie->cie_augdata;
143 while (*aug_p != '\0') {
146 /* Skip one augment in augment data. */
150 /* Skip two augments in augment data. */
151 encode = *augdata_p++;
153 ret = _dwarf_frame_read_lsb_encoded(dbg, cie, &val,
154 augdata_p, &offset, encode, 0, error);
155 if (ret != DW_DLE_NONE)
160 cie->cie_fde_encode = *augdata_p++;
163 DWARF_SET_ERROR(dbg, error,
164 DW_DLE_FRAME_AUGMENTATION_UNKNOWN);
165 return (DW_DLE_FRAME_AUGMENTATION_UNKNOWN);
170 return (DW_DLE_NONE);
174 _dwarf_frame_add_cie(Dwarf_Debug dbg, Dwarf_FrameSec fs, Dwarf_Section *ds,
175 Dwarf_Unsigned *off, Dwarf_Cie *ret_cie, Dwarf_Error *error)
182 /* Check if we already added this CIE. */
183 if (_dwarf_frame_find_cie(fs, *off, &cie) != DW_DLE_NO_ENTRY) {
184 *off += cie->cie_length + 4;
185 return (DW_DLE_NONE);
188 if ((cie = calloc(1, sizeof(struct _Dwarf_Cie))) == NULL) {
189 DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
190 return (DW_DLE_MEMORY);
192 STAILQ_INSERT_TAIL(&fs->fs_cielist, cie, cie_next);
195 cie->cie_index = fs->fs_cielen;
196 cie->cie_offset = *off;
198 length = dbg->read(ds->ds_data, off, 4);
199 if (length == 0xffffffff) {
201 length = dbg->read(ds->ds_data, off, 8);
205 if (length > ds->ds_size - *off) {
206 DWARF_SET_ERROR(dbg, error, DW_DLE_DEBUG_FRAME_LENGTH_BAD);
207 return (DW_DLE_DEBUG_FRAME_LENGTH_BAD);
210 (void) dbg->read(ds->ds_data, off, dwarf_size); /* Skip CIE id. */
211 cie->cie_length = length;
213 cie->cie_version = dbg->read(ds->ds_data, off, 1);
214 if (cie->cie_version != 1 && cie->cie_version != 3 &&
215 cie->cie_version != 4) {
216 DWARF_SET_ERROR(dbg, error, DW_DLE_FRAME_VERSION_BAD);
217 return (DW_DLE_FRAME_VERSION_BAD);
220 cie->cie_augment = ds->ds_data + *off;
221 p = (char *) ds->ds_data;
222 while (p[(*off)++] != '\0')
225 /* We only recognize normal .dwarf_frame and GNU .eh_frame sections. */
226 if (*cie->cie_augment != 0 && *cie->cie_augment != 'z') {
227 *off = cie->cie_offset + ((dwarf_size == 4) ? 4 : 12) +
229 return (DW_DLE_NONE);
232 /* Optional EH Data field for .eh_frame section. */
233 if (strstr((char *)cie->cie_augment, "eh") != NULL)
234 cie->cie_ehdata = dbg->read(ds->ds_data, off,
235 dbg->dbg_pointer_size);
237 /* DWARF4 added "address_size" and "segment_size". */
238 if (cie->cie_version == 4) {
239 cie->cie_addrsize = dbg->read(ds->ds_data, off, 1);
240 cie->cie_segmentsize = dbg->read(ds->ds_data, off, 1);
243 * Otherwise (DWARF[23]) we just set CIE addrsize to the
244 * debug context pointer size.
246 cie->cie_addrsize = dbg->dbg_pointer_size;
249 cie->cie_caf = _dwarf_read_uleb128(ds->ds_data, off);
250 cie->cie_daf = _dwarf_read_sleb128(ds->ds_data, off);
252 /* Return address register. */
253 if (cie->cie_version == 1)
254 cie->cie_ra = dbg->read(ds->ds_data, off, 1);
256 cie->cie_ra = _dwarf_read_uleb128(ds->ds_data, off);
258 /* Optional CIE augmentation data for .eh_frame section. */
259 if (*cie->cie_augment == 'z') {
260 cie->cie_auglen = _dwarf_read_uleb128(ds->ds_data, off);
261 cie->cie_augdata = ds->ds_data + *off;
262 *off += cie->cie_auglen;
264 * XXX Use DW_EH_PE_absptr for default FDE PC start/range,
265 * in case _dwarf_frame_parse_lsb_cie_augment fails to
266 * find out the real encode.
268 cie->cie_fde_encode = DW_EH_PE_absptr;
269 ret = _dwarf_frame_parse_lsb_cie_augment(dbg, cie, error);
270 if (ret != DW_DLE_NONE)
274 /* CIE Initial instructions. */
275 cie->cie_initinst = ds->ds_data + *off;
277 cie->cie_instlen = cie->cie_offset + 4 + length - *off;
279 cie->cie_instlen = cie->cie_offset + 12 + length - *off;
281 *off += cie->cie_instlen;
285 printf("\tcie_version=%u cie_offset=%ju cie_length=%ju cie_augment=%s"
286 " cie_instlen=%ju cie->cie_caf=%ju cie->cie_daf=%jd off=%ju\n",
287 cie->cie_version, cie->cie_offset, cie->cie_length,
288 (char *)cie->cie_augment, cie->cie_instlen, cie->cie_caf,
297 return (DW_DLE_NONE);
301 _dwarf_frame_add_fde(Dwarf_Debug dbg, Dwarf_FrameSec fs, Dwarf_Section *ds,
302 Dwarf_Unsigned *off, int eh_frame, Dwarf_Error *error)
306 Dwarf_Unsigned cieoff;
307 uint64_t length, val;
310 if ((fde = calloc(1, sizeof(struct _Dwarf_Fde))) == NULL) {
311 DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
312 return (DW_DLE_MEMORY);
314 STAILQ_INSERT_TAIL(&fs->fs_fdelist, fde, fde_next);
318 fde->fde_addr = ds->ds_data + *off;
319 fde->fde_offset = *off;
321 length = dbg->read(ds->ds_data, off, 4);
322 if (length == 0xffffffff) {
324 length = dbg->read(ds->ds_data, off, 8);
328 if (length > ds->ds_size - *off) {
329 DWARF_SET_ERROR(dbg, error, DW_DLE_DEBUG_FRAME_LENGTH_BAD);
330 return (DW_DLE_DEBUG_FRAME_LENGTH_BAD);
333 fde->fde_length = length;
336 fde->fde_cieoff = dbg->read(ds->ds_data, off, 4);
337 cieoff = *off - (4 + fde->fde_cieoff);
338 /* This delta should never be 0. */
339 if (cieoff == fde->fde_offset) {
340 DWARF_SET_ERROR(dbg, error, DW_DLE_NO_CIE_FOR_FDE);
341 return (DW_DLE_NO_CIE_FOR_FDE);
344 fde->fde_cieoff = dbg->read(ds->ds_data, off, dwarf_size);
345 cieoff = fde->fde_cieoff;
348 if (_dwarf_frame_find_cie(fs, cieoff, &cie) ==
350 ret = _dwarf_frame_add_cie(dbg, fs, ds, &cieoff, &cie,
352 if (ret != DW_DLE_NONE)
358 * The FDE PC start/range for .eh_frame is encoded according
359 * to the LSB spec's extension to DWARF2.
361 ret = _dwarf_frame_read_lsb_encoded(dbg, cie, &val,
362 ds->ds_data, off, cie->cie_fde_encode, ds->ds_addr + *off,
364 if (ret != DW_DLE_NONE)
366 fde->fde_initloc = val;
368 * FDE PC range should not be relative value to anything.
369 * So pass 0 for pc value.
371 ret = _dwarf_frame_read_lsb_encoded(dbg, cie, &val,
372 ds->ds_data, off, cie->cie_fde_encode, 0, error);
373 if (ret != DW_DLE_NONE)
375 fde->fde_adrange = val;
377 fde->fde_initloc = dbg->read(ds->ds_data, off,
379 fde->fde_adrange = dbg->read(ds->ds_data, off,
383 /* Optional FDE augmentation data for .eh_frame section. (ignored) */
384 if (eh_frame && *cie->cie_augment == 'z') {
385 fde->fde_auglen = _dwarf_read_uleb128(ds->ds_data, off);
386 fde->fde_augdata = ds->ds_data + *off;
387 *off += fde->fde_auglen;
390 fde->fde_inst = ds->ds_data + *off;
392 fde->fde_instlen = fde->fde_offset + 4 + length - *off;
394 fde->fde_instlen = fde->fde_offset + 12 + length - *off;
396 *off += fde->fde_instlen;
401 printf("(eh_frame)");
403 printf("\tfde_offset=%ju fde_length=%ju fde_cieoff=%ju"
404 " fde_instlen=%ju off=%ju\n", fde->fde_offset, fde->fde_length,
405 fde->fde_cieoff, fde->fde_instlen, *off);
410 return (DW_DLE_NONE);
414 _dwarf_frame_section_cleanup(Dwarf_FrameSec fs)
419 STAILQ_FOREACH_SAFE(cie, &fs->fs_cielist, cie_next, tcie) {
420 STAILQ_REMOVE(&fs->fs_cielist, cie, _Dwarf_Cie, cie_next);
424 STAILQ_FOREACH_SAFE(fde, &fs->fs_fdelist, fde_next, tfde) {
425 STAILQ_REMOVE(&fs->fs_fdelist, fde, _Dwarf_Fde, fde_next);
429 if (fs->fs_ciearray != NULL)
430 free(fs->fs_ciearray);
431 if (fs->fs_fdearray != NULL)
432 free(fs->fs_fdearray);
438 _dwarf_frame_section_init(Dwarf_Debug dbg, Dwarf_FrameSec *frame_sec,
439 Dwarf_Section *ds, int eh_frame, Dwarf_Error *error)
444 uint64_t length, offset, cie_id, entry_off;
445 int dwarf_size, i, ret;
447 assert(frame_sec != NULL);
448 assert(*frame_sec == NULL);
450 if ((fs = calloc(1, sizeof(struct _Dwarf_FrameSec))) == NULL) {
451 DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
452 return (DW_DLE_MEMORY);
454 STAILQ_INIT(&fs->fs_cielist);
455 STAILQ_INIT(&fs->fs_fdelist);
458 while (offset < ds->ds_size) {
460 length = dbg->read(ds->ds_data, &offset, 4);
461 if (length == 0xffffffff) {
463 length = dbg->read(ds->ds_data, &offset, 8);
467 if (length > ds->ds_size - offset ||
468 (length == 0 && !eh_frame)) {
469 DWARF_SET_ERROR(dbg, error,
470 DW_DLE_DEBUG_FRAME_LENGTH_BAD);
471 return (DW_DLE_DEBUG_FRAME_LENGTH_BAD);
474 /* Check terminator for .eh_frame */
475 if (eh_frame && length == 0)
478 cie_id = dbg->read(ds->ds_data, &offset, dwarf_size);
481 /* GNU .eh_frame use CIE id 0. */
483 ret = _dwarf_frame_add_cie(dbg, fs, ds,
484 &entry_off, NULL, error);
486 ret = _dwarf_frame_add_fde(dbg, fs, ds,
487 &entry_off, 1, error);
489 /* .dwarf_frame use CIE id ~0 */
490 if ((dwarf_size == 4 && cie_id == ~0U) ||
491 (dwarf_size == 8 && cie_id == ~0ULL))
492 ret = _dwarf_frame_add_cie(dbg, fs, ds,
493 &entry_off, NULL, error);
495 ret = _dwarf_frame_add_fde(dbg, fs, ds,
496 &entry_off, 0, error);
499 if (ret != DW_DLE_NONE)
505 /* Create CIE array. */
506 if (fs->fs_cielen > 0) {
507 if ((fs->fs_ciearray = malloc(sizeof(Dwarf_Cie) *
508 fs->fs_cielen)) == NULL) {
510 DWARF_SET_ERROR(dbg, error, ret);
514 STAILQ_FOREACH(cie, &fs->fs_cielist, cie_next) {
515 fs->fs_ciearray[i++] = cie;
517 assert((Dwarf_Unsigned)i == fs->fs_cielen);
520 /* Create FDE array. */
521 if (fs->fs_fdelen > 0) {
522 if ((fs->fs_fdearray = malloc(sizeof(Dwarf_Fde) *
523 fs->fs_fdelen)) == NULL) {
525 DWARF_SET_ERROR(dbg, error, ret);
529 STAILQ_FOREACH(fde, &fs->fs_fdelist, fde_next) {
530 fs->fs_fdearray[i++] = fde;
532 assert((Dwarf_Unsigned)i == fs->fs_fdelen);
537 return (DW_DLE_NONE);
541 _dwarf_frame_section_cleanup(fs);
547 _dwarf_frame_run_inst(Dwarf_Debug dbg, Dwarf_Regtable3 *rt, uint8_t addr_size,
548 uint8_t *insts, Dwarf_Unsigned len, Dwarf_Unsigned caf, Dwarf_Signed daf,
549 Dwarf_Addr pc, Dwarf_Addr pc_req, Dwarf_Addr *row_pc, Dwarf_Error *error)
551 Dwarf_Regtable3 *init_rt, *saved_rt;
554 uint64_t reg, reg2, uoff, soff;
557 #define CFA rt->rt3_cfa_rule
558 #define INITCFA init_rt->rt3_cfa_rule
559 #define RL rt->rt3_rules
560 #define INITRL init_rt->rt3_rules
562 #define CHECK_TABLE_SIZE(x) \
564 if ((x) >= rt->rt3_reg_table_size) { \
565 DWARF_SET_ERROR(dbg, error, \
566 DW_DLE_DF_REG_NUM_TOO_HIGH); \
567 ret = DW_DLE_DF_REG_NUM_TOO_HIGH; \
573 printf("frame_run_inst: (caf=%ju, daf=%jd)\n", caf, daf);
577 init_rt = saved_rt = NULL;
580 /* Save a copy of the table as initial state. */
581 _dwarf_frame_regtable_copy(dbg, &init_rt, rt, error);
589 printf("p=%p pe=%p pc=%#jx pc_req=%#jx\n", p, pe, pc, pc_req);
592 if (*p == DW_CFA_nop) {
594 printf("DW_CFA_nop\n");
606 case DW_CFA_advance_loc:
609 printf("DW_CFA_advance_loc(%#jx(%u))\n", pc,
617 CHECK_TABLE_SIZE(low6);
618 RL[low6].dw_offset_relevant = 1;
619 RL[low6].dw_value_type = DW_EXPR_OFFSET;
620 RL[low6].dw_regnum = dbg->dbg_frame_cfa_value;
621 RL[low6].dw_offset_or_block_len =
622 _dwarf_decode_uleb128(&p) * daf;
624 printf("DW_CFA_offset(%jd)\n",
625 RL[low6].dw_offset_or_block_len);
630 CHECK_TABLE_SIZE(low6);
631 memcpy(&RL[low6], &INITRL[low6],
632 sizeof(Dwarf_Regtable_Entry3));
634 printf("DW_CFA_restore(%u)\n", low6);
638 DWARF_SET_ERROR(dbg, error,
639 DW_DLE_FRAME_INSTR_EXEC_ERROR);
640 ret = DW_DLE_FRAME_INSTR_EXEC_ERROR;
649 pc = dbg->decode(&p, addr_size);
651 printf("DW_CFA_set_loc(pc=%#jx)\n", pc);
656 case DW_CFA_advance_loc1:
657 pc += dbg->decode(&p, 1) * caf;
659 printf("DW_CFA_set_loc1(pc=%#jx)\n", pc);
664 case DW_CFA_advance_loc2:
665 pc += dbg->decode(&p, 2) * caf;
667 printf("DW_CFA_set_loc2(pc=%#jx)\n", pc);
672 case DW_CFA_advance_loc4:
673 pc += dbg->decode(&p, 4) * caf;
675 printf("DW_CFA_set_loc4(pc=%#jx)\n", pc);
680 case DW_CFA_offset_extended:
682 reg = _dwarf_decode_uleb128(&p);
683 uoff = _dwarf_decode_uleb128(&p);
684 CHECK_TABLE_SIZE(reg);
685 RL[reg].dw_offset_relevant = 1;
686 RL[reg].dw_value_type = DW_EXPR_OFFSET;
687 RL[reg].dw_regnum = dbg->dbg_frame_cfa_value;
688 RL[reg].dw_offset_or_block_len = uoff * daf;
690 printf("DW_CFA_offset_extended(reg=%ju,uoff=%ju)\n",
694 case DW_CFA_restore_extended:
696 reg = _dwarf_decode_uleb128(&p);
697 CHECK_TABLE_SIZE(reg);
698 memcpy(&RL[reg], &INITRL[reg],
699 sizeof(Dwarf_Regtable_Entry3));
701 printf("DW_CFA_restore_extended(%ju)\n", reg);
704 case DW_CFA_undefined:
706 reg = _dwarf_decode_uleb128(&p);
707 CHECK_TABLE_SIZE(reg);
708 RL[reg].dw_offset_relevant = 0;
709 RL[reg].dw_regnum = dbg->dbg_frame_undefined_value;
711 printf("DW_CFA_undefined(%ju)\n", reg);
714 case DW_CFA_same_value:
715 reg = _dwarf_decode_uleb128(&p);
716 CHECK_TABLE_SIZE(reg);
717 RL[reg].dw_offset_relevant = 0;
718 RL[reg].dw_regnum = dbg->dbg_frame_same_value;
720 printf("DW_CFA_same_value(%ju)\n", reg);
723 case DW_CFA_register:
725 reg = _dwarf_decode_uleb128(&p);
726 reg2 = _dwarf_decode_uleb128(&p);
727 CHECK_TABLE_SIZE(reg);
728 RL[reg].dw_offset_relevant = 0;
729 RL[reg].dw_regnum = reg2;
731 printf("DW_CFA_register(reg=%ju,reg2=%ju)\n", reg,
735 case DW_CFA_remember_state:
736 _dwarf_frame_regtable_copy(dbg, &saved_rt, rt, error);
738 printf("DW_CFA_remember_state\n");
741 case DW_CFA_restore_state:
743 _dwarf_frame_regtable_copy(dbg, &rt, saved_rt, error);
745 printf("DW_CFA_restore_state\n");
750 reg = _dwarf_decode_uleb128(&p);
751 uoff = _dwarf_decode_uleb128(&p);
752 CFA.dw_offset_relevant = 1;
753 CFA.dw_value_type = DW_EXPR_OFFSET;
755 CFA.dw_offset_or_block_len = uoff;
757 printf("DW_CFA_def_cfa(reg=%ju,uoff=%ju)\n", reg, uoff);
760 case DW_CFA_def_cfa_register:
762 reg = _dwarf_decode_uleb128(&p);
765 * Note that DW_CFA_def_cfa_register change the CFA
766 * rule register while keep the old offset. So we
767 * should not touch the CFA.dw_offset_relevant flag
771 printf("DW_CFA_def_cfa_register(%ju)\n", reg);
774 case DW_CFA_def_cfa_offset:
776 uoff = _dwarf_decode_uleb128(&p);
777 CFA.dw_offset_relevant = 1;
778 CFA.dw_value_type = DW_EXPR_OFFSET;
779 CFA.dw_offset_or_block_len = uoff;
781 printf("DW_CFA_def_cfa_offset(%ju)\n", uoff);
784 case DW_CFA_def_cfa_expression:
786 CFA.dw_offset_relevant = 0;
787 CFA.dw_value_type = DW_EXPR_EXPRESSION;
788 CFA.dw_offset_or_block_len = _dwarf_decode_uleb128(&p);
789 CFA.dw_block_ptr = p;
790 p += CFA.dw_offset_or_block_len;
792 printf("DW_CFA_def_cfa_expression\n");
795 case DW_CFA_expression:
797 reg = _dwarf_decode_uleb128(&p);
798 CHECK_TABLE_SIZE(reg);
799 RL[reg].dw_offset_relevant = 0;
800 RL[reg].dw_value_type = DW_EXPR_EXPRESSION;
801 RL[reg].dw_offset_or_block_len =
802 _dwarf_decode_uleb128(&p);
803 RL[reg].dw_block_ptr = p;
804 p += RL[reg].dw_offset_or_block_len;
806 printf("DW_CFA_expression\n");
809 case DW_CFA_offset_extended_sf:
811 reg = _dwarf_decode_uleb128(&p);
812 soff = _dwarf_decode_sleb128(&p);
813 CHECK_TABLE_SIZE(reg);
814 RL[reg].dw_offset_relevant = 1;
815 RL[reg].dw_value_type = DW_EXPR_OFFSET;
816 RL[reg].dw_regnum = dbg->dbg_frame_cfa_value;
817 RL[reg].dw_offset_or_block_len = soff * daf;
819 printf("DW_CFA_offset_extended_sf(reg=%ju,soff=%jd)\n",
823 case DW_CFA_def_cfa_sf:
825 reg = _dwarf_decode_uleb128(&p);
826 soff = _dwarf_decode_sleb128(&p);
827 CFA.dw_offset_relevant = 1;
828 CFA.dw_value_type = DW_EXPR_OFFSET;
830 CFA.dw_offset_or_block_len = soff * daf;
832 printf("DW_CFA_def_cfa_sf(reg=%ju,soff=%jd)\n", reg,
836 case DW_CFA_def_cfa_offset_sf:
838 soff = _dwarf_decode_sleb128(&p);
839 CFA.dw_offset_relevant = 1;
840 CFA.dw_value_type = DW_EXPR_OFFSET;
841 CFA.dw_offset_or_block_len = soff * daf;
843 printf("DW_CFA_def_cfa_offset_sf(soff=%jd)\n", soff);
846 case DW_CFA_val_offset:
848 reg = _dwarf_decode_uleb128(&p);
849 uoff = _dwarf_decode_uleb128(&p);
850 CHECK_TABLE_SIZE(reg);
851 RL[reg].dw_offset_relevant = 1;
852 RL[reg].dw_value_type = DW_EXPR_VAL_OFFSET;
853 RL[reg].dw_regnum = dbg->dbg_frame_cfa_value;
854 RL[reg].dw_offset_or_block_len = uoff * daf;
856 printf("DW_CFA_val_offset(reg=%ju,uoff=%ju)\n", reg,
860 case DW_CFA_val_offset_sf:
862 reg = _dwarf_decode_uleb128(&p);
863 soff = _dwarf_decode_sleb128(&p);
864 CHECK_TABLE_SIZE(reg);
865 RL[reg].dw_offset_relevant = 1;
866 RL[reg].dw_value_type = DW_EXPR_VAL_OFFSET;
867 RL[reg].dw_regnum = dbg->dbg_frame_cfa_value;
868 RL[reg].dw_offset_or_block_len = soff * daf;
870 printf("DW_CFA_val_offset_sf(reg=%ju,soff=%jd)\n", reg,
874 case DW_CFA_val_expression:
876 reg = _dwarf_decode_uleb128(&p);
877 CHECK_TABLE_SIZE(reg);
878 RL[reg].dw_offset_relevant = 0;
879 RL[reg].dw_value_type = DW_EXPR_VAL_EXPRESSION;
880 RL[reg].dw_offset_or_block_len =
881 _dwarf_decode_uleb128(&p);
882 RL[reg].dw_block_ptr = p;
883 p += RL[reg].dw_offset_or_block_len;
885 printf("DW_CFA_val_expression\n");
889 DWARF_SET_ERROR(dbg, error,
890 DW_DLE_FRAME_INSTR_EXEC_ERROR);
891 ret = DW_DLE_FRAME_INSTR_EXEC_ERROR;
898 free(init_rt->rt3_rules);
901 free(saved_rt->rt3_rules);
911 #undef CHECK_TABLE_SIZE
915 _dwarf_frame_convert_inst(Dwarf_Debug dbg, uint8_t addr_size, uint8_t *insts,
916 Dwarf_Unsigned len, Dwarf_Unsigned *count, Dwarf_Frame_Op *fop,
917 Dwarf_Frame_Op3 *fop3, Dwarf_Error *error)
921 uint64_t reg, reg2, uoff, soff, blen;
923 #define SET_BASE_OP(x) \
926 fop[*count].fp_base_op = (x) >> 6; \
928 fop3[*count].fp_base_op = (x) >> 6; \
931 #define SET_EXTENDED_OP(x) \
934 fop[*count].fp_extended_op = (x); \
936 fop3[*count].fp_extended_op = (x); \
939 #define SET_REGISTER(x) \
942 fop[*count].fp_register = (x); \
944 fop3[*count].fp_register = (x); \
947 #define SET_OFFSET(x) \
950 fop[*count].fp_offset = (x); \
952 fop3[*count].fp_offset_or_block_len = \
956 #define SET_INSTR_OFFSET(x) \
959 fop[*count].fp_instr_offset = (x); \
961 fop3[*count].fp_instr_offset = (x); \
964 #define SET_BLOCK_LEN(x) \
967 fop3[*count].fp_offset_or_block_len = \
971 #define SET_EXPR_BLOCK(addr, len) \
973 if (fop3 != NULL) { \
974 fop3[*count].fp_expr_block = \
975 malloc((size_t) (len)); \
976 if (fop3[*count].fp_expr_block == NULL) { \
977 DWARF_SET_ERROR(dbg, error, \
979 return (DW_DLE_MEMORY); \
981 memcpy(&fop3[*count].fp_expr_block, \
993 SET_INSTR_OFFSET(p - insts);
995 if (*p == DW_CFA_nop) {
1007 case DW_CFA_advance_loc:
1014 uoff = _dwarf_decode_uleb128(&p);
1017 case DW_CFA_restore:
1022 DWARF_SET_ERROR(dbg, error,
1023 DW_DLE_FRAME_INSTR_EXEC_ERROR);
1024 return (DW_DLE_FRAME_INSTR_EXEC_ERROR);
1031 SET_EXTENDED_OP(low6);
1034 case DW_CFA_set_loc:
1035 uoff = dbg->decode(&p, addr_size);
1038 case DW_CFA_advance_loc1:
1039 uoff = dbg->decode(&p, 1);
1042 case DW_CFA_advance_loc2:
1043 uoff = dbg->decode(&p, 2);
1046 case DW_CFA_advance_loc4:
1047 uoff = dbg->decode(&p, 4);
1050 case DW_CFA_offset_extended:
1051 case DW_CFA_def_cfa:
1052 case DW_CFA_val_offset:
1053 reg = _dwarf_decode_uleb128(&p);
1054 uoff = _dwarf_decode_uleb128(&p);
1058 case DW_CFA_restore_extended:
1059 case DW_CFA_undefined:
1060 case DW_CFA_same_value:
1061 case DW_CFA_def_cfa_register:
1062 reg = _dwarf_decode_uleb128(&p);
1065 case DW_CFA_register:
1066 reg = _dwarf_decode_uleb128(&p);
1067 reg2 = _dwarf_decode_uleb128(&p);
1071 case DW_CFA_remember_state:
1072 case DW_CFA_restore_state:
1074 case DW_CFA_def_cfa_offset:
1075 uoff = _dwarf_decode_uleb128(&p);
1078 case DW_CFA_def_cfa_expression:
1079 blen = _dwarf_decode_uleb128(&p);
1080 SET_BLOCK_LEN(blen);
1081 SET_EXPR_BLOCK(p, blen);
1084 case DW_CFA_expression:
1085 case DW_CFA_val_expression:
1086 reg = _dwarf_decode_uleb128(&p);
1087 blen = _dwarf_decode_uleb128(&p);
1089 SET_BLOCK_LEN(blen);
1090 SET_EXPR_BLOCK(p, blen);
1093 case DW_CFA_offset_extended_sf:
1094 case DW_CFA_def_cfa_sf:
1095 case DW_CFA_val_offset_sf:
1096 reg = _dwarf_decode_uleb128(&p);
1097 soff = _dwarf_decode_sleb128(&p);
1101 case DW_CFA_def_cfa_offset_sf:
1102 soff = _dwarf_decode_sleb128(&p);
1106 DWARF_SET_ERROR(dbg, error,
1107 DW_DLE_FRAME_INSTR_EXEC_ERROR);
1108 return (DW_DLE_FRAME_INSTR_EXEC_ERROR);
1114 return (DW_DLE_NONE);
1118 _dwarf_frame_get_fop(Dwarf_Debug dbg, uint8_t addr_size, uint8_t *insts,
1119 Dwarf_Unsigned len, Dwarf_Frame_Op **ret_oplist, Dwarf_Signed *ret_opcnt,
1122 Dwarf_Frame_Op *oplist;
1123 Dwarf_Unsigned count;
1126 ret = _dwarf_frame_convert_inst(dbg, addr_size, insts, len, &count,
1128 if (ret != DW_DLE_NONE)
1131 if ((oplist = calloc(count, sizeof(Dwarf_Frame_Op))) == NULL) {
1132 DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
1133 return (DW_DLE_MEMORY);
1136 ret = _dwarf_frame_convert_inst(dbg, addr_size, insts, len, &count,
1137 oplist, NULL, error);
1138 if (ret != DW_DLE_NONE) {
1143 *ret_oplist = oplist;
1146 return (DW_DLE_NONE);
1150 _dwarf_frame_regtable_copy(Dwarf_Debug dbg, Dwarf_Regtable3 **dest,
1151 Dwarf_Regtable3 *src, Dwarf_Error *error)
1155 assert(dest != NULL);
1156 assert(src != NULL);
1158 if (*dest == NULL) {
1159 if ((*dest = malloc(sizeof(Dwarf_Regtable3))) == NULL) {
1160 DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
1161 return (DW_DLE_MEMORY);
1163 (*dest)->rt3_reg_table_size = src->rt3_reg_table_size;
1164 (*dest)->rt3_rules = malloc(src->rt3_reg_table_size *
1165 sizeof(Dwarf_Regtable_Entry3));
1166 if ((*dest)->rt3_rules == NULL) {
1168 DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
1169 return (DW_DLE_MEMORY);
1173 memcpy(&(*dest)->rt3_cfa_rule, &src->rt3_cfa_rule,
1174 sizeof(Dwarf_Regtable_Entry3));
1176 for (i = 0; i < (*dest)->rt3_reg_table_size &&
1177 i < src->rt3_reg_table_size; i++)
1178 memcpy(&(*dest)->rt3_rules[i], &src->rt3_rules[i],
1179 sizeof(Dwarf_Regtable_Entry3));
1181 for (; i < (*dest)->rt3_reg_table_size; i++)
1182 (*dest)->rt3_rules[i].dw_regnum =
1183 dbg->dbg_frame_undefined_value;
1185 return (DW_DLE_NONE);
1189 _dwarf_frame_get_internal_table(Dwarf_Fde fde, Dwarf_Addr pc_req,
1190 Dwarf_Regtable3 **ret_rt, Dwarf_Addr *ret_row_pc, Dwarf_Error *error)
1194 Dwarf_Regtable3 *rt;
1198 assert(ret_rt != NULL);
1201 assert(dbg != NULL);
1203 rt = dbg->dbg_internal_reg_table;
1205 /* Clear the content of regtable from previous run. */
1206 memset(&rt->rt3_cfa_rule, 0, sizeof(Dwarf_Regtable_Entry3));
1207 memset(rt->rt3_rules, 0, rt->rt3_reg_table_size *
1208 sizeof(Dwarf_Regtable_Entry3));
1210 /* Set rules to initial values. */
1211 for (i = 0; i < rt->rt3_reg_table_size; i++)
1212 rt->rt3_rules[i].dw_regnum = dbg->dbg_frame_rule_initial_value;
1214 /* Run initial instructions in CIE. */
1216 assert(cie != NULL);
1217 ret = _dwarf_frame_run_inst(dbg, rt, cie->cie_addrsize,
1218 cie->cie_initinst, cie->cie_instlen, cie->cie_caf, cie->cie_daf, 0,
1219 ~0ULL, &row_pc, error);
1220 if (ret != DW_DLE_NONE)
1223 /* Run instructions in FDE. */
1224 if (pc_req >= fde->fde_initloc) {
1225 ret = _dwarf_frame_run_inst(dbg, rt, cie->cie_addrsize,
1226 fde->fde_inst, fde->fde_instlen, cie->cie_caf,
1227 cie->cie_daf, fde->fde_initloc, pc_req, &row_pc, error);
1228 if (ret != DW_DLE_NONE)
1233 *ret_row_pc = row_pc;
1235 return (DW_DLE_NONE);
1239 _dwarf_frame_cleanup(Dwarf_Debug dbg)
1241 Dwarf_Regtable3 *rt;
1243 assert(dbg != NULL && dbg->dbg_mode == DW_DLC_READ);
1245 if (dbg->dbg_internal_reg_table) {
1246 rt = dbg->dbg_internal_reg_table;
1247 free(rt->rt3_rules);
1249 dbg->dbg_internal_reg_table = NULL;
1252 if (dbg->dbg_frame) {
1253 _dwarf_frame_section_cleanup(dbg->dbg_frame);
1254 dbg->dbg_frame = NULL;
1257 if (dbg->dbg_eh_frame) {
1258 _dwarf_frame_section_cleanup(dbg->dbg_eh_frame);
1259 dbg->dbg_eh_frame = NULL;
1264 _dwarf_frame_section_load(Dwarf_Debug dbg, Dwarf_Error *error)
1268 if ((ds = _dwarf_find_section(dbg, ".debug_frame")) != NULL) {
1269 return (_dwarf_frame_section_init(dbg, &dbg->dbg_frame,
1273 return (DW_DLE_NONE);
1277 _dwarf_frame_section_load_eh(Dwarf_Debug dbg, Dwarf_Error *error)
1281 if ((ds = _dwarf_find_section(dbg, ".eh_frame")) != NULL) {
1282 return (_dwarf_frame_section_init(dbg, &dbg->dbg_eh_frame,
1286 return (DW_DLE_NONE);
1290 _dwarf_frame_params_init(Dwarf_Debug dbg)
1293 /* Initialise call frame related parameters. */
1294 dbg->dbg_frame_rule_table_size = DW_FRAME_LAST_REG_NUM;
1295 dbg->dbg_frame_rule_initial_value = DW_FRAME_REG_INITIAL_VALUE;
1296 dbg->dbg_frame_cfa_value = DW_FRAME_CFA_COL3;
1297 dbg->dbg_frame_same_value = DW_FRAME_SAME_VAL;
1298 dbg->dbg_frame_undefined_value = DW_FRAME_UNDEFINED_VAL;
1302 _dwarf_frame_interal_table_init(Dwarf_Debug dbg, Dwarf_Error *error)
1304 Dwarf_Regtable3 *rt;
1306 if (dbg->dbg_internal_reg_table != NULL)
1307 return (DW_DLE_NONE);
1309 /* Initialise internal register table. */
1310 if ((rt = calloc(1, sizeof(Dwarf_Regtable3))) == NULL) {
1311 DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
1312 return (DW_DLE_MEMORY);
1315 rt->rt3_reg_table_size = dbg->dbg_frame_rule_table_size;
1316 if ((rt->rt3_rules = calloc(rt->rt3_reg_table_size,
1317 sizeof(Dwarf_Regtable_Entry3))) == NULL) {
1319 DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
1320 return (DW_DLE_MEMORY);
1323 dbg->dbg_internal_reg_table = rt;
1325 return (DW_DLE_NONE);
1328 #define _FDE_INST_INIT_SIZE 128
1331 _dwarf_frame_fde_add_inst(Dwarf_P_Fde fde, Dwarf_Small op, Dwarf_Unsigned val1,
1332 Dwarf_Unsigned val2, Dwarf_Error *error)
1335 uint8_t high2, low6;
1339 #define ds_data fde_inst
1340 #define ds_cap fde_instcap
1341 #define ds_size fde_instlen
1343 assert(fde != NULL && fde->fde_dbg != NULL);
1346 if (fde->fde_inst == NULL) {
1347 fde->fde_instcap = _FDE_INST_INIT_SIZE;
1348 fde->fde_instlen = 0;
1349 if ((fde->fde_inst = malloc((size_t) fde->fde_instcap)) ==
1351 DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
1352 return (DW_DLE_MEMORY);
1355 assert(fde->fde_instcap != 0);
1357 RCHECK(WRITE_VALUE(op, 1));
1358 if (op == DW_CFA_nop)
1359 return (DW_DLE_NONE);
1366 case DW_CFA_advance_loc:
1367 case DW_CFA_restore:
1370 RCHECK(WRITE_ULEB128(val1));
1373 DWARF_SET_ERROR(dbg, error,
1374 DW_DLE_FRAME_INSTR_EXEC_ERROR);
1375 return (DW_DLE_FRAME_INSTR_EXEC_ERROR);
1377 return (DW_DLE_NONE);
1381 case DW_CFA_set_loc:
1382 RCHECK(WRITE_VALUE(val1, dbg->dbg_pointer_size));
1384 case DW_CFA_advance_loc1:
1385 RCHECK(WRITE_VALUE(val1, 1));
1387 case DW_CFA_advance_loc2:
1388 RCHECK(WRITE_VALUE(val1, 2));
1390 case DW_CFA_advance_loc4:
1391 RCHECK(WRITE_VALUE(val1, 4));
1393 case DW_CFA_offset_extended:
1394 case DW_CFA_def_cfa:
1395 case DW_CFA_register:
1396 RCHECK(WRITE_ULEB128(val1));
1397 RCHECK(WRITE_ULEB128(val2));
1399 case DW_CFA_restore_extended:
1400 case DW_CFA_undefined:
1401 case DW_CFA_same_value:
1402 case DW_CFA_def_cfa_register:
1403 case DW_CFA_def_cfa_offset:
1404 RCHECK(WRITE_ULEB128(val1));
1406 case DW_CFA_remember_state:
1407 case DW_CFA_restore_state:
1410 DWARF_SET_ERROR(dbg, error, DW_DLE_FRAME_INSTR_EXEC_ERROR);
1411 return (DW_DLE_FRAME_INSTR_EXEC_ERROR);
1414 return (DW_DLE_NONE);
1426 _dwarf_frame_gen_cie(Dwarf_P_Debug dbg, Dwarf_P_Section ds, Dwarf_P_Cie cie,
1433 assert(dbg != NULL && ds != NULL && cie != NULL);
1435 cie->cie_offset = offset = ds->ds_size;
1436 cie->cie_length = 0;
1437 cie->cie_version = 1;
1439 /* Length placeholder. */
1440 RCHECK(WRITE_VALUE(cie->cie_length, 4));
1442 /* .debug_frame use CIE id ~0. */
1443 RCHECK(WRITE_VALUE(~0U, 4));
1445 /* .debug_frame version is 1. (DWARF2) */
1446 RCHECK(WRITE_VALUE(cie->cie_version, 1));
1448 /* Write augmentation, if present. */
1449 if (cie->cie_augment != NULL)
1450 RCHECK(WRITE_BLOCK(cie->cie_augment,
1451 strlen((char *) cie->cie_augment) + 1));
1453 RCHECK(WRITE_VALUE(0, 1));
1455 /* Write caf, daf and ra. */
1456 RCHECK(WRITE_ULEB128(cie->cie_caf));
1457 RCHECK(WRITE_SLEB128(cie->cie_daf));
1458 RCHECK(WRITE_VALUE(cie->cie_ra, 1));
1460 /* Write initial instructions, if present. */
1461 if (cie->cie_initinst != NULL)
1462 RCHECK(WRITE_BLOCK(cie->cie_initinst, cie->cie_instlen));
1465 len = ds->ds_size - cie->cie_offset - 4;
1466 cie->cie_length = roundup(len, dbg->dbg_pointer_size);
1467 while (len++ < cie->cie_length)
1468 RCHECK(WRITE_VALUE(DW_CFA_nop, 1));
1470 /* Fill in the length field. */
1471 dbg->write(ds->ds_data, &offset, cie->cie_length, 4);
1473 return (DW_DLE_NONE);
1480 _dwarf_frame_gen_fde(Dwarf_P_Debug dbg, Dwarf_P_Section ds,
1481 Dwarf_Rel_Section drs, Dwarf_P_Fde fde, Dwarf_Error *error)
1487 assert(dbg != NULL && ds != NULL && drs != NULL);
1488 assert(fde != NULL && fde->fde_cie != NULL);
1490 fde->fde_offset = offset = ds->ds_size;
1491 fde->fde_length = 0;
1492 fde->fde_cieoff = fde->fde_cie->cie_offset;
1494 /* Length placeholder. */
1495 RCHECK(WRITE_VALUE(fde->fde_length, 4));
1497 /* Write CIE pointer. */
1498 RCHECK(_dwarf_reloc_entry_add(dbg, drs, ds, dwarf_drt_data_reloc, 4,
1499 ds->ds_size, 0, fde->fde_cieoff, ".debug_frame", error));
1501 /* Write FDE initial location. */
1502 RCHECK(_dwarf_reloc_entry_add(dbg, drs, ds, dwarf_drt_data_reloc,
1503 dbg->dbg_pointer_size, ds->ds_size, fde->fde_symndx,
1504 fde->fde_initloc, NULL, error));
1507 * Write FDE address range. Use a pair of relocation entries if
1508 * application provided end symbol index. Otherwise write the
1509 * length without assoicating any relocation info.
1511 if (fde->fde_esymndx > 0)
1512 RCHECK(_dwarf_reloc_entry_add_pair(dbg, drs, ds,
1513 dbg->dbg_pointer_size, ds->ds_size, fde->fde_symndx,
1514 fde->fde_esymndx, fde->fde_initloc, fde->fde_eoff, error));
1516 RCHECK(WRITE_VALUE(fde->fde_adrange, dbg->dbg_pointer_size));
1518 /* Write FDE frame instructions. */
1519 RCHECK(WRITE_BLOCK(fde->fde_inst, fde->fde_instlen));
1522 len = ds->ds_size - fde->fde_offset - 4;
1523 fde->fde_length = roundup(len, dbg->dbg_pointer_size);
1524 while (len++ < fde->fde_length)
1525 RCHECK(WRITE_VALUE(DW_CFA_nop, 1));
1527 /* Fill in the length field. */
1528 dbg->write(ds->ds_data, &offset, fde->fde_length, 4);
1530 return (DW_DLE_NONE);
1537 _dwarf_frame_gen(Dwarf_P_Debug dbg, Dwarf_Error *error)
1540 Dwarf_Rel_Section drs;
1545 if (STAILQ_EMPTY(&dbg->dbgp_cielist))
1546 return (DW_DLE_NONE);
1548 /* Create .debug_frame section. */
1549 if ((ret = _dwarf_section_init(dbg, &ds, ".debug_frame", 0, error)) !=
1553 /* Create relocation section for .debug_frame */
1554 RCHECK(_dwarf_reloc_section_init(dbg, &drs, ds, error));
1556 /* Generate list of CIE. */
1557 STAILQ_FOREACH(cie, &dbg->dbgp_cielist, cie_next)
1558 RCHECK(_dwarf_frame_gen_cie(dbg, ds, cie, error));
1560 /* Generate list of FDE. */
1561 STAILQ_FOREACH(fde, &dbg->dbgp_fdelist, fde_next)
1562 RCHECK(_dwarf_frame_gen_fde(dbg, ds, drs, fde, error));
1564 /* Inform application the creation of .debug_frame ELF section. */
1565 RCHECK(_dwarf_section_callback(dbg, ds, SHT_PROGBITS, 0, 0, 0, error));
1567 /* Finalize relocation section for .debug_frame */
1568 RCHECK(_dwarf_reloc_section_finalize(dbg, drs, error));
1570 return (DW_DLE_NONE);
1573 _dwarf_reloc_section_free(dbg, &drs);
1576 _dwarf_section_free(dbg, &ds);
1582 _dwarf_frame_pro_cleanup(Dwarf_P_Debug dbg)
1584 Dwarf_P_Cie cie, tcie;
1585 Dwarf_P_Fde fde, tfde;
1587 assert(dbg != NULL && dbg->dbg_mode == DW_DLC_WRITE);
1589 STAILQ_FOREACH_SAFE(cie, &dbg->dbgp_cielist, cie_next, tcie) {
1590 STAILQ_REMOVE(&dbg->dbgp_cielist, cie, _Dwarf_Cie, cie_next);
1591 if (cie->cie_augment)
1592 free(cie->cie_augment);
1593 if (cie->cie_initinst)
1594 free(cie->cie_initinst);
1597 dbg->dbgp_cielen = 0;
1599 STAILQ_FOREACH_SAFE(fde, &dbg->dbgp_fdelist, fde_next, tfde) {
1600 STAILQ_REMOVE(&dbg->dbgp_fdelist, fde, _Dwarf_Fde, fde_next);
1601 if (fde->fde_inst != NULL)
1602 free(fde->fde_inst);
1605 dbg->dbgp_fdelen = 0;