3 Copyright (C) 2000-2006 Silicon Graphics, Inc. All Rights Reserved.
4 Portions Copyright (C) 2007-2010 David Anderson. All Rights Reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of version 2.1 of the GNU Lesser General Public License
8 as published by the Free Software Foundation.
10 This program is distributed in the hope that it would be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 Further, this software is distributed without any warranty that it is
15 free of the rightful claim of any third person regarding infringement
16 or the like. Any license provided herein, whether implied or
17 otherwise, applies only to this software file. Patent licenses, if
18 any, provided herein do not apply to combinations of this program with
19 other software, or any other product whatsoever.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this program; if not, write the Free Software
23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
26 Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
27 Mountain View, CA 94043, or:
31 For further information regarding this notice, see:
33 http://oss.sgi.com/projects/GenInfo/NoticeExplan
36 /* The address of the Free Software Foundation is
37 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
38 Boston, MA 02110-1301, USA.
39 SGI has moved from the Crittenden Lane address.
44 This implements _dwarf_get_fde_list_internal()
45 and related helper functions for reading cie/fde data.
51 #include "dwarf_incl.h"
54 #include <sys/types.h>
55 #include "dwarf_frame.h"
56 #include "dwarf_arange.h" /* using Arange as a way to build a
60 static int dwarf_find_existing_cie_ptr(Dwarf_Small
* cie_ptr
,
61 Dwarf_Cie cur_cie_ptr
,
62 Dwarf_Cie
* cie_ptr_to_use_out
,
63 Dwarf_Cie head_cie_ptr
);
64 static void dealloc_fde_cie_list_internal(Dwarf_Fde head_fde_ptr
,
65 Dwarf_Cie head_cie_ptr
);
66 static int dwarf_create_cie_from_start(Dwarf_Debug dbg
,
67 Dwarf_Small
* cie_ptr_val
,
68 Dwarf_Small
* section_ptr
,
69 Dwarf_Unsigned section_index
,
70 Dwarf_Unsigned section_length
,
71 Dwarf_Small
* frame_ptr_end
,
72 Dwarf_Unsigned cie_id_value
,
73 Dwarf_Unsigned cie_count
,
75 Dwarf_Cie
* cie_ptr_to_use_out
,
78 static Dwarf_Small
*get_cieptr_given_offset(Dwarf_Unsigned cie_id_value
,
80 Dwarf_Small
* section_ptr
,
81 Dwarf_Small
* cie_id_addr
);
82 static int get_gcc_eh_augmentation(Dwarf_Debug dbg
,
83 Dwarf_Small
* frame_ptr
,
85 *size_of_augmentation_data
,
86 enum Dwarf_augmentation_type augtype
,
87 Dwarf_Small
* section_pointer
,
88 Dwarf_Small
* fde_eh_encoding_out
,
92 gnu_aug_encodings(Dwarf_Debug dbg
, char *augmentation
,
93 Dwarf_Small
* aug_data
, Dwarf_Unsigned aug_data_len
,
94 Dwarf_Half address_size
,
95 unsigned char *pers_hand_enc_out
,
96 unsigned char *lsda_enc_out
,
97 unsigned char *fde_begin_enc_out
,
98 Dwarf_Addr
* gnu_pers_addr_out
);
101 static int read_encoded_ptr(Dwarf_Debug dbg
,
102 Dwarf_Small
* section_pointer
,
103 Dwarf_Small
* input_field
,
105 Dwarf_Half address_size
,
106 Dwarf_Unsigned
* addr
,
107 Dwarf_Small
** input_field_out
);
111 static int qsort_compare(const void *elem1
, const void *elem2
);
114 /* Adds 'newone' to the end of the list starting at 'head'
115 and makes the new one 'cur'rent. */
117 chain_up_fde(Dwarf_Fde newone
, Dwarf_Fde
* head
, Dwarf_Fde
* cur
)
122 (*cur
)->fd_next
= newone
;
128 /* Adds 'newone' to the end of the list starting at 'head'
129 and makes the new one 'cur'rent. */
131 chain_up_cie(Dwarf_Cie newone
, Dwarf_Cie
* head
, Dwarf_Cie
* cur
)
136 (*cur
)->ci_next
= newone
;
141 /* The size of the length field plus the
142 value of length must be an integral
143 multiple of the address size. Dwarf4 standard.
145 A constant that gives the number of bytes of the CIE
146 structure, not including the length field itself
147 (where length mod <size of an address> == 0)
148 (see Section 7.2.2). Dwarf3 standard.
150 A uword constant that gives the number of bytes of
151 the CIE structure, not including the
152 length field, itself (length mod <addressing unit size> == 0).
155 validate_length(Dwarf_Debug dbg
,
156 Dwarf_Cie cieptr
, Dwarf_Unsigned length
,
157 Dwarf_Unsigned length_size
,
158 Dwarf_Unsigned extension_size
,
159 Dwarf_Small
* section_ptr
,
160 Dwarf_Small
* ciefde_start
,
161 const char * cieorfde
)
163 Dwarf_Unsigned address_size
= cieptr
->ci_address_size
;
164 Dwarf_Unsigned length_field_summed
= length_size
+ extension_size
;
165 Dwarf_Unsigned total_len
= length
+ length_field_summed
;
166 Dwarf_Unsigned mod
= total_len
% address_size
;
169 char msg
[DW_HARMLESS_ERROR_MSG_STRING_SIZE
];
170 Dwarf_Unsigned sectionoffset
= ciefde_start
- section_ptr
;
171 snprintf(msg
,sizeof(msg
),
172 "DW_DLE_DEBUG_FRAME_LENGTH_NOT_MULTIPLE"
174 ", len size=0x%" DW_PR_DUx
175 ", extn size=0x%" DW_PR_DUx
176 ", totl length=0x%" DW_PR_DUx
177 ", addr size=0x%" DW_PR_DUx
178 ", mod=0x%" DW_PR_DUx
" must be zero"
180 ", offset 0x%" DW_PR_DUx
".",
184 total_len
,address_size
, mod
,
187 dwarf_insert_harmless_error(dbg
,msg
);
194 /* For debugging only. */
196 print_prefix(struct cie_fde_prefix_s
*prefix
, int line
)
198 printf("prefix-print, prefix at 0x%lx, line %d\n",
199 (long) prefix
, line
);
200 printf(" start addr 0x%lx after prefix 0x%lx\n",
201 (long) prefix
->cf_start_addr
,
202 (long) prefix
->cf_addr_after_prefix
);
203 printf(" length 0x%" DW_PR_DUx
", len size %d ext size %d\n",
204 (Dwarf_Unsigned
) prefix
->cf_length
,
205 prefix
->cf_local_length_size
,
206 prefix
->cf_local_extension_size
);
207 printf(" cie_id 0x%" DW_PR_DUx
" cie_id cie_id_addr 0x%lx\n",
208 (Dwarf_Unsigned
) prefix
->cf_cie_id
,
209 (long) prefix
->cf_cie_id_addr
);
211 (" sec ptr 0x%lx sec index %" DW_PR_DSd
" sec len 0x%" DW_PR_DUx
" sec past end 0x%lx\n",
212 (long) prefix
->cf_section_ptr
,
213 (Dwarf_Signed
) prefix
->cf_section_index
,
214 (Dwarf_Unsigned
) prefix
->cf_section_length
,
215 (long) prefix
->cf_section_ptr
+ prefix
->cf_section_length
);
221 /* Internal function called from various places to create
222 lists of CIEs and FDEs. Not directly called
225 _dwarf_get_fde_list_internal(Dwarf_Debug dbg
, Dwarf_Cie
** cie_data
,
226 Dwarf_Signed
* cie_element_count
,
227 Dwarf_Fde
** fde_data
,
228 Dwarf_Signed
* fde_element_count
,
229 Dwarf_Small
* section_ptr
,
230 Dwarf_Unsigned section_index
,
231 Dwarf_Unsigned section_length
,
232 Dwarf_Unsigned cie_id_value
,
233 int use_gnu_cie_calc
, Dwarf_Error
* error
)
235 /* Scans the debug_frame section. */
236 Dwarf_Small
*frame_ptr
= section_ptr
;
237 Dwarf_Small
*frame_ptr_end
= section_ptr
+ section_length
;
242 New_cie points to the Cie being read, and head_cie_ptr and
243 cur_cie_ptr are used for chaining them up in sequence.
244 In case cie's are reused aggressively we need tail_cie_ptr
245 to add to the chain. If we re-use an early cie
246 later on, that does not mean we chain a new cie to the early one,
247 we always chain it to the tail. */
248 Dwarf_Cie head_cie_ptr
= NULL
;
249 Dwarf_Cie cur_cie_ptr
= NULL
;
250 Dwarf_Cie tail_cie_ptr
= NULL
;
251 Dwarf_Word cie_count
= 0;
254 Points to a list of contiguous pointers to Dwarf_Cie structures.
256 Dwarf_Cie
*cie_list_ptr
= 0;
260 New_fde points to the Fde being created, and head_fde_ptr and
261 cur_fde_ptr are used to chain them up. */
262 Dwarf_Fde head_fde_ptr
= NULL
;
263 Dwarf_Fde cur_fde_ptr
= NULL
;
264 Dwarf_Word fde_count
= 0;
267 Points to a list of contiguous pointers to Dwarf_Fde structures.
269 Dwarf_Fde
*fde_list_ptr
= NULL
;
272 int res
= DW_DLV_ERROR
;
274 if (frame_ptr
== 0) {
275 return DW_DLV_NO_ENTRY
;
278 /* We create the fde and cie arrays. Processing each CIE as we come
279 to it or as an FDE refers to it. We cannot process 'late' CIEs
280 late as GNU .eh_frame complexities mean we need the whole CIE
281 before we can process the FDE correctly. */
282 while (frame_ptr
< frame_ptr_end
) {
284 struct cie_fde_prefix_s prefix
;
286 /* First read in the 'common prefix' to figure out what we are
287 to do with this entry. */
288 memset(&prefix
, 0, sizeof(prefix
));
289 res
= dwarf_read_cie_fde_prefix(dbg
,
290 frame_ptr
, section_ptr
,
292 section_length
, &prefix
, error
);
293 if (res
== DW_DLV_ERROR
) {
294 dealloc_fde_cie_list_internal(head_fde_ptr
, head_cie_ptr
);
297 if (res
== DW_DLV_NO_ENTRY
)
299 frame_ptr
= prefix
.cf_addr_after_prefix
;
300 if (frame_ptr
>= frame_ptr_end
) {
301 dealloc_fde_cie_list_internal(head_fde_ptr
, head_cie_ptr
);
302 _dwarf_error(dbg
, error
, DW_DLE_DEBUG_FRAME_LENGTH_BAD
);
307 if (prefix
.cf_cie_id
== cie_id_value
) {
309 Dwarf_Cie cie_ptr_to_use
= 0;
311 int res
= dwarf_find_existing_cie_ptr(prefix
.cf_start_addr
,
316 if (res
== DW_DLV_OK
) {
317 cur_cie_ptr
= cie_ptr_to_use
;
318 /* Ok. Seen already. */
319 } else if (res
== DW_DLV_NO_ENTRY
) {
320 /* CIE before its FDE in this case. */
321 res
= dwarf_create_cie_from_after_start(dbg
,
329 /* ASSERT: res==DW_DLV_NO_ENTRY impossible. */
330 if (res
== DW_DLV_ERROR
) {
331 dealloc_fde_cie_list_internal(head_fde_ptr
,
335 /* ASSERT res != DW_DLV_NO_ENTRY */
337 chain_up_cie(cie_ptr_to_use
, &head_cie_ptr
,
339 cur_cie_ptr
= tail_cie_ptr
;
340 } else { /* res == DW_DLV_ERROR */
342 dealloc_fde_cie_list_internal(head_fde_ptr
,
346 frame_ptr
= cie_ptr_to_use
->ci_cie_start
+
347 cie_ptr_to_use
->ci_length
+
348 cie_ptr_to_use
->ci_length_size
+
349 cie_ptr_to_use
->ci_extension_size
;
352 /* this is an FDE, Frame Description Entry, see the Dwarf
353 Spec, section 6.4.1 */
354 int res
= DW_DLV_ERROR
;
355 Dwarf_Cie cie_ptr_to_use
= 0;
356 Dwarf_Fde fde_ptr_to_use
= 0;
358 /* Do not call this twice on one prefix, as
359 prefix.cf_cie_id_addr is altered as a side effect. */
360 Dwarf_Small
*cieptr_val
=
361 get_cieptr_given_offset(prefix
.cf_cie_id
,
364 prefix
.cf_cie_id_addr
);
366 res
= dwarf_find_existing_cie_ptr(cieptr_val
,
370 if (res
== DW_DLV_OK
) {
371 cur_cie_ptr
= cie_ptr_to_use
;
372 /* Ok. Seen CIE already. */
373 } else if (res
== DW_DLV_NO_ENTRY
) {
374 res
= dwarf_create_cie_from_start(dbg
,
385 if (res
== DW_DLV_ERROR
) {
386 dealloc_fde_cie_list_internal(head_fde_ptr
,
389 } else if (res
== DW_DLV_NO_ENTRY
) {
393 chain_up_cie(cie_ptr_to_use
, &head_cie_ptr
,
395 cur_cie_ptr
= tail_cie_ptr
;
402 res
= dwarf_create_fde_from_after_start(dbg
,
410 if (res
== DW_DLV_ERROR
) {
413 chain_up_fde(fde_ptr_to_use
, &head_fde_ptr
, &cur_fde_ptr
);
415 /* ASSERT: DW_DLV_OK. */
416 frame_ptr
= fde_ptr_to_use
->fd_fde_start
+
417 fde_ptr_to_use
->fd_length
+
418 fde_ptr_to_use
->fd_length_size
+
419 fde_ptr_to_use
->fd_extension_size
;
426 /* Now build list of CIEs from the list. If there are no CIEs
427 there should be no FDEs. */
429 cie_list_ptr
= (Dwarf_Cie
*)
430 _dwarf_get_alloc(dbg
, DW_DLA_LIST
, cie_count
);
433 dealloc_fde_cie_list_internal(head_fde_ptr
, head_cie_ptr
);
434 _dwarf_error(dbg
, error
, DW_DLE_ORPHAN_FDE
);
437 dealloc_fde_cie_list_internal(head_fde_ptr
, head_cie_ptr
);
438 return DW_DLV_NO_ENTRY
;
440 if (cie_list_ptr
== NULL
) {
441 dealloc_fde_cie_list_internal(head_fde_ptr
, head_cie_ptr
);
442 _dwarf_error(dbg
, error
, DW_DLE_ALLOC_FAIL
);
445 cur_cie_ptr
= head_cie_ptr
;
446 for (i
= 0; i
< cie_count
; i
++) {
447 *(cie_list_ptr
+ i
) = cur_cie_ptr
;
448 cur_cie_ptr
= cur_cie_ptr
->ci_next
;
453 /* Now build array of FDEs from the list.
454 With orphan CIEs (meaning no FDEs) lets not return DW_DLV_NO_ENTRY */
456 fde_list_ptr
= (Dwarf_Fde
*)
457 _dwarf_get_alloc(dbg
, DW_DLA_LIST
, fde_count
);
460 /* It is ok if fde_list_ptr is NULL, we just have no fdes. */
461 cur_fde_ptr
= head_fde_ptr
;
462 for (i
= 0; i
< fde_count
; i
++) {
463 *(fde_list_ptr
+ i
) = cur_fde_ptr
;
464 cur_fde_ptr
= cur_fde_ptr
->fd_next
;
468 /* Return arguments. */
469 *cie_data
= cie_list_ptr
;
470 *cie_element_count
= cie_count
;
472 *fde_data
= fde_list_ptr
;
473 *fde_element_count
= fde_count
;
474 if(use_gnu_cie_calc
) {
475 dbg
->de_fde_data_eh
= fde_list_ptr
;
476 dbg
->de_fde_count_eh
= fde_count
;
477 dbg
->de_cie_data_eh
= cie_list_ptr
;
478 dbg
->de_cie_count_eh
= cie_count
;
480 dbg
->de_fde_data
= fde_list_ptr
;
481 dbg
->de_fde_count
= fde_count
;
482 dbg
->de_cie_data
= cie_list_ptr
;
483 dbg
->de_cie_count
= cie_count
;
486 /* Sort the list by the address so that dwarf_get_fde_at_pc() can
487 binary search this list. */
489 qsort((void *) fde_list_ptr
, fde_count
, sizeof(Dwarf_Ptr
),
496 /* Internal function, not called by consumer code.
497 'prefix' has accumulated the info up thru the cie-id
498 and now we consume the rest and build a Dwarf_Cie_s structure.
501 dwarf_create_cie_from_after_start(Dwarf_Debug dbg
,
502 struct cie_fde_prefix_s
*prefix
,
503 Dwarf_Small
* section_pointer
,
504 Dwarf_Small
* frame_ptr
,
505 Dwarf_Unsigned cie_count
,
506 int use_gnu_cie_calc
,
507 Dwarf_Cie
* cie_ptr_out
,
510 Dwarf_Cie new_cie
= 0;
512 /* egcs-1.1.2 .eh_frame uses 0 as the distinguishing id. sgi uses
513 -1 (in .debug_frame). .eh_frame not quite identical to
515 /* We here default the address size as it is not present
516 in DWARF2 or DWARF3 cie data, below we set it right if
518 Dwarf_Half address_size
= dbg
->de_pointer_size
;
519 Dwarf_Small eh_fde_encoding
= 0;
520 Dwarf_Small
*augmentation
= 0;
521 Dwarf_Half segment_size
= 0;
522 Dwarf_Sword data_alignment_factor
= -1;
523 Dwarf_Word code_alignment_factor
= 4;
524 Dwarf_Unsigned return_address_register
= 31;
525 int local_length_size
= 0;
526 Dwarf_Word leb128_length
= 0;
527 Dwarf_Unsigned cie_aug_data_len
= 0;
528 Dwarf_Small
*cie_aug_data
= 0;
529 Dwarf_Addr gnu_personality_handler_addr
= 0;
530 unsigned char gnu_personality_handler_encoding
= 0;
531 unsigned char gnu_lsda_encoding
= 0;
532 unsigned char gnu_fde_begin_encoding
= 0;
535 enum Dwarf_augmentation_type augt
= aug_unknown
;
538 /* this is a CIE, Common Information Entry: See the dwarf spec,
540 Dwarf_Small version
= *(Dwarf_Small
*) frame_ptr
;
543 if (version
!= DW_CIE_VERSION
&& version
!= DW_CIE_VERSION3
&&
544 version
!= DW_CIE_VERSION4
) {
545 _dwarf_error(dbg
, error
, DW_DLE_FRAME_VERSION_BAD
);
546 return (DW_DLV_ERROR
);
549 augmentation
= frame_ptr
;
550 frame_ptr
= frame_ptr
+ strlen((char *) frame_ptr
) + 1;
551 augt
= _dwarf_get_augmentation_type(dbg
,
552 augmentation
, use_gnu_cie_calc
);
553 if (augt
== aug_eh
) {
554 /* REFERENCED *//* Not used in this instance */
555 Dwarf_Unsigned exception_table_addr
;
557 /* this is per egcs-1.1.2 as on RH 6.0 */
558 READ_UNALIGNED(dbg
, exception_table_addr
,
559 Dwarf_Unsigned
, frame_ptr
, local_length_size
);
560 frame_ptr
+= local_length_size
;
563 Dwarf_Unsigned lreg
= 0;
564 unsigned long size
= 0;
566 if( version
== DW_CIE_VERSION4
) {
567 address_size
= *((unsigned char *)frame_ptr
);
569 segment_size
= *((unsigned char *)frame_ptr
);
573 DECODE_LEB128_UWORD(frame_ptr
, lreg
);
574 code_alignment_factor
= (Dwarf_Word
) lreg
;
576 data_alignment_factor
=
577 (Dwarf_Sword
) _dwarf_decode_s_leb128(frame_ptr
,
580 frame_ptr
= frame_ptr
+ leb128_length
;
582 return_address_register
=
583 _dwarf_get_return_address_reg(frame_ptr
, version
, &size
);
584 if (return_address_register
> dbg
->de_frame_reg_rules_entry_count
) {
585 _dwarf_error(dbg
, error
, DW_DLE_CIE_RET_ADDR_REG_ERROR
);
586 return (DW_DLV_ERROR
);
591 case aug_empty_string
:
593 case aug_irix_mti_v1
:
595 case aug_irix_exception_table
:{
596 Dwarf_Unsigned lreg
= 0;
597 Dwarf_Word length_of_augmented_fields
;
599 /* Decode the length of augmented fields. */
600 DECODE_LEB128_UWORD(frame_ptr
, lreg
);
601 length_of_augmented_fields
= (Dwarf_Word
) lreg
;
604 /* set the frame_ptr to point at the instruction start. */
605 frame_ptr
+= length_of_augmented_fields
;
612 unsigned long increment
= 0;
614 if (!use_gnu_cie_calc
) {
615 /* This should be impossible. */
616 _dwarf_error(dbg
, error
,
617 DW_DLE_FRAME_AUGMENTATION_UNKNOWN
);
621 err
= get_gcc_eh_augmentation(dbg
, frame_ptr
, &increment
,
623 prefix
->cf_section_ptr
,
625 (char *) augmentation
);
626 if (err
== DW_DLV_ERROR
) {
627 _dwarf_error(dbg
, error
,
628 DW_DLE_FRAME_AUGMENTATION_UNKNOWN
);
631 frame_ptr
+= increment
;
635 /* Here we have Augmentation Data Length (uleb128) followed
636 by Augmentation Data bytes. */
637 int res
= DW_DLV_ERROR
;
638 Dwarf_Unsigned adlen
= 0;
640 DECODE_LEB128_UWORD(frame_ptr
, adlen
);
641 cie_aug_data_len
= adlen
;
642 cie_aug_data
= frame_ptr
;
643 res
= gnu_aug_encodings(dbg
,
644 (char *) augmentation
,
648 &gnu_personality_handler_encoding
,
650 &gnu_fde_begin_encoding
,
651 &gnu_personality_handler_addr
);
652 if (res
!= DW_DLV_OK
) {
653 _dwarf_error(dbg
, error
,
654 DW_DLE_FRAME_AUGMENTATION_UNKNOWN
);
665 /* We do not understand the augmentation string. No
666 assumption can be made about any fields other than what
667 we have already read. */
668 frame_ptr
= prefix
->cf_start_addr
+
669 prefix
->cf_length
+ prefix
->cf_local_length_size
670 + prefix
->cf_local_extension_size
;
671 /* FIX -- What are the values of data_alignment_factor,
672 code_alignement_factor, return_address_register and
673 instruction start? They were clearly uninitalized in the
674 previous version and I am leaving them the same way. */
677 } /* End switch on augmentation type. */
679 new_cie
= (Dwarf_Cie
) _dwarf_get_alloc(dbg
, DW_DLA_CIE
, 1);
680 if (new_cie
== NULL
) {
681 _dwarf_error(dbg
, error
, DW_DLE_ALLOC_FAIL
);
682 return (DW_DLV_ERROR
);
685 new_cie
->ci_cie_version_number
= version
;
686 new_cie
->ci_initial_table
= NULL
;
687 new_cie
->ci_length
= (Dwarf_Word
) prefix
->cf_length
;
688 new_cie
->ci_length_size
= prefix
->cf_local_length_size
;
689 new_cie
->ci_extension_size
= prefix
->cf_local_extension_size
;
690 new_cie
->ci_augmentation
= (char *) augmentation
;
692 new_cie
->ci_data_alignment_factor
=
693 (Dwarf_Sbyte
) data_alignment_factor
;
694 new_cie
->ci_code_alignment_factor
=
695 (Dwarf_Small
) code_alignment_factor
;
696 new_cie
->ci_return_address_register
= return_address_register
;
697 new_cie
->ci_cie_start
= prefix
->cf_start_addr
;
698 new_cie
->ci_cie_instr_start
= frame_ptr
;
699 new_cie
->ci_dbg
= dbg
;
700 new_cie
->ci_augmentation_type
= augt
;
701 new_cie
->ci_gnu_eh_augmentation_len
= cie_aug_data_len
;
702 new_cie
->ci_gnu_eh_augmentation_bytes
= cie_aug_data
;
703 new_cie
->ci_gnu_personality_handler_encoding
=
704 gnu_personality_handler_encoding
;
705 new_cie
->ci_gnu_personality_handler_addr
=
706 gnu_personality_handler_addr
;
707 new_cie
->ci_gnu_lsda_encoding
= gnu_lsda_encoding
;
708 new_cie
->ci_gnu_fde_begin_encoding
= gnu_fde_begin_encoding
;
710 new_cie
->ci_index
= cie_count
;
711 new_cie
->ci_section_ptr
= prefix
->cf_section_ptr
;
712 /* The Following new in DWARF4 */
713 new_cie
->ci_address_size
= address_size
;
714 new_cie
->ci_segment_size
= segment_size
;
715 validate_length(dbg
,new_cie
,new_cie
->ci_length
,
716 new_cie
->ci_length_size
, new_cie
->ci_extension_size
,
717 new_cie
->ci_section_ptr
,
718 new_cie
->ci_cie_start
,"cie");
720 *cie_ptr_out
= new_cie
;
726 /* Internal function, not called by consumer code.
727 'prefix' has accumulated the info up thru the cie-id
728 and now we consume the rest and build a Dwarf_Fde_s structure.
732 dwarf_create_fde_from_after_start(Dwarf_Debug dbg
,
733 struct cie_fde_prefix_s
*prefix
,
734 Dwarf_Small
* section_pointer
,
735 Dwarf_Small
* frame_ptr
,
736 int use_gnu_cie_calc
,
737 Dwarf_Cie cie_ptr_in
,
738 Dwarf_Fde
* fde_ptr_out
,
741 Dwarf_Fde new_fde
= 0;
742 Dwarf_Cie cieptr
= cie_ptr_in
;
743 Dwarf_Small
*saved_frame_ptr
= 0;
745 Dwarf_Small
*initloc
= frame_ptr
;
746 Dwarf_Signed offset_into_exception_tables
747 /* must be min dwarf_sfixed in size */
748 = (Dwarf_Signed
) DW_DLX_NO_EH_OFFSET
;
749 Dwarf_Small
*fde_aug_data
= 0;
750 Dwarf_Unsigned fde_aug_data_len
= 0;
751 Dwarf_Addr cie_base_offset
= prefix
->cf_cie_id
;
752 Dwarf_Addr initial_location
= 0; /* must be min de_pointer_size
754 Dwarf_Addr address_range
= 0; /* must be min de_pointer_size
756 Dwarf_Half address_size
= cie_ptr_in
->ci_address_size
;
758 enum Dwarf_augmentation_type augt
= cieptr
->ci_augmentation_type
;
760 if (augt
== aug_gcc_eh_z
) {
761 /* If z augmentation this is eh_frame, and initial_location and
762 address_range in the FDE are read according to the CIE
763 augmentation string instructions. */
766 Dwarf_Small
*fp_updated
= 0;
767 int res
= read_encoded_ptr(dbg
,
770 cieptr
-> ci_gnu_fde_begin_encoding
,
774 if (res
!= DW_DLV_OK
) {
775 _dwarf_error(dbg
, error
,
776 DW_DLE_FRAME_AUGMENTATION_UNKNOWN
);
779 frame_ptr
= fp_updated
;
780 /* For the address-range it makes no sense to be
781 pc-relative, so we turn it off with a section_pointer of
782 NULL. Masking off DW_EH_PE_pcrel from the
783 ci_gnu_fde_begin_encoding in this call would also work
784 to turn off DW_EH_PE_pcrel. */
785 res
= read_encoded_ptr(dbg
, (Dwarf_Small
*) NULL
,
787 cieptr
->ci_gnu_fde_begin_encoding
,
789 &address_range
, &fp_updated
);
790 if (res
!= DW_DLV_OK
) {
791 _dwarf_error(dbg
, error
,
792 DW_DLE_FRAME_AUGMENTATION_UNKNOWN
);
795 frame_ptr
= fp_updated
;
798 Dwarf_Unsigned adlen
= 0;
800 DECODE_LEB128_UWORD(frame_ptr
, adlen
);
801 fde_aug_data_len
= adlen
;
802 fde_aug_data
= frame_ptr
;
807 READ_UNALIGNED(dbg
, initial_location
, Dwarf_Addr
,
808 frame_ptr
, address_size
);
809 frame_ptr
+= address_size
;
811 READ_UNALIGNED(dbg
, address_range
, Dwarf_Addr
,
812 frame_ptr
, address_size
);
813 frame_ptr
+= address_size
;
821 case aug_irix_mti_v1
:
822 case aug_empty_string
:
824 case aug_irix_exception_table
:{
825 Dwarf_Unsigned lreg
= 0;
826 Dwarf_Word length_of_augmented_fields
= 0;
828 DECODE_LEB128_UWORD(frame_ptr
, lreg
);
829 length_of_augmented_fields
= (Dwarf_Word
) lreg
;
831 saved_frame_ptr
= frame_ptr
;
832 /* The first word is an offset into exception tables.
833 Defined as a 32bit offset even for CC -64. */
834 READ_UNALIGNED(dbg
, offset_into_exception_tables
,
835 Dwarf_Addr
, frame_ptr
, sizeof(Dwarf_sfixed
));
836 SIGN_EXTEND(offset_into_exception_tables
,
837 sizeof(Dwarf_sfixed
));
838 frame_ptr
= saved_frame_ptr
+ length_of_augmented_fields
;
842 Dwarf_Unsigned eh_table_value
= 0;
844 if (!use_gnu_cie_calc
) {
845 /* This should be impossible. */
846 _dwarf_error(dbg
, error
,
847 DW_DLE_FRAME_AUGMENTATION_UNKNOWN
);
851 /* gnu eh fde case. we do not need to do anything */
852 /*REFERENCED*/ /* Not used in this instance of the
854 READ_UNALIGNED(dbg
, eh_table_value
,
855 Dwarf_Unsigned
, frame_ptr
,
857 frame_ptr
+= address_size
;
862 /* The Augmentation Data Length is here, followed by the
863 Augmentation Data bytes themselves. */
871 _dwarf_error(dbg
, error
, DW_DLE_FRAME_AUGMENTATION_UNKNOWN
);
873 } /* End switch on augmentation type */
874 new_fde
= (Dwarf_Fde
) _dwarf_get_alloc(dbg
, DW_DLA_FDE
, 1);
875 if (new_fde
== NULL
) {
876 _dwarf_error(dbg
, error
, DW_DLE_ALLOC_FAIL
);
877 return (DW_DLV_ERROR
);
880 new_fde
->fd_length
= prefix
->cf_length
;
881 new_fde
->fd_length_size
= prefix
->cf_local_length_size
;
882 new_fde
->fd_extension_size
= prefix
->cf_local_extension_size
;
883 new_fde
->fd_is_eh
= use_gnu_cie_calc
;
884 new_fde
->fd_cie_offset
= cie_base_offset
;
885 new_fde
->fd_cie_index
= cieptr
->ci_index
;
886 new_fde
->fd_cie
= cieptr
;
887 new_fde
->fd_initial_location
= initial_location
;
888 new_fde
->fd_initial_loc_pos
= initloc
;
889 new_fde
->fd_address_range
= address_range
;
890 new_fde
->fd_fde_start
= prefix
->cf_start_addr
;
891 new_fde
->fd_fde_instr_start
= frame_ptr
;
892 new_fde
->fd_dbg
= dbg
;
893 new_fde
->fd_offset_into_exception_tables
=
894 offset_into_exception_tables
;
896 new_fde
->fd_section_ptr
= prefix
->cf_section_ptr
;
897 new_fde
->fd_section_index
= prefix
->cf_section_index
;
898 new_fde
->fd_section_length
= prefix
->cf_section_length
;
900 new_fde
->fd_gnu_eh_augmentation_bytes
= fde_aug_data
;
901 new_fde
->fd_gnu_eh_augmentation_len
= fde_aug_data_len
;
902 validate_length(dbg
,cieptr
,new_fde
->fd_length
,
903 new_fde
->fd_length_size
, new_fde
->fd_extension_size
,
904 new_fde
->fd_section_ptr
,new_fde
->fd_fde_start
,"fde");
907 *fde_ptr_out
= new_fde
;
911 /* called by qsort to compare FDE entries.
912 Consumer code expects the array of FDE pointers to be in address order.
915 qsort_compare(const void *elem1
, const void *elem2
)
917 Dwarf_Fde fde1
= *(Dwarf_Fde
*) elem1
;
918 Dwarf_Fde fde2
= *(Dwarf_Fde
*) elem2
;
919 Dwarf_Addr addr1
= fde1
->fd_initial_location
;
920 Dwarf_Addr addr2
= fde2
->fd_initial_location
;
924 } else if (addr1
> addr2
) {
931 /* Read in the common cie/fde prefix, including reading
932 * the cie-value which shows which this is: cie or fde.
935 dwarf_read_cie_fde_prefix(Dwarf_Debug dbg
,
936 Dwarf_Small
* frame_ptr_in
,
937 Dwarf_Small
* section_ptr_in
,
938 Dwarf_Unsigned section_index_in
,
939 Dwarf_Unsigned section_length_in
,
940 struct cie_fde_prefix_s
*data_out
,
943 Dwarf_Unsigned length
= 0;
944 int local_length_size
= 0;
945 int local_extension_size
= 0;
946 Dwarf_Small
*frame_ptr
= frame_ptr_in
;
947 Dwarf_Small
*cie_ptr_addr
= 0;
948 Dwarf_Unsigned cie_id
= 0;
950 /* READ_AREA_LENGTH updates frame_ptr for consumed bytes */
951 READ_AREA_LENGTH(dbg
, length
, Dwarf_Unsigned
,
952 frame_ptr
, local_length_size
,
953 local_extension_size
);
956 /* nul bytes at end of section, seen at end of egcs eh_frame
957 sections (in a.out). Take this as meaning no more CIE/FDE
958 data. We should be very close to end of section. */
959 return DW_DLV_NO_ENTRY
;
962 cie_ptr_addr
= frame_ptr
;
963 READ_UNALIGNED(dbg
, cie_id
, Dwarf_Unsigned
,
964 frame_ptr
, local_length_size
);
965 SIGN_EXTEND(cie_id
, local_length_size
);
966 frame_ptr
+= local_length_size
;
968 data_out
->cf_start_addr
= frame_ptr_in
;
969 data_out
->cf_addr_after_prefix
= frame_ptr
;
971 data_out
->cf_length
= length
;
972 data_out
->cf_local_length_size
= local_length_size
;
973 data_out
->cf_local_extension_size
= local_extension_size
;
974 data_out
->cf_cie_id
= cie_id
;
975 data_out
->cf_cie_id_addr
= cie_ptr_addr
;
976 data_out
->cf_section_ptr
= section_ptr_in
;
977 data_out
->cf_section_index
= section_index_in
;
978 data_out
->cf_section_length
= section_length_in
;
982 /* On various errors previously-allocated CIEs and FDEs
984 This helps avoid leaks in case of errors.
987 dealloc_fde_cie_list_internal(Dwarf_Fde head_fde_ptr
,
988 Dwarf_Cie head_cie_ptr
)
990 Dwarf_Fde curfde
= 0;
991 Dwarf_Cie curcie
= 0;
992 Dwarf_Fde nextfde
= 0;
993 Dwarf_Cie nextcie
= 0;
995 for (curfde
= head_fde_ptr
; curfde
; curfde
= nextfde
) {
996 nextfde
= curfde
->fd_next
;
997 dwarf_dealloc(curfde
->fd_dbg
, curfde
, DW_DLA_FDE
);
999 for (curcie
= head_cie_ptr
; curcie
; curcie
= nextcie
) {
1000 Dwarf_Frame frame
= curcie
->ci_initial_table
;
1002 nextcie
= curcie
->ci_next
;
1004 dwarf_dealloc(curcie
->ci_dbg
, frame
, DW_DLA_FRAME
);
1005 dwarf_dealloc(curcie
->ci_dbg
, curcie
, DW_DLA_CIE
);
1009 /* Find the cie whose id value is given: the id
1010 * value is, per DWARF2/3, an offset in the section.
1011 * For .debug_frame, zero is a legal offset. For
1012 * GNU .eh_frame it is not a legal offset.
1013 * 'cie_ptr' is a pointer into our section, not an offset. */
1015 dwarf_find_existing_cie_ptr(Dwarf_Small
* cie_ptr
,
1016 Dwarf_Cie cur_cie_ptr
,
1017 Dwarf_Cie
* cie_ptr_to_use_out
,
1018 Dwarf_Cie head_cie_ptr
)
1022 if (cur_cie_ptr
&& cie_ptr
== cur_cie_ptr
->ci_cie_start
) {
1023 /* Usually, we use the same cie again and again. */
1024 *cie_ptr_to_use_out
= cur_cie_ptr
;
1027 for (next
= head_cie_ptr
; next
; next
= next
->ci_next
) {
1028 if (cie_ptr
== next
->ci_cie_start
) {
1029 *cie_ptr_to_use_out
= next
;
1033 return DW_DLV_NO_ENTRY
;
1037 /* We have a valid cie_ptr_val that has not been
1038 * turned into an internal Cie yet. Do so now.
1039 * Returns DW_DLV_OK or DW_DLV_ERROR, never
1042 'section_ptr' - Points to first byte of section data.
1043 'section_length' - Length of the section, in bytes.
1044 'frame_ptr_end' - Points 1-past last byte of section data.
1047 dwarf_create_cie_from_start(Dwarf_Debug dbg
,
1048 Dwarf_Small
* cie_ptr_val
,
1049 Dwarf_Small
* section_ptr
,
1050 Dwarf_Unsigned section_index
,
1051 Dwarf_Unsigned section_length
,
1052 Dwarf_Small
* frame_ptr_end
,
1053 Dwarf_Unsigned cie_id_value
,
1054 Dwarf_Unsigned cie_count
,
1055 int use_gnu_cie_calc
,
1056 Dwarf_Cie
* cie_ptr_to_use_out
,
1057 Dwarf_Error
* error
)
1059 struct cie_fde_prefix_s prefix
;
1060 int res
= DW_DLV_ERROR
;
1061 Dwarf_Small
*frame_ptr
= cie_ptr_val
;
1063 if (frame_ptr
< section_ptr
|| frame_ptr
> frame_ptr_end
) {
1064 _dwarf_error(dbg
, error
, DW_DLE_DEBUG_FRAME_LENGTH_BAD
);
1065 return DW_DLV_ERROR
;
1067 /* First read in the 'common prefix' to figure out what * we are to
1068 do with this entry. If it is not a cie * we are in big trouble. */
1069 memset(&prefix
, 0, sizeof(prefix
));
1070 res
= dwarf_read_cie_fde_prefix(dbg
, frame_ptr
, section_ptr
,
1071 section_index
, section_length
,
1073 if (res
== DW_DLV_ERROR
) {
1076 if (res
== DW_DLV_NO_ENTRY
) {
1078 _dwarf_error(dbg
, error
, DW_DLE_FRAME_CIE_DECODE_ERROR
);
1079 return DW_DLV_ERROR
;
1083 if (prefix
.cf_cie_id
!= cie_id_value
) {
1084 _dwarf_error(dbg
, error
, DW_DLE_FRAME_CIE_DECODE_ERROR
);
1085 return DW_DLV_ERROR
;
1087 frame_ptr
= prefix
.cf_addr_after_prefix
;
1088 res
= dwarf_create_cie_from_after_start(dbg
,
1094 cie_ptr_to_use_out
, error
);
1100 /* This is for gnu eh frames, the 'z' case.
1101 We find the letter involved
1102 Return the augmentation character and, if applicable,
1103 the personality routine address.
1105 personality_routine_out -
1106 if 'P' is augchar, is personality handler addr.
1107 Otherwise is not set.
1108 aug_data - if 'P' points to data space of the
1109 aug_data_len - length of areas aug_data points to.
1113 /* For debugging only. */
1115 dump_bytes(Dwarf_Small
* start
, long len
)
1117 Dwarf_Small
*end
= start
+ len
;
1118 Dwarf_Small
*cur
= start
;
1120 for (; cur
< end
; cur
++) {
1121 printf(" byte %d, data %02x\n", (int) (cur
- start
), *cur
);
1127 gnu_aug_encodings(Dwarf_Debug dbg
, char *augmentation
,
1128 Dwarf_Small
* aug_data
, Dwarf_Unsigned aug_data_len
,
1129 Dwarf_Half address_size
,
1130 unsigned char *pers_hand_enc_out
,
1131 unsigned char *lsda_enc_out
,
1132 unsigned char *fde_begin_enc_out
,
1133 Dwarf_Addr
* gnu_pers_addr_out
)
1136 Dwarf_Small
*cur_aug_p
= aug_data
;
1137 Dwarf_Small
*end_aug_p
= aug_data
+ aug_data_len
;
1139 for (nc
= augmentation
; *nc
; ++nc
) {
1144 /* Means that the augmentation data is present. */
1148 /* Indicates this is a signal stack frame. Debuggers have to do
1149 special handling. We don't need to do more than print this flag at
1150 the right time, though (see dwarfdump where it prints the augmentation
1152 A signal stack frame (in some OS's) can only be
1153 unwound (backtraced) by knowing it is a signal stack frame
1154 (perhaps by noticing the name of the function for the stack frame
1155 if the name can be found somehow) and figuring
1156 out (or knowing) how the kernel and libc pushed a structure
1157 onto the stack and loading registers from that structure.
1158 Totally different from normal stack unwinding.
1159 This flag gives an unwinder a big leg up by decoupling the
1160 'hint: this is a stack frame' from knowledge like
1161 the function name (the name might be unavailable at unwind time).
1166 if (cur_aug_p
> end_aug_p
) {
1167 return DW_DLV_ERROR
;
1169 *lsda_enc_out
= *(unsigned char *) cur_aug_p
;
1173 /* Followed by a one byte argument giving the
1174 pointer encoding for the address pointers in the fde. */
1175 if (cur_aug_p
>= end_aug_p
) {
1176 return DW_DLV_ERROR
;
1178 *fde_begin_enc_out
= *(unsigned char *) cur_aug_p
;
1182 int res
= DW_DLV_ERROR
;
1183 Dwarf_Small
*updated_aug_p
= 0;
1184 unsigned char encoding
= 0;
1186 if (cur_aug_p
>= end_aug_p
) {
1187 return DW_DLV_ERROR
;
1189 encoding
= *(unsigned char *) cur_aug_p
;
1190 *pers_hand_enc_out
= encoding
;
1192 if (cur_aug_p
> end_aug_p
) {
1193 return DW_DLV_ERROR
;
1195 /* DW_EH_PE_pcrel makes no sense here, so we turn it
1196 off via a section pointer of NULL. */
1197 res
= read_encoded_ptr(dbg
,
1198 (Dwarf_Small
*) NULL
,
1204 if (res
!= DW_DLV_OK
) {
1207 cur_aug_p
= updated_aug_p
;
1208 if (cur_aug_p
> end_aug_p
) {
1209 return DW_DLV_ERROR
;
1214 return DW_DLV_ERROR
;
1222 /* Given augmentation character (the encoding) giving the
1223 address format, read the address from input_field
1224 and return an incremented value 1 past the input bytes of the
1226 Push the address read back thru the *addr pointer.
1227 See LSB (Linux Standar Base) exception handling documents.
1230 read_encoded_ptr(Dwarf_Debug dbg
,
1231 Dwarf_Small
* section_pointer
,
1232 Dwarf_Small
* input_field
,
1234 Dwarf_Half address_size
,
1235 Dwarf_Unsigned
* addr
,
1236 Dwarf_Small
** input_field_updated
)
1238 Dwarf_Word length
= 0;
1239 int value_type
= gnu_encoding
& 0xf;
1240 Dwarf_Small
*input_field_original
= input_field
;
1242 if (gnu_encoding
== 0xff) {
1243 /* There is no data here. */
1246 *input_field_updated
= input_field
;
1247 /* Should we return DW_DLV_NO_ENTRY? */
1250 switch (value_type
) {
1251 case DW_EH_PE_absptr
:{
1252 /* value_type is zero. Treat as pointer size of the object.
1254 Dwarf_Unsigned ret_value
= 0;
1256 READ_UNALIGNED(dbg
, ret_value
, Dwarf_Unsigned
,
1257 input_field
, address_size
);
1259 *input_field_updated
= input_field
+ address_size
;
1262 case DW_EH_PE_uleb128
:{
1263 Dwarf_Unsigned val
= _dwarf_decode_u_leb128(input_field
,
1267 *input_field_updated
= input_field
+ length
;
1270 case DW_EH_PE_udata2
:{
1271 Dwarf_Unsigned ret_value
= 0;
1273 READ_UNALIGNED(dbg
, ret_value
, Dwarf_Unsigned
,
1276 *input_field_updated
= input_field
+ 2;
1280 case DW_EH_PE_udata4
:{
1282 Dwarf_Unsigned ret_value
= 0;
1284 /* ASSERT: sizeof(Dwarf_ufixed) == 4 */
1285 READ_UNALIGNED(dbg
, ret_value
, Dwarf_Unsigned
,
1286 input_field
, sizeof(Dwarf_ufixed
));
1288 *input_field_updated
= input_field
+ sizeof(Dwarf_ufixed
);
1292 case DW_EH_PE_udata8
:{
1293 Dwarf_Unsigned ret_value
= 0;
1295 /* ASSERT: sizeof(Dwarf_Unsigned) == 8 */
1296 READ_UNALIGNED(dbg
, ret_value
, Dwarf_Unsigned
,
1297 input_field
, sizeof(Dwarf_Unsigned
));
1299 *input_field_updated
= input_field
+ sizeof(Dwarf_Unsigned
);
1303 case DW_EH_PE_sleb128
:{
1304 Dwarf_Signed val
= _dwarf_decode_s_leb128(input_field
,
1307 *addr
= (Dwarf_Unsigned
) val
;
1308 *input_field_updated
= input_field
+ length
;
1311 case DW_EH_PE_sdata2
:{
1312 Dwarf_Unsigned val
= 0;
1314 READ_UNALIGNED(dbg
, val
, Dwarf_Unsigned
, input_field
, 2);
1315 SIGN_EXTEND(val
, 2);
1316 *addr
= (Dwarf_Unsigned
) val
;
1317 *input_field_updated
= input_field
+ 2;
1321 case DW_EH_PE_sdata4
:{
1322 Dwarf_Unsigned val
= 0;
1324 /* ASSERT: sizeof(Dwarf_ufixed) == 4 */
1325 READ_UNALIGNED(dbg
, val
,
1326 Dwarf_Unsigned
, input_field
,
1327 sizeof(Dwarf_ufixed
));
1328 SIGN_EXTEND(val
, sizeof(Dwarf_ufixed
));
1329 *addr
= (Dwarf_Unsigned
) val
;
1330 *input_field_updated
= input_field
+ sizeof(Dwarf_ufixed
);
1333 case DW_EH_PE_sdata8
:{
1334 Dwarf_Unsigned val
= 0;
1336 /* ASSERT: sizeof(Dwarf_Unsigned) == 8 */
1337 READ_UNALIGNED(dbg
, val
,
1338 Dwarf_Unsigned
, input_field
,
1339 sizeof(Dwarf_Unsigned
));
1340 *addr
= (Dwarf_Unsigned
) val
;
1341 *input_field_updated
= input_field
+ sizeof(Dwarf_Unsigned
);
1345 return DW_DLV_ERROR
;
1348 /* The ELF ABI for gnu does not document the meaning of
1349 DW_EH_PE_pcrel, which is awkward. It apparently means the value
1350 we got above is pc-relative (meaning section-relative), so we
1351 adjust the value. Section_pointer may be null if it is known
1352 DW_EH_PE_pcrel cannot apply, such as for .debug_frame or for an
1353 address-range value. */
1354 if (section_pointer
&& ((gnu_encoding
& 0x70) == DW_EH_PE_pcrel
)) {
1355 /* Address (*addr) above is pc relative with respect to a
1356 section. Add to the offset the base address (from elf) of
1357 section and the distance of the field we are reading from
1358 the section-beginning to get the actual address. */
1359 /* ASSERT: input_field_original >= section_pointer */
1360 Dwarf_Unsigned distance
=
1361 input_field_original
- section_pointer
;
1362 *addr
+= dbg
->de_debug_frame_eh_gnu
.dss_addr
+ distance
;
1372 All augmentation string checking done here now.
1374 For .eh_frame, gcc from 3.3 uses the z style, earlier used
1375 only "eh" as augmentation. We don't yet handle
1376 decoding .eh_frame with the z style extensions like L P.
1378 These are nasty heuristics, but then that's life
1379 as augmentations are implementation specific.
1382 enum Dwarf_augmentation_type
1383 _dwarf_get_augmentation_type(Dwarf_Debug dbg
,
1384 Dwarf_Small
* augmentation_string
,
1385 int is_gcc_eh_frame
)
1387 enum Dwarf_augmentation_type t
= aug_unknown
;
1388 char *ag_string
= (char *) augmentation_string
;
1390 if (ag_string
[0] == 0) {
1391 /* Empty string. We'll just guess that we know what this means:
1392 standard dwarf2/3 with no implementation-defined fields. */
1393 t
= aug_empty_string
;
1394 } else if (strcmp(ag_string
, DW_DEBUG_FRAME_AUGMENTER_STRING
) == 0) {
1395 /* The string is "mti v1". Used internally at SGI, probably
1396 never shipped. Replaced by "z". Treat like 'nothing
1398 t
= aug_irix_mti_v1
;
1399 } else if (ag_string
[0] == 'z') {
1400 /* If it's IRIX cc, z means aug_irix_exception_table. z1 z2
1401 were designed as for IRIX CC, but never implemented */
1402 /* If it's gcc, z may be any of several things. "z" or z
1403 followed optionally followed by one or more of L R P, each
1404 of which means a value may be present. Should be in eh_frame
1406 if (is_gcc_eh_frame
) {
1408 } else if (ag_string
[1] == 0) {
1409 /* This is the normal IRIX C++ case, where there is an
1410 offset into a table in each fde. The table being for
1411 IRIX CC exception handling. */
1412 /* DW_CIE_AUGMENTER_STRING_V0 "z" */
1413 t
= aug_irix_exception_table
;
1414 } /* Else unknown. */
1415 } else if (strncmp(ag_string
, "eh", 2) == 0) {
1416 /* gcc .eh_frame augmentation for egcs and gcc 2.x, at least
1419 } else if (strcmp(ag_string
, "armcc+") == 0) {
1420 /* Arm uses this string to mean a bug in
1421 in Arm compilers was fixed, changing to the standard
1422 calculation of the CFA. See
1423 http://sourceware.org/ml/gdb-patches/2006-12/msg00249.html
1432 /* Using augmentation, and version
1433 read in the augmentation data for GNU eh.
1435 Return DW_DLV_OK if we succeeded,
1436 DW_DLV_ERR if we fail.
1438 On success, update 'size_of_augmentation_data' with
1439 the length of the fields that are part of augmentation (so the
1440 caller can increment frame_ptr appropriately).
1442 'frame_ptr' points within section.
1443 'section_pointer' points to section base address in memory.
1447 get_gcc_eh_augmentation(Dwarf_Debug dbg
, Dwarf_Small
* frame_ptr
,
1448 unsigned long *size_of_augmentation_data
,
1449 enum Dwarf_augmentation_type augtype
,
1450 Dwarf_Small
* section_pointer
,
1451 Dwarf_Small
* fde_eh_encoding_out
,
1455 unsigned long augdata_size
= 0;
1457 if (augtype
== aug_gcc_eh_z
) {
1458 /* Has leading 'z'. */
1459 Dwarf_Word leb128_length
= 0;
1461 /* Dwarf_Unsigned eh_value = */
1462 _dwarf_decode_u_leb128(frame_ptr
, &leb128_length
);
1463 augdata_size
+= leb128_length
;
1464 frame_ptr
+= leb128_length
;
1465 suffix
= augmentation
+ 1;
1467 /* Prefix is 'eh'. As in gcc 3.2. No suffix present
1469 suffix
= augmentation
+ 2;
1471 for (; *suffix
; ++suffix
) {
1472 /* We have no idea what this is as yet. Some extensions beyond
1473 dwarf exist which we do not yet handle. */
1474 return DW_DLV_ERROR
;
1478 *size_of_augmentation_data
= augdata_size
;
1483 /* Make the 'cie_id_addr' consistent across .debug_frame and .eh_frame.
1484 Calculate a pointer into section bytes given a cie_id, which is
1485 trivial for .debug_frame, but a bit more work for .eh_frame.
1487 static Dwarf_Small
*
1488 get_cieptr_given_offset(Dwarf_Unsigned cie_id_value
,
1489 int use_gnu_cie_calc
,
1490 Dwarf_Small
* section_ptr
,
1491 Dwarf_Small
* cie_id_addr
)
1493 Dwarf_Small
*cieptr
= 0;
1495 if (use_gnu_cie_calc
) {
1496 /* cie_id value is offset, in section, of the cie_id itself, to
1497 use vm ptr of the value, less the value, to get to the cie
1498 itself. In addition, munge *cie_id_addr to look *as if* it
1499 was from real dwarf. */
1500 cieptr
= (Dwarf_Small
*)(uintptr_t)
1501 ((Dwarf_Unsigned
)(uintptr_t)cie_id_addr
) -
1502 ((Dwarf_Unsigned
) cie_id_value
);
1504 /* Traditional dwarf section offset is in cie_id */
1505 cieptr
= (section_ptr
+ cie_id_value
);
1510 /* To properly release all spaced used.
1511 Earlier approaches (before July 15, 2005)
1512 letting client do the dealloc directly left
1513 some data allocated.
1514 This is directly called by consumer code.
1517 dwarf_fde_cie_list_dealloc(Dwarf_Debug dbg
,
1518 Dwarf_Cie
* cie_data
,
1519 Dwarf_Signed cie_element_count
,
1520 Dwarf_Fde
* fde_data
,
1521 Dwarf_Signed fde_element_count
)
1525 for (i
= 0; i
< cie_element_count
; ++i
) {
1526 Dwarf_Frame frame
= cie_data
[i
]->ci_initial_table
;
1529 dwarf_dealloc(dbg
, frame
, DW_DLA_FRAME
);
1530 dwarf_dealloc(dbg
, cie_data
[i
], DW_DLA_CIE
);
1532 for (i
= 0; i
< fde_element_count
; ++i
) {
1533 dwarf_dealloc(dbg
, fde_data
[i
], DW_DLA_FDE
);
1536 dwarf_dealloc(dbg
, cie_data
, DW_DLA_LIST
);
1538 dwarf_dealloc(dbg
, fde_data
, DW_DLA_LIST
);