[PATCH 0/3] Use target_read_code in skip_prologue

Yao Qi
2013-11-29T14:27:04Z

GDB is able to cache memory accesses requested in target_read_code,
so target_read_code is more efficient than general target_read_memory.
This patch series use target_read_code and its variant in the
skip_prologue related code, and it improves the performance when doing
'b foo' (foo is a function) in remote debugging.

Nowadays, when we set a breakpoint on function f1, GDB will fetch the
code in f1 to determine the start of the function body (say skip the
prologue), it requests read from target many times on x86, see below,

(gdb) b f1
Sending packet: $m80483c4,1#68...Packet received: 55
Sending packet: $m80483c4,1#68...Packet received: 55
Sending packet: $m80483c4,1#68...Packet received: 55
Sending packet: $m80483c4,1#68...Packet received: 55
Sending packet: $m80483c4,e#9c...Packet received: 5589e5b8000000005dc35589e583
Sending packet: $m80483c4,1#68...Packet received: 55
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c6,5#6e...Packet received: e5b8000000
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c6,5#6e...Packet received: e5b8000000
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c6,1#6a...Packet received: e5
Sending packet: $m80483c7,1#6b...Packet received: b8
Sending packet: $m80483c7,1#6b...Packet received: b8
Sending packet: $m80483c7,1#6b...Packet received: b8
Sending packet: $m80483c4,1#68...Packet received: 55
Sending packet: $m80483c4,1#68...Packet received: 55
Sending packet: $m80483c4,1#68...Packet received: 55
Sending packet: $m80483c4,1#68...Packet received: 55
Sending packet: $m80483c4,1#68...Packet received: 55
Sending packet: $m80483c4,e#9c...Packet received: 5589e5b8000000005dc35589e583
Sending packet: $m80483c4,1#68...Packet received: 55
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c6,5#6e...Packet received: e5b8000000
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c6,5#6e...Packet received: e5b8000000
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c5,1#69...Packet received: 89
Sending packet: $m80483c6,1#6a...Packet received: e5
Sending packet: $m80483c7,1#6b...Packet received: b8
Sending packet: $m80483c7,1#6b...Packet received: b8
Sending packet: $m80483c7,1#6b...Packet received: b8
Sending packet: $m80483c4,1#68...Packet received: 55
Sending packet: $m80483c7,1#6b...Packet received: b8

these address are identical or close to, so caching
should be useful here. With this patch applied, the
number of RSP 'm' packets are reduced,

(gdb) b f1
Sending packet: $m80483c0,40#97...Packet received: ffd0c9c35589e5b8000000005dc35589e583ec188b450c8945f88b45108945fc8b45148945f08b45188945f48b45f80345088945ecdb45ecdc45f0d97dea0fb7
Sending packet: $m80483c7,1#6b...Packet received: b8

Note that once we use target_read_code in breakpoint.c, the last 'm'
will disappear too.

The changes are quite specific to each port, because skip_prologue is
port specific.

Patch #3 adds a perf test case. We run it on x86-linux and get the
result below.

Base Patched
skip-prologue cpu_time 1 1.77 0.08
skip-prologue cpu_time 2 2.66 0.09
skip-prologue cpu_time 3 2.09 0.1
skip-prologue wall_time 1 3.79094099998 0.138980865479
skip-prologue wall_time 2 5.69234204292 0.132542133331
skip-prologue wall_time 3 4.39887309074 0.157964944839
skip-prologue vmsize 1 16336 16336
skip-prologue vmsize 2 16336 16336
skip-prologue vmsize 3 16336 16336

*** BLURB HERE ***

Yao Qi (3):
Use target_read_code in skip_prologue (i386)
skip_prolgoue (amd64)
Perf test case: skip-prologue

gdb/amd64-tdep.c | 10 ++--
gdb/corefile.c | 32 +++++++++++++
gdb/gdbcore.h | 17 +++++++
gdb/i386-tdep.c | 71 +++++++++++++++---------------
gdb/testsuite/gdb.perf/skip-prologue.c | 48 ++++++++++++++++++++
gdb/testsuite/gdb.perf/skip-prologue.exp | 59 +++++++++++++++++++++++++
gdb/testsuite/gdb.perf/skip-prologue.py | 39 ++++++++++++++++
7 files changed, 236 insertions(+), 40 deletions(-)
create mode 100644 gdb/testsuite/gdb.perf/skip-prologue.c
create mode 100644 gdb/testsuite/gdb.perf/skip-prologue.exp
create mode 100644 gdb/testsuite/gdb.perf/skip-prologue.py

--
1.7.7.6