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:54:13 -04:00
parent 53aae3db4d
commit 382587517f
2 changed files with 81 additions and 5 deletions
@@ -1,5 +1,5 @@
/* /*
* Copyright 2012, Rene Gollent, [email protected]. * Copyright 2012-2014, Rene Gollent, [email protected].
* Copyright 2012, Ingo Weinhold, [email protected]. * Copyright 2012, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -12,6 +12,7 @@
#include "StackTrace.h" #include "StackTrace.h"
#include "UserInterface.h" #include "UserInterface.h"
#include "Value.h"
#include "ValueNodeManager.h" #include "ValueNodeManager.h"
// NOTE: This is a simple work-around for EditLine not having any kind of user // 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> { 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), fType(type),
fThreadReference(thread), 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(); return fMemoryBlockReference.Get();
} }
const BString& GetExpression() const
{
return fExpression;
}
status_t GetExpressionResult() const
{
return fExpressionResult;
}
Value* GetExpressionValue() const
{
return fExpressionValue.Get();
}
private: private:
int fType; int fType;
BReference<Thread> fThreadReference; BReference<Thread> fThreadReference;
BReference<TeamMemoryBlock> fMemoryBlockReference; BReference<TeamMemoryBlock> fMemoryBlockReference;
BString fExpression;
status_t fExpressionResult;
BReference<Value> fExpressionValue;
}; };
@@ -76,7 +101,10 @@ CliContext::CliContext()
fCurrentThread(NULL), fCurrentThread(NULL),
fCurrentStackTrace(NULL), fCurrentStackTrace(NULL),
fCurrentStackFrameIndex(-1), fCurrentStackFrameIndex(-1),
fCurrentBlock(NULL) fCurrentBlock(NULL),
fCurrentExpression(NULL),
fExpressionResult(B_OK),
fExpressionValue(NULL)
{ {
sCurrentContext = this; sCurrentContext = this;
} }
@@ -249,6 +277,13 @@ CliContext::SetCurrentStackFrameIndex(int32 index)
} }
void
CliContext::SetCurrentExpression(const char* expression)
{
fCurrentExpression = expression;
}
const char* const char*
CliContext::PromptUser(const char* prompt) CliContext::PromptUser(const char* prompt)
{ {
@@ -396,6 +431,19 @@ CliContext::ProcessPendingEvents()
} }
fCurrentBlock = event->GetMemoryBlock(); fCurrentBlock = event->GetMemoryBlock();
break; 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 void
CliContext::MemoryBlockRetrieved(TeamMemoryBlock* block) CliContext::MemoryBlockRetrieved(TeamMemoryBlock* block)
{ {
@@ -1,5 +1,6 @@
/* /*
* Copyright 2012, Ingo Weinhold, [email protected]. * Copyright 2012, Ingo Weinhold, [email protected].
* Copyright 2014, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef CLI_CONTEXT_H #ifndef CLI_CONTEXT_H
@@ -37,7 +38,8 @@ public:
EVENT_THREAD_STOPPED = 0x10, EVENT_THREAD_STOPPED = 0x10,
EVENT_THREAD_STACK_TRACE_CHANGED = 0x20, EVENT_THREAD_STACK_TRACE_CHANGED = 0x20,
EVENT_VALUE_NODE_CHANGED = 0x40, EVENT_VALUE_NODE_CHANGED = 0x40,
EVENT_TEAM_MEMORY_BLOCK_RETRIEVED = 0x80 EVENT_TEAM_MEMORY_BLOCK_RETRIEVED = 0x80,
EVENT_EXPRESSION_EVALUATED = 0x100
}; };
public: public:
@@ -73,6 +75,13 @@ public:
TeamMemoryBlock* CurrentBlock() const { return fCurrentBlock; } 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); const char* PromptUser(const char* prompt);
void AddLineToInputHistory(const char* line); void AddLineToInputHistory(const char* line);
@@ -97,6 +106,10 @@ private:
virtual void ThreadStackTraceChanged( virtual void ThreadStackTraceChanged(
const Team::ThreadEvent& event); const Team::ThreadEvent& event);
virtual void ExpressionEvaluated(
const Team::ExpressionEvaluationEvent&
event);
// TeamMemoryBlock::Listener // TeamMemoryBlock::Listener
virtual void MemoryBlockRetrieved(TeamMemoryBlock* block); virtual void MemoryBlockRetrieved(TeamMemoryBlock* block);
@@ -135,6 +148,10 @@ private:
int32 fCurrentStackFrameIndex; int32 fCurrentStackFrameIndex;
TeamMemoryBlock* fCurrentBlock; TeamMemoryBlock* fCurrentBlock;
const char* fCurrentExpression;
status_t fExpressionResult;
Value* fExpressionValue;
EventList fPendingEvents; EventList fPendingEvents;
}; };