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

Yao Qi
2012-02-17T02:57:07Z

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.

gdb.trace/strace.exp is updated as well to test this point.

2012-02-14 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-15 Yao Qi <yao@codesourcery.com>

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

diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 3e81fd0..f77ec6e 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -60,6 +60,7 @@
#include "linux-osdata.h"
#include "linux-tdep.h"
#include "agent.h"
+#include "tracepoint.h"

#ifndef SPUFS_MAGIC
#define SPUFS_MAGIC 0x23c9b64e
@@ -4819,6 +4820,73 @@ linux_child_can_use_agent (void)
return agent_loaded_p ();
}

+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. */

@@ -4843,6 +4911,9 @@ linux_target_install_ops (struct target_ops *t)

t->to_use_agent = linux_child_use_agent;
t->to_can_use_agent = linux_child_can_use_agent;
+
+ 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 8b0c4ef..f30eb79 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
@@ -269,6 +255,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 c2801f9..c4bfbd5 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -4701,6 +4701,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