Run code whenever a breakpoint is hit in VSCode/Python

Viewed 250

Is it possible to execute some code whenever a breakpoint is hit in VS Code (PyDev)?

(specifically, I'd like to print some state whenever I hit a break point, rather than have to type that command manually all the time)

2 Answers

In the debug bar is a Watch View. Here you can define expressions that are evaluated when the debugger returns control to the user (breakpoint or step).

From your comments I learned that you can enter expressions with side effects like print statements. This is similar to log statements only that they print the stuff when the debugger stops.

You can't run code if I see this correctly.

But you can enter a Log Message that will print when the breakpoint is hit. Just right-click on the breakpoint, "Edit Breakpoint" and then choose "Log Message" as the type.

Related