Commit 202d44ec authored by Robert Liao's avatar Robert Liao Committed by Chromium LUCI CQ

Add base::CommandLine Support to chromeexts

BUG=1168231

Change-Id: I7d0249efadf3da294414932f9511e18d1752994e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2638550
Auto-Submit: Robert Liao <robliao@chromium.org>
Reviewed-by: default avatarWei Li <weili@chromium.org>
Commit-Queue: Robert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845286}
parent 28f9b681
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
#include "tools/win/chromeexts/chrome_exts_command.h" #include "tools/win/chromeexts/chrome_exts_command.h"
#include <string>
#include "base/check.h" #include "base/check.h"
#include "base/strings/utf_string_conversions.h"
namespace tools { namespace tools {
namespace win { namespace win {
...@@ -18,12 +21,18 @@ HRESULT ChromeExtsCommand::Initialize(IDebugClient* debug_client, ...@@ -18,12 +21,18 @@ HRESULT ChromeExtsCommand::Initialize(IDebugClient* debug_client,
const char* args) { const char* args) {
DCHECK(debug_client); DCHECK(debug_client);
DCHECK(args); DCHECK(args);
args_ = args;
debug_client_ = debug_client; debug_client_ = debug_client;
debug_control_ = GetDebugClientAs<IDebugControl>(); debug_control_ = GetDebugClientAs<IDebugControl>();
if (!debug_control_) { if (!debug_control_) {
return E_FAIL; return E_FAIL;
} }
// base::CommandLine assumes the first token to be the command itself. The
// windbg args do not include this and must be included manually.
command_line_.ParseFromString(std::wstring(L"cmd ") +
base::ASCIIToWide(args));
return S_OK; return S_OK;
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "base/command_line.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
...@@ -57,7 +58,7 @@ class ChromeExtsCommand { ...@@ -57,7 +58,7 @@ class ChromeExtsCommand {
HRESULT PrintErrorf(const char* format, ...); HRESULT PrintErrorf(const char* format, ...);
HRESULT PrintErrorV(const char* format, va_list ap); HRESULT PrintErrorV(const char* format, va_list ap);
const std::string& args() const { return args_; } const base::CommandLine& command_line() const { return command_line_; }
// Returns the Debug Client as T, null ComPtr<T> otherwise. // Returns the Debug Client as T, null ComPtr<T> otherwise.
template <typename T> template <typename T>
...@@ -68,7 +69,7 @@ class ChromeExtsCommand { ...@@ -68,7 +69,7 @@ class ChromeExtsCommand {
} }
private: private:
std::string args_; base::CommandLine command_line_{base::CommandLine::NO_PROGRAM};
ComPtr<IDebugClient> debug_client_; ComPtr<IDebugClient> debug_client_;
ComPtr<IDebugControl> debug_control_; ComPtr<IDebugControl> debug_control_;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <dbgeng.h> #include <dbgeng.h>
#include <windows.h> #include <windows.h>
#include "base/strings/utf_string_conversions.h"
namespace tools { namespace tools {
namespace win { namespace win {
namespace chromeexts { namespace chromeexts {
...@@ -20,21 +22,30 @@ HwndCommand::HwndCommand() = default; ...@@ -20,21 +22,30 @@ HwndCommand::HwndCommand() = default;
HwndCommand::~HwndCommand() = default; HwndCommand::~HwndCommand() = default;
HRESULT HwndCommand::Execute() { HRESULT HwndCommand::Execute() {
auto remaining_arguments = command_line().GetArgs();
if (remaining_arguments.size() != 1) {
Printf("Only expected 1 argument. Got %d instead.\n",
remaining_arguments.size());
return E_FAIL;
}
std::string hwnd_expression = base::WideToASCII(remaining_arguments[0]);
// While sizeof(HWND) can change between 32-bit and 64-bit platforms, Windows // While sizeof(HWND) can change between 32-bit and 64-bit platforms, Windows
// only cares about the lower 32-bits. We evaluate as 64-bit as a convenience // only cares about the lower 32-bits. We evaluate as 64-bit as a convenience
// and truncate the displayed hwnds to 32-bit below. // and truncate the displayed hwnds to 32-bit below.
// See https://msdn.microsoft.com/en-us/library/aa384203.aspx // See https://msdn.microsoft.com/en-us/library/aa384203.aspx
DEBUG_VALUE value; DEBUG_VALUE value;
HRESULT hr = GetDebugClientAs<IDebugControl>()->Evaluate( HRESULT hr = GetDebugClientAs<IDebugControl>()->Evaluate(
args().c_str(), DEBUG_VALUE_INT64, &value, nullptr); hwnd_expression.c_str(), DEBUG_VALUE_INT64, &value, nullptr);
if (FAILED(hr)) { if (FAILED(hr)) {
PrintErrorf("Unable to evaluate %s\n", args().c_str()); PrintErrorf("Unable to evaluate %s\n", hwnd_expression.c_str());
return hr; return hr;
} }
HWND hwnd = reinterpret_cast<HWND>(value.I64); HWND hwnd = reinterpret_cast<HWND>(value.I64);
if (!IsWindow(hwnd)) { if (!IsWindow(hwnd)) {
PrintErrorf("Not a window: %s\n", args().c_str()); PrintErrorf("Not a window: %s\n", hwnd_expression.c_str());
return E_FAIL; return E_FAIL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment