Fix garbled java class name problem of uobjnew.py
authordenghui.ddh <denghui.ddh@alibaba-inc.com>
Tue, 9 Nov 2021 13:11:40 +0000 (21:11 +0800)
committeryonghong-song <ys114321@gmail.com>
Fri, 12 Nov 2021 04:25:16 +0000 (20:25 -0800)
After this fix, the output may look like this:
NAME/TYPE                      # ALLOCS      # BYTES
[B                                    1         1016
[D                                    1         8016

tools/lib/uobjnew.py

index f75ba048348160d9a556d711adf79144a574bf0a..60359c427ea9469434630cd17e5e7a5c05d12577 100755 (executable)
@@ -96,9 +96,11 @@ int alloc_entry(struct pt_regs *ctx) {
     struct key_t key = {};
     struct val_t *valp, zero = {};
     u64 classptr = 0, size = 0;
+    u32 length = 0;
     bpf_usdt_readarg(2, ctx, &classptr);
+    bpf_usdt_readarg(3, ctx, &length);
     bpf_usdt_readarg(4, ctx, &size);
-    bpf_probe_read_user(&key.name, sizeof(key.name), (void *)classptr);
+    bpf_probe_read_user(&key.name, min(sizeof(key.name), (size_t)length), (void *)classptr);
     valp = allocs.lookup_or_try_init(&key, &zero);
     if (valp) {
         valp->total_size += size;