2 * Copyright 2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Michael Lotz, mmlr@mlotz.ch
9 #include <libroot_private.h>
12 /*! Captures a stack trace (the return addresses) of the current thread.
13 \param returnAddresses The array the return address shall be written to.
14 \param maxCount The maximum number of return addresses to be captured.
15 \param skipFrames The number of stack frames that shall be skipped.
16 \param stackBase The base address of the thread stack.
17 \param stackEnd The first address past the thread stack.
18 \return The number of return addresses written to the given array.
21 __arch_get_stack_trace(addr_t
* returnAddresses
, int32 maxCount
,
22 int32 skipFrames
, addr_t stackBase
, addr_t stackEnd
)
25 addr_t basePointer
= (addr_t
)get_stack_frame();
27 while (basePointer
!= 0 && count
< maxCount
) {
28 if (basePointer
< stackBase
|| basePointer
>= stackEnd
)
33 addr_t return_address
;
36 stack_frame
* frame
= (stack_frame
*)basePointer
;
39 returnAddresses
[count
++] = frame
->return_address
;
43 basePointer
= frame
->previous
;