From af79919aa9457b3c1e5de82c96195a8b830a68f2 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Wed, 29 Oct 2014 11:49:04 -0400 Subject: [PATCH] Debugger: Adapt CliDumpMemoryCommand to new expression interface. - CliDumpMemoryCommand now requests asynchronous expression evaluation like the other users of expressions. --- .../cli/commands/CliDumpMemoryCommand.cpp | 46 +++++++++++++++---- .../cli/commands/CliDumpMemoryCommand.h | 8 +++- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/apps/debugger/user_interface/cli/commands/CliDumpMemoryCommand.cpp b/src/apps/debugger/user_interface/cli/commands/CliDumpMemoryCommand.cpp index e18fcf2fc5..becafde7b5 100644 --- a/src/apps/debugger/user_interface/cli/commands/CliDumpMemoryCommand.cpp +++ b/src/apps/debugger/user_interface/cli/commands/CliDumpMemoryCommand.cpp @@ -16,13 +16,14 @@ #include -#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() @@ -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(); } @@ -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; } diff --git a/src/apps/debugger/user_interface/cli/commands/CliDumpMemoryCommand.h b/src/apps/debugger/user_interface/cli/commands/CliDumpMemoryCommand.h index 5c8a0fb00f..79a66ce611 100644 --- a/src/apps/debugger/user_interface/cli/commands/CliDumpMemoryCommand.h +++ b/src/apps/debugger/user_interface/cli/commands/CliDumpMemoryCommand.h @@ -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 @@ -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; };