2014-01-06 80 views
0

我正在編寫腳本來檢查覈心轉儲。目標是使用while循環執行gdb命令進行分析。在gdb腳本中使用while循環

#!/usr/local/bin/bash 

# 
# A script to extract core-file informations 
# 

#Binary image 
binimg=$1 

# Today and yesterdays cores 
core=$2 

gdblogfile=$3 

loop = 3 

gdb -batch \ 
    -ex "set logging file $gdblogfile" \ 
    -ex "set logging on" \ 
    -ex "set pagination off" \ 
    -ex "file $binimg" \ 
    -ex "core-file $core" \ 
    -ex "bt" \ 
    -ex "frame 8" \ 
    -ex "while $loop > 0 { print this->_tag; set $loop = $loop - 1; end }" 
    -ex "quit" 

此腳本不while循環後執行。它停在while循環中,期待命令行gdb命令。我不確定爲什麼它不會繼續並打印標籤的值並繼續循環。你能讓我知道我做錯了什麼嗎?

回答

1

大括號在gdb中不起作用。不知道你爲什麼這麼想,但無論你從哪裏得到的是錯誤的 - 你應該讓他們知道。

如果要繼續此路徑,請將這些命令放入一個文件中,並使用「gdb -x」而不是「-ex」。但是,在Python中執行腳本編程可能會有更好的體驗。