public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Ari Hannula <ari.hannula@intel.com>
To: gdb-patches@sourceware.org
Cc: Tim Wiederhake <tim.wiederhake@intel.com>,
	Ari Hannula <ari.hannula@intel.com>
Subject: [PATCH 5/5] [func_call] Add function-call-history command to MI.
Date: Thu, 10 Feb 2022 14:52:43 +0100	[thread overview]
Message-ID: <20220210135243.3127629-6-ari.hannula@intel.com> (raw)
In-Reply-To: <20220210135243.3127629-1-ari.hannula@intel.com>

From: Tim Wiederhake <tim.wiederhake@intel.com>

This allows MI clients like Eclipse to retrieve the function call history.

gdb/ChangeLog:
2018-12-27  Tim Wiederhake  <tim.wiederhake@intel.com>

	* mi/mi-cmds.c (mi_cmds): Add mi_cmd_record_function_call_history.
	* mi/mi-cmds.h (mi_cmd_record_function_call_history): New declaration.
	* record.c (mi_cmd_record_function_call_history): New function.
	* record.h (mi_cmd_record_function_call_hisotry): New declaration.

gdb/testsuite/ChangeLog:
2018-12-27  Tim Wiederhake  <tim.wiederhake@intel.com>

	* gdb.mi/mi-function_call_history.exp: Add tests.

Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com>
Signed-off-by: Ari Hannula <ari.hannula@intel.com>
---
 gdb/mi/mi-cmds.c                              |  1 +
 gdb/mi/mi-cmds.h                              |  1 +
 gdb/record.c                                  | 50 ++++++++++
 gdb/record.h                                  |  5 +
 .../gdb.mi/mi-function_call_history.exp       | 95 +++++++++++++++++++
 5 files changed, 152 insertions(+)

diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
index 945a439d3a..f41b5aa01a 100644
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -281,6 +281,7 @@ add_builtin_mi_commands ()
 		 mi_cmd_fix_multi_location_breakpoint_output);
   add_mi_cmd_mi ("function-call-history-length",
 		 mi_cmd_record_function_call_history_length);
+  add_mi_cmd_mi ("function-call-history", mi_cmd_record_function_call_history);
   add_mi_cmd_mi ("gdb-exit", mi_cmd_gdb_exit);
   add_mi_cmd_cli ("gdb-set", "set", 1,
 		  &mi_suppress_notification.cmd_param_changed);
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index 63da17ed01..6256c2001b 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -89,6 +89,7 @@ extern mi_cmd_argv_ftype mi_cmd_list_features;
 extern mi_cmd_argv_ftype mi_cmd_list_target_features;
 extern mi_cmd_argv_ftype mi_cmd_list_thread_groups;
 extern mi_cmd_argv_ftype mi_cmd_record_function_call_history_length;
+extern mi_cmd_argv_ftype mi_cmd_record_function_call_history;
 extern mi_cmd_argv_ftype mi_cmd_remove_inferior;
 extern mi_cmd_argv_ftype mi_cmd_stack_info_depth;
 extern mi_cmd_argv_ftype mi_cmd_stack_info_frame;
diff --git a/gdb/record.c b/gdb/record.c
index 75375b4288..191f831dec 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -766,6 +766,56 @@ mi_cmd_record_function_call_history_length (const char *command,
   target_call_history_length ();
 }
 
+void
+mi_cmd_record_function_call_history (const char *command, char **argv,
+				     int argc)
+{
+  record_print_flags flags = 0;
+  unsigned int low, high;
+  char *charend;
+
+  if ((argc < 0) || (argc > 3))
+    error (_("-function-call-history: Invalid number of arguments."));
+
+  require_record_target ();
+
+  if ((argc == 1) || (argc == 3))
+    {
+      const char *targv = argv[0];
+      flags = get_call_history_modifiers (&targv);
+    }
+
+  if ((argc == 0) || (argc == 1))
+    {
+      const int size = command_size_to_target_size (record_call_history_size);
+      target_call_history (size, flags);
+      return;
+    }
+
+  if (argc == 3)
+    {
+      low = strtoul (argv[1], &charend, 10);
+      if (*charend != '\0')
+	error (_("Invalid syntax of begin func id '%s'"), argv[1]);
+
+      high = strtoul (argv[2], &charend, 10);
+      if (*charend != '\0')
+	error (_("Invalid syntax of end func id '%s'"), argv[2]);
+    }
+  else
+    {
+      low = strtoul (argv[0], &charend, 10);
+      if (*charend != '\0')
+	error (_("Invalid syntax of begin func id '%s'"), argv[0]);
+
+      high = strtoul (argv[1], &charend, 10);
+      if (*charend != '\0')
+	error (_("Invalid syntax of end func id '%s'"), argv[1]);
+    }
+
+  target_call_history_range (low, high, flags);
+}
+
 void _initialize_record ();
 void
 _initialize_record ()
diff --git a/gdb/record.h b/gdb/record.h
index 174b71c67c..96825bac49 100644
--- a/gdb/record.h
+++ b/gdb/record.h
@@ -120,4 +120,9 @@ extern void mi_cmd_record_function_call_history_length (char *command,
 							char **argv,
 							int argc);
 
+/* The MI version of the command to get the function call history for record
+   targets.  */
+extern void mi_cmd_record_function_call_history (char *command, char **argv,
+						 int argc);
+
 #endif /* RECORD_H */
diff --git a/gdb/testsuite/gdb.mi/mi-function_call_history.exp b/gdb/testsuite/gdb.mi/mi-function_call_history.exp
index 948a04a5ed..7876cf9d16 100644
--- a/gdb/testsuite/gdb.mi/mi-function_call_history.exp
+++ b/gdb/testsuite/gdb.mi/mi-function_call_history.exp
@@ -69,10 +69,57 @@ mi_send_resuming_command "exec-continue" "continue to bp.1"
 mi_expect_stop "breakpoint-hit" "main" ".*" "$testfile.c" 41 \
     {"" "disp=\".*\"" } "run to breakpoint bp.1"
 
+mi_gdb_test "121-function-call-history" \
+    "121\\^done,func history=\\\[\{index=\"12\",function=\"inc\"\},\{index=\"13\",function=\"main\"\},\{index=\"14\",function=\"inc\"\},\{index=\"15\",function=\"main\"\},\{index=\"16\",function=\"inc\"\},\{index=\"17\",function=\"main\"\},\{index=\"18\",function=\"inc\"\},\{index=\"19\",function=\"main\"\},\{index=\"20\",function=\"inc\"\},\{index=\"21\",function=\"main\"\}\\\]" \
+    "121 function call history default without flags"
+
+send_gdb "122-function-call-history\n"
+gdb_expect {
+    -re "\"At the end of the branch trace record..*\\^done,func history=[].*$mi_gdb_prompt$" {
+	#Done
+    }
+    default {
+	perror "122 Function call history failed"
+	return -1
+    }
+}
+
+mi_gdb_test "123-function-call-history 12 16" \
+    "123\\^done,func history=\\\[\{index=\"12\",function=\"inc\"\},\{index=\"13\",function=\"main\"\},\{index=\"14\",function=\"inc\"\},\{index=\"15\",function=\"main\"\},\{index=\"16\",function=\"inc\"\}\\\]" \
+    "123 function call history range without flags"
+
+mi_gdb_test "124-function-call-history 12 13" \
+    "124\\^done,func history=\\\[\{index=\"12\",function=\"inc\"\},\{index=\"13\",function=\"main\"\}\\\]" \
+    "124 function call history range without flags"
+
 mi_gdb_test "125-function-call-history-length" \
     "125\\^done,func history length=\\\[\{end=\"21\"\}\\\]" \
     "125 function call history length"
 
+mi_gdb_test "126-function-call-history 22 23" \
+    "126\\^error,msg=\"Range out of bounds.\"" \
+    "126 function call history range error check"
+
+mi_gdb_test "127-function-call-history /lc" \
+    "127\\^done,func history=\\\[\{index=\"14\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"15\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"16\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"17\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"18\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"19\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"20\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"21\",level=\"0\",function=\"main\",file=\"$srcdir/$subdir/$testfile.c\",.*\}\\\]" \
+    "127 function call history default with flags"
+
+mi_gdb_test "128-function-call-history /lc 14 20" \
+    "128\\^done,func history=\\\[\{index=\"14\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"15\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"16\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"17\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"18\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"19\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"20\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*\}\\\]" \
+    "128 function call history range with flags"
+
+mi_gdb_test "129-function-call-history /lc 1 5" \
+    "129\\^done,func history=\\\[\{index=\"1\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"2\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"3\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"4\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"5\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*\}\\\]" \
+    "129 function call history range with flags"
+
+mi_gdb_test "130-function-call-history /l 1 5" \
+    "130\\^done,func history=\\\[\{index=\"1\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"2\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"3\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"4\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"5\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*\}\\\]" \
+    "130 function call history range with flags"
+
+mi_gdb_test "131-function-call-history /c 1 5" \
+    "131\\^done,func history=\\\[\{index=\"1\",level=\"0\",function=\"main\"\},\{index=\"2\",level=\"1\",function=\"inc\"\},\{index=\"3\",level=\"0\",function=\"main\"\},\{index=\"4\",level=\"1\",function=\"inc\"\},\{index=\"5\",level=\"0\",function=\"main\"\}\\\]" \
+    "131 function call history range with flags"
+
 mi_create_breakpoint "-t $testfile.c:42" "insert temp breakpoint at $testfile.c:42" \
     -number 3 -disp del -func main -file "$srcdir/$subdir/$testfile.c" -line 42
 
@@ -81,8 +128,56 @@ mi_send_resuming_command "exec-continue" "continue to bp.2"
 mi_expect_stop "breakpoint-hit" "main" ".*" "$testfile.c" 42 \
     {"" "disp=\".*\"" } "run to breakpoint bp.2"
 
+mi_gdb_test "221-function-call-history" \
+    "221\\^done,func history=\\\[\{index=\"366\",function=\"fib\"\},\{index=\"367\",function=\"fib\"\},\{index=\"368\",function=\"fib\"\},\{index=\"369\",function=\"fib\"\},\{index=\"370\",function=\"fib\"\},\{index=\"371\",function=\"fib\"\},\{index=\"372\",function=\"fib\"\},\{index=\"373\",function=\"fib\"\},\{index=\"374\",function=\"fib\"\},\{index=\"375\",function=\"main\"\}\\\]" \
+    "221 function call history default without flags"
+
+send_gdb "222-function-call-history\n"
+
+gdb_expect {
+    -re "\"At the end of the branch trace record..*\\^done,func history=[].*$mi_gdb_prompt$" {
+	#Done
+    }
+    default {
+	perror "222 Function call history failed"
+	return -1
+    }
+}
+
+mi_gdb_test "223-function-call-history 12 16" \
+    "223\\^done,func history=\\\[\{index=\"12\",function=\"inc\"\},\{index=\"13\",function=\"main\"\},\{index=\"14\",function=\"inc\"\},\{index=\"15\",function=\"main\"\},\{index=\"16\",function=\"inc\"\}\\\]" \
+    "223 function call history range without flags"
+
+mi_gdb_test "224-function-call-history 366 368" \
+    "224\\^done,func history=\\\[\{index=\"366\",function=\"fib\"\},\{index=\"367\",function=\"fib\"\},\{index=\"368\",function=\"fib\"\}\\\]" \
+    "224 function call history range without flags"
+
 mi_gdb_test "225-function-call-history-length" \
     "225\\^done,func history length=\\\[\{end=\"375\"\}\\\]" \
     "225 function call history length"
 
+mi_gdb_test "226-function-call-history 376 400" \
+    "226\\^error,msg=\"Range out of bounds.\"" \
+    "226 function call history range error check"
+
+mi_gdb_test "227-function-call-history /lc" \
+    "227\\^done,func history=\\\[\{index=\"369\",level=\"6\",function=\"fib\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"370\",level=\"5\",function=\"fib\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"371\",level=\"4\",function=\"fib\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"372\",level=\"3\",function=\"fib\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"373\",level=\"2\",function=\"fib\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"374\",level=\"1\",function=\"fib\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"375\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*}\\\]" \
+    "227 function call history default with flags"
+
+mi_gdb_test "228-function-call-history /lc 14 20" \
+    "228\\^done,func history=\\\[\{index=\"14\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"15\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"16\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"17\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"18\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"19\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"20\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*\}\\\]" \
+    "228 function call history range with flags"
+
+mi_gdb_test "229-function-call-history /lc 1 5" \
+    "229\\^done,func history=\\\[\{index=\"1\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"2\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"3\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"4\",level=\"1\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"5\",level=\"0\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*\}\\\]" \
+    "229 function call history range with flags"
+
+mi_gdb_test "230-function-call-history /l 1 5" \
+    "230\\^done,func history=\\\[\{index=\"1\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"2\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"3\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"4\",function=\"inc\"\,file=\"$srcdir/$subdir/$testfile.c\",.*},\{index=\"5\",function=\"main\"\,file=\"$srcdir/$subdir/$testfile.c\",.*\}\\\]" \
+    "230 function call history range with flags"
+
+mi_gdb_test "231-function-call-history /c 1 5" \
+    "231\\^done,func history=\\\[\{index=\"1\",level=\"0\",function=\"main\"\},\{index=\"2\",level=\"1\",function=\"inc\"\},\{index=\"3\",level=\"0\",function=\"main\"\},\{index=\"4\",level=\"1\",function=\"inc\"\},\{index=\"5\",level=\"0\",function=\"main\"\}\\\]" \
+    "231 function call history range with flags"
+
 mi_gdb_exit
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


      parent reply	other threads:[~2022-02-10 13:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-10 13:52 [PATCH 0/5] Functions call history patches Ari Hannula
2022-02-10 13:52 ` [PATCH 1/5] [func_call] Add possible spelling of linker error message Ari Hannula
2022-03-17 17:58   ` Metzger, Markus T
2022-03-17 18:45     ` Keith Seitz
2022-02-10 13:52 ` [PATCH 2/5] [func_call] New tests for a btrace crash Ari Hannula
2022-03-17 17:58   ` Metzger, Markus T
2022-02-10 13:52 ` [PATCH 3/5] [func_call] Fix MI output for function call history Ari Hannula
2022-03-17 17:58   ` Metzger, Markus T
2022-02-10 13:52 ` [PATCH 4/5] [func_call] Add function-call-history-length command to MI Ari Hannula
2022-03-17 17:59   ` Metzger, Markus T
2022-02-10 13:52 ` Ari Hannula [this message]

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=20220210135243.3127629-6-ari.hannula@intel.com \
    --to=ari.hannula@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tim.wiederhake@intel.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).