[英]Dart how to drop a breakpoint or debugger
In Python, I can insert a breakpoint()
keyword on any line of code, and when I run the script from the command-line, it will stop when it reaches that line, and I'll have an opportunity to interact with or access any previously-defined variables.在 Python 中,我可以在任何代码行插入
breakpoint()
关键字,当我从命令行运行脚本时,它会在到达该行时停止,我将有机会与之交互或访问任何先前定义的变量。 I was looking for a way to do this in the Dart language but so far without success.我正在寻找一种用 Dart 语言执行此操作的方法,但到目前为止还没有成功。
I've seen references to the debugger
keyword provided by the dart:developer
library, but instead of allowing me to interact, the script just hangs:我已经看到了
dart:developer
库提供的debugger
关键字的引用,但该脚本并未允许我进行交互,而是挂起:
// bin/my_script.dart
import "dart:developer"; // source of debugger();
main() {
var x = 5;
print("X: ${x}"); //> X: 5
debugger(); // ... just hangs
print("END");
}
I've also seen references to the console
package, but I'm not seeing it do anything:我还看到了对
console
包的引用,但我没有看到它做任何事情:
// bin/my_script.dart
import "package:console/console.dart"; // source of Console.init()
main() {
var x = 5;
print("X: ${x}"); //> X: 5
Console.init(); // ... nothing happens
print("END");
}
FYI: I'm running this script via dart bin/my_script.dart
, and a command-line solution would be ideal, but a solution using the VS Code text editor would also be sufficient.仅供参考:我通过
dart bin/my_script.dart
运行此脚本,命令行解决方案是理想的,但使用 VS Code 文本编辑器的解决方案也足够了。
You can't debug without a debugger attached, that's why running from the command line will hang in the breakpoint, since you can step on the next instruction.没有附加调试器就无法调试,这就是为什么从命令行运行将挂在断点上的原因,因为您可以执行下一条指令。
If you use VS Code or Intellij and use the debugger()
while in debug mode Shift + Cmd + R , it will trigger a breakpoint there and you can analyze your variables and step forward to the next instructions.如果您使用 VS Code 或 Intellij 并在调试模式下使用
debugger()
Shift + Cmd + R ,它将在那里触发断点,您可以分析变量并前进到下一个指令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.