断点存储在哪里

Che*_*ian 4 visual-studio-code

在 VSCode 中,断点存储在哪里?

当我重新启动 VSCode 时,这些断点仍然存在,因此 VSCode 应该有一个地方来存储它们。但它既不存储在工作区中,也不存储在.vscode.

我需要知道它们存储在哪里,以便我可以方便有效地备份/恢复/添加/修改/删除多个断点。

Sco*_*eak 6

断点存储在哪里?

在 Windows 上,断点存储在:

%APPDATA%/Code/User/workspaceStorage/(long_hash)/state.vscdb
Run Code Online (Sandbox Code Playgroud)

在 Linux 上,它们位于(根据 Matt 的评论):

$HOME/.config/Code/User/workspaceStorage/(long_hash)/state.vscdb
Run Code Online (Sandbox Code Playgroud)

为了定位(long_hash),我添加了一个断点并查找最近修改过的文件。如果您有Cygwin bash,那么在添加或删除断点后就可以使用这样的命令:

  $ cd $APPDATA/Code
  $ find . -mmin -1
Run Code Online (Sandbox Code Playgroud)

state.vscdb文件是一个SQLite数据库。我可以使用strings(另一个 Cygwin 命令)从中提取一些数据:

  $ strings state.vscdb | grep 'debug.breakpoint'
  debug.breakpoint
  debug.breakpoint
  debug.breakpoint[{"enabled":true,"uri":{"$mid":1,"fsPath":"d:\\wrk\\learn\\vscode\\cpphello\\helloworld.cpp","_sep":1,"external":"file:///d%3A/wrk/learn/vscode/cpphello/helloworld.cpp","path":"/D:/wrk/learn/vscode/cpphello/helloworld.cpp","scheme":"file"},"lineNumber":12},{"enabled":true,"uri":{"$mid":1,"fsPath":"d:\\wrk\\learn\\vscode\\cpphello\\helloworld.cpp","_sep":1,"external":"file:///d%3A/wrk/learn/vscode/cpphello/helloworld.cpp","path":"/D:/wrk/learn/vscode/cpphello/helloworld.cpp","scheme":"file"},"lineNumber":13}]g
  debug.breakpoint[{"enabled":true,"uri":{"$mid":1,"fsPath":"d:\\wrk\\learn\\vscode\\cpphello\\helloworld.cpp","_sep":1,"external":"file:///d%3A/wrk/learn/vscode/cpphello/helloworld.cpp","path":"/D:/wrk/learn/vscode/cpphello/helloworld.cpp","scheme":"file"},"lineNumber":12}]
Run Code Online (Sandbox Code Playgroud)

以上是helloworld.cpp第 12 行的单个断点。

访问这个文件是个好主意吗?

可能不是!

如果您的目标是通过修改此文件自己查询或操作断点,我会警告说这可能会损坏 VSCode 的内部存储(即使使用适当的 SQLite 客户端)。

我建议改为使用 VSCode 扩展 API debug.breakpointsdebug.addBreakpoints并从 VSCode 中查询和修改它们。

  • @陈天 不客气!如果此答案或任何答案解决了您的问题,请考虑通过单击复选标记来[接受](https://meta.stackexchange.com/q/5234/179419)。这向更广泛的社区表明您已经找到了解决方案,并为回答者和您自己提供了一些声誉。没有义务这样做。 (2认同)