Skip to content

Commit

Permalink
More adjustments to CliContext.
Browse files Browse the repository at this point in the history
- CliContext now listens for value node container events so that
  commands can request such a wait as well
- Implement an event wait mechanism for commands to make use of.
  Adjust CliStackTrace and CliPrintVariable accordingly.
  • Loading branch information
anevilyak committed Dec 18, 2012
1 parent 486c4d3 commit 03289a3
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 15 deletions.
49 changes: 49 additions & 0 deletions src/apps/debugger/user_interface/cli/CliContext.cpp
Expand Up @@ -118,6 +118,7 @@ CliContext::Init(Team* team, UserInterfaceListener* listener)
fNodeManager = new(std::nothrow) ValueNodeManager();
if (fNodeManager == NULL)
return B_NO_MEMORY;
fNodeManager->AddListener(this);

return B_OK;
}
Expand Down Expand Up @@ -316,6 +317,25 @@ CliContext::WaitForThreadOrUser()
}


void
CliContext::WaitForEvents(int32 eventMask)
{
for (;;) {
_PrepareToWaitForEvents(eventMask | EVENT_USER_INTERRUPT);
uint32 events = fEventsOccurred;
if ((events & eventMask) == 0) {
events = _WaitForEvents();
}

if ((events & EVENT_QUIT) != 0 || (events & eventMask) != 0) {
_SignalInputLoop(eventMask);
ProcessPendingEvents();
return;
}
}
}


void
CliContext::ProcessPendingEvents()
{
Expand Down Expand Up @@ -404,6 +424,35 @@ CliContext::ThreadStackTraceChanged(const Team::ThreadEvent& threadEvent)
}


void
CliContext::ValueNodeChanged(ValueNodeChild* nodeChild, ValueNode* oldNode,
ValueNode* newNode)
{
_SignalInputLoop(EVENT_VALUE_NODE_CHANGED);
}


void
CliContext::ValueNodeChildrenCreated(ValueNode* node)
{
_SignalInputLoop(EVENT_VALUE_NODE_CHANGED);
}


void
CliContext::ValueNodeChildrenDeleted(ValueNode* node)
{
_SignalInputLoop(EVENT_VALUE_NODE_CHANGED);
}


void
CliContext::ValueNodeValueChanged(ValueNode* oldNode)
{
_SignalInputLoop(EVENT_VALUE_NODE_CHANGED);
}


void
CliContext::_QueueEvent(Event* event)
{
Expand Down
15 changes: 13 additions & 2 deletions src/apps/debugger/user_interface/cli/CliContext.h
Expand Up @@ -13,6 +13,7 @@
#include <Locker.h>

#include "Team.h"
#include "ValueNodeContainer.h"


class StackFrame;
Expand All @@ -22,15 +23,17 @@ class UserInterfaceListener;
class ValueNodeManager;


class CliContext : private Team::Listener {
class CliContext : private Team::Listener,
private ValueNodeContainer::Listener {
public:
enum {
EVENT_QUIT = 0x01,
EVENT_USER_INTERRUPT = 0x02,
EVENT_THREAD_ADDED = 0x04,
EVENT_THREAD_REMOVED = 0x08,
EVENT_THREAD_STOPPED = 0x10,
EVENT_THREAD_STACK_TRACE_CHANGED = 0x20
EVENT_THREAD_STACK_TRACE_CHANGED = 0x20,
EVENT_VALUE_NODE_CHANGED = 0x40
};

public:
Expand Down Expand Up @@ -70,6 +73,7 @@ class CliContext : private Team::Listener {
void QuitSession(bool killTeam);

void WaitForThreadOrUser();
void WaitForEvents(int32 eventMask);
void ProcessPendingEvents();

private:
Expand All @@ -87,6 +91,13 @@ class CliContext : private Team::Listener {
virtual void ThreadStackTraceChanged(
const Team::ThreadEvent& event);

// ValueNodeContainer::Listener
virtual void ValueNodeChanged(ValueNodeChild* nodeChild,
ValueNode* oldNode, ValueNode* newNode);
virtual void ValueNodeChildrenCreated(ValueNode* node);
virtual void ValueNodeChildrenDeleted(ValueNode* node);
virtual void ValueNodeValueChanged(ValueNode* node);

private:
void _QueueEvent(Event* event);

Expand Down
14 changes: 6 additions & 8 deletions src/apps/debugger/user_interface/cli/CliPrintVariableCommand.cpp
Expand Up @@ -116,16 +116,14 @@ CliPrintVariableCommand::_ResolveValueIfNeeded(ValueNode* node,
context.GetUserInterfaceListener()->ValueNodeValueRequested(
context.CurrentThread()->GetCpuState(), container, node);

// TODO: implement proper waiting
while (!context.IsTerminating()) {
context.ProcessPendingEvents();
if (node->LocationAndValueResolutionState()
!= VALUE_NODE_UNRESOLVED) {
break;
}

while (node->LocationAndValueResolutionState()
== VALUE_NODE_UNRESOLVED) {
containerLocker.Unlock();
snooze(20000);
context.WaitForEvents(CliContext::EVENT_VALUE_NODE_CHANGED);
containerLocker.Lock();
if (context.IsTerminating())
return B_ERROR;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/apps/debugger/user_interface/cli/CliStackTraceCommand.cpp
Expand Up @@ -45,11 +45,11 @@ CliStackTraceCommand::Execute(int argc, const char* const* argv,

// get its stack trace
StackTrace* stackTrace = thread->GetStackTrace();
if (stackTrace == NULL) {
// TODO: Wait for stack trace!
printf("Current thread doesn't have a stack trace. Waiting not "
"implemented yet\n");
return;
while (stackTrace == NULL) {
context.WaitForEvents(CliContext::EVENT_THREAD_STACK_TRACE_CHANGED);
if (context.IsTerminating())
return;
stackTrace = thread->GetStackTrace();
}
BReference<StackTrace> stackTraceReference(stackTrace);
// hold a reference until we're done
Expand Down

0 comments on commit 03289a3

Please sign in to comment.