Skip to content

Commit

Permalink
Extend DebuggerInterface.
Browse files Browse the repository at this point in the history
- Factor out an _GetDebugCpuState() call to share between
{Get,Set}CpuState().

- Add SetCpuState() which allows to update the state of a given thread.
  • Loading branch information
anevilyak committed May 17, 2013
1 parent 93b54e5 commit c21b8ec
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
63 changes: 51 additions & 12 deletions src/apps/debugger/debugger_interface/DebuggerInterface.cpp
Expand Up @@ -23,6 +23,7 @@
#include "ArchitectureX86.h"
#include "ArchitectureX8664.h"
#include "AreaInfo.h"
#include "AutoDeleter.h"
#include "CpuState.h"
#include "DebugEvent.h"
#include "ImageInfo.h"
Expand Down Expand Up @@ -663,24 +664,37 @@ DebuggerInterface::GetThreadInfo(thread_id thread, ThreadInfo& info)
status_t
DebuggerInterface::GetCpuState(thread_id thread, CpuState*& _state)
{
DebugContextGetter contextGetter(fDebugContextPool);
debug_cpu_state debugState;
status_t error = _GetDebugCpuState(thread, debugState);
if (error != B_OK)
return error;
return fArchitecture->CreateCpuState(&debugState, sizeof(debug_cpu_state),
_state);
}

debug_nub_get_cpu_state message;
message.reply_port = contextGetter.Context()->reply_port;
message.thread = thread;

debug_nub_get_cpu_state_reply reply;
status_t
DebuggerInterface::SetCpuState(thread_id thread, const CpuState* state)
{
debug_cpu_state debugState;
status_t error = _GetDebugCpuState(thread, debugState);
if (error != B_OK)
return error;

status_t error = send_debug_message(contextGetter.Context(),
B_DEBUG_MESSAGE_GET_CPU_STATE, &message, sizeof(message), &reply,
sizeof(reply));
DebugContextGetter contextGetter(fDebugContextPool);

error = state->UpdateDebugState(&debugState, sizeof(debugState));
if (error != B_OK)
return error;
if (reply.error != B_OK)
return reply.error;

return fArchitecture->CreateCpuState(&reply.cpu_state,
sizeof(debug_cpu_state), _state);
debug_nub_set_cpu_state message;
message.thread = thread;

memcpy(&message.cpu_state, &debugState, sizeof(debugState));

return send_debug_message(contextGetter.Context(),
B_DEBUG_MESSAGE_SET_CPU_STATE, &message, sizeof(message), NULL,
0);
}


Expand Down Expand Up @@ -883,3 +897,28 @@ DebuggerInterface::_GetNextSystemWatchEvent(DebugEvent*& _event,

return error;
}


status_t
DebuggerInterface::_GetDebugCpuState(thread_id thread, debug_cpu_state& _state)
{
DebugContextGetter contextGetter(fDebugContextPool);

debug_nub_get_cpu_state message;
message.reply_port = contextGetter.Context()->reply_port;
message.thread = thread;

debug_nub_get_cpu_state_reply reply;

status_t error = send_debug_message(contextGetter.Context(),
B_DEBUG_MESSAGE_GET_CPU_STATE, &message, sizeof(message), &reply,
sizeof(reply));
if (error != B_OK)
return error;
if (reply.error != B_OK)
return reply.error;

memcpy(&_state, &reply.cpu_state, sizeof(debug_cpu_state));

return B_OK;
}
5 changes: 5 additions & 0 deletions src/apps/debugger/debugger_interface/DebuggerInterface.h
Expand Up @@ -74,6 +74,8 @@ class DebuggerInterface : public TeamMemory {
virtual status_t GetCpuState(thread_id thread,
CpuState*& _state);
// returns a reference to the caller
virtual status_t SetCpuState(thread_id thread,
const CpuState* state);

// TeamMemory
virtual ssize_t ReadMemory(target_addr_t address, void* buffer,
Expand All @@ -94,6 +96,9 @@ class DebuggerInterface : public TeamMemory {
status_t _GetNextSystemWatchEvent(DebugEvent*& _event,
BPrivate::KMessage& message);

status_t _GetDebugCpuState(thread_id thread,
debug_cpu_state& _state);

private:
team_id fTeamID;
port_id fDebuggerPort;
Expand Down

0 comments on commit c21b8ec

Please sign in to comment.