2017-02-28 37 views
1

我的CPU是arm的。如果函數參數的值被優化了,怎麼才能知道函數的參數值?gdb - 優化值分析

例如:

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 <[email protected]> 
(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 <[email protected]> 

124 
125  mFd = dup(fd); 
    0xb02aaa84 <+16>: mov r0, r6 
    0xb02aaa86 <+18>: blx 0xb027e5d8 <[email protected]> 
    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的結果是無效的。

回答

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並找到r2offset

+0

一個問題,偏移量是int64_t,但r2是32bit,r2如何存儲一個64位變量? – beetlej

1

聽起來像示例代碼已經將參數變量分配給本地變量,所以打印該值將與優化後的參數完全相同。

mOffset = offset; 
mLength = length;