Skip to content

Commit

Permalink
Debugger: Adapt CliDumpMemoryCommand to new expression interface.
Browse files Browse the repository at this point in the history
- CliDumpMemoryCommand now requests asynchronous expression evaluation
  like the other users of expressions.
  • Loading branch information
anevilyak committed Oct 29, 2014
1 parent 3825875 commit af79919
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
Expand Up @@ -16,13 +16,14 @@

#include <AutoLocker.h>

#include "CLanguageExpressionEvaluator.h"
#include "CliContext.h"
#include "CppLanguage.h"
#include "Number.h"
#include "Team.h"
#include "TeamMemoryBlock.h"
#include "UiUtils.h"
#include "UserInterface.h"
#include "Value.h"


CliDumpMemoryCommand::CliDumpMemoryCommand()
Expand All @@ -31,6 +32,14 @@ CliDumpMemoryCommand::CliDumpMemoryCommand()
"%s [\"]address|expression[\"] [num]\n"
"Reads and displays the contents of memory at the target address.")
{
fLanguage = new(std::nothrow) CppLanguage();
}


CliDumpMemoryCommand::~CliDumpMemoryCommand()
{
if (fLanguage != NULL)
fLanguage->ReleaseReference();
}


Expand All @@ -43,13 +52,34 @@ CliDumpMemoryCommand::Execute(int argc, const char* const* argv,
return;
}

CLanguageExpressionEvaluator evaluator;
target_addr_t address;
try {
Number value = evaluator.Evaluate(argv[1], B_UINT64_TYPE);
address = value.GetValue().ToUInt64();
} catch(...) {
printf("Error parsing address/expression.\n");
if (fLanguage == NULL) {
printf("Unable to evaluate expression: %s\n", strerror(B_NO_MEMORY));
return;
}

target_addr_t address = 0;
context.SetCurrentExpression(argv[1]);
context.GetUserInterfaceListener()->ExpressionEvaluationRequested(
fLanguage, argv[1], B_UINT64_TYPE);
context.WaitForEvents(CliContext::EVENT_EXPRESSION_EVALUATED);
if (context.IsTerminating())
return;

BString errorMessage;
Value* value = context.GetExpressionValue();
if (value != NULL) {
BVariant variantValue;
value->ToVariant(variantValue);
if (variantValue.Type() == B_UINT64_TYPE)
address = variantValue.ToUInt64();
else
value->ToString(errorMessage);
} else
errorMessage = strerror(context.GetExpressionResult());

if (!errorMessage.IsEmpty()) {
printf("Unable to evaluate expression: %s\n",
errorMessage.String());
return;
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012, Rene Gollent, rene@gollent.com.
* Copyright 2012-2014, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef CLI_DUMP_MEMORY_COMMAND_H
Expand All @@ -9,13 +9,19 @@
#include "CliCommand.h"


class SourceLanguage;


class CliDumpMemoryCommand : public CliCommand {
public:
CliDumpMemoryCommand();
virtual ~CliDumpMemoryCommand();

virtual void Execute(int argc, const char* const* argv,
CliContext& context);

private:
SourceLanguage* fLanguage;
};


Expand Down

0 comments on commit af79919

Please sign in to comment.