[PATCH 2/2] btrace: avoid symbol lookup

Markus Metzger markus.t.metzger@intel.com
Fri Mar 7 08:57:00 GMT 2014


The debug symbol lookup is quite expensive, particularly if no symbol
is found for a given PC.

Avoid the lookup when computing the function trace if we already found
a minimal symbol.

The only different seems to be that some function names are now printed
without '()'.

2014-03-07  Markus Metzger  <markus.t.metzger@intel.com>

	* btrace.c (ftrace_update_function): Lookup symbol only if there
	is no minimal symbol.

testsuite/
	* gdb.btrace/exception.exp: Update.
	* gdb.btrace/static_functions.exp: New.
---
 gdb/btrace.c                                  | 12 ++++--
 gdb/testsuite/gdb.btrace/exception.exp        |  4 +-
 gdb/testsuite/gdb.btrace/static_functions.exp | 62 +++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 6 deletions(-)
 create mode 100644 gdb/testsuite/gdb.btrace/static_functions.exp

diff --git a/gdb/btrace.c b/gdb/btrace.c
index b2e34b7..feb7bea 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -451,13 +451,17 @@ ftrace_update_function (struct gdbarch *gdbarch,
   struct symbol *fun;
   struct btrace_insn *last;
 
-  /* Try to determine the function we're in.  We use both types of symbols
-     to avoid surprises when we sometimes get a full symbol and sometimes
-     only a minimal symbol.  */
-  fun = find_pc_function (pc);
+  /* Try to determine the function we're in.  */
   bmfun = lookup_minimal_symbol_by_pc (pc);
   mfun = bmfun.minsym;
 
+  /* We only lookup the symbol in the debug information if we have not found
+     a minimal symbol.  This avoids the expensive lookup for globally visible
+     symbols.  */
+  fun = NULL;
+  if (mfun == NULL)
+    fun = find_pc_function (pc);
+
   if (fun == NULL && mfun == NULL)
     DEBUG_FTRACE ("no symbol at %s", core_addr_to_string_nz (pc));
 
diff --git a/gdb/testsuite/gdb.btrace/exception.exp b/gdb/testsuite/gdb.btrace/exception.exp
index 0279a7f..71f54a2 100755
--- a/gdb/testsuite/gdb.btrace/exception.exp
+++ b/gdb/testsuite/gdb.btrace/exception.exp
@@ -47,7 +47,7 @@ gdb_continue_to_breakpoint "cont to bp.2" ".*$srcfile:$bp_2\r\n.*"
 send_gdb "record function-call-history 1\n"
 gdb_expect_list "flat" "\r\n$gdb_prompt $" [list \
   [join [list \
-    "1\tmain\\(\\)" \
+    "1\tmain" \
     "2\ttest\\(\\)" \
     "3\tfoo\\(\\)" \
     "4\tbar\\(\\)" \
@@ -60,7 +60,7 @@ gdb_expect_list "flat" "\r\n$gdb_prompt $" [list \
 send_gdb "record function-call-history /c 1\n"
 gdb_expect_list "indented" "\r\n$gdb_prompt $" [list \
   [join [list \
-    "1\tmain\\(\\)" \
+    "1\tmain" \
   "2\t  test\\(\\)" \
   "3\t    foo\\(\\)" \
   "4\t      bar\\(\\)" \
diff --git a/gdb/testsuite/gdb.btrace/static_functions.exp b/gdb/testsuite/gdb.btrace/static_functions.exp
new file mode 100644
index 0000000..34ed485
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/static_functions.exp
@@ -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 unknown_functions.c
+
+# discard local symbols
+set ldflags "additional_flags=-Wl,-x"
+if [prepare_for_testing $testfile.exp $testfile $srcfile {$ldflags debug}] {
+    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\ttest" \
+  "2\tfoo" \
+  "3\tbar" \
+  "4\tfoo" \
+  "5\ttest" \
+  "6\tmain" \
+  "7\ttest" \
+  ] "\r\n"] "flat"
+
+# show the branch trace with calls indented
+gdb_test "record function-call-history /c 1" [join [list \
+  "1\t  test" \
+  "2\t    foo" \
+  "3\t      bar" \
+  "4\t    foo" \
+  "5\t  test" \
+  "6\tmain" \
+  "7\t  test" \
+  ] "\r\n"] "indented"
-- 
1.8.3.1



More information about the Gdb-patches mailing list