gdb脚本

100个gdb小技巧

https://wizardforcel.gitbooks.io/100-gdb-tips/index.html

 

循环

set $seq=0

while ($seq < 32)

set $seq++

end

 

  • 宏定义

define dump_history

    set var $slab_id = $arg0

    set var $object = $arg1

    set var $history_info = ((slab_context_t*)($slab_id + 64))->history_info

    set var $begin_idx = (uint64_t)((history_info_t *)($history_info))->history_idx[0]

    set var $history_bucket_num = ((history_info_t *)($history_info))->history_bucket_num

    set var $end_idx = 0

    set var $entry_addr = 0

   

    if $begin_idx > $history_bucket_num

        set $end_idx = $begin_idx - $history_bucket_num

    end

   

    set var $cur_idx = $begin_idx

   

    printf "begin_idx:%u, end_idx:%u\n", $begin_idx, $end_idx

 

    while $cur_idx != $end_idx

        set $entry_addr = (uint64_t)(&((history_info_t *)($history_info))->history_entrys[0][($cur_idx - 1) % 102400])

        if ($object == *(uint64_t*)($entry_addr + 8))

            set var $function_name = *(uint64_t*)($entry_addr)

            set var $alloc_time = *(uint32_t*)($entry_addr + 16)

            set var $module_id = *(uint16_t*)($entry_addr + 20)

            set var $opt_type = *(uint8_t*)($entry_addr + 22)

            printf "idx:%u, addr:%p, function:%s, time:%u, mid:%u, type:%u\n", $cur_idx, *(uint64_t*)($entry_addr+8), $function_name, $alloc_time, $module_id, $opt_type

        end

 

        set $cur_idx = $cur_idx - 1

       

        if (($cur_idx) % 10000) == 0

            printf "cur_idx: %u\n", $cur_idx

        end

    end

end

 

  • 宏使用

dump_history 0x7f290816f000[arg0] 0x7f2787182dd0[arg1]

你可能感兴趣的:(GDB,Linux)