Debugger: Add asynchronous expression evaluation interface.

- Add UserInterfaceListener hook to request expression evaluation.
- Add corresponding events/handlers in Team and TeamDebugger.

These allow callers to request evaluation of expressions by the
debugger core's worker threads with asynchronous notifications of
results. While not strictly necessary right now, this paves the way
for further changes to come, as handling of variables will
potentially require resolving their values if they haven't been
already, and this shouldn't be done from user interface threads.
This commit is contained in:
Rene Gollent
2014-10-28 23:30:01 -04:00
parent feab8604c9
commit 2d5794a1a3
8 changed files with 166 additions and 4 deletions
@@ -40,6 +40,7 @@
#include "MessageCodes.h"
#include "SettingsManager.h"
#include "SourceCode.h"
#include "SourceLanguage.h"
#include "SpecificImageDebugInfo.h"
#include "SpecificImageDebugInfoLoadingState.h"
#include "StackFrame.h"
@@ -701,6 +702,40 @@ TeamDebugger::MessageReceived(BMessage* message)
break;
}
case MSG_EVALUATE_EXPRESSION:
{
SourceLanguage* language;
if (message->FindPointer("language",
reinterpret_cast<void**>(&language)) != B_OK) {
break;
}
// ExpressionEvaluationRequested() acquires a reference
// on our behalf.
BReference<SourceLanguage> reference(language, true);
const char* expression;
if (message->FindString("expression", &expression) != B_OK)
break;
type_code resultType;
if (message->FindInt32("type",
reinterpret_cast<int32*>(&resultType)) != B_OK) {
break;
}
StackFrame* frame;
if (message->FindPointer("frame",
reinterpret_cast<void**>(&frame)) != B_OK) {
// the stack frame isn't needed, unless variable
// evaluation is desired.
frame = NULL;
}
_HandleEvaluateExpression(language, expression, resultType, frame);
break;
}
case MSG_GENERATE_DEBUG_REPORT:
{
fReportGenerator->PostMessage(message);
@@ -1050,6 +1085,23 @@ TeamDebugger::InspectRequested(target_addr_t address,
}
void
TeamDebugger::ExpressionEvaluationRequested(SourceLanguage* language,
const char* expression, type_code resultType, StackFrame* frame)
{
BMessage message(MSG_EVALUATE_EXPRESSION);
message.AddPointer("language", language);
message.AddString("expression", expression);
message.AddInt32("type", resultType);
if (frame != NULL)
message.AddPointer("frame", frame);
BReference<SourceLanguage> reference(language);
if (PostMessage(&message) == B_OK)
reference.Detach();
}
void
TeamDebugger::DebugReportRequested(entry_ref* targetPath)
{
@@ -1928,6 +1980,20 @@ TeamDebugger::_HandleInspectAddress(target_addr_t address,
}
void
TeamDebugger::_HandleEvaluateExpression(SourceLanguage* language,
const char* expression, type_code resultType, StackFrame* frame)
{
status_t result = fWorker->ScheduleJob(
new(std::nothrow) ExpressionEvaluationJob(fTeam, language,
expression, resultType, frame));
if (result != B_OK) {
_NotifyUser("Evaluate Expression", "Failed to evaluate expression: %s",
strerror(result));
}
}
status_t
TeamDebugger::_HandleSetArguments(int argc, const char* const* argv)
{