Avoid walking all symbols for unknown address
authorTeng Qin <qinteng@fb.com>
Wed, 3 May 2017 09:16:21 +0000 (02:16 -0700)
committerSasha Goldshtein <goldshtn@gmail.com>
Wed, 3 May 2017 14:57:33 +0000 (17:57 +0300)
src/cc/bcc_syms.cc

index ff88c6694e932163d5736353870a63573df31dd8..f2dc36de5ffe752f51e503dad168b0a53a889bf5 100644 (file)
@@ -284,12 +284,20 @@ bool ProcSyms::Module::find_addr(uint64_t addr, struct bcc_symbol *sym) {
   // brings us to bar, which does not contain offset 0x12 and is nested inside
   // foo. Going back one more symbol brings us to foo, which contains 0x12
   // and is a match.
-  for (--it; offset >= it->start; --it) {
+  // However, we also don't want to walk through the entire symbol list for
+  // unknown / missing symbols. So we will break if we reach a function that
+  // doesn't cover the function immediately before 'it', which means it is
+  // not possibly a nested function containing the address we're looking for.
+  --it;
+  uint64_t limit = it->start;
+  for (; offset >= it->start; --it) {
     if (offset < it->start + it->size) {
       sym->name = it->name->c_str();
       sym->offset = (offset - it->start);
       return true;
     }
+    if (limit > it->start + it->size)
+      break;
     // But don't step beyond begin()!
     if (it == syms_.begin())
       break;