2014-01-06 147 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中执行脚本编程可能会有更好的体验。