[v3] Update btrace data in maintenance btrace commands

Message ID 20210914093353.703496-1-sroettger@google.com
State New
Headers show
Series
  • [v3] Update btrace data in maintenance btrace commands
Related show

Commit Message

Lancelot SIX via Gdb-patches Sept. 14, 2021, 9:33 a.m.
From: Stephen Roettger <sroettger@google.com>


When calling `maintenance btrace packet-history` or `maintenance info btrace`,
the commands wouldn't show any data unless it was updated previously by some
other means, for example by running `info record`.
To fix this, use the require_btrace function from record-brace.h which
will update the data before returning the btrace_thread_info pointer.

Change to v1: moved the require_btrace comment to record-btrace.h
Change to v2: fix the style in the function declaration
---
 gdb/btrace.c        | 13 ++-----------
 gdb/record-btrace.c |  8 ++------
 gdb/record-btrace.h |  7 +++++++
 3 files changed, 11 insertions(+), 17 deletions(-)

-- 
2.33.0.309.g3052b89438-goog

Patch

diff --git a/gdb/btrace.c b/gdb/btrace.c
index c697f37f46c..177e818f0cf 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -3231,12 +3231,8 @@  maint_btrace_packet_history_cmd (const char *arg, int from_tty)
   struct btrace_thread_info *btinfo;
   unsigned int size, begin, end, from, to;
 
-  thread_info *tp = find_thread_ptid (current_inferior (), inferior_ptid);
-  if (tp == NULL)
-    error (_("No thread."));
-
+  btinfo = require_btrace ();
   size = 10;
-  btinfo = &tp->btrace;
 
   btrace_maint_update_packets (btinfo, &begin, &end, &from, &to);
   if (begin == end)
@@ -3372,12 +3368,7 @@  maint_info_btrace_cmd (const char *args, int from_tty)
   if (args != NULL && *args != 0)
     error (_("Invalid argument."));
 
-  if (inferior_ptid == null_ptid)
-    error (_("No thread."));
-
-  thread_info *tp = inferior_thread ();
-
-  btinfo = &tp->btrace;
+  btinfo = require_btrace ();
 
   conf = btrace_conf (btinfo);
   if (conf == NULL)
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index b7b3c91f85d..8945eb73277 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -263,13 +263,9 @@  require_btrace_thread (void)
   return tp;
 }
 
-/* Update the branch trace for the current thread and return a pointer to its
-   branch trace information struct.
-
-   Throws an error if there is no thread or no trace.  This function never
-   returns NULL.  */
+/* See record-btrace.h.  */
 
-static struct btrace_thread_info *
+struct btrace_thread_info *
 require_btrace (void)
 {
   struct thread_info *tp;
diff --git a/gdb/record-btrace.h b/gdb/record-btrace.h
index 8e7bbd90e60..f9c3eac8efe 100644
--- a/gdb/record-btrace.h
+++ b/gdb/record-btrace.h
@@ -29,4 +29,11 @@  extern void record_btrace_push_target (void);
    NULL if the cpu was configured as auto.  */
 extern const struct btrace_cpu *record_btrace_get_cpu (void);
 
+/* Update the branch trace for the current thread and return a pointer to its
+   branch trace information struct.
+
+   Throws an error if there is no thread or no trace.  This function never
+   returns NULL.  */
+extern struct btrace_thread_info *require_btrace ();
+
 #endif /* RECORD_BTRACE_H */