btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / debug / arch / x86_64 / arch_debug_support.cpp
blob83f6b35cdf6009b4ccfbbe76ec6a60ed3aa54af7
1 /*
2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
3 * Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
4 * Distributed under the terms of the MIT License.
5 */
8 #include <debug_support.h>
10 #include "arch_debug_support.h"
13 struct stack_frame {
14 struct stack_frame *previous;
15 void *return_address;
19 status_t
20 arch_debug_get_instruction_pointer(debug_context *context, thread_id thread,
21 void **ip, void **stackFrameAddress)
23 // get the CPU state
24 debug_cpu_state cpuState;
25 status_t error = debug_get_cpu_state(context, thread, NULL, &cpuState);
26 if (error != B_OK)
27 return error;
29 *ip = (void*)cpuState.rip;
30 *stackFrameAddress = (void*)cpuState.rbp;
32 return B_OK;
36 status_t
37 arch_debug_get_stack_frame(debug_context *context, void *stackFrameAddress,
38 debug_stack_frame_info *stackFrameInfo)
40 stack_frame stackFrame;
41 ssize_t bytesRead = debug_read_memory(context, stackFrameAddress,
42 &stackFrame, sizeof(stackFrame));
43 if (bytesRead < B_OK)
44 return bytesRead;
45 if (bytesRead != sizeof(stackFrame))
46 return B_ERROR;
48 stackFrameInfo->frame = stackFrameAddress;
49 stackFrameInfo->parent_frame = stackFrame.previous;
50 stackFrameInfo->return_address = stackFrame.return_address;
51 return B_OK;