From 3e3aea48e21e35069ec893c4b5d49de494f8329c Mon Sep 17 00:00:00 2001 From: Markus Metzger Date: Mon, 11 Mar 2013 08:25:58 +0000 Subject: [PATCH] Install the btrace target ops for i386-linux-nat and amd64-linux-nat. gdb/ * amd64-linux-nat.c: Include btrace.h and linux-btrace.h. (amd64_linux_enable_btrace): New. (amd64_linux_disable_btrace): New. (amd64_linux_teardown_btrace): New. (_initialize_amd64_linux_nat): Initialize btrace ops. * i386-linux.nat.c: Include btrace.h and linux-btrace.h. (i386_linux_enable_btrace): New. (i386_linux_disable_btrace): New. (i386_linux_teardown_btrace): New. (_initialize_i386_linux_nat): Initialize btrace ops. * config/i386/linux.mh: Add linux-btrace.o. * config/i386/linux64.mh: Add linux-btrace.o. --- gdb/ChangeLog | 15 +++++++++++ gdb/amd64-linux-nat.c | 51 ++++++++++++++++++++++++++++++++++++++ gdb/config/i386/linux.mh | 3 ++- gdb/config/i386/linux64.mh | 2 +- gdb/i386-linux-nat.c | 51 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 58727970a4f..7156011e8ca 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,18 @@ +2013-03-11 Markus Metzger + + * amd64-linux-nat.c: Include btrace.h and linux-btrace.h. + (amd64_linux_enable_btrace): New. + (amd64_linux_disable_btrace): New. + (amd64_linux_teardown_btrace): New. + (_initialize_amd64_linux_nat): Initialize btrace ops. + * i386-linux.nat.c: Include btrace.h and linux-btrace.h. + (i386_linux_enable_btrace): New. + (i386_linux_disable_btrace): New. + (i386_linux_teardown_btrace): New. + (_initialize_i386_linux_nat): Initialize btrace ops. + * config/i386/linux.mh: Add linux-btrace.o. + * config/i386/linux64.mh: Add linux-btrace.o. + 2013-03-11 Markus Metzger * common/linux_btrace.h: New file. diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c index 3d1983b6d15..8dfe7c5a0e1 100644 --- a/gdb/amd64-linux-nat.c +++ b/gdb/amd64-linux-nat.c @@ -25,6 +25,8 @@ #include "regset.h" #include "linux-nat.h" #include "amd64-linux-tdep.h" +#include "linux-btrace.h" +#include "btrace.h" #include "gdb_assert.h" #include "gdb_string.h" @@ -1119,6 +1121,48 @@ amd64_linux_read_description (struct target_ops *ops) } } +/* Enable branch tracing. */ + +static struct btrace_target_info * +amd64_linux_enable_btrace (ptid_t ptid) +{ + struct btrace_target_info *tinfo; + struct gdbarch *gdbarch; + + errno = 0; + tinfo = linux_enable_btrace (ptid); + + if (tinfo == NULL) + error (_("Could not enable branch tracing for %s: %s."), + target_pid_to_str (ptid), safe_strerror (errno)); + + /* Fill in the size of a pointer in bits. */ + gdbarch = target_thread_architecture (ptid); + tinfo->ptr_bits = gdbarch_ptr_bit (gdbarch); + + return tinfo; +} + +/* Disable branch tracing. */ + +static void +amd64_linux_disable_btrace (struct btrace_target_info *tinfo) +{ + int errcode = linux_disable_btrace (tinfo); + + if (errcode != 0) + error (_("Could not disable branch tracing: %s."), safe_strerror (errcode)); +} + +/* Teardown branch tracing. */ + +static void +amd64_linux_teardown_btrace (struct btrace_target_info *tinfo) +{ + /* Ignore errors. */ + linux_disable_btrace (tinfo); +} + /* Provide a prototype to silence -Wmissing-prototypes. */ void _initialize_amd64_linux_nat (void); @@ -1157,6 +1201,13 @@ _initialize_amd64_linux_nat (void) t->to_read_description = amd64_linux_read_description; + /* Add btrace methods. */ + t->to_supports_btrace = linux_supports_btrace; + t->to_enable_btrace = amd64_linux_enable_btrace; + t->to_disable_btrace = amd64_linux_disable_btrace; + t->to_teardown_btrace = amd64_linux_teardown_btrace; + t->to_read_btrace = linux_read_btrace; + /* Register the target. */ linux_nat_add_target (t); linux_nat_set_new_thread (t, amd64_linux_new_thread); diff --git a/gdb/config/i386/linux.mh b/gdb/config/i386/linux.mh index 8316d870eac..7c64e836325 100644 --- a/gdb/config/i386/linux.mh +++ b/gdb/config/i386/linux.mh @@ -4,7 +4,8 @@ NAT_FILE= config/nm-linux.h NATDEPFILES= inf-ptrace.o fork-child.o \ i386-nat.o i386-linux-nat.o \ proc-service.o linux-thread-db.o \ - linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o + linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \ + linux-btrace.o NAT_CDEPS = $(srcdir)/proc-service.list # The dynamically loaded libthread_db needs access to symbols in the diff --git a/gdb/config/i386/linux64.mh b/gdb/config/i386/linux64.mh index d2b95fd605c..8d782c1a335 100644 --- a/gdb/config/i386/linux64.mh +++ b/gdb/config/i386/linux64.mh @@ -3,7 +3,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \ i386-nat.o amd64-nat.o amd64-linux-nat.o \ linux-nat.o linux-osdata.o \ proc-service.o linux-thread-db.o linux-fork.o \ - linux-procfs.o linux-ptrace.o + linux-procfs.o linux-ptrace.o linux-btrace.o NAT_FILE= config/nm-linux.h NAT_CDEPS = $(srcdir)/proc-service.list diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c index 11b510dc493..be2b6c9f9c9 100644 --- a/gdb/i386-linux-nat.c +++ b/gdb/i386-linux-nat.c @@ -25,6 +25,8 @@ #include "regset.h" #include "target.h" #include "linux-nat.h" +#include "linux-btrace.h" +#include "btrace.h" #include "gdb_assert.h" #include "gdb_string.h" @@ -1046,6 +1048,48 @@ i386_linux_read_description (struct target_ops *ops) return tdesc_i386_linux; } +/* Enable branch tracing. */ + +static struct btrace_target_info * +i386_linux_enable_btrace (ptid_t ptid) +{ + struct btrace_target_info *tinfo; + struct gdbarch *gdbarch; + + errno = 0; + tinfo = linux_enable_btrace (ptid); + + if (tinfo == NULL) + error (_("Could not enable branch tracing for %s: %s."), + target_pid_to_str (ptid), safe_strerror (errno)); + + /* Fill in the size of a pointer in bits. */ + gdbarch = target_thread_architecture (ptid); + tinfo->ptr_bits = gdbarch_ptr_bit (gdbarch); + + return tinfo; +} + +/* Disable branch tracing. */ + +static void +i386_linux_disable_btrace (struct btrace_target_info *tinfo) +{ + int errcode = linux_disable_btrace (tinfo); + + if (errcode != 0) + error (_("Could not disable branch tracing: %s."), safe_strerror (errcode)); +} + +/* Teardown branch tracing. */ + +static void +i386_linux_teardown_btrace (struct btrace_target_info *tinfo) +{ + /* Ignore errors. */ + linux_disable_btrace (tinfo); +} + /* -Wmissing-prototypes */ extern initialize_file_ftype _initialize_i386_linux_nat; @@ -1079,6 +1123,13 @@ _initialize_i386_linux_nat (void) t->to_read_description = i386_linux_read_description; + /* Add btrace methods. */ + t->to_supports_btrace = linux_supports_btrace; + t->to_enable_btrace = i386_linux_enable_btrace; + t->to_disable_btrace = i386_linux_disable_btrace; + t->to_teardown_btrace = i386_linux_teardown_btrace; + t->to_read_btrace = linux_read_btrace; + /* Register the target. */ linux_nat_add_target (t); linux_nat_set_new_thread (t, i386_linux_new_thread); -- 2.30.2