This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 09/17] btrace, linux: add linux native btrace target ops
- From: markus dot t dot metzger at intel dot com
- To: jan dot kratochvil at redhat dot com
- Cc: gdb-patches at sourceware dot org, markus dot t dot metzger at gmail dot com, Markus Metzger <markus dot t dot metzger at intel dot com>
- Date: Wed, 6 Jun 2012 14:32:27 +0200
- Subject: [PATCH 09/17] btrace, linux: add linux native btrace target ops
- References: <1338985955-28749-1-git-send-email-markus.t.metzger@intel.com>
From: Markus Metzger <markus.t.metzger@intel.com>
Implement btrace target ops for linux native based on the common linux btrace
support.
We use a separate file for this to allow sharing between multiple targets
(i.e. i386 and x86_64) and to avoid having to guard this for targets that do not
support branch tracing.
2012-06-06 Markus Metzger <markus.t.metzger@intel.com>
gdb/
* linux-nat-btrace.h: New file.
* linux-nat-btrace.c: New file.
---
gdb/linux-nat-btrace.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++
gdb/linux-nat-btrace.h | 30 ++++++++++++++
2 files changed, 130 insertions(+), 0 deletions(-)
create mode 100644 gdb/linux-nat-btrace.c
create mode 100644 gdb/linux-nat-btrace.h
diff --git a/gdb/linux-nat-btrace.c b/gdb/linux-nat-btrace.c
new file mode 100644
index 0000000..1b655c2
--- /dev/null
+++ b/gdb/linux-nat-btrace.c
@@ -0,0 +1,100 @@
+/* Branch trace support for GDB, the GNU debugger.
+
+ Copyright (C) 2012 Free Software Foundation, Inc.
+
+ Contributed by Intel Corp. <markus.t.metzger@intel.com>.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "linux-nat-btrace.h"
+#include "linux-btrace.h"
+#include "btrace.h"
+#include "target.h"
+#include "gdbarch.h"
+#include "arch-utils.h"
+#include <errno.h>
+
+/* Enable branch tracing for @ptid. */
+static struct btrace_target_info *
+linux_nat_enable_btrace (ptid_t ptid)
+{
+ struct btrace_target_info *tinfo;
+
+ errno = 0;
+ tinfo = linux_enable_btrace (ptid);
+
+ if (!tinfo)
+ error (_("Could not enable branch tracing for %s: %s."),
+ target_pid_to_str (ptid), safe_strerror (errno));
+
+ return tinfo;
+}
+
+/* Disable branch tracing for @ptid. */
+static void
+linux_nat_disable_btrace (struct btrace_target_info *tinfo)
+{
+ int errcode = linux_disable_btrace (tinfo);
+
+ if (errcode)
+ error (_("Could not disable branch tracing: %s."), safe_strerror (errcode));
+}
+
+/* A read btrace callback creating a vector of btrace blocks. */
+static int
+linux_nat_push_btrace_record (struct linux_btrace_block *raw, void *arg)
+{
+ VEC (btrace_block_s) **btrace = arg;
+ struct btrace_block *block;
+
+ block = VEC_safe_push (btrace_block_s, *btrace, NULL);
+ block->begin = raw->begin;
+ block->end = raw->end;
+
+ return 0;
+}
+
+/* Read branch trace data for @tinfo. */
+static VEC (btrace_block_s) *
+linux_nat_read_btrace (struct btrace_target_info *tinfo)
+{
+ VEC (btrace_block_s) *btrace = NULL;
+ int errcode;
+
+ /* Fill in the number of bits in a pointer for this architecture. */
+ if (!tinfo->ptr_bits)
+ {
+ struct gdbarch *gdbarch = target_gdbarch;
+
+ if (gdbarch)
+ tinfo->ptr_bits = gdbarch_ptr_bit (gdbarch);
+ }
+
+ linux_read_btrace (tinfo, linux_nat_push_btrace_record, &btrace);
+
+ return btrace;
+}
+
+/* Documentation see linux-nat-btrace.h. */
+void
+linux_nat_add_btrace_ops (struct target_ops *t)
+{
+ t->to_supports_btrace = linux_supports_btrace;
+ t->to_enable_btrace = linux_nat_enable_btrace;
+ t->to_disable_btrace = linux_nat_disable_btrace;
+ t->to_btrace_has_changed = linux_btrace_has_changed;
+ t->to_read_btrace = linux_nat_read_btrace;
+}
diff --git a/gdb/linux-nat-btrace.h b/gdb/linux-nat-btrace.h
new file mode 100644
index 0000000..4f0a18d
--- /dev/null
+++ b/gdb/linux-nat-btrace.h
@@ -0,0 +1,30 @@
+/* Branch trace support for GDB, the GNU debugger.
+
+ Copyright (C) 2012 Free Software Foundation, Inc.
+
+ Contributed by Intel Corp. <markus.t.metzger@intel.com>.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef LINUX_NAT_BTRACE_H
+#define LINUX_NAT_BTRACE_H
+
+struct target_ops;
+
+/* Add linux native branch tracing operations. */
+extern void linux_nat_add_btrace_ops (struct target_ops *);
+
+#endif /* LINUX_NAT_BTRACE_H */
--
1.7.1