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/ucalls.py b/tools/lib/ucalls.py
index d072af0..1175195 100755
--- a/tools/lib/ucalls.py
+++ b/tools/lib/ucalls.py
@@ -164,7 +164,9 @@
(void *)method);
#ifndef LATENCY
valp = counts.lookup_or_init(&data.method, &val);
- ++(*valp);
+ if (valp) {
+ ++(*valp);
+ }
#endif
#ifdef LATENCY
entry.update(&data, ×tamp);
@@ -189,8 +191,10 @@
return 0; // missed the entry event
}
info = times.lookup_or_init(&data.method, &zero);
- info->num_calls += 1;
- info->total_ns += bpf_ktime_get_ns() - *entry_timestamp;
+ if (info) {
+ info->num_calls += 1;
+ info->total_ns += bpf_ktime_get_ns() - *entry_timestamp;
+ }
entry.delete(&data);
return 0;
}
@@ -210,7 +214,9 @@
#endif
#ifndef LATENCY
valp = syscounts.lookup_or_init(&id, &val);
- ++(*valp);
+ if (valp) {
+ ++(*valp);
+ }
#endif
return 0;
}
@@ -227,8 +233,10 @@
}
id = e->id;
info = systimes.lookup_or_init(&id, &zero);
- info->num_calls += 1;
- info->total_ns += bpf_ktime_get_ns() - e->timestamp;
+ if (info) {
+ info->num_calls += 1;
+ info->total_ns += bpf_ktime_get_ns() - e->timestamp;
+ }
sysentry.delete(&pid);
return 0;
}