Debugger: Add expression support to CliContext.

- Extend CliContext::Event to be able to store expression
  event results.
- Extend CliContext to watch for team expression events and
  handle them accordingly.
This commit is contained in:
Rene Gollent 2014-10-29 11:48:03 -04:00
parent 53aae3db4d
commit 382587517f
2 changed files with 81 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012, Rene Gollent, rene@gollent.com.
* Copyright 2012-2014, Rene Gollent, rene@gollent.com.
* Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
@ -12,6 +12,7 @@
#include "StackTrace.h"
#include "UserInterface.h"
#include "Value.h"
#include "ValueNodeManager.h"
// NOTE: This is a simple work-around for EditLine not having any kind of user
@ -26,11 +27,16 @@ static CliContext* sCurrentContext;
struct CliContext::Event : DoublyLinkedListLinkImpl<CliContext::Event> {
Event(int type, Thread* thread = NULL, TeamMemoryBlock* block = NULL)
Event(int type, Thread* thread = NULL, TeamMemoryBlock* block = NULL,
const char* expression = NULL, status_t expressionResult = B_OK,
Value* expressionValue = NULL)
:
fType(type),
fThreadReference(thread),
fMemoryBlockReference(block)
fMemoryBlockReference(block),
fExpression(expression),
fExpressionResult(expressionResult),
fExpressionValue(expressionValue)
{
}
@ -49,10 +55,29 @@ struct CliContext::Event : DoublyLinkedListLinkImpl<CliContext::Event> {
return fMemoryBlockReference.Get();
}
const BString& GetExpression() const
{
return fExpression;
}
status_t GetExpressionResult() const
{
return fExpressionResult;
}
Value* GetExpressionValue() const
{
return fExpressionValue.Get();
}
private:
int fType;
BReference<Thread> fThreadReference;
BReference<TeamMemoryBlock> fMemoryBlockReference;
BString fExpression;
status_t fExpressionResult;
BReference<Value> fExpressionValue;
};
@ -76,7 +101,10 @@ CliContext::CliContext()
fCurrentThread(NULL),
fCurrentStackTrace(NULL),
fCurrentStackFrameIndex(-1),
fCurrentBlock(NULL)
fCurrentBlock(NULL),
fCurrentExpression(NULL),
fExpressionResult(B_OK),
fExpressionValue(NULL)
{
sCurrentContext = this;
}
@ -249,6 +277,13 @@ CliContext::SetCurrentStackFrameIndex(int32 index)
}
void
CliContext::SetCurrentExpression(const char* expression)
{
fCurrentExpression = expression;
}
const char*
CliContext::PromptUser(const char* prompt)
{
@ -396,6 +431,19 @@ CliContext::ProcessPendingEvents()
}
fCurrentBlock = event->GetMemoryBlock();
break;
case EVENT_EXPRESSION_EVALUATED:
if (event->GetExpression() == fCurrentExpression) {
fCurrentExpression = NULL;
fExpressionResult = event->GetExpressionResult();
if (fExpressionValue != NULL) {
fExpressionValue->ReleaseReference();
fExpressionValue = NULL;
}
fExpressionValue = event->GetExpressionValue();
if (fExpressionValue != NULL)
fExpressionValue->AcquireReference();
}
break;
}
}
}
@ -444,6 +492,17 @@ CliContext::ThreadStackTraceChanged(const Team::ThreadEvent& threadEvent)
}
void
CliContext::ExpressionEvaluated(const Team::ExpressionEvaluationEvent& event)
{
_QueueEvent(
new(std::nothrow) Event(EVENT_EXPRESSION_EVALUATED,
NULL, NULL, event.GetExpression(), event.GetResult(),
event.GetValue()));
_SignalInputLoop(EVENT_EXPRESSION_EVALUATED);
}
void
CliContext::MemoryBlockRetrieved(TeamMemoryBlock* block)
{

View File

@ -1,5 +1,6 @@
/*
* Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2014, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef CLI_CONTEXT_H
@ -37,7 +38,8 @@ public:
EVENT_THREAD_STOPPED = 0x10,
EVENT_THREAD_STACK_TRACE_CHANGED = 0x20,
EVENT_VALUE_NODE_CHANGED = 0x40,
EVENT_TEAM_MEMORY_BLOCK_RETRIEVED = 0x80
EVENT_TEAM_MEMORY_BLOCK_RETRIEVED = 0x80,
EVENT_EXPRESSION_EVALUATED = 0x100
};
public:
@ -73,6 +75,13 @@ public:
TeamMemoryBlock* CurrentBlock() const { return fCurrentBlock; }
void SetCurrentExpression(const char* expression);
status_t GetExpressionResult() const
{ return fExpressionResult; }
Value* GetExpressionValue() const
{ return fExpressionValue; }
const char* PromptUser(const char* prompt);
void AddLineToInputHistory(const char* line);
@ -97,6 +106,10 @@ private:
virtual void ThreadStackTraceChanged(
const Team::ThreadEvent& event);
virtual void ExpressionEvaluated(
const Team::ExpressionEvaluationEvent&
event);
// TeamMemoryBlock::Listener
virtual void MemoryBlockRetrieved(TeamMemoryBlock* block);
@ -135,6 +148,10 @@ private:
int32 fCurrentStackFrameIndex;
TeamMemoryBlock* fCurrentBlock;
const char* fCurrentExpression;
status_t fExpressionResult;
Value* fExpressionValue;
EventList fPendingEvents;
};