Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Markus Metzger <markus.t.metzger@intel.com>
To: jan.kratochvil@redhat.com
Cc: gdb-patches@sourceware.org
Subject: [PATCH 2/2] btrace: avoid symbol lookup
Date: Fri, 07 Mar 2014 08:57:00 -0000	[thread overview]
Message-ID: <1394182665-14164-3-git-send-email-markus.t.metzger@intel.com> (raw)
In-Reply-To: <1394182665-14164-1-git-send-email-markus.t.metzger@intel.com>

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


  parent reply	other threads:[~2014-03-07  8:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-07  8:57 [PATCH 0/2] btrace: perf improvements Markus Metzger
2014-03-07  8:57 ` [PATCH 1/2] btrace: only search for lines in current symtab Markus Metzger
2014-03-21 17:43   ` Jan Kratochvil
2014-03-07  8:57 ` Markus Metzger [this message]
2014-03-07 15:55   ` [PATCH 2/2] btrace: avoid symbol lookup Pedro Alves
2014-03-10  8:05     ` Metzger, Markus T
2014-03-07 15:56   ` Pedro Alves
2014-03-10 21:43   ` Jan Kratochvil
2014-03-11 10:08     ` Metzger, Markus T
2014-03-21 17:22       ` Jan Kratochvil
2014-03-24  7:57         ` Metzger, Markus T
2014-03-24  8:37           ` Jan Kratochvil
2014-03-24  9:21             ` Metzger, Markus T

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=1394182665-14164-3-git-send-email-markus.t.metzger@intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.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