Fixes #2518 -- weird behaviour of lookup_or_init (#2520)
* Allow lookup_or_init to return NULL (rather than just returning from the current function)
* Fixed a couple of bad edits found when running tests. Also fixed a bug in the
test runner. Also fixed a bug in libbcc where the python signature did not match
the actual implementation.
diff --git a/tools/lib/uobjnew.py b/tools/lib/uobjnew.py
index 85f5768..63dd80a 100755
--- a/tools/lib/uobjnew.py
+++ b/tools/lib/uobjnew.py
@@ -80,8 +80,10 @@
struct val_t *valp, zero = {};
key.size = size;
valp = allocs.lookup_or_init(&key, &zero);
- valp->total_size += size;
- valp->num_allocs += 1;
+ if (valp) {
+ valp->total_size += size;
+ valp->num_allocs += 1;
+ }
return 0;
}
"""
@@ -98,8 +100,10 @@
bpf_usdt_readarg(4, ctx, &size);
bpf_probe_read(&key.name, sizeof(key.name), (void *)classptr);
valp = allocs.lookup_or_init(&key, &zero);
- valp->total_size += size;
- valp->num_allocs += 1;
+ if (valp) {
+ valp->total_size += size;
+ valp->num_allocs += 1;
+ }
return 0;
}
"""
@@ -115,8 +119,10 @@
u64 size = 0;
bpf_usdt_readarg(1, ctx, &size);
valp = allocs.lookup_or_init(&key, &zero);
- valp->total_size += size;
- valp->num_allocs += 1;
+ if (valp) {
+ valp->total_size += size;
+ valp->num_allocs += 1;
+ }
return 0;
}
"""
@@ -128,7 +134,9 @@
bpf_usdt_readarg(1, ctx, &classptr);
bpf_probe_read(&key.name, sizeof(key.name), (void *)classptr);
valp = allocs.lookup_or_init(&key, &zero);
- valp->num_allocs += 1; // We don't know the size, unfortunately
+ if (valp) {
+ valp->num_allocs += 1; // We don't know the size, unfortunately
+ }
return 0;
}
"""
@@ -146,7 +154,9 @@
struct key_t key = { .name = "<ALL>" };
struct val_t *valp, zero = {};
valp = allocs.lookup_or_init(&key, &zero);
- valp->num_allocs += 1;
+ if (valp) {
+ valp->num_allocs += 1;
+ }
return 0;
}
"""