| OLD | NEW |
| (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(DEBUG_OUTPUT_NORMAL, |
| 30 "Chrome Windows Debugger Extension\n"); |
| 31 debug_control->Output(DEBUG_OUTPUT_NORMAL, |
| 32 "hwnd - Displays basic hwnd info.\n"); |
| 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 // While sizeof(HWND) can change between 32-bit and 64-bit platforms, Windows |
| 44 // only cares about the lower 32-bits. We evaluate as 64-bit as a convenience |
| 45 // and truncate the displayed hwnds to 32-bit below. |
| 46 // See https://msdn.microsoft.com/en-us/library/aa384203.aspx |
| 47 DEBUG_VALUE value; |
| 48 hr = debug_control->Evaluate(args, DEBUG_VALUE_INT64, &value, nullptr); |
| 49 if (FAILED(hr)) { |
| 50 debug_control->Output(DEBUG_OUTPUT_ERROR, "Unable to evaluate %s\n", args); |
| 51 return hr; |
| 52 } |
| 53 |
| 54 HWND hwnd = reinterpret_cast<HWND>(value.I64); |
| 55 if (!IsWindow(hwnd)) { |
| 56 debug_control->Output(DEBUG_OUTPUT_NORMAL, "Not a window: %s\n", args); |
| 57 return E_FAIL; |
| 58 } |
| 59 |
| 60 wchar_t title[kMaxWindowStringLength]; |
| 61 GetWindowText(hwnd, title, ARRAYSIZE(title)); |
| 62 debug_control->Output(DEBUG_OUTPUT_NORMAL, "Title: %ws\n", title); |
| 63 wchar_t window_class[kMaxWindowStringLength]; |
| 64 GetClassName(hwnd, window_class, ARRAYSIZE(window_class)); |
| 65 debug_control->Output(DEBUG_OUTPUT_NORMAL, "Class: %ws\n", window_class); |
| 66 debug_control->Output(DEBUG_OUTPUT_NORMAL, "Hierarchy: \n"); |
| 67 debug_control->Output(DEBUG_OUTPUT_NORMAL, " Owner: %08x Parent: %08x\n", |
| 68 GetWindow(hwnd, GW_OWNER), GetParent(hwnd)); |
| 69 debug_control->Output(DEBUG_OUTPUT_NORMAL, " Prev: %08x Next: %08x\n", |
| 70 GetNextWindow(hwnd, GW_HWNDPREV), |
| 71 GetNextWindow(hwnd, GW_HWNDNEXT)); |
| 72 debug_control->Output(DEBUG_OUTPUT_NORMAL, "Styles: %08x (Ex: %08x)\n", |
| 73 GetWindowLong(hwnd, GWL_STYLE), |
| 74 GetWindowLong(hwnd, GWL_EXSTYLE)); |
| 75 RECT window_rect; |
| 76 if (GetWindowRect(hwnd, &window_rect)) { |
| 77 debug_control->Output(DEBUG_OUTPUT_NORMAL, "Bounds: (%d, %d) %dx%d\n", |
| 78 window_rect.left, window_rect.top, |
| 79 window_rect.right - window_rect.left, |
| 80 window_rect.bottom - window_rect.top); |
| 81 } else { |
| 82 DWORD last_error = GetLastError(); |
| 83 debug_control->Output(DEBUG_OUTPUT_NORMAL, |
| 84 "Bounds: Unavailable (Last Error = %d)\n", |
| 85 last_error); |
| 86 } |
| 87 return S_OK; |
| 88 } |
| OLD | NEW |