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 | |
| 55 | 1. On the debug tab, on the drop-down next to the play button, select “Add |
| 56 | Config” |
| 57 | 2. Add the following to the configurations array in “launch”: |
| 58 | |
| 59 | ``` |
| 60 | { |
| 61 | "name":"Python: Local", |
| 62 | "type":"python", |
| 63 | "request":"attach", |
| 64 | "processId":"${command:pickProcess}" |
| 65 | } |
| 66 | ``` |
| 67 | |
| 68 | 3. Add the following to your program: |
| 69 | |
| 70 | ``` |
| 71 | import debugpy |
| 72 | |
| 73 | # Your code here! |
| 74 | |
| 75 | print("Wait for attach...") |
| 76 | debugpy.wait_for_attach() |
| 77 | debugpy.brerakpoint() |
| 78 | ``` |
| 79 | |
| 80 | 4. Start your program. |
| 81 | 5. Start the debugger. A dialog box will pop up asking you to select your |
| 82 | running program. |