简体   繁体   中英

Run code whenever a breakpoint is hit in VSCode/Python

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM