Skip to content

Commit b5b9c67

Browse files
committed
Add debugging w/ VS and some more cleanup
1 parent b81057c commit b5b9c67

File tree

5 files changed

+105
-7
lines changed

5 files changed

+105
-7
lines changed

Sources/WebKit/WebKit.docc/Build&Debug/Build.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,24 @@ This will enable ASan build. If want to attach a debugger, you can also specify
139139
Once you don’t need to build or run ASan anymore, you can specify `--no-asan` in place of `--asan` to disable ASan.
140140
Note that this configuration is saved by creating a file called Asan in the WebKitBuild directory,
141141
so if you are trying to do a clean Asan build by deleting the build directory you need to rerun this command.
142+
143+
## Building with compile_commands.json
144+
145+
### macOS
146+
147+
```
148+
make r EXPORT_COMPILE_COMMANDS=YES
149+
generate-compile-commands WebKitBuild/Release
150+
```
151+
152+
I would recommend running this command each time you pull the latest code.
153+
If you add or remove files during development, recompile with `make r EXPORT_COMPILE_COMMANDS=YES` and rerun `generate-compile-commands WebKitBuild/Release`.
154+
155+
156+
157+
### Linux and Windows
158+
159+
```
160+
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1
161+
```
162+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Debugging With Visual Studio
2+
3+
Debugging With Visual Studio IDE
4+
5+
## Configuring Debugger
6+
7+
Copy ​WebKit.natvis to the appropriate directory, which contains custom views for WebKit fundamental types.
8+
9+
## Debugging WebKit
10+
11+
There are three ways to debugging WebKit with Visual Studio. Openning the generated WebKit.sln, openning an exe file directly, and attaching running WebKit.
12+
13+
Invoke build-webkit, and open `WebKitBuild\Release\WebKit.sln` using Visual Studio.
14+
If you get errors about not being able to find .props files, run Tools/Scripts/update-webkit, then close and relaunch Cygwin and Visual Studio.
15+
16+
Set MiniBrowser as the solution's StartUp project.
17+
Select the MiniBrowser project in the Solution Explorer, then choose `Project > Set as StartUp Project`. This will cause the project to turn bold in the Solution Explorer.
18+
19+
Launch the debugger
20+
Choose `Debug > Start Debugging`.
21+
22+
In Ninja builds, there is no solution files. In such case, open the exe file directly.
23+
24+
```
25+
devenv -debugexe .\WebKitBuild\Debug\bin64\MiniBrowser.exe
26+
```
27+
28+
## Debugging DumpRenderTree
29+
30+
Set DumpRenderTree as your startup project.
31+
Configure the arguments and environment variables for the test runner.
32+
In the DumpRenderTree project in the Solution Explorer window, right-click and select Properties....
33+
34+
In the Command Arguments section, enter the absolute paths for the tests you want to run, separated by spaces.
35+
In the Environment section, put `PATH=$(ProgramFiles)\Common Files\Apple\Apple Application Support;$(PATH)`
36+
Click OK to close the Project Properties window.
37+
38+
Launch the debugger.
39+
Right-click on the DumpRenderTree project, and choose `Debug > Start New Instance`.
40+
41+
## Miscellaneous Tips
42+
43+
Follow the ​instructions for using the Microsoft and Safari symbol servers so that Visual Studio can show you backtraces that involve closed-source components.
44+
45+
## Using Watch Window
46+
47+
You can open any of the Watch windows using the `Debug > Windows > Watch` submenu.
48+
49+
​MSDN Magazine published a very useful ​article about Watch window pseudo-variables and format specifiers. Those of particular interest to WebKit developers are mentioned explicitly below, but the whole article is worth a read.
50+
51+
Adding $err,hr to the Watch Window will show you what ::GetLastError() would return at this moment, and will show you both the numerical error value and the error string associated with it.
52+
Calling CFShow
53+
54+
When debugging code that uses CF types, you can invoke the ​CFShow function in the Immediate window (Debug > Windows > Immediate or Ctrl+Alt+I) to print a debug description of a CF object to the Output window like so:
55+
56+
```
57+
{,,CoreFoundation}CFShow((void*)0x12345678)
58+
```
59+
Note that you usually won't be able to pass a variable name as the parameter to CFShow, as the Immediate window will get confused and think you're specifying a symbol in CoreFoundation.dll rather than whatever code you're debugging. It's usually easiest just to pass the address of the object directly as above.
60+
61+
## Debugging Multiple Processes
62+
63+
You can attach a single debugger to more than one process. To do this, launch or attach to the first process, then use Tools > Attach to Process… or Ctrl+Alt+P to attach to the second process. Your breakpoints will apply to both processes.
64+
65+
There is a Visual Studio Extension to attach child processes automatically. ​Introducing the Child Process Debugging Power Tool
66+
67+
There are two ways to see which process the debugger is currently operating on, and to switch the current process: the Processes window and the Debug Location toolbar.
68+
You can open the Processes window using `Debug > Windows > Processes` or `Ctrl+Shift+Alt+P`. You can show the Debug Location toolbar using View > Toolbars > Debug Location.
69+
70+
Visual Studio will always pause all processes (i.e., you can't pause just one process). Similarly, Visual Studio will always step all processes when using the Step In/Over/Out commands.
71+
72+
## Inspecting WebKit2 API types
73+
74+
You can inspect WebKit2 API types in Visual Studio by casting them to their underlying WebKit2 implementation type. For example, say you have a WKMutableDictionaryRef that points to address 0x12345678 and want to see what it contains. You can view its contents using the following watch expression (in either the Watch Window or Quick Watch Window):
75+
76+
```
77+
{,,WebKit}(WebKit::MutableDictionary*)0x12345678
78+
```
79+
The same technique will work for other WebKit2 API types as long as you substitute the appropriate type for MutableDictionary above.

Sources/WebKit/WebKit.docc/InDepth/MemoryManagement.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ we typically use [`std::unique_ptr`](https://en.cppreference.com/w/cpp/memory/un
99
WebKit uses two primary management strategies when objects in other cases:
1010
[garbage collection](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)) and [reference counting](https://en.wikipedia.org/wiki/Reference_counting).
1111

12-
## Garbage collection in WebKit
13-
14-
FIXME: Write this.
15-
1612
## Reference counting in WebKit
1713

1814
### Overview

Sources/WebKit/WebKit.docc/Other/Todo.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Articles that need to be written.
66

77
| Topic | Description |
88
| ----- | ----------- |
9-
| Inserting or Removing DOM Nodes | FIXME: Talk about how a node insertion or removal works. |
10-
| Understanding Style and Render Tree | FIXME: Describe rendering/layers/compositing |
11-
| Security Model of Web | For starters, refer to https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy. FIXME: Write this section. |
9+
| Inserting or Removing DOM Nodes | Talk about how a node insertion or removal works. |
10+
| Understanding Style and Render Tree | Describe rendering/layers/compositing |
11+
| Security Model of Web | For starters, refer to https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy.|
12+
| Garbage collection in WebKit | Write this. |

Sources/WebKit/WebKit.docc/WebKit.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ For details on submitting your code to the project, read [Contributing Code](htt
4949

5050
- <doc:Build>
5151
- <doc:DebuggingWithXcode>
52+
- <doc:DebuggingWithVS>
5253
- <doc:Logging>
5354
- <doc:Tests>
5455

0 commit comments

Comments
 (0)