BPicture: Fix archive constructor.
[haiku.git] / src / kits / debug / DebugContext.cpp
blob0663b5e3df5ad37f0551cc6dbeb9db6ed1b058ee
1 /*
2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <DebugContext.h>
10 BDebugContext::BDebugContext()
12 fContext.team = -1;
16 BDebugContext::~BDebugContext()
18 Uninit();
22 status_t
23 BDebugContext::Init(team_id team, port_id nubPort)
25 Uninit();
27 status_t error = init_debug_context(&fContext, team, nubPort);
28 if (error != B_OK) {
29 fContext.team = -1;
30 return error;
33 return B_OK;
37 void
38 BDebugContext::Uninit()
40 if (fContext.team >= 0) {
41 destroy_debug_context(&fContext);
42 fContext.team = -1;
47 status_t
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,
52 reply, replySize);
56 status_t
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);
67 ssize_t
68 BDebugContext::ReadMemoryPartial(const void* address, void* buffer, size_t size)
70 return debug_read_memory_partial(&fContext, address, buffer, size);
74 ssize_t
75 BDebugContext::ReadMemory(const void* address, void* buffer, size_t size)
77 return debug_read_memory(&fContext, address, buffer, size);
81 ssize_t
82 BDebugContext::ReadString(const void* address, char* buffer, size_t size)
84 return debug_read_string(&fContext, address, buffer, size);
88 status_t
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;
103 status_t
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);
114 status_t
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;
120 message.type = type;
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;
131 status_t
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);
142 status_t
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);
155 status_t
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);
167 status_t
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);