record-btrace: optionally indent function call history
authorMarkus Metzger <markus.t.metzger@intel.com>
Thu, 18 Apr 2013 08:58:05 +0000 (10:58 +0200)
committerMarkus Metzger <markus.t.metzger@intel.com>
Thu, 16 Jan 2014 12:03:41 +0000 (13:03 +0100)
Add a new modifier /c to the "record function-call-history" command to
indent the function name based on its depth in the call stack.

Also reorder the optional fields to have the indentation at the very beginning.
Prefix the insn range (/i modifier) with "inst ".
Prefix the source line (/l modifier) with "at ".
Change the range syntax from "begin-end" to "begin,end" to allow copy&paste to
the "record instruction-history" and "list" commands.

Adjust the respective tests and add new tests for the /c modifier.

2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>

* record.h (enum record_print_flag)
<record_print_indent_calls>: New.
* record.c (get_call_history_modifiers): Recognize /c modifier.
(_initialize_record): Document /c modifier.
* record-btrace.c (btrace_call_history): Add btinfo parameter.
Reorder fields.  Optionally indent the function name.  Update
all users.
* NEWS: Announce changes.

testsuite/
* gdb.btrace/function_call_history.exp: Fix expected field
order for "record function-call-history".
Add new tests for "record function-call-history /c".
* gdb.btrace/exception.cc: New.
* gdb.btrace/exception.exp: New.
* gdb.btrace/tailcall.exp: New.
* gdb.btrace/x86-tailcall.S: New.
* gdb.btrace/x86-tailcall.c: New.
* gdb.btrace/unknown_functions.c: New.
* gdb.btrace/unknown_functions.exp: New.
* gdb.btrace/Makefile.in (EXECUTABLES): Add new.

doc/
* gdb.texinfo (Process Record and Replay): Document new /c
modifier accepted by "record function-call-history".
Add /i modifier to "record function-call-history" example.

18 files changed:
gdb/ChangeLog
gdb/NEWS
gdb/btrace.c
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/record-btrace.c
gdb/record.c
gdb/record.h
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.btrace/Makefile.in
gdb/testsuite/gdb.btrace/exception.cc [new file with mode: 0644]
gdb/testsuite/gdb.btrace/exception.exp [new file with mode: 0755]
gdb/testsuite/gdb.btrace/function_call_history.exp
gdb/testsuite/gdb.btrace/tailcall.exp [new file with mode: 0644]
gdb/testsuite/gdb.btrace/unknown_functions.c [new file with mode: 0644]
gdb/testsuite/gdb.btrace/unknown_functions.exp [new file with mode: 0644]
gdb/testsuite/gdb.btrace/x86-tailcall.S [new file with mode: 0644]
gdb/testsuite/gdb.btrace/x86-tailcall.c [new file with mode: 0644]

index 50c6bcd6988c2e65e94692da115e7e9a10164779..b67e66b041cf560af97ae19a229976c352fc9f5a 100644 (file)
@@ -1,3 +1,14 @@
+2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>
+
+       * record.h (enum record_print_flag)
+       <record_print_indent_calls>: New.
+       * record.c (get_call_history_modifiers): Recognize /c modifier.
+       (_initialize_record): Document /c modifier.
+       * record-btrace.c (btrace_call_history): Add btinfo parameter.
+       Reorder fields.  Optionally indent the function name.  Update
+       all users.
+       * NEWS: Announce changes.
+
 2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>
 
        * common/linux-btrace.c (linux_enable_btrace): Enlarge buffer.
index 9b3ae6f7c2d7d4ba083baabf7b01721ea153568a..98ad637e7ec4583e2092937fb7183c882dcf5417 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -7,6 +7,14 @@
   at one.  This also affects the instruction ranges reported by the
   'record function-call-history' command when given the /i modifier.
 
+* The command 'record function-call-history' supports a new modifier '/c' to
+  indent the function names based on their call stack depth.
+  The fields for the '/i' and '/l' modifier have been reordered.
+  The source line range is now prefixed with 'at'.
+  The instruction range is now prefixed with 'inst'.
+  Both ranges are now printed as '<from>, <to>' to allow copy&paste to the
+  "record instruction-history" and "list" commands.
+
 *** Changes in GDB 7.7
 
 * Improved support for process record-replay and reverse debugging on
index 2e9e0080ef8afbddc0961abdd294535472276fff..1d060d3eb8efcb5fc94377571e7e9f9ceecf62e0 100644 (file)
@@ -630,8 +630,10 @@ btrace_compute_ftrace (struct btrace_thread_info *btinfo,
          if (begin == NULL)
            begin = end;
 
-         /* Maintain the function level offset.  */
-         level = min (level, end->level);
+         /* Maintain the function level offset.
+            For all but the last block, we do it here.  */
+         if (blk != 0)
+           level = min (level, end->level);
 
          ftrace_update_insns (end, pc);
          ftrace_update_lines (end, pc);
@@ -651,6 +653,15 @@ btrace_compute_ftrace (struct btrace_thread_info *btinfo,
            }
 
          pc += size;
+
+         /* Maintain the function level offset.
+            For the last block, we do it here to not consider the last
+            instruction.
+            Since the last instruction corresponds to the current instruction
+            and is not really part of the execution history, it shouldn't
+            affect the level.  */
+         if (blk == 0)
+           level = min (level, end->level);
        }
     }
 
index 9ec5fd42ff0a2cf9791a8c9806dc5412b9acfb58..f28610b51f0fbb2fcfac541f70751a6e0c77eb86 100644 (file)
@@ -1,3 +1,9 @@
+2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>
+
+       * gdb.texinfo (Process Record and Replay): Document new /c
+       modifier accepted by "record function-call-history".
+       Add /i modifier to "record function-call-history" example.
+
 2014-01-15  Yuanhui Zhang  <asmwarrior@gmail.com>
            Joel Brobecker  <brobecker@adacore.com>
 
index 94e8d48e2874cd3650d23d1715ccbc68e8eafab4..51f1c41bcb35920ef7af28c1699f7abee802e26b 100644 (file)
@@ -6490,7 +6490,10 @@ line for each sequence of instructions that belong to the same
 function giving the name of that function, the source lines
 for this instruction sequence (if the @code{/l} modifier is
 specified), and the instructions numbers that form the sequence (if
-the @code{/i} modifier is specified).
+the @code{/i} modifier is specified).  The function names are indented
+to reflect the call stack depth if the @code{/c} modifier is
+specified.  The @code{/l}, @code{/i}, and @code{/c} modifiers can be
+given together.
 
 @smallexample
 (@value{GDBP}) @b{list 1, 10}
@@ -6504,10 +6507,10 @@ the @code{/i} modifier is specified).
 8     foo ();
 9     ...
 10  @}
-(@value{GDBP}) @b{record function-call-history /l}
-1  foo.c:6-8   bar
-2  foo.c:2-3   foo
-3  foo.c:9-10  bar
+(@value{GDBP}) @b{record function-call-history /ilc}
+1  bar     inst 1,4     at foo.c:6,8
+2    foo   inst 5,10    at foo.c:2,3
+3  bar     inst 11,13   at foo.c:9,10
 @end smallexample
 
 By default, ten lines are printed.  This can be changed using the
index 97d38fc5255a891114473097b5a811cf121f279a..c53aceca16c62871e47454f57970bdf0169d1261 100644 (file)
@@ -433,7 +433,7 @@ btrace_call_history_insn_range (struct ui_out *uiout,
   end = begin + size - 1;
 
   ui_out_field_uint (uiout, "insn begin", begin);
-  ui_out_text (uiout, "-");
+  ui_out_text (uiout, ",");
   ui_out_field_uint (uiout, "insn end", end);
 }
 
@@ -465,7 +465,7 @@ btrace_call_history_src_line (struct ui_out *uiout,
   if (end == begin)
     return;
 
-  ui_out_text (uiout, "-");
+  ui_out_text (uiout, ",");
   ui_out_field_int (uiout, "max line", end);
 }
 
@@ -473,6 +473,7 @@ btrace_call_history_src_line (struct ui_out *uiout,
 
 static void
 btrace_call_history (struct ui_out *uiout,
+                    const struct btrace_thread_info *btinfo,
                     const struct btrace_call_iterator *begin,
                     const struct btrace_call_iterator *end,
                     enum record_print_flag flags)
@@ -496,23 +497,33 @@ btrace_call_history (struct ui_out *uiout,
       ui_out_field_uint (uiout, "index", bfun->number);
       ui_out_text (uiout, "\t");
 
+      if ((flags & RECORD_PRINT_INDENT_CALLS) != 0)
+       {
+         int level = bfun->level + btinfo->level, i;
+
+         for (i = 0; i < level; ++i)
+           ui_out_text (uiout, "  ");
+       }
+
+      if (sym != NULL)
+       ui_out_field_string (uiout, "function", SYMBOL_PRINT_NAME (sym));
+      else if (msym != NULL)
+       ui_out_field_string (uiout, "function", SYMBOL_PRINT_NAME (msym));
+      else if (!ui_out_is_mi_like_p (uiout))
+       ui_out_field_string (uiout, "function", "??");
+
       if ((flags & RECORD_PRINT_INSN_RANGE) != 0)
        {
+         ui_out_text (uiout, _("\tinst "));
          btrace_call_history_insn_range (uiout, bfun);
-         ui_out_text (uiout, "\t");
        }
 
       if ((flags & RECORD_PRINT_SRC_LINE) != 0)
        {
+         ui_out_text (uiout, _("\tat "));
          btrace_call_history_src_line (uiout, bfun);
-         ui_out_text (uiout, "\t");
        }
 
-      if (sym != NULL)
-       ui_out_field_string (uiout, "function", SYMBOL_PRINT_NAME (sym));
-      else if (msym != NULL)
-       ui_out_field_string (uiout, "function", SYMBOL_PRINT_NAME (msym));
-
       ui_out_text (uiout, "\n");
     }
 }
@@ -569,7 +580,7 @@ record_btrace_call_history (int size, int flags)
     }
 
   if (covered > 0)
-    btrace_call_history (uiout, &begin, &end, flags);
+    btrace_call_history (uiout, btinfo, &begin, &end, flags);
   else
     {
       if (size < 0)
@@ -621,7 +632,7 @@ record_btrace_call_history_range (ULONGEST from, ULONGEST to, int flags)
   if (found == 0)
     btrace_call_end (&end, btinfo);
 
-  btrace_call_history (uiout, &begin, &end, flags);
+  btrace_call_history (uiout, btinfo, &begin, &end, flags);
   btrace_set_call_history (btinfo, &begin, &end);
 
   do_cleanups (uiout_cleanup);
index f2cfcc86d90067292471de866e6a355c059e44db..4c671927c25a0e0c14189a4d29aa08c1ca0a2e48 100644 (file)
@@ -586,6 +586,9 @@ get_call_history_modifiers (char **arg)
            case 'i':
              modifiers |= RECORD_PRINT_INSN_RANGE;
              break;
+           case 'c':
+             modifiers |= RECORD_PRINT_INDENT_CALLS;
+             break;
            default:
              error (_("Invalid modifier: %c."), *args);
            }
@@ -820,6 +823,7 @@ function.\n\
 Without modifiers, it prints the function name.\n\
 With a /l modifier, the source file and line number range is included.\n\
 With a /i modifier, the instruction number range is included.\n\
+With a /c modifier, the output is indented based on the call stack depth.\n\
 With no argument, prints ten more lines after the previous ten-line print.\n\
 \"record function-call-history -\" prints ten lines before a previous ten-line \
 print.\n\
index 962e3826d9cd9e14727b2a8ff9d50f01e8637eda..17d1772dac4466eba203e6827725f6c17b0516ab 100644 (file)
@@ -38,6 +38,9 @@ enum record_print_flag
 
   /* Print the instruction number range (if applicable).  */
   RECORD_PRINT_INSN_RANGE = (1 << 1),
+
+  /* Indent based on call stack depth (if applicable).  */
+  RECORD_PRINT_INDENT_CALLS = (1 << 2)
 };
 
 /* Wrapper for target_read_memory that prints a debug message if
index 390b951d993e610406f9db3be4f3c71ba7f94fea..f1fd8a19983bccec334e833198f4ae9038844c41 100644 (file)
@@ -1,3 +1,17 @@
+2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>
+
+       * gdb.btrace/function_call_history.exp: Fix expected field
+       order for "record function-call-history".
+       Add new tests for "record function-call-history /c".
+       * gdb.btrace/exception.cc: New.
+       * gdb.btrace/exception.exp: New.
+       * gdb.btrace/tailcall.exp: New.
+       * gdb.btrace/x86-tailcall.S: New.
+       * gdb.btrace/x86-tailcall.c: New.
+       * gdb.btrace/unknown_functions.c: New.
+       * gdb.btrace/unknown_functions.exp: New.
+       * gdb.btrace/Makefile.in (EXECUTABLES): Add new.
+
 2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>
 
        * gdb.btrace/instruction_history.exp: Update.
index f4c06d11523b91b55c08776e41eeb97b872065c4..606de6e30a60ea6d417a641bc5979102f7a77245 100644 (file)
@@ -1,7 +1,8 @@
 VPATH = @srcdir@
 srcdir = @srcdir@
 
-EXECUTABLES   = enable function_call_history instruction_history
+EXECUTABLES   = enable function_call_history instruction_history tailcall \
+  exception unknown_functions
 
 MISCELLANEOUS =
 
diff --git a/gdb/testsuite/gdb.btrace/exception.cc b/gdb/testsuite/gdb.btrace/exception.cc
new file mode 100644 (file)
index 0000000..029a4bc
--- /dev/null
@@ -0,0 +1,56 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2013 Free Software Foundation, Inc.
+
+   Contributed by Intel Corp. <markus.t.metzger@intel.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+static void
+bad (void)
+{
+  throw 42;
+}
+
+static void
+bar (void)
+{
+  bad ();
+}
+
+static void
+foo (void)
+{
+  bar ();
+}
+
+static void
+test (void)
+{
+  try
+    {
+      foo ();
+    }
+  catch (...)
+    {
+    }
+}
+
+int
+main (void)
+{
+  test ();
+  test (); /* bp.1  */
+  return 0; /* bp.2  */
+}
diff --git a/gdb/testsuite/gdb.btrace/exception.exp b/gdb/testsuite/gdb.btrace/exception.exp
new file mode 100755 (executable)
index 0000000..46ed542
--- /dev/null
@@ -0,0 +1,68 @@
+# This testcase is part of GDB, the GNU debugger.
+#
+# Copyright 2013 Free Software Foundation, Inc.
+#
+# Contributed by Intel Corp. <markus.t.metzger@intel.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# check for btrace support
+if { [skip_btrace_tests] } { return -1 }
+
+# start inferior
+standard_testfile exception.cc
+if [prepare_for_testing $testfile.exp $testfile $srcfile {c++ debug}] {
+    return -1
+}
+if ![runto_main] {
+    return -1
+}
+
+# we want to see the full trace for this test
+gdb_test_no_output "set record function-call-history-size 0"
+
+# set bp
+set bp_1 [gdb_get_line_number "bp.1" $srcfile]
+set bp_2 [gdb_get_line_number "bp.2" $srcfile]
+gdb_breakpoint $bp_1
+gdb_breakpoint $bp_2
+
+# trace the code between the two breakpoints
+gdb_continue_to_breakpoint "cont to bp.1" ".*$srcfile:$bp_1\r\n.*"
+gdb_test_no_output "record btrace"
+gdb_continue_to_breakpoint "cont to bp.2" ".*$srcfile:$bp_2\r\n.*"
+
+# show the flat branch trace
+send_gdb "record function-call-history 1\n"
+gdb_expect_list "flat" "\r\n$gdb_prompt $" [list \
+  [join [list \
+    "1\ttest\\(\\)" \
+    "2\tfoo\\(\\)" \
+    "3\tbar\\(\\)" \
+    "4\tbad\\(\\)" \
+  ] "\r\n"] \
+  "" \
+  "\[0-9\]*\ttest\\(\\)"]
+
+# show the branch trace with calls indented
+send_gdb "record function-call-history /c 1\n"
+gdb_expect_list "indented" "\r\n$gdb_prompt $" [list \
+  [join [list \
+    "1\ttest\\(\\)" \
+    "2\t  foo\\(\\)" \
+    "3\t    bar\\(\\)" \
+    "4\t      bad\\(\\)\r" \
+    ] "\r\n"] \
+  "" \
+  "\[0-9\]*\ttest\\(\\)"]
index cd94dece1eb756881076b0ccd74ddac0ea9747e7..f7a92336282bfd2b255802e2cf2d61cb44292ea0 100644 (file)
@@ -137,32 +137,37 @@ gdb_test "record function-call-history -" "At the start of the branch trace reco
 # make sure we cannot move any further back
 gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 4"
 
+# don't mess around with path names
+gdb_test_no_output "set filename-display basename"
+
 # moving forward again, but this time with file and line number, expected to see the first 15 entries
 gdb_test "record function-call-history /l +" [join [list \
-  ".*$srcfile:40-41\tmain" \
-  ".*$srcfile:22-24\tinc" \
-  ".*$srcfile:40-41\tmain" \
-  ".*$srcfile:22-24\tinc" \
-  ".*$srcfile:40-41\tmain" \
-  ".*$srcfile:22-24\tinc" \
-  ".*$srcfile:40-41\tmain" \
-  ".*$srcfile:22-24\tinc" \
-  ".*$srcfile:40-41\tmain" \
-  ".*$srcfile:22-24\tinc" \
-  ".*$srcfile:40-41\tmain" \
-  ".*$srcfile:22-24\tinc" \
-  ".*$srcfile:40-41\tmain" \
-  ".*$srcfile:22-24\tinc" \
-  ".*$srcfile:40-41\tmain"] "\r\n"] "forward /l - 1"
+  "\[0-9\]*\tmain\tat $srcfile:40,41" \
+  "\[0-9\]*\tinc\tat $srcfile:22,24" \
+  "\[0-9\]*\tmain\tat $srcfile:40,41" \
+  "\[0-9\]*\tinc\tat $srcfile:22,24" \
+  "\[0-9\]*\tmain\tat $srcfile:40,41" \
+  "\[0-9\]*\tinc\tat $srcfile:22,24" \
+  "\[0-9\]*\tmain\tat $srcfile:40,41" \
+  "\[0-9\]*\tinc\tat $srcfile:22,24" \
+  "\[0-9\]*\tmain\tat $srcfile:40,41" \
+  "\[0-9\]*\tinc\tat $srcfile:22,24" \
+  "\[0-9\]*\tmain\tat $srcfile:40,41" \
+  "\[0-9\]*\tinc\tat $srcfile:22,24" \
+  "\[0-9\]*\tmain\tat $srcfile:40,41" \
+  "\[0-9\]*\tinc\tat $srcfile:22,24" \
+  "\[0-9\]*\tmain\tat $srcfile:40,41" \
+  ] "\r\n"] "forward /l - 1"
 
 # moving forward and expect to see the latest 6 entries
 gdb_test "record function-call-history /l +" [join [list \
-  ".*$srcfile:22-24\tinc" \
-  ".*$srcfile:40-41\tmain" \
-  ".*$srcfile:22-24\tinc" \
-  ".*$srcfile:40-41\tmain" \
-  ".*$srcfile:22-24\tinc" \
-  ".*$srcfile:40-43\tmain"] "\r\n"] "forward /l - 2"
+  "\[0-9\]*\tinc\tat $srcfile:22,24" \
+  "\[0-9\]*\tmain\tat $srcfile:40,41" \
+  "\[0-9\]*\tinc\tat $srcfile:22,24" \
+  "\[0-9\]*\tmain\tat $srcfile:40,41" \
+  "\[0-9\]*\tinc\tat $srcfile:22,24" \
+  "\[0-9\]*\tmain\tat $srcfile:40,43" \
+  ] "\r\n"] "forward /l - 2"
 
 # moving further forward shouldn't work
 gdb_test "record function-call-history /l +" "At the end of the branch trace record\\." "forward /l - 3"
@@ -202,3 +207,48 @@ gdb_test "record function-call-history" [join [list \
   "29\tfib" \
   "30\tfib" \
   "31\tmain"] "\r\n"] "recursive"
+
+# show indented function call history for fib
+gdb_test "record function-call-history /c 21, +11" [join [list \
+  "21\tmain" \
+  "22\t  fib" \
+  "23\t    fib" \
+  "24\t  fib" \
+  "25\t    fib" \
+  "26\t      fib" \
+  "27\t    fib" \
+  "28\t      fib" \
+  "29\t    fib" \
+  "30\t  fib" \
+  "31\tmain" \
+  ] "\r\n"] "indented"
+
+# make sure we can handle incomplete trace with respect to indentation
+if ![runto_main] {
+    return -1
+}
+# navigate to the fib in line 24 above
+gdb_breakpoint fib
+gdb_continue_to_breakpoint "cont to fib.1"
+gdb_continue_to_breakpoint "cont to fib.2"
+gdb_continue_to_breakpoint "cont to fib.3"
+gdb_continue_to_breakpoint "cont to fib.4"
+
+# start tracing
+gdb_test_no_output "record btrace"
+
+# continue until line 30 above
+delete_breakpoints
+set bp_location [gdb_get_line_number "bp.2" $testfile.c]
+gdb_breakpoint $bp_location
+gdb_continue_to_breakpoint "cont to bp.2" ".*$testfile.c:$bp_location\r\n.*"
+
+# let's look at the trace. we expect to see the tail of the above listing.
+gdb_test "record function-call-history /c" [join [list \
+  "1\t      fib" \
+  "2\t    fib" \
+  "3\t      fib" \
+  "4\t    fib" \
+  "5\t  fib" \
+  "6\tmain" \
+  ] "\r\n"] "indented tail"
diff --git a/gdb/testsuite/gdb.btrace/tailcall.exp b/gdb/testsuite/gdb.btrace/tailcall.exp
new file mode 100644 (file)
index 0000000..c965675
--- /dev/null
@@ -0,0 +1,62 @@
+# This testcase is part of GDB, the GNU debugger.
+#
+# Copyright 2013 Free Software Foundation, Inc.
+#
+# Contributed by Intel Corp. <markus.t.metzger@intel.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# check for btrace support
+if { [skip_btrace_tests] } { return -1 }
+
+# start inferior
+standard_testfile x86-tailcall.S
+
+set opts {}
+if [info exists COMPILE] {
+    # make check RUNTESTFLAGS="gdb.btrace/tailcall.exp COMPILE=1"
+    standard_testfile x86-tailcall.c
+    lappend opts debug optimize=-O2
+} elseif { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
+    verbose "Skipping ${testfile}."
+    return
+}
+
+if [prepare_for_testing tailcall.exp $testfile $srcfile $opts] {
+    return -1
+}
+if ![runto_main] {
+    return -1
+}
+
+# we want to see the full trace for this test
+gdb_test_no_output "set record function-call-history-size 0"
+
+# trace the call to foo
+gdb_test_no_output "record btrace"
+gdb_test "next"
+
+# show the flat branch trace
+gdb_test "record function-call-history 1" [join [list \
+  "1\tfoo" \
+  "2\tbar" \
+  "3\tmain" \
+  ] "\r\n"] "flat"
+
+# show the branch trace with calls indented
+gdb_test "record function-call-history /c 1" [join [list \
+  "1\t  foo" \
+  "2\t    bar" \
+  "3\tmain" \
+  ] "\r\n"] "indented"
diff --git a/gdb/testsuite/gdb.btrace/unknown_functions.c b/gdb/testsuite/gdb.btrace/unknown_functions.c
new file mode 100644 (file)
index 0000000..178c3e9
--- /dev/null
@@ -0,0 +1,45 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2013 Free Software Foundation, Inc.
+
+   Contributed by Intel Corp. <markus.t.metzger@intel.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+static int foo (void);
+
+int test (void)
+{
+  return foo ();
+}
+
+static int
+bar (void)
+{
+  return 42;
+}
+
+static int
+foo (void)
+{
+  return bar ();
+}
+
+int
+main (void)
+{
+  test ();
+  test ();
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.btrace/unknown_functions.exp b/gdb/testsuite/gdb.btrace/unknown_functions.exp
new file mode 100644 (file)
index 0000000..f678358
--- /dev/null
@@ -0,0 +1,60 @@
+# This testcase is part of GDB, the GNU debugger.
+#
+# Copyright 2013 Free Software Foundation, Inc.
+#
+# Contributed by Intel Corp. <markus.t.metzger@intel.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# check for btrace support
+if { [skip_btrace_tests] } { return -1 }
+
+# start inferior
+standard_testfile
+
+# discard local symbols
+set ldflags "additional_flags=-Wl,-x"
+if [prepare_for_testing $testfile.exp $testfile $srcfile $ldflags] {
+    return -1
+}
+if ![runto test] {
+    return -1
+}
+
+# we want to see the full trace for this test
+gdb_test_no_output "set record function-call-history-size 0"
+
+# trace from one call of test to the next
+gdb_test_no_output "record btrace"
+gdb_continue_to_breakpoint "cont to test" ".*test.*"
+
+# show the flat branch trace
+gdb_test "record function-call-history 1" [join [list \
+  "1\t\\\?\\\?" \
+  "2\t\\\?\\\?" \
+  "3\t\\\?\\\?" \
+  "4\ttest" \
+  "5\tmain" \
+  "6\ttest" \
+  ] "\r\n"] "flat"
+
+# show the branch trace with calls indented
+gdb_test "record function-call-history /c 1" [join [list \
+  "1\t    \\\?\\\?" \
+  "2\t      \\\?\\\?" \
+  "3\t    \\\?\\\?" \
+  "4\t  test" \
+  "5\tmain" \
+  "6\t  test" \
+  ] "\r\n"] "indented"
diff --git a/gdb/testsuite/gdb.btrace/x86-tailcall.S b/gdb/testsuite/gdb.btrace/x86-tailcall.S
new file mode 100644 (file)
index 0000000..edf9a3b
--- /dev/null
@@ -0,0 +1,279 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2013 Free Software Foundation, Inc.
+
+   Contributed by Intel Corp. <markus.t.metzger@intel.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+   This file has been generated using:
+   gcc -S -O2 -dA -g x86-tailcall.c -o x86-tailcall.S  */
+
+       .file   "x86-tailcall.c"
+       .section        .debug_abbrev,"",@progbits
+.Ldebug_abbrev0:
+       .section        .debug_info,"",@progbits
+.Ldebug_info0:
+       .section        .debug_line,"",@progbits
+.Ldebug_line0:
+       .text
+.Ltext0:
+       .p2align 4,,15
+       .type   bar, @function
+bar:
+.LFB0:
+       .file 1 "x86-tailcall.c"
+       # x86-tailcall.c:22
+       .loc 1 22 0
+       .cfi_startproc
+       # basic block 2
+       # x86-tailcall.c:24
+       .loc 1 24 0
+       movl    $42, %eax
+       ret
+       .cfi_endproc
+.LFE0:
+       .size   bar, .-bar
+       .p2align 4,,15
+       .type   foo, @function
+foo:
+.LFB1:
+       # x86-tailcall.c:28
+       .loc 1 28 0
+       .cfi_startproc
+       # basic block 2
+       # x86-tailcall.c:29
+       .loc 1 29 0
+       jmp     bar
+       .cfi_endproc
+.LFE1:
+       .size   foo, .-foo
+       .p2align 4,,15
+.globl main
+       .type   main, @function
+main:
+.LFB2:
+       # x86-tailcall.c:34
+       .loc 1 34 0
+       .cfi_startproc
+       # basic block 2
+       # x86-tailcall.c:37
+       .loc 1 37 0
+       call    foo
+.LVL0:
+       addl    $1, %eax
+.LVL1:
+       # x86-tailcall.c:39
+       .loc 1 39 0
+       ret
+       .cfi_endproc
+.LFE2:
+       .size   main, .-main
+.Letext0:
+       .section        .debug_loc,"",@progbits
+.Ldebug_loc0:
+.LLST0:
+       .quad   .LVL0-.Ltext0   # Location list begin address (*.LLST0)
+       .quad   .LVL1-.Ltext0   # Location list end address (*.LLST0)
+       .value  0x3     # Location expression size
+       .byte   0x70    # DW_OP_breg0
+       .sleb128 1
+       .byte   0x9f    # DW_OP_stack_value
+       .quad   .LVL1-.Ltext0   # Location list begin address (*.LLST0)
+       .quad   .LFE2-.Ltext0   # Location list end address (*.LLST0)
+       .value  0x1     # Location expression size
+       .byte   0x50    # DW_OP_reg0
+       .quad   0x0     # Location list terminator begin (*.LLST0)
+       .quad   0x0     # Location list terminator end (*.LLST0)
+       .section        .debug_info
+       .long   0x9c    # Length of Compilation Unit Info
+       .value  0x3     # DWARF version number
+       .long   .Ldebug_abbrev0 # Offset Into Abbrev. Section
+       .byte   0x8     # Pointer Size (in bytes)
+       .uleb128 0x1    # (DIE (0xb) DW_TAG_compile_unit)
+       .long   .LASF0  # DW_AT_producer: "GNU C 4.4.4 20100726 (Red Hat 4.4.4-13)"
+       .byte   0x1     # DW_AT_language
+       .long   .LASF1  # DW_AT_name: "x86-tailcall.c"
+       .long   .LASF2  # DW_AT_comp_dir: ""
+       .quad   .Ltext0 # DW_AT_low_pc
+       .quad   .Letext0        # DW_AT_high_pc
+       .long   .Ldebug_line0   # DW_AT_stmt_list
+       .uleb128 0x2    # (DIE (0x2d) DW_TAG_subprogram)
+       .ascii "bar\0"  # DW_AT_name
+       .byte   0x1     # DW_AT_decl_file (x86-tailcall.c)
+       .byte   0x15    # DW_AT_decl_line
+       .byte   0x1     # DW_AT_prototyped
+       .long   0x4b    # DW_AT_type
+       .quad   .LFB0   # DW_AT_low_pc
+       .quad   .LFE0   # DW_AT_high_pc
+       .byte   0x1     # DW_AT_frame_base
+       .byte   0x9c    # DW_OP_call_frame_cfa
+       .uleb128 0x3    # (DIE (0x4b) DW_TAG_base_type)
+       .byte   0x4     # DW_AT_byte_size
+       .byte   0x5     # DW_AT_encoding
+       .ascii "int\0"  # DW_AT_name
+       .uleb128 0x2    # (DIE (0x52) DW_TAG_subprogram)
+       .ascii "foo\0"  # DW_AT_name
+       .byte   0x1     # DW_AT_decl_file (x86-tailcall.c)
+       .byte   0x1b    # DW_AT_decl_line
+       .byte   0x1     # DW_AT_prototyped
+       .long   0x4b    # DW_AT_type
+       .quad   .LFB1   # DW_AT_low_pc
+       .quad   .LFE1   # DW_AT_high_pc
+       .byte   0x1     # DW_AT_frame_base
+       .byte   0x9c    # DW_OP_call_frame_cfa
+       .uleb128 0x4    # (DIE (0x70) DW_TAG_subprogram)
+       .byte   0x1     # DW_AT_external
+       .long   .LASF3  # DW_AT_name: "main"
+       .byte   0x1     # DW_AT_decl_file (x86-tailcall.c)
+       .byte   0x21    # DW_AT_decl_line
+       .byte   0x1     # DW_AT_prototyped
+       .long   0x4b    # DW_AT_type
+       .quad   .LFB2   # DW_AT_low_pc
+       .quad   .LFE2   # DW_AT_high_pc
+       .byte   0x1     # DW_AT_frame_base
+       .byte   0x9c    # DW_OP_call_frame_cfa
+       .uleb128 0x5    # (DIE (0x8f) DW_TAG_variable)
+       .long   .LASF4  # DW_AT_name: "answer"
+       .byte   0x1     # DW_AT_decl_file (x86-tailcall.c)
+       .byte   0x23    # DW_AT_decl_line
+       .long   0x4b    # DW_AT_type
+       .long   .LLST0  # DW_AT_location
+       .byte   0x0     # end of children of DIE 0x70
+       .byte   0x0     # end of children of DIE 0xb
+       .section        .debug_abbrev
+       .uleb128 0x1    # (abbrev code)
+       .uleb128 0x11   # (TAG: DW_TAG_compile_unit)
+       .byte   0x1     # DW_children_yes
+       .uleb128 0x25   # (DW_AT_producer)
+       .uleb128 0xe    # (DW_FORM_strp)
+       .uleb128 0x13   # (DW_AT_language)
+       .uleb128 0xb    # (DW_FORM_data1)
+       .uleb128 0x3    # (DW_AT_name)
+       .uleb128 0xe    # (DW_FORM_strp)
+       .uleb128 0x1b   # (DW_AT_comp_dir)
+       .uleb128 0xe    # (DW_FORM_strp)
+       .uleb128 0x11   # (DW_AT_low_pc)
+       .uleb128 0x1    # (DW_FORM_addr)
+       .uleb128 0x12   # (DW_AT_high_pc)
+       .uleb128 0x1    # (DW_FORM_addr)
+       .uleb128 0x10   # (DW_AT_stmt_list)
+       .uleb128 0x6    # (DW_FORM_data4)
+       .byte   0x0
+       .byte   0x0
+       .uleb128 0x2    # (abbrev code)
+       .uleb128 0x2e   # (TAG: DW_TAG_subprogram)
+       .byte   0x0     # DW_children_no
+       .uleb128 0x3    # (DW_AT_name)
+       .uleb128 0x8    # (DW_FORM_string)
+       .uleb128 0x3a   # (DW_AT_decl_file)
+       .uleb128 0xb    # (DW_FORM_data1)
+       .uleb128 0x3b   # (DW_AT_decl_line)
+       .uleb128 0xb    # (DW_FORM_data1)
+       .uleb128 0x27   # (DW_AT_prototyped)
+       .uleb128 0xc    # (DW_FORM_flag)
+       .uleb128 0x49   # (DW_AT_type)
+       .uleb128 0x13   # (DW_FORM_ref4)
+       .uleb128 0x11   # (DW_AT_low_pc)
+       .uleb128 0x1    # (DW_FORM_addr)
+       .uleb128 0x12   # (DW_AT_high_pc)
+       .uleb128 0x1    # (DW_FORM_addr)
+       .uleb128 0x40   # (DW_AT_frame_base)
+       .uleb128 0xa    # (DW_FORM_block1)
+       .byte   0x0
+       .byte   0x0
+       .uleb128 0x3    # (abbrev code)
+       .uleb128 0x24   # (TAG: DW_TAG_base_type)
+       .byte   0x0     # DW_children_no
+       .uleb128 0xb    # (DW_AT_byte_size)
+       .uleb128 0xb    # (DW_FORM_data1)
+       .uleb128 0x3e   # (DW_AT_encoding)
+       .uleb128 0xb    # (DW_FORM_data1)
+       .uleb128 0x3    # (DW_AT_name)
+       .uleb128 0x8    # (DW_FORM_string)
+       .byte   0x0
+       .byte   0x0
+       .uleb128 0x4    # (abbrev code)
+       .uleb128 0x2e   # (TAG: DW_TAG_subprogram)
+       .byte   0x1     # DW_children_yes
+       .uleb128 0x3f   # (DW_AT_external)
+       .uleb128 0xc    # (DW_FORM_flag)
+       .uleb128 0x3    # (DW_AT_name)
+       .uleb128 0xe    # (DW_FORM_strp)
+       .uleb128 0x3a   # (DW_AT_decl_file)
+       .uleb128 0xb    # (DW_FORM_data1)
+       .uleb128 0x3b   # (DW_AT_decl_line)
+       .uleb128 0xb    # (DW_FORM_data1)
+       .uleb128 0x27   # (DW_AT_prototyped)
+       .uleb128 0xc    # (DW_FORM_flag)
+       .uleb128 0x49   # (DW_AT_type)
+       .uleb128 0x13   # (DW_FORM_ref4)
+       .uleb128 0x11   # (DW_AT_low_pc)
+       .uleb128 0x1    # (DW_FORM_addr)
+       .uleb128 0x12   # (DW_AT_high_pc)
+       .uleb128 0x1    # (DW_FORM_addr)
+       .uleb128 0x40   # (DW_AT_frame_base)
+       .uleb128 0xa    # (DW_FORM_block1)
+       .byte   0x0
+       .byte   0x0
+       .uleb128 0x5    # (abbrev code)
+       .uleb128 0x34   # (TAG: DW_TAG_variable)
+       .byte   0x0     # DW_children_no
+       .uleb128 0x3    # (DW_AT_name)
+       .uleb128 0xe    # (DW_FORM_strp)
+       .uleb128 0x3a   # (DW_AT_decl_file)
+       .uleb128 0xb    # (DW_FORM_data1)
+       .uleb128 0x3b   # (DW_AT_decl_line)
+       .uleb128 0xb    # (DW_FORM_data1)
+       .uleb128 0x49   # (DW_AT_type)
+       .uleb128 0x13   # (DW_FORM_ref4)
+       .uleb128 0x2    # (DW_AT_location)
+       .uleb128 0x6    # (DW_FORM_data4)
+       .byte   0x0
+       .byte   0x0
+       .byte   0x0
+       .section        .debug_pubnames,"",@progbits
+       .long   0x17    # Length of Public Names Info
+       .value  0x2     # DWARF Version
+       .long   .Ldebug_info0   # Offset of Compilation Unit Info
+       .long   0xa0    # Compilation Unit Length
+       .long   0x70    # DIE offset
+       .ascii "main\0" # external name
+       .long   0x0
+       .section        .debug_aranges,"",@progbits
+       .long   0x2c    # Length of Address Ranges Info
+       .value  0x2     # DWARF Version
+       .long   .Ldebug_info0   # Offset of Compilation Unit Info
+       .byte   0x8     # Size of Address
+       .byte   0x0     # Size of Segment Descriptor
+       .value  0x0     # Pad to 16 byte boundary
+       .value  0x0
+       .quad   .Ltext0 # Address
+       .quad   .Letext0-.Ltext0        # Length
+       .quad   0x0
+       .quad   0x0
+       .section        .debug_str,"MS",@progbits,1
+.LASF0:
+       .string "GNU C 4.4.4 20100726 (Red Hat 4.4.4-13)"
+.LASF3:
+       .string "main"
+.LASF4:
+       .string "answer"
+.LASF2:
+       .string ""
+.LASF1:
+       .string "x86-tailcall.c"
+       .ident  "GCC: (GNU) 4.4.4 20100726 (Red Hat 4.4.4-13)"
+       .section        .note.GNU-stack,"",@progbits
diff --git a/gdb/testsuite/gdb.btrace/x86-tailcall.c b/gdb/testsuite/gdb.btrace/x86-tailcall.c
new file mode 100644 (file)
index 0000000..9e3b183
--- /dev/null
@@ -0,0 +1,39 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2013 Free Software Foundation, Inc.
+
+   Contributed by Intel Corp. <markus.t.metzger@intel.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+static __attribute__ ((noinline)) int
+bar (void)
+{
+  return 42;
+}
+
+static __attribute__ ((noinline)) int
+foo (void)
+{
+  return bar ();
+}
+
+int
+main (void)
+{
+  int answer;
+
+  answer = foo ();
+  return ++answer;
+}
This page took 0.074849 seconds and 4 git commands to generate.