gdb 脚本

C程序:

/* 编译:$gcc -g3 -o gs this_file.c */
#include <stdio.h>

int main(void)
{
        int x = 3;

        if (x < 4)
                printf("AAAA\n");
        else
                printf("BBBB\n");

        return 0;
}


gdb脚本:

#!/bin/bash
#this file name is gdb-script.sh

if [ `md5sum ./gs | awk '{print $1}'` = "7db9e82087eb6a49a571d28b0426ae1e" ]; then
        echo "OK, file right" 
else
        echo "Bad file"
        exit 0
fi

echo $1

gdb << GDBEOF
file ./gs
b 7
run
shell echo "OKkkk $1"
set x=$1
continue
quit
GDBEOF

gdb脚本还可以是:


#!/bin/bash

if [ `md5sum ./gs | awk '{print $1}'` = "7db9e82087eb6a49a571d28b0426ae1e" ]; then
        echo "OK, file right" 
else
        echo "Bad file"
        exit 0
fi

echo $1

gdb << GDBEOF
file ./gs
define setx
        shell echo "OKkkk $1"
        set x=$1
end

b 7
run
setx
continue
quit
GDBEOF



运行:

$chmod +x gdb-script.sh
$./gdb-script.sh 9


你可能感兴趣的:(gdb 脚本)