【问题标题】:gdb - optimized value analysisgdb - 优化的价值分析
【发布时间】:2017-07-20 00:52:20
【问题描述】:

我的CPU是arm,如果优化出来了怎么算出函数参数值?

例如:

status_t NuPlayer::GenericSource::setDataSource(
        int fd, int64_t offset, int64_t length) {
    resetDataSource();

    mFd = dup(fd);
    mOffset = offset;
    mLength = length;

上面的函数有3个参数,当我尝试打印第二个参数偏移量时,我会得到以下结果:

Thread 4 "Binder:15082_3" hit Breakpoint 1, android::NuPlayer::GenericSource::setDataSource (this=0xae63bb40, fd=8, offset=<optimized out>, length=9384436) at frameworks/av/media/libmediaplayerservice/nuplayer/GenericSource.cpp:123
123     resetDataSource();
(gdb) x/i $pc
=> 0xb02aaa80 <android::NuPlayer::GenericSource::setDataSource(int, long long, long long)+12>:  blx 0xb0282454 <_ZN7android8NuPlayer13GenericSource15resetDataSourceEv@plt>
(gdb) n
125     mFd = dup(fd);
(gdb) print offset
$1 = <optimized out>
(gdb) p $eax

$2 = void
(gdb) disassemble /m
Dump of assembler code for function android::NuPlayer::GenericSource::setDataSource(int, long long, long long):
122         int fd, int64_t offset, int64_t length) {
   0xb02aaa74 <+0>: push    {r4, r5, r6, r7, lr}
   0xb02aaa76 <+2>: sub sp, #4
   0xb02aaa78 <+4>: mov r4, r3
   0xb02aaa7a <+6>: mov r5, r2
   0xb02aaa7c <+8>: mov r6, r1
   0xb02aaa7e <+10>:    mov r7, r0

123     resetDataSource();
=> 0xb02aaa80 <+12>:    blx 0xb0282454 <_ZN7android8NuPlayer13GenericSource15resetDataSourceEv@plt>

124 
125     mFd = dup(fd);
   0xb02aaa84 <+16>:    mov r0, r6
   0xb02aaa86 <+18>:    blx 0xb027e5d8 <dup@plt>
   0xb02aaa8a <+22>:    ldrd    r2, r1, [sp, #24]
   0xb02aaa8e <+26>:    str.w   r0, [r7, #224]  ; 0xe0
   0xb02aaa92 <+30>:    movs    r0, #0

126     mOffset = offset;
   0xb02aaa94 <+32>:    strd    r5, r4, [r7, #232]  ; 0xe8

127     mLength = length;
   0xb02aaa98 <+36>:    strd    r2, r1, [r7, #240]  ; 0xf0

128 
129     // delay data source creation to prepareAsync() to avoid blocking
130     // the calling thread in setDataSource for any significant time.
131     return OK;
   0xb02aaa9c <+40>:    add sp, #4
   0xb02aaa9e <+42>:    pop {r4, r5, r6, r7, pc}

End of assembler dump.
(gdb) 

我猜它在某个寄存器中,但 $eax 的结果是无效的。

【问题讨论】:

    标签: gdb


    【解决方案1】:

    我猜它在某个寄存器中,但 $eax 的结果是无效的。

    ARM 上没有名为eax 的寄存器。

    要知道参数在哪个寄存器,需要知道calling convention

    看起来您使用的是 32 位 ARM。从上面的链接:

    r0 to r3: used to hold argument values passed to a subroutine
    

    所以你应该做info registers,验证r0 == 0xae63bb40r1 == 8并在r2中找到offset

    【讨论】:

    • 一个问题,offset是int64_t而r2是32bit,r2怎么存储一个64bit的变量?
    【解决方案2】:

    听起来示例代码已经将参数变量分配给局部变量,因此打印该值将与优化后的参数完全相同。

    mOffset = offset;
    mLength = length;
    

    【讨论】:

      猜你喜欢
      • 2017-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-02
      相关资源
      最近更新 更多