1/*
2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include <debug_support.h>
8
9#include "arch_debug_support.h"
10
11
12struct stack_frame {
13	struct stack_frame	*previous;
14	void				*return_address;
15};
16
17
18status_t
19arch_debug_get_instruction_pointer(debug_context *context, thread_id thread,
20	void **ip, void **stackFrameAddress)
21{
22	// get the CPU state
23	debug_cpu_state cpuState;
24	status_t error = debug_get_cpu_state(context, thread, NULL, &cpuState);
25	if (error != B_OK)
26		return error;
27
28	*ip = (void*)cpuState.eip;
29	*stackFrameAddress = (void*)cpuState.ebp;
30
31	return B_OK;
32}
33
34
35status_t
36arch_debug_get_stack_frame(debug_context *context, void *stackFrameAddress,
37	debug_stack_frame_info *stackFrameInfo)
38{
39	stack_frame stackFrame;
40	ssize_t bytesRead = debug_read_memory(context, stackFrameAddress, &stackFrame,
41		sizeof(stackFrame));
42	if (bytesRead < B_OK)
43		return bytesRead;
44	if (bytesRead != sizeof(stackFrame))
45		return B_ERROR;
46
47	stackFrameInfo->frame = stackFrameAddress;
48	stackFrameInfo->parent_frame = stackFrame.previous;
49	stackFrameInfo->return_address = stackFrame.return_address;
50	return B_OK;
51}
52