Ryan Heise | 9a71143 | 2020-10-14 23:55:39 | [diff] [blame] | 1 | # Debugging Chromium Python With The VSCode Debugger |
| 2 | |
| 3 | ## Before You Begin |
| 4 | |
| 5 | 1. Patch in [this CL](https://chromium-review.googlesource.com/c/chromium/src/+/2466896). |
| 6 | 2. Run gclient sync. |
| 7 | |
| 8 | ## Via SSH |
| 9 | |
| 10 | SSH is useful if you’re modifying and debugging code on another device, such as |
| 11 | the desktop sitting at your office desk. To do so: |
| 12 | |
| 13 | 1. Set up VSCode to work with normal development by following the instructions |
| 14 | in the Remote Visual Studio Code section |
| 15 | [here](https://docs.google.com/document/d/1ZlG8VQxudxvDs-EtpQvaPVcAPfSMdYlXr42s_487wLo/edit#bookmark=id.j10hyv6nlkws). |
| 16 | 2. Open the Connection Dialog of Chrome’s SSH plugin:  |
| 18 | 3. Create a new connection and set the username, hostname, port, and SSH relay |
| 19 | server options as you normally would. Then, set SSH arguments to "-2 -L |
| 20 | 50371:localhost:50371" |
| 21 | |
| 22 | a. You can replace 50371 with a different value, so long as it's consistent |
| 23 | with step 7b. |
| 24 | |
| 25 | 4. Open a connection, and set this window aside. |
| 26 | 5. In VSCode, open the code you want to set a breakpoint in, and add the |
| 27 | following: |
| 28 | |
| 29 | ``` |
| 30 | import debugpy |
| 31 | |
| 32 | # Your code here! |
| 33 | debugpy.listen(50371) |
| 34 | print("Wait for attach...") |
| 35 | debugpy.wait_for_attach() |
| 36 | debugpy.brerakpoint() |
| 37 | ``` |
| 38 | |
| 39 | Note: The port passed to debugpy.listen() should match the port configured in (3). |
| 40 | |
| 41 | 6. Click on the Debug tab |
| 42 | 7. Click Run. A dialog will appear asking you to set up a debug configuration. |
| 43 | Do so, and select “Remote Debug”. |
| 44 | |
| 45 | a. Leave the hostname as-is |
| 46 | |
| 47 | b. Set the port to 50371 |
| 48 | |
| 49 | 8. Run your program on the remote machine. It should stop executing at “Wait for |
| 50 | attach”. |
| 51 | 9. Start the debugger in VSCode. It should attach! |
| 52 | |
| 53 | ## Locally |
| 54 | |
Ryan Heise | 7e36b15 | 2020-10-16 16:55:33 | [diff] [blame] | 55 | Follow the same steps as above, but start from step 5. |