Skip to content

Commit

Permalink
Debugger: Add hook for variable value writing.
Browse files Browse the repository at this point in the history
WriteValueNodeJob:
- Implement async job that creates a ValueWriter to update a variable
  value on request.

UserInterfaceListener:
- Add hook for requesting that a node be updated with a new value.
  Implement in TeamDebugger by scheduling a WriteValueNodeJob.
  • Loading branch information
anevilyak committed Jul 24, 2015
1 parent 9b0d975 commit 7d25ab9
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/apps/debugger/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ local sources =
ResolveValueNodeJob.cpp
RetrieveMemoryBlockJob.cpp
WriteMemoryJob.cpp
WriteValueNodeJob.cpp

# model
AreaInfo.cpp
Expand Down
20 changes: 19 additions & 1 deletion src/apps/debugger/controllers/TeamDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,13 +1035,31 @@ TeamDebugger::ValueNodeValueRequested(CpuState* cpuState,
status_t error = fWorker->ScheduleJob(
new(std::nothrow) ResolveValueNodeValueJob(fDebuggerInterface,
fDebuggerInterface->GetArchitecture(), cpuState,
fTeam->GetTeamTypeInformation(), container, valueNode), this);
fTeam->GetTeamTypeInformation(), container, valueNode), this);
if (error != B_OK) {
// scheduling failed -- set the value to invalid
valueNode->SetLocationAndValue(NULL, NULL, error);
}
}

void
TeamDebugger::ValueNodeWriteRequested(ValueNode* node, CpuState* state,
Value* newValue)
{
// schedule the job
status_t error = fWorker->ScheduleJob(
new(std::nothrow) WriteValueNodeValueJob(fDebuggerInterface,
fDebuggerInterface->GetArchitecture(), state,
fTeam->GetTeamTypeInformation(), node, newValue), this);
if (error != B_OK) {
BString message;
message.SetToFormat("Request to write new value for variable %s "
"failed: %s.\n", node->Name().String(), strerror(error));
fUserInterface->NotifyUser("Error", message.String(),
USER_NOTIFICATION_ERROR);
}
}


void
TeamDebugger::ThreadActionRequested(thread_id threadID,
Expand Down
3 changes: 3 additions & 0 deletions src/apps/debugger/controllers/TeamDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class TeamDebugger : public BLooper, private UserInterfaceListener,
virtual void ValueNodeValueRequested(CpuState* cpuState,
ValueNodeContainer* container,
ValueNode* valueNode);
virtual void ValueNodeWriteRequested(ValueNode* node,
CpuState* state,
Value* newValue);
virtual void ThreadActionRequested(thread_id threadID,
uint32 action, target_addr_t address);

Expand Down
27 changes: 27 additions & 0 deletions src/apps/debugger/jobs/Jobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum {
JOB_TYPE_LOAD_SOURCE_CODE,
JOB_TYPE_GET_STACK_FRAME_VALUE,
JOB_TYPE_RESOLVE_VALUE_NODE_VALUE,
JOB_TYPE_WRITE_VALUE_NODE_VALUE,
JOB_TYPE_GET_MEMORY_BLOCK,
JOB_TYPE_WRITE_MEMORY,
JOB_TYPE_EVALUATE_EXPRESSION
Expand Down Expand Up @@ -216,6 +217,32 @@ class ResolveValueNodeValueJob : public Job {
};


class WriteValueNodeValueJob : public Job {
public:
WriteValueNodeValueJob(
DebuggerInterface* debuggerInterface,
Architecture* architecture,
CpuState* cpuState,
TeamTypeInformation* typeInformation,
ValueNode* valueNode,
Value* newValue);
virtual ~WriteValueNodeValueJob();

virtual const JobKey& Key() const;
virtual status_t Do();

private:
SimpleJobKey fKey;
DebuggerInterface* fDebuggerInterface;
Architecture* fArchitecture;
CpuState* fCpuState;
TeamTypeInformation*
fTypeInformation;
ValueNode* fValueNode;
Value* fNewValue;
};


class RetrieveMemoryBlockJob : public Job {
public:
RetrieveMemoryBlockJob(Team* team,
Expand Down
80 changes: 80 additions & 0 deletions src/apps/debugger/jobs/WriteValueNodeJob.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2015, Rene Gollent, rene@gollent.com.
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/

#include "Jobs.h"

#include <AutoLocker.h>

#include "Architecture.h"
#include "CpuState.h"
#include "DebuggerInterface.h"
#include "TeamTypeInformation.h"
#include "Tracing.h"
#include "Value.h"
#include "ValueLocation.h"
#include "ValueNode.h"
#include "ValueNodeContainer.h"
#include "ValueWriter.h"


WriteValueNodeValueJob::WriteValueNodeValueJob(
DebuggerInterface* debuggerInterface, Architecture* architecture,
CpuState* cpuState, TeamTypeInformation* typeInformation,
ValueNode* valueNode, Value* newValue)
:
fKey(valueNode, JOB_TYPE_WRITE_VALUE_NODE_VALUE),
fDebuggerInterface(debuggerInterface),
fArchitecture(architecture),
fCpuState(cpuState),
fTypeInformation(typeInformation),
fValueNode(valueNode),
fNewValue(newValue)
{
if (fCpuState != NULL)
fCpuState->AcquireReference();
fValueNode->AcquireReference();
fNewValue->AcquireReference();
}


WriteValueNodeValueJob::~WriteValueNodeValueJob()
{
if (fCpuState != NULL)
fCpuState->ReleaseReference();
fValueNode->ReleaseReference();
fNewValue->ReleaseReference();
}


const JobKey&
WriteValueNodeValueJob::Key() const
{
return fKey;
}


status_t
WriteValueNodeValueJob::Do()
{
ValueNodeContainer* container = fValueNode->Container();
if (container == NULL)
return B_BAD_VALUE;

ValueWriter writer(fArchitecture, fDebuggerInterface,
fCpuState, -1);

BVariant value;
fNewValue->ToVariant(value);

status_t error = writer.WriteValue(fValueNode->Location(), value);
if (error != B_OK)
return error;

AutoLocker<ValueNodeContainer> containerLocker(container);
fValueNode->SetLocationAndValue(fValueNode->Location(), fNewValue, B_OK);

return B_OK;
}
6 changes: 4 additions & 2 deletions src/apps/debugger/user_interface/UserInterface.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2013-2014, Rene Gollent, rene@gollent.com.
* Copyright 2013-2015, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef USER_INTERFACE_H
Expand Down Expand Up @@ -30,9 +30,9 @@ class Thread;
class TypeComponentPath;
class UserBreakpoint;
class UserInterfaceListener;
class Value;
class ValueNode;
class ValueNodeContainer;
class Variable;
class Watchpoint;


Expand Down Expand Up @@ -101,6 +101,8 @@ class UserInterfaceListener {
virtual void ValueNodeValueRequested(CpuState* cpuState,
ValueNodeContainer* container,
ValueNode* valueNode) = 0;
virtual void ValueNodeWriteRequested(ValueNode* node,
CpuState* state, Value* newValue) = 0;
virtual void ThreadActionRequested(thread_id threadID,
uint32 action,
target_addr_t address = 0) = 0;
Expand Down

0 comments on commit 7d25ab9

Please sign in to comment.