Support symbol option in C++ API stack table
authorTeng Qin <qinteng@fb.com>
Tue, 23 May 2017 18:30:33 +0000 (11:30 -0700)
committerTeng Qin <qinteng@fb.com>
Tue, 23 May 2017 18:30:33 +0000 (11:30 -0700)
src/cc/BPF.cc
src/cc/BPF.h
src/cc/BPFTable.cc
src/cc/BPFTable.h
src/cc/bcc_syms.cc
src/cc/bcc_syms.h

index 74577ffadb585a48980c07fdcf4f9cd8d7693203..ab51bd78e5bbf59dd1cc3220f2362db6fd2f3310 100644 (file)
@@ -504,11 +504,13 @@ BPFProgTable BPF::get_prog_table(const std::string& name) {
   return BPFProgTable({});
 }
 
-BPFStackTable BPF::get_stack_table(const std::string& name) {
+BPFStackTable BPF::get_stack_table(const std::string& name,
+                                   bool use_debug_file,
+                                   bool check_debug_file_crc) {
   TableStorage::iterator it;
   if (bpf_module_->table_storage().Find(Path({bpf_module_->id(), name}), it))
-    return BPFStackTable(it->second);
-  return BPFStackTable({});
+    return BPFStackTable(it->second, use_debug_file, check_debug_file_crc);
+  return BPFStackTable({}, use_debug_file, check_debug_file_crc);
 }
 
 std::string BPF::get_uprobe_event(const std::string& binary_path,
index b9f298edb47a5e5b3528d9b6cafd692e6d97b0a7..30c864aecf55677728bfe11ec9996f0367d12a1f 100644 (file)
@@ -115,7 +115,9 @@ public:
 
   BPFProgTable get_prog_table(const std::string& name);
 
-  BPFStackTable get_stack_table(const std::string& name);
+  BPFStackTable get_stack_table(const std::string& name,
+                                bool use_debug_file = true,
+                                bool check_debug_file_crc = true);
 
   StatusTuple open_perf_buffer(const std::string& name,
                                perf_reader_raw_cb cb,
index 2fa928b197620a12f15c7efaa04ec9572ccb9b45..b9f6397cc6ca156cd0ca4d1ad6d92415cbc3c403 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <linux/elf.h>
 #include <sys/epoll.h>
 #include <unistd.h>
 #include <cerrno>
@@ -86,6 +87,17 @@ StatusTuple BPFTable::remove_value(const std::string& key_str) {
   return StatusTuple(0);
 }
 
+BPFStackTable::BPFStackTable(const TableDesc& desc,
+                             bool use_debug_file,
+                             bool check_debug_file_crc)
+  : BPFTableBase<int, stacktrace_t>(desc) {
+  symbol_option_ = {
+    .use_debug_file = use_debug_file,
+    .check_debug_file_crc = check_debug_file_crc,
+    .use_symbol_type = (1 << STT_FUNC) | (1 << STT_GNU_IFUNC)
+  };
+}
+
 BPFStackTable::~BPFStackTable() {
   for (auto it : pid_sym_)
     bcc_free_symcache(it.second, it.first);
@@ -110,7 +122,7 @@ std::vector<std::string> BPFStackTable::get_stack_symbol(int stack_id,
   if (pid < 0)
     pid = -1;
   if (pid_sym_.find(pid) == pid_sym_.end())
-    pid_sym_[pid] = bcc_symcache_new(pid, nullptr);
+    pid_sym_[pid] = bcc_symcache_new(pid, &symbol_option_);
   void* cache = pid_sym_[pid];
 
   bcc_symbol symbol;
index 655e9332056ad6415fe9879cbf5bf762f2efde2b..7e7763be77bd9a9063a60411d962751bc936d1dc 100644 (file)
@@ -26,6 +26,7 @@
 #include <vector>
 
 #include "bcc_exception.h"
+#include "bcc_syms.h"
 #include "bpf_module.h"
 #include "libbpf.h"
 #include "perf_reader.h"
@@ -205,14 +206,16 @@ struct stacktrace_t {
 
 class BPFStackTable : public BPFTableBase<int, stacktrace_t> {
  public:
-  BPFStackTable(const TableDesc& desc)
-      : BPFTableBase<int, stacktrace_t>(desc) {}
+  BPFStackTable(const TableDesc& desc,
+                bool use_debug_file,
+                bool check_debug_file_crc);
   ~BPFStackTable();
 
   std::vector<uintptr_t> get_stack_addr(int stack_id);
   std::vector<std::string> get_stack_symbol(int stack_id, int pid);
 
  private:
+  bcc_symbol_option symbol_option_;
   std::map<int, void*> pid_sym_;
 };
 
index 0d3b4a4a6bb445fdc56c38f20d8646aa1add734b..75e5e4fd72d11d6f689d6ce049ac39179e64af22 100644 (file)
 #include "syms.h"
 #include "vendor/tinyformat.hpp"
 
-#ifndef STT_GNU_IFUNC
-#define STT_GNU_IFUNC 10
-#endif
-
 ino_t ProcStat::getinode_() {
   struct stat s;
   return (!stat(procfs_.c_str(), &s)) ? s.st_ino : -1;
index 03047f2ac9297fd0ba643d6345f6c4f398dce447..5550f9514acf99863e853c0d6a11fcb5567bacac 100644 (file)
@@ -31,6 +31,9 @@ struct bcc_symbol {
 
 typedef int (*SYM_CB)(const char *symname, uint64_t addr);
 
+#ifndef STT_GNU_IFUNC
+#define STT_GNU_IFUNC 10
+#endif
 static const uint32_t BCC_SYM_ALL_TYPES = 65535;
 struct bcc_symbol_option {
   int use_debug_file;