Commit dfcdf0a0 authored by Brenden Blanco's avatar Brenden Blanco

Fix recursive loop in parsing pointer to self struct

Issue occurs in the description visitor class, when the struct used in a
map key is a pointer to self, as in:

struct node;
struct node {
  struct node *next;
};

Avoid this in the desc by using "unsigned long long" for all pointers.
Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 0d7245dc
......@@ -64,7 +64,10 @@ bool BMapDeclVisitor::VisitRecordDecl(RecordDecl *D) {
result_ += "\", [";
for (auto F : D->getDefinition()->fields()) {
result_ += "[";
TraverseDecl(F);
if (F->getType()->isPointerType())
result_ += "\"unsigned long long\"";
else
TraverseDecl(F);
if (F->isBitField())
result_ += ", " + to_string(F->getBitWidthValue(C));
result_ += "], ";
......
......@@ -65,5 +65,26 @@ int foo(void *ctx) {
self.assertEqual(l.s.a, 5)
self.assertEqual(l.s.b, 6)
def test_iosnoop(self):
text = """
#include <linux/blkdev.h>
#include <uapi/linux/ptrace.h>
struct key_t {
struct request *req;
};
BPF_TABLE("hash", struct key_t, u64, start, 1024);
int do_request(struct pt_regs *ctx, struct request *req) {
struct key_t key = {};
bpf_trace_printk("traced start %d\\n", req->__data_len);
return 0;
}
"""
b = BPF(text=text, debug=0)
fn = b.load_func("do_request", BPF.KPROBE)
if __name__ == "__main__":
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment