gdb:
authorYao Qi <yao@codesourcery.com>
Sat, 3 Mar 2012 04:04:35 +0000 (04:04 +0000)
committerYao Qi <yao@codesourcery.com>
Sat, 3 Mar 2012 04:04:35 +0000 (04:04 +0000)
* common/agent.c (struct ipa_sym_addresses) <addr_capability>: New.
(agent_capability_check, agent_capability_invalidate): New.
(symbol_list): New array element.
* common/agent.h (enum agent_capa): New.
* target.c (target_pre_inferior): Call agent_capability_invalidate.

gdb/gdbserver:
* tracepoint.c (gdb_agent_capability): New global.
(in_process_agent_loaded_ust): Renamed to
`in_process_agent_supports_ust'.
Update callers.
(in_process_agent_supports_ust): Call agent_capability_check.
(clear_installed_tracepoints): Assert that agent supports
agent.

gdb/ChangeLog
gdb/common/agent.c
gdb/common/agent.h
gdb/gdbserver/ChangeLog
gdb/gdbserver/tracepoint.c
gdb/target.c

index 3e6e5010cd7421526f3e60d72ba73a7699b4fdf8..a6a7db7d55661aa81b78eb827d0802eb227261a5 100644 (file)
@@ -1,3 +1,11 @@
+2012-03-03  Yao Qi  <yao@codesourcery.com>
+
+       * common/agent.c (struct ipa_sym_addresses) <addr_capability>: New.
+       (agent_capability_check, agent_capability_invalidate): New.
+       (symbol_list): New array element.
+       * common/agent.h (enum agent_capa): New.
+       * target.c (target_pre_inferior): Call agent_capability_invalidate.
+
 2012-03-03  Yao Qi  <yao@codesourcery.com>
 
        * target.h (struct target_ops) <to_use_agent>: New field.
index 2bd3206d3e979ce6ae003c277274136532474b64..f3bdafcfaeb81566e07d30e017e9893907ffcdb0 100644 (file)
@@ -51,6 +51,7 @@ struct ipa_sym_addresses
 {
   CORE_ADDR addr_helper_thread_id;
   CORE_ADDR addr_cmd_buf;
+  CORE_ADDR addr_capability;
 };
 
 /* Cache of the helper thread id.  FIXME: this global should be made
@@ -65,6 +66,7 @@ static struct
 } symbol_list[] = {
   IPA_SYM(helper_thread_id),
   IPA_SYM(cmd_buf),
+  IPA_SYM(capability),
 };
 
 static struct ipa_sym_addresses ipa_sym_addrs;
@@ -303,3 +305,41 @@ agent_run_command (int pid, const char *cmd)
 
   return 0;
 }
+
+/* Each bit of it stands for a capability of agent.  */
+static unsigned int agent_capability = 0;
+
+/* Return true if agent has capability AGENT_CAP, otherwise return false.  */
+
+int
+agent_capability_check (enum agent_capa agent_capa)
+{
+  if (agent_capability == 0)
+    {
+#ifdef GDBSERVER
+      if (read_inferior_memory (ipa_sym_addrs.addr_capability,
+                               (unsigned char *) &agent_capability,
+                               sizeof agent_capability))
+#else
+      enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
+      gdb_byte buf[4];
+
+      if (target_read_memory (ipa_sym_addrs.addr_capability,
+                             buf, sizeof buf) == 0)
+       agent_capability = extract_unsigned_integer (buf, sizeof buf,
+                                                    byte_order);
+      else
+#endif
+       warning ("Error reading capability of agent");
+    }
+  return agent_capability & agent_capa;
+}
+
+/* Invalidate the cache of agent capability, so we'll read it from inferior
+   again.  Call it when launches a new program or reconnect to remote stub.  */
+
+void
+agent_capability_invalidate (void)
+{
+  agent_capability = 0;
+}
index 296521579ca153befd65707822bbda13d3abe47e..a1ac9b20d2304345a5161c9fd4244142bba21b6c 100644 (file)
@@ -36,3 +36,20 @@ int agent_look_up_symbols (void);
 extern int debug_agent;
 
 extern int use_agent;
+
+/* Capability of agent.  Different agents may have different capabilities,
+   such as installing fast tracepoint or evaluating breakpoint conditions.
+   Capabilities are represented by bit-maps, and each capability occupies one
+   bit.  */
+
+enum agent_capa
+{
+  /* Capability to install fast tracepoint.  */
+  AGENT_CAPA_FAST_TRACE = 0x1,
+  /* Capability to install static tracepoint.  */
+  AGENT_CAPA_STATIC_TRACE = (0x1 << 1),
+};
+
+int agent_capability_check (enum agent_capa);
+
+void agent_capability_invalidate (void);
index b115b239bb7eb242228f63a5f253756eb8417bc8..b96cd7bf9ac272060450415d12fcb05deeb8f21a 100644 (file)
@@ -1,3 +1,13 @@
+2012-03-03  Yao Qi  <yao@codesourcery.com>
+
+       * tracepoint.c (gdb_agent_capability): New global.
+       (in_process_agent_loaded_ust): Renamed to
+       `in_process_agent_supports_ust'.
+       Update callers.
+       (in_process_agent_supports_ust): Call agent_capability_check.
+       (clear_installed_tracepoints): Assert that agent supports
+       agent.
+
 2012-03-03  Yao Qi  <yao@codesourcery.com>
 
        * linux-low.c (linux_supports_agent): New.
index f5f506a29833b11d9dec54dea63b5a4de8817a13..bef28a3292477bff91434a3bdc6705572b03cfa9 100644 (file)
@@ -232,10 +232,11 @@ in_process_agent_loaded (void)
 static int read_inferior_integer (CORE_ADDR symaddr, int *val);
 
 /* Returns true if both the in-process agent library and the static
-   tracepoints libraries are loaded in the inferior.  */
+   tracepoints libraries are loaded in the inferior, and agent has
+   capability on static tracepoints.  */
 
 static int
-in_process_agent_loaded_ust (void)
+in_process_agent_supports_ust (void)
 {
   int loaded = 0;
 
@@ -245,13 +246,20 @@ in_process_agent_loaded_ust (void)
       return 0;
     }
 
-  if (read_inferior_integer (ipa_sym_addrs.addr_ust_loaded, &loaded))
+  if (agent_capability_check (AGENT_CAPA_STATIC_TRACE))
     {
-      warning ("Error reading ust_loaded in lib");
-      return 0;
-    }
+      /* Agent understands static tracepoint, then check whether UST is in
+        fact loaded in the inferior.  */
+      if (read_inferior_integer (ipa_sym_addrs.addr_ust_loaded, &loaded))
+       {
+         warning ("Error reading ust_loaded in lib");
+         return 0;
+       }
 
-  return loaded;
+      return loaded;
+    }
+  else
+    return 0;
 }
 
 static void
@@ -303,7 +311,7 @@ maybe_write_ipa_ust_not_loaded (char *buffer)
       write_e_ipa_not_loaded (buffer);
       return 1;
     }
-  else if (!in_process_agent_loaded_ust ())
+  else if (!in_process_agent_supports_ust ())
     {
       write_e_ust_not_loaded (buffer);
       return 1;
@@ -2907,7 +2915,8 @@ install_tracepoint (struct tracepoint *tpoint, char *own_buf)
          write_e_ipa_not_loaded (own_buf);
          return;
        }
-      if (tpoint->type == static_tracepoint && !in_process_agent_loaded_ust ())
+      if (tpoint->type == static_tracepoint
+         && !in_process_agent_supports_ust ())
        {
          trace_debug ("Requested a static tracepoint, but static "
                       "tracepoints are not supported.");
@@ -6826,6 +6835,8 @@ gdb_agent_helper_thread (void *arg)
 #include <signal.h>
 #include <pthread.h>
 
+IP_AGENT_EXPORT int gdb_agent_capability = AGENT_CAPA_STATIC_TRACE;
+
 static void
 gdb_agent_init (void)
 {
index 87ecf79fe5cee0c6449a66258ced3a0f37be1819..88703ea6e5d353b8b03dc49c768bbafa85a69e1f 100644 (file)
@@ -43,6 +43,7 @@
 #include "inline-frame.h"
 #include "tracepoint.h"
 #include "gdb/fileio.h"
+#include "agent.h"
 
 static void target_info (char *, int);
 
@@ -2500,6 +2501,8 @@ target_pre_inferior (int from_tty)
 
       target_clear_description ();
     }
+
+  agent_capability_invalidate ();
 }
 
 /* Callback for iterate_over_inferiors.  Gets rid of the given