1. 03 Oct, 2017 1 commit
    • Yonghong Song's avatar
      add debug option to dump asm insns embedded with source · 91837cac
      Yonghong Song authored
      The patch adds a new debug option "DEBUG_SOURCE = 8" to
      dump insns embedded with source. In C++ API, users
      can change BPF constructor "flag" value to enable debug output.
      In Python API, users can change "debug" value to enable
      debug output. For example, for python test program test_usdt.py,
      the debug output looks like below:
      
      ......
      Disassembly of section .bpf.fn.do_trace1:
      do_trace1:
      ; int do_trace1(struct pt_regs *ctx) { // Line 110
         0:   bf 16 00 00 00 00 00 00         r6 = r1
         1:   b7 01 00 00 00 00 00 00         r1 = 0
      ; struct probe_result_t1 result = {}; // Line 111
         2:   7b 1a f0 ff 00 00 00 00         *(u64 *)(r10 - 16) = r1
      ; switch(ctx->ip) { // Line   5
         3:   79 61 80 00 00 00 00 00         r1 = *(u64 *)(r6 + 128)
         4:   15 01 04 00 d7 06 40 00         if r1 == 4196055 goto 4
         5:   55 01 06 00 ce 06 40 00         if r1 != 4196046 goto 6
      ; case 0x4006ceULL: *((int8_t *)dest) = ctx->ax; __asm__ __volatile__("": : :"memory"); return 0; // Line   6
         6:   79 61 50 00 00 00 00 00         r1 = *(u64 *)(r6 + 80)
      ......
      
      For asm insns, byte code is also dumped out (similar to objdump).
      For source codes, only lines in the module file are printed (as expected).
      The line number is added at the end of source code, which is
      especially helpful for inlined functions.
      
      This functionality is only in llvm 6.x (the trunk version), which
      provides an public interface to create a dwarf context based on
      a set of in-memory debug sections. llvm 5.x also provides
      such a public interface in a different way, and this patch
      does not support it in bcc yet. llvm 4.x and lower do not
      have such a public interface and hence will not be supported
      in bcc.
      
      In this patch, the debug output only goes to stderr.
      A subsequent patch will dump the per-function output into
      <BCC_PROG_TAG_DIR>/bpf_prog_<tag>/ if it is available.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      91837cac
  2. 01 Oct, 2017 1 commit
  3. 29 Sep, 2017 1 commit
    • Paul Chaignon's avatar
      Traces external pointers in parenthesized expressions · c5ca2a67
      Paul Chaignon authored
      Partially reverts 80667b7b, "Fix unary operator handling of probe
      reads with parens", keeping the test case. With 4c6ecb46,
      "Restrict rewrite of unary operators to dereference operator," only
      dereferences are rewritten, removing the need for the previous fix.
      
      Reverting 80667b7b allows bcc to rewrite more dereferences, as
      highlighted in the new test case.
      c5ca2a67
  4. 28 Sep, 2017 3 commits
  5. 27 Sep, 2017 1 commit
  6. 26 Sep, 2017 6 commits
  7. 25 Sep, 2017 4 commits
    • Teng Qin's avatar
      Add ELF load ranges for executable binaries · 5db9d37b
      Teng Qin authored
      5db9d37b
    • Teng Qin's avatar
      Add common helper to read Process executable · 97562956
      Teng Qin authored
      97562956
    • yonghong-song's avatar
      Merge pull request #1357 from palmtenor/load_section · 899d3e92
      yonghong-song authored
      Fix edge case when doing symbol name -> address resolution
      899d3e92
    • Kirill Smelkov's avatar
      bpf_probe_read*: src argument should be const void *. · 2dc7daad
      Kirill Smelkov authored
      For the following program:
      
          #include <linux/interrupt.h>
      
          // remember t(last-interrupt) on interface
          int kprobe__handle_irq_event_percpu(struct pt_regs *ctx, struct irq_desc *desc) {
              const char *irqname = desc->action->name;
      
              char c;
      
              bpf_probe_read(&c, 1, &irqname[0]);
              if (c != 'e') return 0;
      
              bpf_probe_read(&c, 1, &irqname[1]);
              if (c != 't') return 0;
      
              ...
      
      LLVM gives warnings because irqaction->name is `const char *`:
      
          /virtual/main.c:10:27: warning: passing 'const char *' to parameter of type 'void *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
              bpf_probe_read(&c, 1, &irqname[0]);
                                    ^~~~~~~~~~~
          /virtual/main.c:13:27: warning: passing 'const char *' to parameter of type 'void *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
              bpf_probe_read(&c, 1, &irqname[1]);
                                    ^~~~~~~~~~~
          ...
      
      Instead of adding casts in source everywhere fix bpf_probe_read* signature to
      indicate the memory referenced by src won't be modified, as it should be.
      
      P.S.
      
      bpf_probe_read_str was in fact already marked so in several places in comments
      but not in actual signature.
      2dc7daad
  8. 21 Sep, 2017 6 commits
  9. 20 Sep, 2017 3 commits
  10. 15 Sep, 2017 2 commits
  11. 13 Sep, 2017 1 commit
  12. 12 Sep, 2017 2 commits
  13. 09 Sep, 2017 2 commits
  14. 08 Sep, 2017 4 commits
  15. 07 Sep, 2017 3 commits
    • 4ast's avatar
      Merge pull request #1336 from palmtenor/noinstance · 6aec3099
      4ast authored
      Do not create instance for kprobe
      6aec3099
    • Brendan Gregg's avatar
      Merge pull request #1333 from samuelnair/fix-py-tut · 08dbf13f
      Brendan Gregg authored
      Fix for bug in lesson 4 of the Python developer tutorial
      08dbf13f
    • Alexei Starovoitov's avatar
      annotate program tag · 4f47e3b5
      Alexei Starovoitov authored
      during debug of production systems it's difficult to trace back
      the kernel reported 'bpf_prog_4985bb0bd6c69631' symbols to the source code
      of the program, hence teach bcc to store the main function source
      in the /var/tmp/bcc/bpf_prog_4985bb0bd6c69631/ directory.
      
      This program tag is stable. Every time the script is called the tag
      will be the same unless source code of the program changes.
      During active development of bcc scripts the /var/tmp/bcc/ dir can
      get a bunch of stale tags. The users have to trim that dir manually.
      
      Python scripts can be modified to use this feature too, but probably
      need to be gated by the flag. For c++ api I think it makes sense
      to store the source code always, since the cost is minimal and
      c++ api is used by long running services.
      
      Example:
      $ ./examples/cpp/LLCStat
      $ ls -l /var/tmp/bcc/bpf_prog_4985bb0bd6c69631/
      total 16
      -rw-r--r--. 1 root root 226 Sep  1 17:30 on_cache_miss.c
      -rw-r--r--. 1 root root 487 Sep  1 17:30 on_cache_miss.rewritten.c
      -rw-r--r--. 1 root root 224 Sep  1 17:30 on_cache_ref.c
      -rw-r--r--. 1 root root 484 Sep  1 17:30 on_cache_ref.rewritten.c
      
      Note that there are two .c files there, since two different
      bpf programs have exactly the same bytecode hence same prog_tag.
      
      $ cat /var/tmp/bcc/bpf_prog_4985bb0bd6c69631/on_cache_miss.c
      int on_cache_miss(struct bpf_perf_event_data *ctx) {
          struct event_t key = {};
          get_key(&key);
      
          u64 zero = 0, *val;
          val = miss_count.lookup_or_init(&key, &zero);
      ...
      Signed-off-by: default avatarAlexei Starovoitov <ast@fb.com>
      4f47e3b5