Skip to content

Commit

Permalink
Merge pull request iovisor#456 from yadutaf/jt-endian
Browse files Browse the repository at this point in the history
Minor endian and debug enhancement
  • Loading branch information
drzaeus77 committed Mar 29, 2016
2 parents 354ee0c + 7d37bf4 commit 6c08dcb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/cc/frontends/clang/b_frontend_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ BFrontendAction::BFrontendAction(llvm::raw_ostream &os, unsigned flags)
}

void BFrontendAction::EndSourceFileAction() {
if (flags_ & 0x4)
if (flags_ & DEBUG_PREPROCESSOR)
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID()).write(llvm::errs());
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID()).write(os_);
os_.flush();
Expand Down
2 changes: 2 additions & 0 deletions src/cc/frontends/clang/b_frontend_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include "table_desc.h"

#define DEBUG_PREPROCESSOR 0x4

namespace clang {
class ASTConsumer;
class ASTContext;
Expand Down
3 changes: 3 additions & 0 deletions src/cc/frontends/clang/kbuild_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ int KBuildHelper::get_flags(const char *uname_machine, vector<string> *cflags) {
cflags->push_back("-include");
cflags->push_back("./include/linux/kconfig.h");
cflags->push_back("-D__KERNEL__");
cflags->push_back("-D__HAVE_BUILTIN_BSWAP16__");
cflags->push_back("-D__HAVE_BUILTIN_BSWAP32__");
cflags->push_back("-D__HAVE_BUILTIN_BSWAP64__");
cflags->push_back("-Wno-unused-value");
cflags->push_back("-Wno-pointer-sign");

Expand Down
2 changes: 1 addition & 1 deletion src/cc/frontends/clang/loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int ClangLoader::parse(unique_ptr<llvm::Module> *mod, unique_ptr<vector<TableDes
// Initialize a compiler invocation object from the clang (-cc1) arguments.
const driver::ArgStringList &ccargs = cmd.getArguments();

if (flags_ & 0x4) {
if (flags_ & DEBUG_PREPROCESSOR) {
llvm::errs() << "clang";
for (auto arg : ccargs)
llvm::errs() << " " << arg;
Expand Down
17 changes: 8 additions & 9 deletions src/python/bcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@
ksym_names = {}
ksym_loaded = 0
_kprobe_limit = 1000
BASE_CFLAGS = [
'-D__HAVE_BUILTIN_BSWAP16__',
'-D__HAVE_BUILTIN_BSWAP32__',
'-D__HAVE_BUILTIN_BSWAP64__',
]

DEBUG_LLVM_IR = 0x1
DEBUG_BPF = 0x2
DEBUG_PREPROCESSOR = 0x4

@atexit.register
def cleanup_kprobes():
Expand Down Expand Up @@ -137,16 +136,16 @@ def __init__(self, src_file="", hdr_file="", text=None, cb=None, debug=0, cflags
hdr_file (Optional[str]): Path to a helper header file for the `src_file`
text (Optional[str]): Contents of a source file for the module
debug (Optional[int]): Flags used for debug prints, can be |'d together
0x1: print LLVM IR to stderr
0x2: print BPF bytecode to stderr
DEBUG_LLVM_IR: print LLVM IR to stderr
DEBUG_BPF: print BPF bytecode to stderr
DEBUG_PREPROCESSOR: print Preprocessed C file to stderr
"""

self._reader_cb_impl = _CB_TYPE(BPF._reader_cb)
self._user_cb = cb
self.debug = debug
self.funcs = {}
self.tables = {}
cflags = BASE_CFLAGS + cflags
cflags_array = (ct.c_char_p * len(cflags))()
for i, s in enumerate(cflags): cflags_array[i] = s.encode("ascii")
if text:
Expand Down Expand Up @@ -198,7 +197,7 @@ def load_func(self, func_name, prog_type):
lib.bpf_module_kern_version(self.module),
log_buf, ct.sizeof(log_buf) if log_buf else 0)

if self.debug & 0x2:
if self.debug & DEBUG_BPF:
print(log_buf.value.decode(), file=sys.stderr)

if fd < 0:
Expand Down

0 comments on commit 6c08dcb

Please sign in to comment.