简体   繁体   English

每当在 VSCode/Python 中遇到断点时运行代码

[英]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)?每当在 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) (具体来说,我想在遇到断点时打印一些 state,而不是一直手动输入该命令)

In the debug bar is a Watch View.在调试栏中是一个Watch视图。 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.从您的评论中,我了解到您可以输入带有副作用的表达式,例如print语句。 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.只需右键单击断点,“编辑断点”,然后选择“日志消息”作为类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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