如何打印正在用LLDB调试的C/ c++函数的内存地址和参数值
How to print the memory address and the value of the arguments of a C/C++ function that is being debugged with LLDB?
我正在准备我的操作系统测试。我们使用的工具之一是调试器(LLDB),我的目标是检查C函数或c++方法的参数。
例如:我怎样才能看到内存地址和参数的值传递给_SMenuItemCommandID??-我尝试过不同的事情,但在尝试中死亡。
HITestBox`_SMenuItemCommandID(MenuData*, unsigned short, unsigned long):
0x9a7bfc35: pushl %ebp
0x9a7bfc36: movl %esp, %ebp
0x9a7bfc38: pushl %esi
0x9a7bfc39: subl $52, %esp
0x9a7bfc3c: movl 8(%ebp), %esi
0x9a7bfc3f: movl 88(%esi), %eax
0x9a7bfc42: movl %eax, -16(%ebp)
0x9a7bfc45: movzwl 12(%ebp), %ecx
0x9a7bfc49: movw %cx, -12(%ebp)
0x9a7bfc4d: movl $0, -8(%ebp)
0x9a7bfc54: leal -8(%ebp), %edx
0x9a7bfc57: movl %edx, 28(%esp)
0x9a7bfc5b: movl %ecx, 4(%esp)
0x9a7bfc5f: movl %eax, (%esp)
0x9a7bfc62: movl $0, 24(%esp)
0x9a7bfc6a: movl $4, 20(%esp)
0x9a7bfc72: movl $0, 16(%esp)
0x9a7bfc7a: movl $1835232612, 12(%esp)
0x9a7bfc82: movl $12, 8(%esp)
0x9a7bfc8a: calll 0x9a5f7c9b ; elementGetDataAtIndex
0x9a7bfc8f: movl 16(%ebp), %eax
0x9a7bfc92: cmpl %eax, -8(%ebp)
0x9a7bfc95: je 0x9a7bfcae ; _SMenuItemCommandID(MenuData*, unsigned short, unsigned long) + 121
0x9a7bfc97: movl %eax, 4(%esp)
0x9a7bfc9b: leal -16(%ebp), %eax
0x9a7bfc9e: movl %eax, (%esp)
0x9a7bfca1: calll 0x9a7e2914 ; mID::SetCommandID(unsigned long)
0x9a7bfca6: movl %esi, (%esp)
0x9a7bfca9: calll 0x9a5f7c65 ; invalidate(MenuData*)
0x9a7bfcae: xorl %eax, %eax
0x9a7bfcb0: addl $52, %esp
0x9a7bfcb3: popl %esi
0x9a7bfcb4: popl %ebp
0x9a7bfcb5: ret
编辑:假设我正在调试一个没有源代码的应用程序,但我导出了符号。例如,在某个时刻执行以下代码:
MenuData *myData = (MenuData *)0x28ff44;;
SMenuItemCommandID(myData, 3, 4);
我需要做什么(与LLDB)来获得:
arg0 = 0x28ff44
arg1 =3
arg2 =4
您发布的反汇编是x86。参数在堆栈上。如果在函数prolog之前中断,则参数相对于堆栈指针%esp
(在lldb
中作为$esp
访问):
# The return address:
x/w $esp
# The first argument:
x/w $esp+4
# The second argument:
x/w $esp+8
如果您在序言之后中断(在您的示例中是0x9a7bfc3c
),这是通常放置符号断点的地方,则相对于帧指针(%ebp
又称$ebp
)找到参数:
# The saved frame pointer of the previous frame:
x/w $ebp
# The return address:
x/w $ebp+4
# The first argument:
x/w $ebp+8
# The second argument:
x/w $ebp+12
对于其他体系结构,实参将以不同的方式存储,通常存储在寄存器中。同样,上面的代码假设使用"cdecl"调用约定。还有其他的。您是否被告知您应该熟悉哪些架构和调用约定?
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 为什么使用 "this" 指针调用派生成员函数?
- 将对象数组的引用传递给函数
- 函数调用中参数的顺序重要吗
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用不带参数的函数访问结构元素
- 代码在main()中运行,但在函数中出现错误
- 内置函数可查看CPP中的成员变量
- 如何获取std::result_of函数的返回类型
- 如何在c++中为模板函数实例创建快捷方式
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗