1 /* Subroutines needed for unwinding stack frames for exception handling. */
2 /* Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Jason Merrill <jason@cygnus.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file. (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
21 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
22 WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 You should have received a copy of the GNU General Public License
27 along with GCC; see the file COPYING. If not, write to the Free
28 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
31 #ifndef _Unwind_Find_FDE
36 #define NO_BASE_OF_ENCODED_VALUE
37 #include "unwind-pe.h"
38 #include "unwind-dw2-fde.h"
42 /* The unseen_objects list contains objects that have been registered
43 but not yet categorized in any way. The seen_objects list has had
44 it's pc_begin and count fields initialized at minimum, and is sorted
45 by decreasing value of pc_begin. */
46 static struct object
*unseen_objects
;
47 static struct object
*seen_objects
;
49 #ifdef __GTHREAD_MUTEX_INIT
50 static __gthread_mutex_t object_mutex
= __GTHREAD_MUTEX_INIT
;
52 static __gthread_mutex_t object_mutex
;
55 #ifdef __GTHREAD_MUTEX_INIT_FUNCTION
57 init_object_mutex (void)
59 __GTHREAD_MUTEX_INIT_FUNCTION (&object_mutex
);
63 init_object_mutex_once (void)
65 static __gthread_once_t once
= __GTHREAD_ONCE_INIT
;
66 __gthread_once (&once
, init_object_mutex
);
69 #define init_object_mutex_once()
72 /* Called from crtbegin.o to register the unwind info for an object. */
75 __register_frame_info_bases (void *begin
, struct object
*ob
,
76 void *tbase
, void *dbase
)
78 /* If .eh_frame is empty, don't register at all. */
79 if (*(uword
*) begin
== 0)
82 ob
->pc_begin
= (void *)-1;
87 ob
->s
.b
.encoding
= DW_EH_PE_omit
;
89 init_object_mutex_once ();
90 __gthread_mutex_lock (&object_mutex
);
92 ob
->next
= unseen_objects
;
95 __gthread_mutex_unlock (&object_mutex
);
99 __register_frame_info (void *begin
, struct object
*ob
)
101 __register_frame_info_bases (begin
, ob
, 0, 0);
105 __register_frame (void *begin
)
109 /* If .eh_frame is empty, don't register at all. */
110 if (*(uword
*) begin
== 0)
113 ob
= (struct object
*) malloc (sizeof (struct object
));
114 __register_frame_info (begin
, ob
);
117 /* Similar, but BEGIN is actually a pointer to a table of unwind entries
118 for different translation units. Called from the file generated by
122 __register_frame_info_table_bases (void *begin
, struct object
*ob
,
123 void *tbase
, void *dbase
)
125 ob
->pc_begin
= (void *)-1;
130 ob
->s
.b
.from_array
= 1;
131 ob
->s
.b
.encoding
= DW_EH_PE_omit
;
133 init_object_mutex_once ();
134 __gthread_mutex_lock (&object_mutex
);
136 ob
->next
= unseen_objects
;
139 __gthread_mutex_unlock (&object_mutex
);
143 __register_frame_info_table (void *begin
, struct object
*ob
)
145 __register_frame_info_table_bases (begin
, ob
, 0, 0);
149 __register_frame_table (void *begin
)
151 struct object
*ob
= (struct object
*) malloc (sizeof (struct object
));
152 __register_frame_info_table (begin
, ob
);
155 /* Called from crtbegin.o to deregister the unwind info for an object. */
156 /* ??? Glibc has for a while now exported __register_frame_info and
157 __deregister_frame_info. If we call __register_frame_info_bases
158 from crtbegin (wherein it is declared weak), and this object does
159 not get pulled from libgcc.a for other reasons, then the
160 invocation of __deregister_frame_info will be resolved from glibc.
161 Since the registration did not happen there, we'll abort.
163 Therefore, declare a new deregistration entry point that does the
164 exact same thing, but will resolve to the same library as
165 implements __register_frame_info_bases. */
168 __deregister_frame_info_bases (void *begin
)
171 struct object
*ob
= 0;
173 /* If .eh_frame is empty, we haven't registered. */
174 if (*(uword
*) begin
== 0)
177 init_object_mutex_once ();
178 __gthread_mutex_lock (&object_mutex
);
180 for (p
= &unseen_objects
; *p
; p
= &(*p
)->next
)
181 if ((*p
)->u
.single
== begin
)
188 for (p
= &seen_objects
; *p
; p
= &(*p
)->next
)
189 if ((*p
)->s
.b
.sorted
)
191 if ((*p
)->u
.sort
->orig_data
== begin
)
201 if ((*p
)->u
.single
== begin
)
209 __gthread_mutex_unlock (&object_mutex
);
213 __gthread_mutex_unlock (&object_mutex
);
218 __deregister_frame_info (void *begin
)
220 return __deregister_frame_info_bases (begin
);
224 __deregister_frame (void *begin
)
226 /* If .eh_frame is empty, we haven't registered. */
227 if (*(uword
*) begin
!= 0)
228 free (__deregister_frame_info (begin
));
232 /* Like base_of_encoded_value, but take the base from a struct object
233 instead of an _Unwind_Context. */
236 base_from_object (unsigned char encoding
, struct object
*ob
)
238 if (encoding
== DW_EH_PE_omit
)
241 switch (encoding
& 0x70)
243 case DW_EH_PE_absptr
:
245 case DW_EH_PE_aligned
:
248 case DW_EH_PE_textrel
:
249 return (_Unwind_Ptr
) ob
->tbase
;
250 case DW_EH_PE_datarel
:
251 return (_Unwind_Ptr
) ob
->dbase
;
256 /* Return the FDE pointer encoding from the CIE. */
257 /* ??? This is a subset of extract_cie_info from unwind-dw2.c. */
260 get_cie_encoding (struct dwarf_cie
*cie
)
262 const unsigned char *aug
, *p
;
267 aug
= cie
->augmentation
;
269 return DW_EH_PE_absptr
;
271 p
= aug
+ strlen (aug
) + 1; /* Skip the augmentation string. */
272 p
= read_uleb128 (p
, &utmp
); /* Skip code alignment. */
273 p
= read_sleb128 (p
, &stmp
); /* Skip data alignment. */
274 p
++; /* Skip return address column. */
276 aug
++; /* Skip 'z' */
277 p
= read_uleb128 (p
, &utmp
); /* Skip augmentation length. */
280 /* This is what we're looking for. */
283 /* Personality encoding and pointer. */
284 else if (*aug
== 'P')
286 /* ??? Avoid dereferencing indirect pointers, since we're
287 faking the base address. Gotta keep DW_EH_PE_aligned
289 p
= read_encoded_value_with_base (*p
& 0x7F, 0, p
+ 1, &dummy
);
292 else if (*aug
== 'L')
294 /* Otherwise end of string, or unknown augmentation. */
296 return DW_EH_PE_absptr
;
302 get_fde_encoding (struct dwarf_fde
*f
)
304 return get_cie_encoding (get_cie (f
));
308 /* Sorting an array of FDEs by address.
309 (Ideally we would have the linker sort the FDEs so we don't have to do
310 it at run time. But the linkers are not yet prepared for this.) */
312 /* Comparison routines. Three variants of increasing complexity. */
315 fde_unencoded_compare (struct object
*ob
__attribute__((unused
)),
318 _Unwind_Ptr x_ptr
= *(_Unwind_Ptr
*) x
->pc_begin
;
319 _Unwind_Ptr y_ptr
= *(_Unwind_Ptr
*) y
->pc_begin
;
329 fde_single_encoding_compare (struct object
*ob
, fde
*x
, fde
*y
)
331 _Unwind_Ptr base
, x_ptr
, y_ptr
;
333 base
= base_from_object (ob
->s
.b
.encoding
, ob
);
334 read_encoded_value_with_base (ob
->s
.b
.encoding
, base
, x
->pc_begin
, &x_ptr
);
335 read_encoded_value_with_base (ob
->s
.b
.encoding
, base
, y
->pc_begin
, &y_ptr
);
345 fde_mixed_encoding_compare (struct object
*ob
, fde
*x
, fde
*y
)
347 int x_encoding
, y_encoding
;
348 _Unwind_Ptr x_ptr
, y_ptr
;
350 x_encoding
= get_fde_encoding (x
);
351 read_encoded_value_with_base (x_encoding
, base_from_object (x_encoding
, ob
),
352 x
->pc_begin
, &x_ptr
);
354 y_encoding
= get_fde_encoding (y
);
355 read_encoded_value_with_base (y_encoding
, base_from_object (y_encoding
, ob
),
356 y
->pc_begin
, &y_ptr
);
365 typedef int (*fde_compare_t
) (struct object
*, fde
*, fde
*);
368 /* This is a special mix of insertion sort and heap sort, optimized for
369 the data sets that actually occur. They look like
370 101 102 103 127 128 105 108 110 190 111 115 119 125 160 126 129 130.
371 I.e. a linearly increasing sequence (coming from functions in the text
372 section), with additionally a few unordered elements (coming from functions
373 in gnu_linkonce sections) whose values are higher than the values in the
374 surrounding linear sequence (but not necessarily higher than the values
375 at the end of the linear sequence!).
376 The worst-case total run time is O(N) + O(n log (n)), where N is the
377 total number of FDEs and n is the number of erratic ones. */
379 struct fde_accumulator
381 struct fde_vector
*linear
;
382 struct fde_vector
*erratic
;
386 start_fde_sort (struct fde_accumulator
*accu
, size_t count
)
392 size
= sizeof (struct fde_vector
) + sizeof (fde
*) * count
;
393 if ((accu
->linear
= (struct fde_vector
*) malloc (size
)))
395 accu
->linear
->count
= 0;
396 if ((accu
->erratic
= (struct fde_vector
*) malloc (size
)))
397 accu
->erratic
->count
= 0;
405 fde_insert (struct fde_accumulator
*accu
, fde
*this_fde
)
408 accu
->linear
->array
[accu
->linear
->count
++] = this_fde
;
411 /* Split LINEAR into a linear sequence with low values and an erratic
412 sequence with high values, put the linear one (of longest possible
413 length) into LINEAR and the erratic one into ERRATIC. This is O(N).
415 Because the longest linear sequence we are trying to locate within the
416 incoming LINEAR array can be interspersed with (high valued) erratic
417 entries. We construct a chain indicating the sequenced entries.
418 To avoid having to allocate this chain, we overlay it onto the space of
419 the ERRATIC array during construction. A final pass iterates over the
420 chain to determine what should be placed in the ERRATIC array, and
421 what is the linear sequence. This overlay is safe from aliasing. */
424 fde_split (struct object
*ob
, fde_compare_t fde_compare
,
425 struct fde_vector
*linear
, struct fde_vector
*erratic
)
428 size_t count
= linear
->count
;
429 fde
**chain_end
= &marker
;
432 /* This should optimize out, but it is wise to make sure this assumption
433 is correct. Should these have different sizes, we cannot cast between
434 them and the overlaying onto ERRATIC will not work. */
435 if (sizeof (fde
*) != sizeof (fde
**))
438 for (i
= 0; i
< count
; i
++)
442 for (probe
= chain_end
;
443 probe
!= &marker
&& fde_compare (ob
, linear
->array
[i
], *probe
) < 0;
446 chain_end
= (fde
**) erratic
->array
[probe
- linear
->array
];
447 erratic
->array
[probe
- linear
->array
] = NULL
;
449 erratic
->array
[i
] = (fde
*) chain_end
;
450 chain_end
= &linear
->array
[i
];
453 /* Each entry in LINEAR which is part of the linear sequence we have
454 discovered will correspond to a non-NULL entry in the chain we built in
455 the ERRATIC array. */
456 for (i
= j
= k
= 0; i
< count
; i
++)
457 if (erratic
->array
[i
])
458 linear
->array
[j
++] = linear
->array
[i
];
460 erratic
->array
[k
++] = linear
->array
[i
];
465 /* This is O(n log(n)). BSD/OS defines heapsort in stdlib.h, so we must
466 use a name that does not conflict. */
469 frame_heapsort (struct object
*ob
, fde_compare_t fde_compare
,
470 struct fde_vector
*erratic
)
472 /* For a description of this algorithm, see:
473 Samuel P. Harbison, Guy L. Steele Jr.: C, a reference manual, 2nd ed.,
475 fde
** a
= erratic
->array
;
476 /* A portion of the array is called a "heap" if for all i>=0:
477 If i and 2i+1 are valid indices, then a[i] >= a[2i+1].
478 If i and 2i+2 are valid indices, then a[i] >= a[2i+2]. */
479 #define SWAP(x,y) do { fde * tmp = x; x = y; y = tmp; } while (0)
480 size_t n
= erratic
->count
;
486 /* Invariant: a[m..n-1] is a heap. */
488 for (i
= m
; 2*i
+1 < n
; )
491 && fde_compare (ob
, a
[2*i
+2], a
[2*i
+1]) > 0
492 && fde_compare (ob
, a
[2*i
+2], a
[i
]) > 0)
494 SWAP (a
[i
], a
[2*i
+2]);
497 else if (fde_compare (ob
, a
[2*i
+1], a
[i
]) > 0)
499 SWAP (a
[i
], a
[2*i
+1]);
508 /* Invariant: a[0..n-1] is a heap. */
511 for (i
= 0; 2*i
+1 < n
; )
514 && fde_compare (ob
, a
[2*i
+2], a
[2*i
+1]) > 0
515 && fde_compare (ob
, a
[2*i
+2], a
[i
]) > 0)
517 SWAP (a
[i
], a
[2*i
+2]);
520 else if (fde_compare (ob
, a
[2*i
+1], a
[i
]) > 0)
522 SWAP (a
[i
], a
[2*i
+1]);
532 /* Merge V1 and V2, both sorted, and put the result into V1. */
534 fde_merge (struct object
*ob
, fde_compare_t fde_compare
,
535 struct fde_vector
*v1
, struct fde_vector
*v2
)
547 fde2
= v2
->array
[i2
];
548 while (i1
> 0 && fde_compare (ob
, v1
->array
[i1
-1], fde2
) > 0)
550 v1
->array
[i1
+i2
] = v1
->array
[i1
-1];
553 v1
->array
[i1
+i2
] = fde2
;
556 v1
->count
+= v2
->count
;
561 end_fde_sort (struct object
*ob
, struct fde_accumulator
*accu
, size_t count
)
563 fde_compare_t fde_compare
;
565 if (accu
->linear
&& accu
->linear
->count
!= count
)
568 if (ob
->s
.b
.mixed_encoding
)
569 fde_compare
= fde_mixed_encoding_compare
;
570 else if (ob
->s
.b
.encoding
== DW_EH_PE_absptr
)
571 fde_compare
= fde_unencoded_compare
;
573 fde_compare
= fde_single_encoding_compare
;
577 fde_split (ob
, fde_compare
, accu
->linear
, accu
->erratic
);
578 if (accu
->linear
->count
+ accu
->erratic
->count
!= count
)
580 frame_heapsort (ob
, fde_compare
, accu
->erratic
);
581 fde_merge (ob
, fde_compare
, accu
->linear
, accu
->erratic
);
582 free (accu
->erratic
);
586 /* We've not managed to malloc an erratic array,
587 so heap sort in the linear one. */
588 frame_heapsort (ob
, fde_compare
, accu
->linear
);
593 /* Update encoding, mixed_encoding, and pc_begin for OB for the
594 fde array beginning at THIS_FDE. Return the number of fdes
595 encountered along the way. */
598 classify_object_over_fdes (struct object
*ob
, fde
*this_fde
)
600 struct dwarf_cie
*last_cie
= 0;
602 int encoding
= DW_EH_PE_absptr
;
603 _Unwind_Ptr base
= 0;
605 for (; this_fde
->length
!= 0; this_fde
= next_fde (this_fde
))
607 struct dwarf_cie
*this_cie
;
608 _Unwind_Ptr mask
, pc_begin
;
611 if (this_fde
->CIE_delta
== 0)
614 /* Determine the encoding for this FDE. Note mixed encoded
615 objects for later. */
616 this_cie
= get_cie (this_fde
);
617 if (this_cie
!= last_cie
)
620 encoding
= get_cie_encoding (this_cie
);
621 base
= base_from_object (encoding
, ob
);
622 if (ob
->s
.b
.encoding
== DW_EH_PE_omit
)
623 ob
->s
.b
.encoding
= encoding
;
624 else if (ob
->s
.b
.encoding
!= encoding
)
625 ob
->s
.b
.mixed_encoding
= 1;
628 read_encoded_value_with_base (encoding
, base
, this_fde
->pc_begin
,
631 /* Take care to ignore link-once functions that were removed.
632 In these cases, the function address will be NULL, but if
633 the encoding is smaller than a pointer a true NULL may not
634 be representable. Assume 0 in the representable bits is NULL. */
635 mask
= size_of_encoded_value (encoding
);
636 if (mask
< sizeof (void *))
637 mask
= (1L << (mask
<< 3)) - 1;
641 if ((pc_begin
& mask
) == 0)
645 if ((void *) pc_begin
< ob
->pc_begin
)
646 ob
->pc_begin
= (void *) pc_begin
;
653 add_fdes (struct object
*ob
, struct fde_accumulator
*accu
, fde
*this_fde
)
655 struct dwarf_cie
*last_cie
= 0;
656 int encoding
= ob
->s
.b
.encoding
;
657 _Unwind_Ptr base
= base_from_object (ob
->s
.b
.encoding
, ob
);
659 for (; this_fde
->length
!= 0; this_fde
= next_fde (this_fde
))
661 struct dwarf_cie
*this_cie
;
664 if (this_fde
->CIE_delta
== 0)
667 if (ob
->s
.b
.mixed_encoding
)
669 /* Determine the encoding for this FDE. Note mixed encoded
670 objects for later. */
671 this_cie
= get_cie (this_fde
);
672 if (this_cie
!= last_cie
)
675 encoding
= get_cie_encoding (this_cie
);
676 base
= base_from_object (encoding
, ob
);
680 if (encoding
== DW_EH_PE_absptr
)
682 if (*(_Unwind_Ptr
*) this_fde
->pc_begin
== 0)
687 _Unwind_Ptr pc_begin
, mask
;
689 read_encoded_value_with_base (encoding
, base
, this_fde
->pc_begin
,
692 /* Take care to ignore link-once functions that were removed.
693 In these cases, the function address will be NULL, but if
694 the encoding is smaller than a pointer a true NULL may not
695 be representable. Assume 0 in the representable bits is NULL. */
696 mask
= size_of_encoded_value (encoding
);
697 if (mask
< sizeof (void *))
698 mask
= (1L << (mask
<< 3)) - 1;
702 if ((pc_begin
& mask
) == 0)
706 fde_insert (accu
, this_fde
);
710 /* Set up a sorted array of pointers to FDEs for a loaded object. We
711 count up the entries before allocating the array because it's likely to
712 be faster. We can be called multiple times, should we have failed to
713 allocate a sorted fde array on a previous occasion. */
716 init_object (struct object
* ob
)
718 struct fde_accumulator accu
;
721 count
= ob
->s
.b
.count
;
724 if (ob
->s
.b
.from_array
)
726 fde
**p
= ob
->u
.array
;
727 for (count
= 0; *p
; ++p
)
728 count
+= classify_object_over_fdes (ob
, *p
);
731 count
= classify_object_over_fdes (ob
, ob
->u
.single
);
733 /* The count field we have in the main struct object is somewhat
734 limited, but should suffice for virtually all cases. If the
735 counted value doesn't fit, re-write a zero. The worst that
736 happens is that we re-count next time -- admittedly non-trivial
737 in that this implies some 2M fdes, but at least we function. */
738 ob
->s
.b
.count
= count
;
739 if (ob
->s
.b
.count
!= count
)
743 if (!start_fde_sort (&accu
, count
))
746 if (ob
->s
.b
.from_array
)
749 for (p
= ob
->u
.array
; *p
; ++p
)
750 add_fdes (ob
, &accu
, *p
);
753 add_fdes (ob
, &accu
, ob
->u
.single
);
755 end_fde_sort (ob
, &accu
, count
);
757 /* Save the original fde pointer, since this is the key by which the
758 DSO will deregister the object. */
759 accu
.linear
->orig_data
= ob
->u
.single
;
760 ob
->u
.sort
= accu
.linear
;
765 /* A linear search through a set of FDEs for the given PC. This is
766 used when there was insufficient memory to allocate and sort an
770 linear_search_fdes (struct object
*ob
, fde
*this_fde
, void *pc
)
772 struct dwarf_cie
*last_cie
= 0;
773 int encoding
= ob
->s
.b
.encoding
;
774 _Unwind_Ptr base
= base_from_object (ob
->s
.b
.encoding
, ob
);
776 for (; this_fde
->length
!= 0; this_fde
= next_fde (this_fde
))
778 struct dwarf_cie
*this_cie
;
779 _Unwind_Ptr pc_begin
, pc_range
;
782 if (this_fde
->CIE_delta
== 0)
785 if (ob
->s
.b
.mixed_encoding
)
787 /* Determine the encoding for this FDE. Note mixed encoded
788 objects for later. */
789 this_cie
= get_cie (this_fde
);
790 if (this_cie
!= last_cie
)
793 encoding
= get_cie_encoding (this_cie
);
794 base
= base_from_object (encoding
, ob
);
798 if (encoding
== DW_EH_PE_absptr
)
800 pc_begin
= ((_Unwind_Ptr
*) this_fde
->pc_begin
)[0];
801 pc_range
= ((_Unwind_Ptr
*) this_fde
->pc_begin
)[1];
810 p
= read_encoded_value_with_base (encoding
, base
,
811 this_fde
->pc_begin
, &pc_begin
);
812 read_encoded_value_with_base (encoding
& 0x0F, 0, p
, &pc_range
);
814 /* Take care to ignore link-once functions that were removed.
815 In these cases, the function address will be NULL, but if
816 the encoding is smaller than a pointer a true NULL may not
817 be representable. Assume 0 in the representable bits is NULL. */
818 mask
= size_of_encoded_value (encoding
);
819 if (mask
< sizeof (void *))
820 mask
= (1L << (mask
<< 3)) - 1;
824 if ((pc_begin
& mask
) == 0)
828 if ((_Unwind_Ptr
) pc
- pc_begin
< pc_range
)
835 /* Binary search for an FDE containing the given PC. Here are three
836 implementations of increasing complexity. */
839 binary_search_unencoded_fdes (struct object
*ob
, void *pc
)
841 struct fde_vector
*vec
= ob
->u
.sort
;
844 for (lo
= 0, hi
= vec
->count
; lo
< hi
; )
846 size_t i
= (lo
+ hi
) / 2;
847 fde
*f
= vec
->array
[i
];
851 pc_begin
= ((void **) f
->pc_begin
)[0];
852 pc_range
= ((uaddr
*) f
->pc_begin
)[1];
856 else if (pc
>= pc_begin
+ pc_range
)
866 binary_search_single_encoding_fdes (struct object
*ob
, void *pc
)
868 struct fde_vector
*vec
= ob
->u
.sort
;
869 int encoding
= ob
->s
.b
.encoding
;
870 _Unwind_Ptr base
= base_from_object (encoding
, ob
);
873 for (lo
= 0, hi
= vec
->count
; lo
< hi
; )
875 size_t i
= (lo
+ hi
) / 2;
876 fde
*f
= vec
->array
[i
];
877 _Unwind_Ptr pc_begin
, pc_range
;
880 p
= read_encoded_value_with_base (encoding
, base
, f
->pc_begin
,
882 read_encoded_value_with_base (encoding
& 0x0F, 0, p
, &pc_range
);
884 if ((_Unwind_Ptr
) pc
< pc_begin
)
886 else if ((_Unwind_Ptr
) pc
>= pc_begin
+ pc_range
)
896 binary_search_mixed_encoding_fdes (struct object
*ob
, void *pc
)
898 struct fde_vector
*vec
= ob
->u
.sort
;
901 for (lo
= 0, hi
= vec
->count
; lo
< hi
; )
903 size_t i
= (lo
+ hi
) / 2;
904 fde
*f
= vec
->array
[i
];
905 _Unwind_Ptr pc_begin
, pc_range
;
909 encoding
= get_fde_encoding (f
);
910 p
= read_encoded_value_with_base (encoding
,
911 base_from_object (encoding
, ob
),
912 f
->pc_begin
, &pc_begin
);
913 read_encoded_value_with_base (encoding
& 0x0F, 0, p
, &pc_range
);
915 if ((_Unwind_Ptr
) pc
< pc_begin
)
917 else if ((_Unwind_Ptr
) pc
>= pc_begin
+ pc_range
)
927 search_object (struct object
* ob
, void *pc
)
929 /* If the data hasn't been sorted, try to do this now. We may have
930 more memory available than last time we tried. */
931 if (! ob
->s
.b
.sorted
)
935 /* Despite the above comment, the normal reason to get here is
936 that we've not processed this object before. A quick range
937 check is in order. */
938 if (pc
< ob
->pc_begin
)
944 if (ob
->s
.b
.mixed_encoding
)
945 return binary_search_mixed_encoding_fdes (ob
, pc
);
946 else if (ob
->s
.b
.encoding
== DW_EH_PE_absptr
)
947 return binary_search_unencoded_fdes (ob
, pc
);
949 return binary_search_single_encoding_fdes (ob
, pc
);
953 /* Long slow labourious linear search, cos we've no memory. */
954 if (ob
->s
.b
.from_array
)
957 for (p
= ob
->u
.array
; *p
; p
++)
959 fde
*f
= linear_search_fdes (ob
, *p
, pc
);
966 return linear_search_fdes (ob
, ob
->u
.single
, pc
);
971 _Unwind_Find_FDE (void *pc
, struct dwarf_eh_bases
*bases
)
976 init_object_mutex_once ();
977 __gthread_mutex_lock (&object_mutex
);
979 /* Linear search through the classified objects, to find the one
980 containing the pc. Note that pc_begin is sorted descending, and
981 we expect objects to be non-overlapping. */
982 for (ob
= seen_objects
; ob
; ob
= ob
->next
)
983 if (pc
>= ob
->pc_begin
)
985 f
= search_object (ob
, pc
);
991 /* Classify and search the objects we've not yet processed. */
992 while ((ob
= unseen_objects
))
996 unseen_objects
= ob
->next
;
997 f
= search_object (ob
, pc
);
999 /* Insert the object into the classified list. */
1000 for (p
= &seen_objects
; *p
; p
= &(*p
)->next
)
1001 if ((*p
)->pc_begin
< ob
->pc_begin
)
1011 __gthread_mutex_unlock (&object_mutex
);
1017 bases
->tbase
= ob
->tbase
;
1018 bases
->dbase
= ob
->dbase
;
1020 encoding
= ob
->s
.b
.encoding
;
1021 if (ob
->s
.b
.mixed_encoding
)
1022 encoding
= get_fde_encoding (f
);
1023 read_encoded_value_with_base (encoding
, base_from_object (encoding
, ob
),
1024 f
->pc_begin
, (_Unwind_Ptr
*)&bases
->func
);