首页 > 解决方案 > 将字符和不可打印的值作为参数传递到 LLDB

问题描述

使用 lldb,如何将包含十六进制字符的长字符串作为命令行参数传递?一些十六进制字符可能是不可打印的。

(lldb) setting set target.run-args "AAAA\\x66\\x6f\\x6f"

(lldb) settings show target.run-args
target.run-args (array of strings) =
  [0]: "AAAA\x66\x6f\x6f"

// when I want it to read: "AAAAfoo"

在 gdb 中我可以使用echo -n -e 'AAAA\x66\x6f\x6f'.

标签: debugginggdblldb

解决方案


我找到了答案。如果发送到的目标参数lldb是:

string 1:  "AAAABBBBCCCCDDDDEEEEFFFF" appended with 0x00000e30
string 2:  "GGGGYYYYZZZZ"

使用printf而不是echo以下工作:

B=$(printf "AAAABBBBCCCCDDDDEEEEFFFF\x30\x0e\x00\x00")
lldb my_c_program $B "GGGGYYYYZZZZ"

这是有趣的一点。

(lldb) settings show target.run-args
target.run-args (array of strings) =
  [0]: "AAAABBBBCCCCDDDDEEEEFFFF0"
  [1]: "GGGGYYYYZZZZ"

由于您有不可打印的字符,很容易认为 lldb 没有收到这些字符。事实并非如此。如果您lldb) run甚至正确传递了不可打印的字符。


推荐阅读