Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hypothetical syntax #16

Closed
4ast opened this issue May 26, 2015 · 1 comment
Closed

hypothetical syntax #16

4ast opened this issue May 26, 2015 · 1 comment

Comments

@4ast
Copy link
Member

4ast commented May 26, 2015

Is it possible to support the following .py?

#!/usr/bin/env python

from ctypes import c_uint, c_ulong, Structure
from bpf import BPF
from time import sleep
import sys

s = """
#include <linux/ptrace.h>
#include "../../src/cc/bpf_helpers.h"
struct Ptr { u64 ptr; };
struct Counters { u64 stat1; };

BPF_TABLE("hash", struct Ptr, struct Counters, stats, 1024);

int count_sched(struct pt_regs *ctx) {
  struct Ptr key = {.ptr=ctx->bx};
  struct Counters zleaf = {0};
  stats.upsert(&key, &zleaf)->stat1++;
  return 0;
}

int count_sched2(struct pt_regs *ctx) {
  return 0;
}
"""

class Ptr(Structure):
    _fields_ = [("ptr", c_ulong)]
class Counters(Structure):
    _fields_ = [("stat1", c_ulong)]

blob = BPF(s)

blob["count_sched"].load(BPF.BPF_PROG_TYPE_KPROBE)
blob["count_sched2"].load(BPF.BPF_PROG_TYPE_KPROBE)

stats[2] = blob["count_sched"].fd
stats[3] = blob["count_sched2"].fd

stats = blob.table("stats", Ptr, Counters)
attach_kprobe(blob["count_sched"].fd, "schedule", 0, -1)

for i in range(0, 100):
    sleep(0.01)
for key in stats.iter():
    leaf = stats.get(key)
    print("ptr %x:" % key.ptr, "stat1 %x" % leaf.stat1)
drzaeus77 pushed a commit that referenced this issue May 27, 2015
* Introduce Function object in bpf.py
 - prog load types (kprobe, socket, etc.) are independent
 - fd is a member of each function, to be used later (e.g. tail call table)
* Allow functions to be defined inline in the .py as a text argument
* Rename BPFProgram to BPFModule, which should make more sense

Signed-off-by: Brenden Blanco <[email protected]>
4ast pushed a commit that referenced this issue May 27, 2015
@drzaeus77
Copy link
Collaborator

This is now supported in the C flavor of the frontend. Considering closed for now unless we want to introduce this for B as well.

chantra added a commit to chantra/bcc that referenced this issue Jul 8, 2022
Testing: Added a new test to test_clang that loads a program of type `CGROUP_SOCKOPT`

```
16: .
16: ----------------------------------------------------------------------
16: Ran 84 tests in 83.695s
16:
16: OK (skipped=4)
16: 0
16/41 Test iovisor#16: py_test_clang ....................   Passed   84.14 sec
```
ekyooo added a commit to ekyooo/bcc that referenced this issue Dec 29, 2023
offcputime may display inaccurate DSO information in the stacktrace.
Here's an example of the issue:

It shows the same DSO offset for different addresses, which is incorrect.
  $ ./offcputime -v
    ..
    iovisor#14 0x00007f8b912a8c (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#15 0x000044000a3ee0 (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#16 0x000044001fc56c (/usr/lib/libcbe.so_0x22afa8c)

This is why syms__map_addr_dso simply returns NULL when syms__find_dso also
returns NULL. In that case, the values of dso_name and dso_offset are not
changed. If the dso_name and dso_offset variables have a garbage value before
calling syms__map_addr_dso, those garbage values are maintained after calling
syms__map_addr_dso.

To ensure consistent usage of DSO info and symbol info, the prototype of
syms__map_addr_dso has been modified to be similar to dladdr[1].

This is the prototype of dladdr:
  int dladdr(void *addr, Dl_info *info);

The information is returned in a Dl_info structure. If no symbol matching addr
could be found, then dli_sname and dli_saddr are set to NULL.
  typedef struct {
      const char *dli_fname;  /* Pathname of shared object that
                                contains address */
      void       *dli_fbase;  /* Base address at which shared
                                object is loaded */
      const char *dli_sname;  /* Name of symbol whose definition
                                overlaps addr */
      void       *dli_saddr;  /* Exact address of symbol named
                                in dli_sname */
   } Dl_info;

Similarly, if no symbol matching the addr could be found, then sym_name and
sym_offset are set to NULL in syms__map_addr_dso of this patch.

Also, apply the modified API usage to offcputime, futexctn, and memleak.

[1] https://man7.org/linux/man-pages/man3/dladdr.3.html
ekyooo added a commit to ekyooo/bcc that referenced this issue Dec 29, 2023
offcputime may display inaccurate DSO information in the stacktrace.
Here's an example of the issue:

It shows the same DSO offset for different addresses, which is incorrect.
  $ ./offcputime -v
    ..
    iovisor#14 0x00007f8b912a8c (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#15 0x000044000a3ee0 (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#16 0x000044001fc56c (/usr/lib/libcbe.so_0x22afa8c)

This is why syms__map_addr_dso simply returns NULL when syms__find_dso also
returns NULL. In that case, the values of dso_name and dso_offset are not
changed. If the dso_name and dso_offset variables have a garbage value before
calling syms__map_addr_dso, those garbage values are maintained after calling
syms__map_addr_dso.

To ensure consistent usage of DSO info and symbol info, the prototype of
syms__map_addr_dso has been modified to be similar to dladdr[1].

This is the prototype of dladdr:
  int dladdr(void *addr, Dl_info *info);

The information is returned in a Dl_info structure. If no symbol matching addr
could be found, then dli_sname and dli_saddr are set to NULL.
  typedef struct {
      const char *dli_fname;  /* Pathname of shared object that
                                contains address */
      void       *dli_fbase;  /* Base address at which shared
                                object is loaded */
      const char *dli_sname;  /* Name of symbol whose definition
                                overlaps addr */
      void       *dli_saddr;  /* Exact address of symbol named
                                in dli_sname */
   } Dl_info;

Similarly, if no symbol matching the addr could be found, then sym_name and
sym_offset are set to NULL in syms__map_addr_dso of this patch.

Also, apply the modified API usage to offcputime, futexctn, and memleak.

[1] https://man7.org/linux/man-pages/man3/dladdr.3.html
ekyooo added a commit to ekyooo/bcc that referenced this issue Jan 2, 2024
offcputime may display inaccurate DSO information in the stacktrace.
Here's an example of the issue:

It shows the same DSO offset for different addresses, which is incorrect.
  $ ./offcputime -v
    ..
    iovisor#14 0x00007f8b912a8c (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#15 0x000044000a3ee0 (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#16 0x000044001fc56c (/usr/lib/libcbe.so_0x22afa8c)

This is why syms__map_addr_dso simply returns NULL when syms__find_dso also
returns NULL. In that case, the values of dso_name and dso_offset are not
changed. If the dso_name and dso_offset variables have a garbage value before
calling syms__map_addr_dso, those garbage values are maintained after calling
syms__map_addr_dso.

To ensure consistent usage of DSO info and symbol info, the prototype of
syms__map_addr_dso has been modified to be similar to dladdr[1].

This is the prototype of dladdr:
  int dladdr(void *addr, Dl_info *info);

The information is returned in a Dl_info structure. If no symbol matching addr
could be found, then dli_sname and dli_saddr are set to NULL.
  typedef struct {
      const char *dli_fname;  /* Pathname of shared object that
                                contains address */
      void       *dli_fbase;  /* Base address at which shared
                                object is loaded */
      const char *dli_sname;  /* Name of symbol whose definition
                                overlaps addr */
      void       *dli_saddr;  /* Exact address of symbol named
                                in dli_sname */
   } Dl_info;

Similarly, if no symbol matching the addr could be found, then sym_name and
sym_offset are set to NULL in syms__map_addr_dso of this patch.

Also, apply the modified API usage to offcputime, futexctn, and memleak.

[1] https://man7.org/linux/man-pages/man3/dladdr.3.html
ekyooo added a commit to ekyooo/bcc that referenced this issue Feb 6, 2024
…tacktrace

offcputime may display inaccurate DSO information in the stacktrace.
Here's an example of the issue:

It shows the same DSO offset for different addresses, which is incorrect.
  $ ./offcputime -v
    ..
    iovisor#14 0x00007f8b912a8c (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#15 0x000044000a3ee0 (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#16 0x000044001fc56c (/usr/lib/libcbe.so_0x22afa8c)

This is why syms__map_addr_dso simply returns NULL when syms__find_dso also
returns NULL. In that case, the values of dso_name and dso_offset are not
changed. If the dso_name and dso_offset variables have a garbage value before
calling syms__map_addr_dso, those garbage values are maintained after calling
syms__map_addr_dso.

This patch fixes the issue by reinitializing dso_name and dso_offset variables
before calling syms__map_addr_dso.
ekyooo added a commit to ekyooo/bcc that referenced this issue Feb 6, 2024
offcputime may display inaccurate DSO information in the stacktrace.
Here's an example of the issue:

It shows the same DSO offset for different addresses, which is incorrect.
  $ ./offcputime -v
    ..
    iovisor#14 0x00007f8b912a8c (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#15 0x000044000a3ee0 (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#16 0x000044001fc56c (/usr/lib/libcbe.so_0x22afa8c)

This is why syms__map_addr_dso simply returns NULL when syms__find_dso also
returns NULL. In that case, the values of dso_name and dso_offset are not
changed. If the dso_name and dso_offset variables have a garbage value before
calling syms__map_addr_dso, those garbage values are maintained after calling
syms__map_addr_dso.

To ensure consistent usage of DSO info and symbol info, the prototype of
syms__map_addr_dso has been modified to be similar to dladdr[1].

This is the prototype of dladdr:
  int dladdr(void *addr, Dl_info *info);

The information is returned in a Dl_info structure. If no symbol matching addr
could be found, then dli_sname and dli_saddr are set to NULL.
  typedef struct {
      const char *dli_fname;  /* Pathname of shared object that
                                contains address */
      void       *dli_fbase;  /* Base address at which shared
                                object is loaded */
      const char *dli_sname;  /* Name of symbol whose definition
                                overlaps addr */
      void       *dli_saddr;  /* Exact address of symbol named
                                in dli_sname */
   } Dl_info;

Similarly, if no symbol matching the addr could be found, then sym_name and
sym_offset are set to NULL in syms__map_addr_dso of this patch.

Also, apply the modified API usage to offcputime, futexctn, and memleak.

[1] https://man7.org/linux/man-pages/man3/dladdr.3.html
yonghong-song pushed a commit that referenced this issue Feb 6, 2024
…tacktrace (#4902)

offcputime may display inaccurate DSO information in the stacktrace.
Here's an example of the issue:

It shows the same DSO offset for different addresses, which is incorrect.
  $ ./offcputime -v
    ..
    #14 0x00007f8b912a8c (/usr/lib/libcbe.so_0x22afa8c)
    #15 0x000044000a3ee0 (/usr/lib/libcbe.so_0x22afa8c)
    #16 0x000044001fc56c (/usr/lib/libcbe.so_0x22afa8c)

This is why syms__map_addr_dso simply returns NULL when syms__find_dso also
returns NULL. In that case, the values of dso_name and dso_offset are not
changed. If the dso_name and dso_offset variables have a garbage value before
calling syms__map_addr_dso, those garbage values are maintained after calling
syms__map_addr_dso.

This patch fixes the issue by reinitializing dso_name and dso_offset variables
before calling syms__map_addr_dso.

Co-authored-by: Eunseon Lee <[email protected]>
ekyooo added a commit to ekyooo/bcc that referenced this issue Apr 16, 2024
offcputime may display inaccurate DSO information in the stacktrace.
Here's an example of the issue:

It shows the same DSO offset for different addresses, which is incorrect.
  $ ./offcputime -v
    ..
    iovisor#14 0x00007f8b912a8c (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#15 0x000044000a3ee0 (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#16 0x000044001fc56c (/usr/lib/libcbe.so_0x22afa8c)

This is why syms__map_addr_dso simply returns NULL when syms__find_dso also
returns NULL. In that case, the values of dso_name and dso_offset are not
changed. If the dso_name and dso_offset variables have a garbage value before
calling syms__map_addr_dso, those garbage values are maintained after calling
syms__map_addr_dso.

To ensure consistent usage of DSO info and symbol info, the prototype of
syms__map_addr_dso has been modified to be similar to dladdr[1].

This is the prototype of dladdr:
  int dladdr(void *addr, Dl_info *info);

The information is returned in a Dl_info structure. If no symbol matching addr
could be found, then dli_sname and dli_saddr are set to NULL.
  typedef struct {
      const char *dli_fname;  /* Pathname of shared object that
                                contains address */
      void       *dli_fbase;  /* Base address at which shared
                                object is loaded */
      const char *dli_sname;  /* Name of symbol whose definition
                                overlaps addr */
      void       *dli_saddr;  /* Exact address of symbol named
                                in dli_sname */
   } Dl_info;

Similarly, if no symbol matching the addr could be found, then sym_name and
sym_offset are set to NULL in syms__map_addr_dso of this patch.

Also, apply the modified API usage to offcputime, futexctn, and memleak.

[1] https://man7.org/linux/man-pages/man3/dladdr.3.html
chenhengqi pushed a commit that referenced this issue May 2, 2024
offcputime may display inaccurate DSO information in the stacktrace.
Here's an example of the issue:

It shows the same DSO offset for different addresses, which is incorrect.
  $ ./offcputime -v
    ..
    #14 0x00007f8b912a8c (/usr/lib/libcbe.so_0x22afa8c)
    #15 0x000044000a3ee0 (/usr/lib/libcbe.so_0x22afa8c)
    #16 0x000044001fc56c (/usr/lib/libcbe.so_0x22afa8c)

This is why syms__map_addr_dso simply returns NULL when syms__find_dso also
returns NULL. In that case, the values of dso_name and dso_offset are not
changed. If the dso_name and dso_offset variables have a garbage value before
calling syms__map_addr_dso, those garbage values are maintained after calling
syms__map_addr_dso.

To ensure consistent usage of DSO info and symbol info, the prototype of
syms__map_addr_dso has been modified to be similar to dladdr[1].

This is the prototype of dladdr:
  int dladdr(void *addr, Dl_info *info);

The information is returned in a Dl_info structure. If no symbol matching addr
could be found, then dli_sname and dli_saddr are set to NULL.
  typedef struct {
      const char *dli_fname;  /* Pathname of shared object that
                                contains address */
      void       *dli_fbase;  /* Base address at which shared
                                object is loaded */
      const char *dli_sname;  /* Name of symbol whose definition
                                overlaps addr */
      void       *dli_saddr;  /* Exact address of symbol named
                                in dli_sname */
   } Dl_info;

Similarly, if no symbol matching the addr could be found, then sym_name and
sym_offset are set to NULL in syms__map_addr_dso of this patch.

Also, apply the modified API usage to offcputime, futexctn, and memleak.

[1] https://man7.org/linux/man-pages/man3/dladdr.3.html
dkruces pushed a commit to dkruces/bcc that referenced this issue Nov 28, 2024
…tacktrace (iovisor#4902)

offcputime may display inaccurate DSO information in the stacktrace.
Here's an example of the issue:

It shows the same DSO offset for different addresses, which is incorrect.
  $ ./offcputime -v
    ..
    iovisor#14 0x00007f8b912a8c (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#15 0x000044000a3ee0 (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#16 0x000044001fc56c (/usr/lib/libcbe.so_0x22afa8c)

This is why syms__map_addr_dso simply returns NULL when syms__find_dso also
returns NULL. In that case, the values of dso_name and dso_offset are not
changed. If the dso_name and dso_offset variables have a garbage value before
calling syms__map_addr_dso, those garbage values are maintained after calling
syms__map_addr_dso.

This patch fixes the issue by reinitializing dso_name and dso_offset variables
before calling syms__map_addr_dso.

Co-authored-by: Eunseon Lee <[email protected]>
dkruces pushed a commit to dkruces/bcc that referenced this issue Nov 28, 2024
offcputime may display inaccurate DSO information in the stacktrace.
Here's an example of the issue:

It shows the same DSO offset for different addresses, which is incorrect.
  $ ./offcputime -v
    ..
    iovisor#14 0x00007f8b912a8c (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#15 0x000044000a3ee0 (/usr/lib/libcbe.so_0x22afa8c)
    iovisor#16 0x000044001fc56c (/usr/lib/libcbe.so_0x22afa8c)

This is why syms__map_addr_dso simply returns NULL when syms__find_dso also
returns NULL. In that case, the values of dso_name and dso_offset are not
changed. If the dso_name and dso_offset variables have a garbage value before
calling syms__map_addr_dso, those garbage values are maintained after calling
syms__map_addr_dso.

To ensure consistent usage of DSO info and symbol info, the prototype of
syms__map_addr_dso has been modified to be similar to dladdr[1].

This is the prototype of dladdr:
  int dladdr(void *addr, Dl_info *info);

The information is returned in a Dl_info structure. If no symbol matching addr
could be found, then dli_sname and dli_saddr are set to NULL.
  typedef struct {
      const char *dli_fname;  /* Pathname of shared object that
                                contains address */
      void       *dli_fbase;  /* Base address at which shared
                                object is loaded */
      const char *dli_sname;  /* Name of symbol whose definition
                                overlaps addr */
      void       *dli_saddr;  /* Exact address of symbol named
                                in dli_sname */
   } Dl_info;

Similarly, if no symbol matching the addr could be found, then sym_name and
sym_offset are set to NULL in syms__map_addr_dso of this patch.

Also, apply the modified API usage to offcputime, futexctn, and memleak.

[1] https://man7.org/linux/man-pages/man3/dladdr.3.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants