如何查看堆栈中的字符串值?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何查看堆栈中的字符串值?相关的知识,希望对你有一定的参考价值。

我有以下汇编代码。

我可以在“ lea”之后看到“%rax”寄存器中的字符串值-(A)

(gdb) p (char*)0x558efff0a010
$1 = 0x558efff0a010 "abc"

但是在“移动”之后我看不到堆栈中的值-(B)

(gdb) p (char*)0x7fff2754b2a8
$2 = 0x7fff2754b2a8 "\020\240\360\377\216U"

我想念什么吗?

汇编代码

.data
.L0:
    .string "abc"
    .text
    .global f
f:
    push %rbp
    mov %rsp, %rbp
    sub $8, %rsp
    lea .L0(%rip), %rax -- (A)
    mov %rax, -8(%rbp) -- (B)
    leave
    ret

main:

rax            0x558effd095fa   94072665576954
rbp            0x7fff2754b2c0   0x7fff2754b2c0
rsp            0x7fff2754b2c0   0x7fff2754b2c0

--------------|--------------
ADDRESS       |VALUE
--------------|--------------
0x7fff2754b2c0|                        <= rbp, rsp
--------------|--------------

f()

rax            0x0  0
rbp            0x7fff2754b2c0   0x7fff2754b2c0
rsp            0x7fff2754b2b8   0x7fff2754b2b8

--------------|--------------
ADDRESS       |VALUE
--------------|--------------
0x7fff2754b2c0|                        <= rbp
--------------|--------------
0x7fff2754b2b8|                       <= rsp
--------------|--------------

push%rbp

rax            0x0  0
rbp            0x7fff2754b2c0   0x7fff2754b2c0
rsp            0x7fff2754b2b0   0x7fff2754b2b0

--------------|--------------
ADDRESS       |VALUE
--------------|--------------
0x7fff2754b2c0|                       <= rbp
--------------|--------------
0x7fff2754b2b8|                      
--------------|--------------
0x7fff2754b2b0|                       <= rsp
--------------|--------------

mov%rsp,%rbp

rax            0x0  0
rbp            0x7fff2754b2b0   0x7fff2754b2b0
rsp            0x7fff2754b2b0   0x7fff2754b2b0

--------------|--------------
ADDRESS       |VALUE
--------------|--------------
0x7fff2754b2c0|                       
--------------|--------------
0x7fff2754b2b8|                      
--------------|--------------
0x7fff2754b2b0|                      <= rbp, rsp
--------------|--------------

[sub $ 8,%rsp

rax            0x0  0
rbp            0x7fff2754b2b0   0x7fff2754b2b0
rsp            0x7fff2754b2a8   0x7fff2754b2a8

--------------|--------------
ADDRESS       |VALUE
--------------|--------------
0x7fff2754b2c0|                       
--------------|--------------
0x7fff2754b2b8|                      
--------------|--------------
0x7fff2754b2b0|                      <= rbp
--------------|--------------
0x7fff2754b2a8|                      <= rsp
--------------|--------------

lea .L0(%rip),%rax

rax            0x558efff0a010   94072667676688
rbp            0x7fff2754b2b0   0x7fff2754b2b0
rsp            0x7fff2754b2a8   0x7fff2754b2a8

--------------|--------------
ADDRESS       |VALUE
--------------|--------------
0x7fff2754b2c0|                       
--------------|--------------
0x7fff2754b2b8|                      
--------------|--------------
0x7fff2754b2b0|                      <= rbp
--------------|--------------
0x7fff2754b2a8|                      <= rsp
--------------|--------------

(gdb) p (char*)0x558efff0a010
$1 = 0x558efff0a010 "abc"

mov%rax,-8(%rbp)

rax            0x558efff0a010   94072667676688
rbp            0x7fff2754b2b0   0x7fff2754b2b0
rsp            0x7fff2754b2a8   0x7fff2754b2a8

--------------|--------------
ADDRESS       |VALUE
--------------|--------------
0x7fff2754b2c0|                       
--------------|--------------
0x7fff2754b2b8|                      
--------------|--------------
0x7fff2754b2b0|                      <= rbp
--------------|--------------
0x7fff2754b2a8|                      <= rsp
--------------|--------------

(gdb) p (char*)0x7fff2754b2a8
$2 = 0x7fff2754b2a8 "\020\240\360\377\216U"
答案

字符串数据仍然仅位于绝对地址0x558efff0a010

以上是关于如何查看堆栈中的字符串值?的主要内容,如果未能解决你的问题,请参考以下文章

如何查看DLL中的函数信息

如何使用导航组件切换到不同后堆栈中的其他片段?

如何知道何时调用了`navController.popBackStack()`?

如何从该片段中的 onItemSelectedListener 中获取微调器单击的项目?

切换片段时如何维护子视图的状态?

添加到后台堆栈时如何保持片段状态?