Skip to content

Commit

Permalink
Debugger: Add expression support to CliContext.
Browse files Browse the repository at this point in the history
- Extend CliContext::Event to be able to store expression
  event results.
- Extend CliContext to watch for team expression events and
  handle them accordingly.
  • Loading branch information
anevilyak committed Oct 29, 2014
1 parent 53aae3d commit 3825875
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 5 deletions.
67 changes: 63 additions & 4 deletions src/apps/debugger/user_interface/cli/CliContext.cpp
@@ -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.
*/
Expand All @@ -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
Expand All @@ -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)
{
}

Expand All @@ -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;
};


Expand All @@ -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;
}
Expand Down Expand Up @@ -249,6 +277,13 @@ CliContext::SetCurrentStackFrameIndex(int32 index)
}


void
CliContext::SetCurrentExpression(const char* expression)
{
fCurrentExpression = expression;
}


const char*
CliContext::PromptUser(const char* prompt)
{
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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)
{
Expand Down
19 changes: 18 additions & 1 deletion src/apps/debugger/user_interface/cli/CliContext.h
@@ -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
Expand Down Expand Up @@ -37,7 +38,8 @@ class CliContext : private Team::Listener,
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:
Expand Down Expand Up @@ -73,6 +75,13 @@ class CliContext : private Team::Listener,

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);

Expand All @@ -97,6 +106,10 @@ class CliContext : private Team::Listener,
virtual void ThreadStackTraceChanged(
const Team::ThreadEvent& event);

virtual void ExpressionEvaluated(
const Team::ExpressionEvaluationEvent&
event);

// TeamMemoryBlock::Listener
virtual void MemoryBlockRetrieved(TeamMemoryBlock* block);

Expand Down Expand Up @@ -135,6 +148,10 @@ class CliContext : private Team::Listener,
int32 fCurrentStackFrameIndex;
TeamMemoryBlock* fCurrentBlock;

const char* fCurrentExpression;
status_t fExpressionResult;
Value* fExpressionValue;

EventList fPendingEvents;
};

Expand Down

0 comments on commit 3825875

Please sign in to comment.