Skip to content

Commit

Permalink
implement DEBUG_BTF flag (iovisor#2202)
Browse files Browse the repository at this point in the history
silence BTF related warning messages by default.
The DEBUG_BTF is added to enable such warning messages.

Signed-off-by: Yonghong Song <[email protected]>
  • Loading branch information
yonghong-song committed Feb 14, 2019
1 parent 6c79c68 commit 75a1f3d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
26 changes: 22 additions & 4 deletions src/cc/bcc_btf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/

#include "bcc_btf.h"
#include <stdarg.h>
#include <string.h>
#include "linux/btf.h"
#include "libbpf.h"
#include "libbpf/src/libbpf.h"
#include "libbpf/src/btf.h"
#include <vector>

Expand All @@ -41,11 +43,27 @@ uint32_t BTFStringTable::addString(std::string S) {
return Offset;
}

BTF::BTF(bool debug) : debug_(debug), btf_(nullptr), btf_ext_(nullptr) {
if (!debug)
libbpf_set_print(NULL);
}

BTF::~BTF() {
btf__free(btf_);
btf_ext__free(btf_ext_);
}

void BTF::warning(const char *format, ...) {
va_list args;

if (!debug_)
return;

va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}

// The compiler doesn't have source code for remapped files.
// So we modify .BTF and .BTF.ext sections here to add these
// missing line source codes.
Expand Down Expand Up @@ -153,14 +171,14 @@ int BTF::load(uint8_t *btf_sec, uintptr_t btf_sec_size,
btf = btf__new(btf_sec, btf_sec_size);
}
if (BCC_IS_ERR(btf)) {
fprintf(stderr, "Processing .BTF section failure\n");
warning("Processing .BTF section failed\n");
return -1;
}

btf_ext = btf_ext__new(btf_ext_sec, btf_ext_sec_size);
if (BCC_IS_ERR(btf_ext)) {
btf__free(btf);
fprintf(stderr, "Processing .BTF.ext section failure\n");
warning("Processing .BTF.ext section failed\n");
return -1;
}

Expand Down Expand Up @@ -189,14 +207,14 @@ int BTF::get_btf_info(const char *fname,
ret = btf_ext__reloc_func_info(btf_, btf_ext_, fname, 0,
func_info, func_info_cnt);
if (ret) {
fprintf(stderr, ".BTF.ext reloc func_info not successful\n");
warning(".BTF.ext reloc func_info failed\n");
return ret;
}

ret = btf_ext__reloc_line_info(btf_, btf_ext_, fname, 0,
line_info, line_info_cnt);
if (ret) {
fprintf(stderr, ".BTF.ext reloc line_info not successful\n");
warning(".BTF.ext reloc line_info failed\n");
return ret;
}

Expand Down
3 changes: 3 additions & 0 deletions src/cc/bcc_btf.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class BTFStringTable {

class BTF {
public:
BTF(bool debug);
~BTF();
int load(uint8_t *btf_sec, uintptr_t btf_sec_size,
uint8_t *btf_ext_sec, uintptr_t btf_ext_sec_size,
Expand All @@ -62,8 +63,10 @@ class BTF {
uint8_t *btf_ext_sec, uintptr_t btf_ext_sec_size,
std::map<std::string, std::string> &remapped_sources,
uint8_t **new_btf_sec, uintptr_t *new_btf_sec_size);
void warning(const char *format, ...);

private:
bool debug_;
struct btf *btf_;
struct btf_ext *btf_ext_;
};
Expand Down
2 changes: 1 addition & 1 deletion src/cc/bpf_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void BPFModule::load_btf(std::map<std::string, std::tuple<uint8_t *, uintptr_t>>
remapped_sources["/virtual/main.c"] = mod_src_;
remapped_sources["/virtual/include/bcc/helpers.h"] = helpers_h->second;

BTF *btf = new BTF();
BTF *btf = new BTF(flags_ & DEBUG_BTF);
int ret = btf->load(btf_sec, btf_sec_size, btf_ext_sec, btf_ext_sec_size,
remapped_sources);
if (ret) {
Expand Down
2 changes: 2 additions & 0 deletions src/cc/bpf_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ enum {
DEBUG_SOURCE = 0x8,
// Debug output register state on all instructions in addition to DEBUG_BPF.
DEBUG_BPF_REGISTER_STATE = 0x10,
// Debug BTF.
DEBUG_BTF = 0x20,
};

class TableDesc;
Expand Down
4 changes: 3 additions & 1 deletion src/python/bcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ def _get_num_open_probes():
DEBUG_PREPROCESSOR = 0x4
# Debug output ASM instructions embedded with source.
DEBUG_SOURCE = 0x8
#Debug output register state on all instructions in addition to DEBUG_BPF.
# Debug output register state on all instructions in addition to DEBUG_BPF.
DEBUG_BPF_REGISTER_STATE = 0x10
# Debug BTF.
DEBUG_BTF = 0x20

class SymbolCache(object):
def __init__(self, pid):
Expand Down

0 comments on commit 75a1f3d

Please sign in to comment.