2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include <DebugContext.h>
10 BDebugContext::BDebugContext()
16 BDebugContext::~BDebugContext()
23 BDebugContext::Init(team_id team
, port_id nubPort
)
27 status_t error
= init_debug_context(&fContext
, team
, nubPort
);
38 BDebugContext::Uninit()
40 if (fContext
.team
>= 0) {
41 destroy_debug_context(&fContext
);
48 BDebugContext::SendDebugMessage(int32 messageCode
, const void *message
,
49 size_t messageSize
, void* reply
, size_t replySize
)
51 return send_debug_message(&fContext
, messageCode
, message
, messageSize
,
57 BDebugContext::SetTeamDebuggingFlags(int32 flags
)
59 debug_nub_set_team_flags message
;
60 message
.flags
= flags
;
62 return SendDebugMessage(B_DEBUG_MESSAGE_SET_TEAM_FLAGS
, &message
,
63 sizeof(message
), NULL
, 0);
68 BDebugContext::ReadMemoryPartial(const void* address
, void* buffer
, size_t size
)
70 return debug_read_memory_partial(&fContext
, address
, buffer
, size
);
75 BDebugContext::ReadMemory(const void* address
, void* buffer
, size_t size
)
77 return debug_read_memory(&fContext
, address
, buffer
, size
);
82 BDebugContext::ReadString(const void* address
, char* buffer
, size_t size
)
84 return debug_read_string(&fContext
, address
, buffer
, size
);
89 BDebugContext::SetBreakpoint(void* address
)
91 debug_nub_set_breakpoint message
;
92 message
.reply_port
= fContext
.reply_port
;
93 message
.address
= address
;
95 debug_nub_set_breakpoint_reply reply
;
96 status_t error
= SendDebugMessage(B_DEBUG_MESSAGE_SET_BREAKPOINT
, &message
,
97 sizeof(message
), &reply
, sizeof(reply
));
99 return error
== B_OK
? reply
.error
: error
;
104 BDebugContext::ClearBreakpoint(void* address
)
106 debug_nub_clear_breakpoint message
;
107 message
.address
= address
;
109 return SendDebugMessage(B_DEBUG_MESSAGE_CLEAR_BREAKPOINT
, &message
,
110 sizeof(message
), NULL
, 0);
115 BDebugContext::SetWatchpoint(void* address
, uint32 type
, int32 length
)
117 debug_nub_set_watchpoint message
;
118 message
.reply_port
= fContext
.reply_port
;
119 message
.address
= address
;
121 message
.length
= length
;
123 debug_nub_set_watchpoint_reply reply
;
124 status_t error
= SendDebugMessage(B_DEBUG_MESSAGE_SET_WATCHPOINT
, &message
,
125 sizeof(message
), &reply
, sizeof(reply
));
127 return error
== B_OK
? reply
.error
: error
;
132 BDebugContext::ClearWatchpoint(void* address
)
134 debug_nub_clear_watchpoint message
;
135 message
.address
= address
;
137 return SendDebugMessage(B_DEBUG_MESSAGE_CLEAR_WATCHPOINT
, &message
,
138 sizeof(message
), NULL
, 0);
143 BDebugContext::ContinueThread(thread_id thread
, bool singleStep
)
145 debug_nub_continue_thread message
;
146 message
.thread
= thread
;
147 message
.handle_event
= B_THREAD_DEBUG_HANDLE_EVENT
;
148 message
.single_step
= singleStep
;
150 return SendDebugMessage(B_DEBUG_MESSAGE_CONTINUE_THREAD
, &message
,
151 sizeof(message
), NULL
, 0);
156 BDebugContext::SetThreadDebuggingFlags(thread_id thread
, int32 flags
)
158 debug_nub_set_thread_flags message
;
159 message
.thread
= thread
;
160 message
.flags
= flags
;
162 return SendDebugMessage(B_DEBUG_MESSAGE_SET_THREAD_FLAGS
, &message
,
163 sizeof(message
), NULL
, 0);
168 BDebugContext::GetThreadCpuState(thread_id thread
,
169 debug_debugger_message
* _messageCode
, debug_cpu_state
* cpuState
)
171 return debug_get_cpu_state(&fContext
, thread
, _messageCode
, cpuState
);