Git Product home page Git Product logo

Comments (13)

drzaeus77 avatar drzaeus77 commented on May 14, 2024

The pending fix addresses the buggy rewrite pass that was mangling the sample you included. However, you will still need to pass &req, since the prototype for lookup/delete/etc. is a pointer to a key, which therefore should be struct request **

from bcc.

brendangregg avatar brendangregg commented on May 14, 2024

ok, sounds good, thanks.

from bcc.

brendangregg avatar brendangregg commented on May 14, 2024

I really want to use this, but got a build error:

[...]
/mnt/src/bcc/src/cc/frontends/clang/b_frontend_action.cc: At global scope:
/mnt/src/bcc/src/cc/frontends/clang/b_frontend_action.cc:437:1: error: prototype for ‘ebpf::BFrontendAction::BFrontendAction(llvm::raw_ostream&, unsigned int)’ does not match any in class ‘ebpf::BFrontendAction’
 BFrontendAction::BFrontendAction(llvm::raw_ostream &os, unsigned flags)
 ^
In file included from /mnt/src/bcc/src/cc/frontends/clang/b_frontend_action.cc:26:0:
/mnt/src/bcc/src/cc/frontends/clang/b_frontend_action.h:95:7: error: candidates are: ebpf::BFrontendAction::BFrontendAction(ebpf::BFrontendAction&&)
 class BFrontendAction : public clang::ASTFrontendAction {
       ^
/mnt/src/bcc/src/cc/frontends/clang/b_frontend_action.h:95:7: error:                 ebpf::BFrontendAction::BFrontendAction(const ebpf::BFrontendAction&)
/mnt/src/bcc/src/cc/frontends/clang/b_frontend_action.h:99:12: error:                 ebpf::BFrontendAction::BFrontendAction(llvm::raw_ostream&)
   explicit BFrontendAction(llvm::raw_ostream &os);
            ^
/mnt/src/bcc/src/cc/frontends/clang/b_frontend_action.cc: In member function ‘virtual void ebpf::BFrontendAction::EndSourceFileAction()’:
/mnt/src/bcc/src/cc/frontends/clang/b_frontend_action.cc:443:7: error: ‘flags_’ was not declared in this scope
   if (flags_ & 0x4)
       ^
make[2]: *** [src/cc/frontends/clang/CMakeFiles/clang_frontend.dir/b_frontend_action.cc.o] Error 1
make[1]: *** [src/cc/frontends/clang/CMakeFiles/clang_frontend.dir/all] Error 2
make: *** [all] Error 2

from bcc.

drzaeus77 avatar drzaeus77 commented on May 14, 2024

There must be some stale code hanging around somewhere. Did you try the usual suspects, like cleaning the build directory?

from bcc.

brendangregg avatar brendangregg commented on May 14, 2024

Yes, both make clean, and deleting the build directory...

# cksum src/cc/frontends/clang/b_frontend_action.cc tests/cc/test_clang.py 
2865925912 18014 src/cc/frontends/clang/b_frontend_action.cc
4147208165 3547 tests/cc/test_clang.py

from bcc.

drzaeus77 avatar drzaeus77 commented on May 14, 2024

That's indeed very odd. Nothing comes to mind...let me know how I might help. The build passed on both buildbots, with gcc4.8+ubuntu14.04 and clang+fedora22 variants, as well as my arch linux gcc 5.2 box.

from bcc.

brendangregg avatar brendangregg commented on May 14, 2024

Might have been an older clang (rebuilding). I get further on a newer built system:

# ./disksnoop.py 
<bcc-memory-buffer>:24:51: error: cannot take the address of an rvalue of type 'u64' (aka 'unsigned long long')
        bpf_map_update_elem((void *)bpf_pseudo_fd(1, 3), &((u64)ctx->di), &ts, BPF_ANY);
                                                         ^ ~~~~~~~~~~~~
<bcc-memory-buffer>:33:60: error: use of undeclared identifier 'u'
        tsp = bpf_map_lookup_elem((void *)bpf_pseudo_fd(1, 3), &((u);
                                                                  ^
<bcc-memory-buffer>:43:2: error: expected '}'
}
 ^
<bcc-memory-buffer>:30:74: note: to match this '{'
int kprobe__blk_update_request(struct pt_regs *ctx, struct request *req) {
                                                                         ^
3 errors generated.
Traceback (most recent call last):
  File "./disksnoop.py", line 19, in <module>
    b = BPF(src_file="disksnoop.c")
  File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 349, in __init__
    raise Exception("Failed to compile BPF module %s" % src_file)
Exception: Failed to compile BPF module disksnoop.c

Running:

#include <uapi/linux/ptrace.h>
#include <linux/blkdev.h>

BPF_HASH(start, struct request *);

int kprobe__blk_start_request(struct pt_regs *ctx, struct request *req) {
    u64 ts;

    // stash start timestamp by request ptr
    ts = bpf_ktime_get_ns();
    start.update(&req, &ts);

    return 0;
}

int kprobe__blk_update_request(struct pt_regs *ctx, struct request *req) {
    u64 *tsp, delta;

    tsp = start.lookup(&req);

    if (tsp != 0) {
        delta = bpf_ktime_get_ns() - *tsp;
        bpf_trace_printk("%d %x %d\n", req->__data_len,
            req->cmd_flags, delta / 1000);
        start.delete(&req);
    }

    return 0;
}

from bcc.

drzaeus77 avatar drzaeus77 commented on May 14, 2024

This should have been fixed by this very commit. Have you done make install?

A new parameter with the recent changeset is BPF(..., debug=0x4) which will print the clang-rewritten source. If you see no output when providing that flag, then the old library is still being loaded.

from bcc.

brendangregg avatar brendangregg commented on May 14, 2024

debug=0x4 prints nothing new. I've done a fresh bcc build with https://raw.githubusercontent.com/iovisor/bcc/3c4a29ced84bea80b957d21256d529afb02eb634/src/cc/frontends/clang/b_frontend_action.cc ...

from bcc.

drzaeus77 avatar drzaeus77 commented on May 14, 2024

Can you try from HEAD? There is a further fix that went in at 0ac26e8, as well the debug=0x4 flag requires a bunch of extra file changes to pass the flag to BFrontendAction.

from bcc.

brendangregg avatar brendangregg commented on May 14, 2024

I still can't see any debug code...

# clang --version
clang version 3.8.0 (http://llvm.org/git/clang.git 93885ee97cd4a65cc773a654cb2d15b2890c81a2) (http://llvm.org/git/llvm.git 2354b37ae030104dd424149804946722fce72872)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /mnt/src/llvm/build/install/bin

from bcc.

brendangregg avatar brendangregg commented on May 14, 2024

Ok, back to the system I rebuilt clang on... that now works with disksnoop.c as listed previously. This works, thanks!

from bcc.

drzaeus77 avatar drzaeus77 commented on May 14, 2024

Ok, closing then :)

from bcc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.