简体   繁体   English

LLDB获取argv的内存地址

[英]LLDB get memory address of argv

I'm reading through Jon Erickson's Hacking and on page 61 there's an example using gdb to explore the array of pointers-to-string stored in argv . 我正在阅读乔恩·埃里克森(Jon Erickson)的《 黑客技术》 ,在第61页上,有一个示例使用gdb探索存储在argv的字符串指针数组。 It looks like when you break at main in gdb, the value of argc and address of argv are part of the log statement. 它看起来就像当你在突破main在gdb,价值argc和地址argv是日志语句的一部分。 Eg, 例如,

Breakpoint 1, main(argc=2, argv=0xbffff894) at convert2.c:14

I'm trying to do the same thing with lldb, and while I can use settings show target.run-args to get the args, what I really want is the address of argv . 我正在尝试使用lldb做同样的事情,虽然我可以使用settings show target.run-args来获取args,但我真正想要的是argv的地址。 Is this possible? 这可能吗?

For ARM and x86_64, it is quite easy: stop at main, and do: 对于ARM和x86_64,这很容易:在main处停下来,然后执行:

(lldb) memory read -t "char *" -c `(int) $arg1` $arg2

"memory read -t" is functionally the same as the gdb print's "@" syntax. “内存读取-t”在功能上与gdb打印的“ @”语法相同。 Just says "read the memory pointed to by the address passed to the command as an array of the type given by the -t argument" 只是说“读取传递给命令的地址所指向的内存为-t参数给定类型的数组”

lldb defines "convenience variables" $arg1, $arg2, etc, which are aliases for the registers that are used to pass the first, second, etc arguments to a function. lldb定义了“便利变量” $ arg1,$ arg2等,它们是用于将第一个,第二个等参数传递给函数的寄存器的别名。 You have to be right at the beginning of the function for these to have the correct value, since these are just registers and they will get reused. 您必须在函数的开头正确使它们具有正确的值,因为它们只是寄存器,它们将被重用。 32-bit Intel doesn't use registers for argument passing, so you'll have to get them from the stack. 32位Intel不使用寄存器进行参数传递,因此您必须从堆栈中获取它们。

This command uses $arg2, which will hold the argv variable as the memory address to read. 该命令使用$ arg2,它将argv变量保存为要读取的内存地址。

The other interesting thing about this command is it is using lldb's backtick - which means evaluate this argument as an expression - to read the count from the first (argc) argument. 关于此命令的另一个有趣的事情是它使用lldb的反引号-意味着将此参数作为表达式进行求值-从第一个(argc)参数中读取计数。

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

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