Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: tools/win/chromeexts/chromeexts.cc

Issue 2612193002: Chrome Windows Debugger Extension Skeleton (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <windows.h>
6 #include <dbgeng.h>
7 #include <wrl/client.h>
8
9 namespace {
10 using Microsoft::WRL::ComPtr;
11 constexpr size_t kMaxWindowStringLength = 256;
12 } // namespace
13
14 HRESULT CALLBACK DebugExtensionInitialize(ULONG* version, ULONG* flags) {
15 *version = DEBUG_EXTENSION_VERSION(0, 1);
16 *flags = 0;
17 return S_OK;
18 }
19
20 void CALLBACK DebugExtensionUninitialize() {}
21
22 HRESULT CALLBACK help(IDebugClient* client, PCSTR args) {
23 ComPtr<IDebugControl> debug_control;
24 HRESULT hr = client->QueryInterface(IID_PPV_ARGS(&debug_control));
25 if (FAILED(hr)) {
26 return hr;
27 }
28
29 debug_control->Output(
30 DEBUG_OUTPUT_NORMAL, "Chrome Windows Debugger Extension\n");
31 debug_control->Output(
32 DEBUG_OUTPUT_NORMAL, "hwnd - Displays basic hwnd info.\n");
scottmg 2017/01/05 15:53:46 nit; The number of spaces between hwnd and - seems
robliao 2017/01/06 02:31:06 This was a loose convention in !help for other ext
33 return S_OK;
34 }
35
36 HRESULT CALLBACK hwnd(IDebugClient* client, PCSTR args) {
37 ComPtr<IDebugControl> debug_control;
38 HRESULT hr = client->QueryInterface(IID_PPV_ARGS(&debug_control));
39 if (FAILED(hr)) {
40 return hr;
41 }
42
43 DEBUG_VALUE value;
44 hr = debug_control->Evaluate(args, DEBUG_VALUE_INT64, &value, nullptr);
scottmg 2017/01/05 15:53:46 I assume this will work on x86?
scottmg 2017/01/05 15:53:46 Is it necessary to call SetExpressionSyntax(DEBUG_
robliao 2017/01/06 02:31:06 Yep, this works on x86 and x64. Since the upper-bi
45 if (FAILED(hr)) {
46 debug_control->Output(
47 DEBUG_OUTPUT_ERROR,"Unavailable to evaluate %s\n", args);
scottmg 2017/01/05 15:53:46 nit; "Unavailable" sounds weird, how about "Unable
scottmg 2017/01/05 15:53:46 Missing space before opening ". (Run the whole th
robliao 2017/01/06 02:31:06 Done and done.
48 return hr;
49 }
50
51 // While sizeof(HWND) can change between 32-bit and 64-bit platforms, Windows
52 // only cares about the lower 32-bits. We evaluate as 64-bit as a convenience
53 // and truncate the displayed hwnds to 32-bit below.
54 // See https://msdn.microsoft.com/en-us/library/aa384203.aspx
55 HWND hwnd = reinterpret_cast<HWND>(value.I64);
56 if (!IsWindow(hwnd)) {
57 debug_control->Output(DEBUG_OUTPUT_NORMAL, "Not a window: %s\n", args);
58 return E_FAIL;
59 }
60
61 wchar_t title[kMaxWindowStringLength];
62 GetWindowText(hwnd, title, ARRAYSIZE(title));
63 debug_control->Output(
64 DEBUG_OUTPUT_NORMAL, "Title: %ws\n", title);
65 wchar_t window_class[kMaxWindowStringLength];
66 GetClassName(hwnd, window_class, ARRAYSIZE(window_class));
67 debug_control->Output(
68 DEBUG_OUTPUT_NORMAL, "Class: %ws\n", window_class);
69 debug_control->Output(DEBUG_OUTPUT_NORMAL, "Hierarchy: \n");
70 debug_control->Output(
71 DEBUG_OUTPUT_NORMAL, " Owner: %08x Parent: %08x\n",
72 GetWindow(hwnd, GW_OWNER), GetParent(hwnd));
73 debug_control->Output(
74 DEBUG_OUTPUT_NORMAL, " Prev: %08x Next: %08x\n",
75 GetNextWindow(hwnd, GW_HWNDPREV), GetNextWindow(hwnd, GW_HWNDNEXT));
76 debug_control->Output(
77 DEBUG_OUTPUT_NORMAL, "Styles: %08x (Ex: %08x)\n",
78 GetWindowLong(hwnd, GWL_STYLE), GetWindowLong(hwnd, GWL_EXSTYLE));
79 RECT window_rect;
80 if (GetWindowRect(hwnd, &window_rect)) {
81 debug_control->Output(
82 DEBUG_OUTPUT_NORMAL, "Bounds: (%d, %d) %dx%d\n",
83 window_rect.left, window_rect.top,
84 window_rect.right - window_rect.left,
85 window_rect.bottom - window_rect.top);
86 } else {
87 DWORD last_error = GetLastError();
88 debug_control->Output(
89 DEBUG_OUTPUT_NORMAL, "Bounds: Unavailable (Last Error = %d)\n",
90 last_error);
91 }
92 return S_OK;
93 }
94
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698