CodeLLDB和VSCode -如何打印数组

r8uurelv  于 2022-12-02  发布在  Vscode
关注(0)|答案(1)|浏览(266)

使用CodeLLDB扩展,我成功地在VSCode中调试了带有lldb的C项目。
问题是我无法在VSCode监 windows 口中使用lldb命令。
例如,我尝试使用parray <COUNT> <EXPRESSION>打印数组中的前10项。
这是我得到的:

是否有一种使用lldb操作数据的方法?
作为参考,您可以使用GDB在VSCode中执行*myarr@10

k5ifujac

k5ifujac1#

parray is an lldb command line command. It looks like the watch window expects an expression, not lldb commands. lldb's expression parser, unlike gdb's, is just the underlying language parser (e.g. it uses a copy of clang for C++). That makes it a more faithful evaluator of the expressions you hand it, but limits what debugger centric syntax we can introduce (like the gdb @10 ). So you could watch the elements one by one, but there isn't C syntax for "elements 0-9 of an array" so the expression parser doesn't support that either.
Presumably, VSCode has a "debugger console" for debugger commands. That's where you would enter the parray command. lldb also has stop hooks , so if you wanted to see this array's values in the console each time you stopped, you could do:

(lldb) target stop-hook add -o "parray 10 passport.data"

stop hooks can be set to trigger only for certain functions, so you could limit this printing to the function where passport is defined, as well.

相关问题