This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 9/9] info static tracepoint in linux-nat.


On 02/17/2012 10:55 AM, Yao Qi wrote:
> This patch is to exercise agent in linux native gdb by command `info
> static-tracepoint-marker'.  The implementation of `linux_child_static_tracepoint_markers_by_strid'
> is quite similar to its counterpart in remote target, except bits to pause and unpause
> all threads in current process.

Even target_ops hook `can_use_agent' and `use_agent' are implemented in
inf-child.c by patch

  [PATCH 8/9] impl of use_agent and can_use_agent in linux-nat
  http://sourceware.org/ml/gdb-patches/2012-02/msg00553.html

I am still inclined to implement static_tracepoint_markers_by_strid in
linux-nat, because there is no agent at all for non-linux system.
Although agent itself is quite generic to all unix system, it still
needs de-couple from tracepoint.  On the other hand, UST is
Linux-specific, so it is better to keep
static_tracepoint_markers_by_strid implemented in linux-nat.

-- 
Yao (éå)
2012-02-17  Yao Qi  <yao@codesourcery.com>

	* linux-nat.c (linux_child_static_tracepoint_markers_by_strid):
	New.
        (linux_target_install_ops): Initialize field
	`to_static_tracepoint_markers_by_strid'.
	* remote.c (free_current_marker): Move it to ...
	* tracepoint.c (free_current_marker): ... here.  New.
	(cleanup_target_stop): New.
	* tracepoint.h: Declare free_current_marker.

gdb/testsuite/
2012-02-17  Yao Qi  <yao@codesourcery.com>

	* gdb.trace/strace.exp: run strace_info_marker in linux native gdb.
---
 gdb/linux-nat.c                    |   72 ++++++++++++++++++++++++++++++++++++
 gdb/remote.c                       |   14 -------
 gdb/testsuite/gdb.trace/strace.exp |   35 ++++++++++-------
 gdb/tracepoint.c                   |   14 +++++++
 gdb/tracepoint.h                   |    1 +
 5 files changed, 108 insertions(+), 28 deletions(-)

diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 6aab087..82b7b57 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -59,6 +59,8 @@
 #include "solib.h"
 #include "linux-osdata.h"
 #include "linux-tdep.h"
+#include "agent.h"
+#include "tracepoint.h"
 
 #ifndef SPUFS_MAGIC
 #define SPUFS_MAGIC 0x23c9b64e
@@ -4800,6 +4802,73 @@ linux_xfer_partial (struct target_ops *ops, enum target_object object,
 			     offset, len);
 }
 
+static void
+cleanup_target_stop (void *arg)
+{
+  ptid_t *ptid = (ptid_t *) arg;
+
+  gdb_assert (arg != NULL);
+
+  /* Unpause all */
+  target_resume (*ptid, 0, TARGET_SIGNAL_0);
+}
+
+static VEC(static_tracepoint_marker_p) *
+linux_child_static_tracepoint_markers_by_strid (const char *strid)
+{
+  char s[IPA_CMD_BUF_SIZE];
+  struct cleanup *old_chain;
+  int pid = ptid_get_pid (inferior_ptid);
+  VEC(static_tracepoint_marker_p) *markers = NULL;
+  struct static_tracepoint_marker *marker = NULL;
+  char *p = s;
+  ptid_t ptid = ptid_build (pid, 0, 0);
+
+  /* Pause all */
+  target_stop (ptid);
+
+  memcpy (s, "qTfSTM", sizeof ("qTfSTM"));
+  s[sizeof ("qTfSTM")] = 0;
+
+  agent_run_command (pid, s);
+
+  old_chain = make_cleanup (free_current_marker, &marker);
+  make_cleanup (cleanup_target_stop, &ptid);
+
+  while (*p++ == 'm')
+    {
+      if (marker == NULL)
+	marker = XCNEW (struct static_tracepoint_marker);
+
+      do
+	{
+	  parse_static_tracepoint_marker_definition (p, &p, marker);
+
+	  if (strid == NULL || strcmp (strid, marker->str_id) == 0)
+	    {
+	      VEC_safe_push (static_tracepoint_marker_p,
+			     markers, marker);
+	      marker = NULL;
+	    }
+	  else
+	    {
+	      release_static_tracepoint_marker (marker);
+	      memset (marker, 0, sizeof (*marker));
+	    }
+	}
+      while (*p++ == ',');	/* comma-separated list */
+
+      memcpy (s, "qTsSTM", sizeof ("qTsSTM"));
+      s[sizeof ("qTsSTM")] = 0;
+      agent_run_command (pid, s);
+      p = s;
+    }
+
+  do_cleanups (old_chain);
+
+  return markers;
+}
+
 /* Create a prototype generic GNU/Linux target.  The client can override
    it with local methods.  */
 
@@ -4821,6 +4890,9 @@ linux_target_install_ops (struct target_ops *t)
 
   super_xfer_partial = t->to_xfer_partial;
   t->to_xfer_partial = linux_xfer_partial;
+
+  t->to_static_tracepoint_markers_by_strid
+    = linux_child_static_tracepoint_markers_by_strid;
 }
 
 struct target_ops *
diff --git a/gdb/remote.c b/gdb/remote.c
index 2977e31..422c7d4 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -2846,20 +2846,6 @@ remote_static_tracepoint_marker_at (CORE_ADDR addr,
   return 0;
 }
 
-static void
-free_current_marker (void *arg)
-{
-  struct static_tracepoint_marker **marker_p = arg;
-
-  if (*marker_p != NULL)
-    {
-      release_static_tracepoint_marker (*marker_p);
-      xfree (*marker_p);
-    }
-  else
-    *marker_p = NULL;
-}
-
 static VEC(static_tracepoint_marker_p) *
 remote_static_tracepoint_markers_by_strid (const char *strid)
 {
diff --git a/gdb/testsuite/gdb.trace/strace.exp b/gdb/testsuite/gdb.trace/strace.exp
index 4d6ea10..d4a9a9e 100644
--- a/gdb/testsuite/gdb.trace/strace.exp
+++ b/gdb/testsuite/gdb.trace/strace.exp
@@ -38,20 +38,6 @@ if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags
     return -1
 }
 
-clean_restart $executable
-
-if ![runto_main] {
-    fail "Can't run to main to check for trace support"
-    return -1
-}
-
-if { ![gdb_target_supports_trace] } then {
-    unsupported "Current target does not support trace"
-    return -1;
-}
-
-gdb_load_shlibs $libipa
-
 proc strace_info_marker { } {
     global executable
     global pf_prefix
@@ -265,6 +251,27 @@ proc strace_trace_on_diff_addr { } {
     set pf_prefix $old_pf_prefix
 }
 
+clean_restart $executable
+
+if ![runto_main] {
+    fail "Can't run to main to check for trace support"
+    return -1
+}
+
+# Run it on native x86/x86_64 linux.
+if { ![is_remote target]
+     && ([istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]) } {
+    strace_info_marker
+    return
+}
+
+if { ![gdb_target_supports_trace] } then {
+    unsupported "Current target does not support trace"
+    return -1;
+}
+
+gdb_load_shlibs $libipa
+
 strace_info_marker
 strace_probe_marker
 
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 194977b..243ec4d 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -4700,6 +4700,20 @@ init_tfile_ops (void)
   tfile_ops.to_magic = OPS_MAGIC;
 }
 
+void
+free_current_marker (void *arg)
+{
+  struct static_tracepoint_marker **marker_p = arg;
+
+  if (*marker_p != NULL)
+    {
+      release_static_tracepoint_marker (*marker_p);
+      xfree (*marker_p);
+    }
+  else
+    *marker_p = NULL;
+}
+
 /* Given a line of text defining a static tracepoint marker, parse it
    into a "static tracepoint marker" object.  Throws an error is
    parsing fails.  If PP is non-null, it points to one past the end of
diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h
index 00c4d7c..30a810a 100644
--- a/gdb/tracepoint.h
+++ b/gdb/tracepoint.h
@@ -209,6 +209,7 @@ extern void parse_static_tracepoint_marker_definition
   (char *line, char **pp,
    struct static_tracepoint_marker *marker);
 extern void release_static_tracepoint_marker (struct static_tracepoint_marker *);
+extern void free_current_marker (void *arg);
 
 /* A hook used to notify the UI of tracepoint operations.  */
 
-- 
1.7.0.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]