=begin
= MachineInstructionsTraceWithGDB

== new gdb function trace_machine_instructions

Usage:
$ gdb -x .gdbinit ... # run gdb with .gdbinit
(gdb) b foo # set breakpoint to function `foo'
(gdb) run # execute debuggee program
... # and stop at break point
(gdb) trace_machine_instructions
... # continue program and show each instructions
... # all output will be saved on 'gdb.txt'

Example:
$ gdb -x ../clean-trunk/.gdbinit --args ./miniruby ../clean-trunk/benchmark/bm_app_fib.rb
GNU gdb (GDB) 7.0.1-debian
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/...
Reading symbols from /home/ko1/build/ruby/clean-build/miniruby...done.
(gdb)
(gdb) b vm_exec
Breakpoint 1 at 0x81c4c00: file ../clean-trunk/vm.c, line 1116.
(gdb) run
Starting program: /home/ko1/build/ruby/clean-build/miniruby ../clean-trunk/benchmark/bm_app_fib.rb
[Thread debugging using libthread_db enabled]
[New Thread 0xb7c80b70 (LWP 7878)]

Breakpoint 1, vm_exec (th=0x8264b88) at ../clean-trunk/vm.c:1116
1116 {
(gdb) continue
Continuing.

Breakpoint 1, vm_exec (th=0x8264b88) at ../clean-trunk/vm.c:1116
1116 {
(gdb) (gdb) trace_machine_instructions
Line 1116 of "../clean-trunk/vm.c" starts at address 0x81c4c00 and ends at 0x81c4c01 .
1122 TH_PUSH_TAG(th);
1: x/i $pc
0x81c4c01 : mov %eax,%edx
Line 1122 of "../clean-trunk/vm.c" starts at address 0x81c4c01 and ends at 0x81c4c03 .
1116 {
1: x/i $pc
0x81c4c03 : mov %esp,%ebp
Line 1116 of "../clean-trunk/vm.c" starts at address 0x81c4c03 and ends at 0x81c4c19 .
0x081c4c05 1116 {
1: x/i $pc
0x81c4c05 : push %edi
Line 1116 of "../clean-trunk/vm.c" starts at address 0x81c4c03 and ends at 0x81c4c19 .
0x081c4c06 1116 {
1: x/i $pc
0x81c4c06 : push %esi
Line 1116 of "../clean-trunk/vm.c" starts at address 0x81c4c03 and ends at 0x81c4c19 .
0x081c4c07 1116 {
1: x/i $pc
0x81c4c07 : push %ebx
Line 1116 of "../clean-trunk/vm.c" starts at address 0x81c4c03 and ends at 0x81c4c19 .
0x081c4c08 1116 {
1: x/i $pc
0x81c4c08 : sub $0x15c,%esp
Line 1116 of "../clean-trunk/vm.c" starts at address 0x81c4c03 and ends at 0x81c4c19 .
0x081c4c0e 1116 {
...
(gdb) quit

You can see all outputs in `gdb.txt'.

== pretty log

The attached script gdb-logparse.rb ' make slim log fromgdb.txt'

Example output:
vm_exec+1 mov %eax,%edx ../clean-trunk/vm.c:1122
vm_exec+3 mov %esp,%ebp ../clean-trunk/vm.c:1116
vm_exec+5 push %edi ../clean-trunk/vm.c:1116
vm_exec+6 push %esi ../clean-trunk/vm.c:1116
vm_exec+7 push %ebx ../clean-trunk/vm.c:1116
vm_exec+8 sub $0x15c,%esp ../clean-trunk/vm.c:1116
vm_exec+14 call 0x805c3c0 <_i686.get_pc_thunk.bx> ../clean-trunk/vm.c:1116
_i686.get_pc_thunk.bx mov (%esp),%ebx

__i686.get
pc_thunk.bx+3 ret

vm
exec+19 add $0x8dd1d,%ebx ../clean-trunk/vm.c:1116
vm_exec+25 mov %eax,-0xcc(%ebp) ../clean-trunk/vm.c:1116
...

=end

gdb-logparse.rb Magnifier (1.3 KB) Koichi Sasada, 06/07/2012 03:27 PM