-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Machine Instructions Trace with GDB
Jemma Issroff edited this page May 30, 2023
·
1 revision
$ 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'
$ 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 <vm_exec> and ends at 0x81c4c01 <vm_exec+1>.
1122 TH_PUSH_TAG(th);
1: x/i $pc
0x81c4c01 <vm_exec+1>: mov %eax,%edx
Line 1122 of "../clean-trunk/vm.c" starts at address 0x81c4c01 <vm_exec+1> and ends at 0x81c4c03 <vm_exec+3>.
1116 {
1: x/i $pc
0x81c4c03 <vm_exec+3>: mov %esp,%ebp
Line 1116 of "../clean-trunk/vm.c" starts at address 0x81c4c03 <vm_exec+3> and ends at 0x81c4c19 <vm_exec+25>.
0x081c4c05 1116 {
1: x/i $pc
0x81c4c05 <vm_exec+5>: push %edi
Line 1116 of "../clean-trunk/vm.c" starts at address 0x81c4c03 <vm_exec+3> and ends at 0x81c4c19 <vm_exec+25>.
0x081c4c06 1116 {
1: x/i $pc
0x81c4c06 <vm_exec+6>: push %esi
Line 1116 of "../clean-trunk/vm.c" starts at address 0x81c4c03 <vm_exec+3> and ends at 0x81c4c19 <vm_exec+25>.
0x081c4c07 1116 {
1: x/i $pc
0x81c4c07 <vm_exec+7>: push %ebx
Line 1116 of "../clean-trunk/vm.c" starts at address 0x81c4c03 <vm_exec+3> and ends at 0x81c4c19 <vm_exec+25>.
0x081c4c08 1116 {
1: x/i $pc
0x81c4c08 <vm_exec+8>: sub $0x15c,%esp
Line 1116 of "../clean-trunk/vm.c" starts at address 0x81c4c03 <vm_exec+3> and ends at 0x81c4c19 <vm_exec+25>.
0x081c4c0e 1116 {
...
(gdb) quit
You can see all outputs in `gdb.txt'.
The attached script gdb-logparse.rb ' make slim log from
gdb.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
...
- Developer How To, Developer How To JA
- How To Contribute
- How To Report, How To Report JA
- How To Request Backport
- How To Request Features
- Developers Meeting