Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Markus Metzger <markus.t.metzger@intel.com>
To: jan.kratochvil@redhat.com
Cc: gdb-patches@sourceware.org, markus.t.metzger@gmail.com
Subject: [patch v10 03/21] linux, i386, amd64: enable btrace for 32bit and 64bit linux native
Date: Fri, 08 Mar 2013 09:19:00 -0000	[thread overview]
Message-ID: <1362734168-1725-4-git-send-email-markus.t.metzger@intel.com> (raw)
In-Reply-To: <1362734168-1725-1-git-send-email-markus.t.metzger@intel.com>

Install the btrace target ops for i386-linux-nat and amd64-linux-nat.

Approved by Jan Kratochvil.

2013-03-08  Markus Metzger  <markus.t.metzger@intel.com>

	* amd64-linux-nat.c: Include btrace.h and linux-btrace.h.
	(amd64_linux_enable_btrace): New.
	(amd64_linux_disable_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.
	(_initialize_i386_linux_nat): Initialize btrace ops.
	* config/i386/linux.mh: Add linux-btrace.o.
	* config/i386/linux64.mh: Add linux-btrace.o.


---
 gdb/amd64-linux-nat.c      |   41 +++++++++++++++++++++++++++++++++++++++++
 gdb/config/i386/linux.mh   |    3 ++-
 gdb/config/i386/linux64.mh |    2 +-
 gdb/i386-linux-nat.c       |   41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
index 3d1983b..6f13fca 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,39 @@ 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));
+}
+
 /* Provide a prototype to silence -Wmissing-prototypes.  */
 void _initialize_amd64_linux_nat (void);
 
@@ -1157,6 +1192,12 @@ _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_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 8316d87..7c64e83 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 d2b95fd..8d782c1 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 11b510d..715c6d4 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,39 @@ 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));
+}
+
 /* -Wmissing-prototypes */
 extern initialize_file_ftype _initialize_i386_linux_nat;
 
@@ -1079,6 +1114,12 @@ _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_read_btrace = linux_read_btrace;
+
   /* Register the target.  */
   linux_nat_add_target (t);
   linux_nat_set_new_thread (t, i386_linux_new_thread);
-- 
1.7.1


  parent reply	other threads:[~2013-03-08  9:17 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-08  9:19 [patch v10 00/21] branch tracing for Atom Markus Metzger
2013-03-08  9:16 ` [patch v10 07/21] btrace, doc: document remote serial protocol Markus Metzger
2013-03-08  9:17 ` [patch v10 21/21] btrace: fix crash when losing the remote connection on process exit Markus Metzger
2013-03-08 13:58   ` Jan Kratochvil
2013-03-08 14:18     ` Metzger, Markus T
2013-03-08  9:17 ` [patch v10 16/21] record: add "record function-call-history" command Markus Metzger
2013-03-08  9:17 ` [patch v10 01/21] thread, btrace: add generic branch trace support Markus Metzger
2013-03-08  9:17 ` [patch v10 09/21] target: add add_deprecated_target_alias Markus Metzger
2013-03-08  9:17 ` [patch v10 06/21] remote, gdbserver: add btrace support Markus Metzger
2013-03-08  9:17 ` [patch v10 14/21] record: default target methods Markus Metzger
2013-03-08  9:17 ` [patch v10 08/21] btrace, x86: disable on some processors Markus Metzger
2013-03-08  9:17 ` [patch v10 04/21] xml, btrace: define btrace xml document style Markus Metzger
2013-03-08  9:18 ` [patch v10 11/21] record: make it build again Markus Metzger
2013-03-08  9:18 ` [patch v10 20/21] testsuite, gdb.btrace: add btrace tests Markus Metzger
2013-03-08 13:22   ` Jan Kratochvil
2013-03-08 13:28     ` Metzger, Markus T
2013-03-08 13:33       ` Jan Kratochvil
2013-03-08  9:18 ` [patch v10 02/21] linux, btrace: perf_event based branch tracing Markus Metzger
2013-03-08  9:19 ` [patch v10 10/21] record: split record Markus Metzger
2013-03-08  9:19 ` Markus Metzger [this message]
2013-03-08  9:19 ` [patch v10 15/21] record: add "record instruction-history" command Markus Metzger
2013-03-08  9:19 ` [patch v10 18/21] record-btrace, disas: omit pc prefix Markus Metzger
2013-03-08  9:19 ` [patch v10 17/21] record, btrace: add record-btrace target Markus Metzger
2013-03-08  9:19 ` [patch v10 12/21] record-full.c: rename record_ in record_full_ Markus Metzger
2013-03-08  9:19 ` [patch v10 05/21] gdbserver: preserve error message in handle_qXfer Markus Metzger
2013-03-08 12:01   ` Jan Kratochvil
2013-03-08  9:19 ` [patch v10 19/21] doc, record: document record changes Markus Metzger
2013-03-08  9:19 ` [patch v10 13/21] record-full.h: rename record_ into record_full_ Markus Metzger
2013-03-08 12:16 ` [patch v10 00/21] branch tracing for Atom Jan Kratochvil
2013-03-08 12:32   ` Metzger, Markus T
2013-03-08 14:00 ` Jan Kratochvil
2013-03-08 14:58   ` Jan Kratochvil
2013-03-08 15:13     ` Metzger, Markus T
2013-03-08 15:42       ` Jan Kratochvil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362734168-1725-4-git-send-email-markus.t.metzger@intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=markus.t.metzger@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox