• Okash Khawaja's avatar
    bpf: btf: print map dump and lookup with btf info · 2d3feca8
    Okash Khawaja authored
    This patch augments the output of bpftool's map dump and map lookup
    commands to print data along side btf info, if the correspondin btf
    info is available. The outputs for each of  map dump and map lookup
    commands are augmented in two ways:
    
    1. when neither of -j and -p are supplied, btf-ful map data is printed
    whose aim is human readability. This means no commitments for json- or
    backward- compatibility.
    
    2. when either -j or -p are supplied, a new json object named
    "formatted" is added for each key-value pair. This object contains the
    same data as the key-value pair, but with btf info. "formatted" object
    promises json- and backward- compatibility. Below is a sample output.
    
    $ bpftool map dump -p id 8
    [{
            "key": ["0x0f","0x00","0x00","0x00"
            ],
            "value": ["0x03", "0x00", "0x00", "0x00", ...
            ],
            "formatted": {
                    "key": 15,
                    "value": {
                            "int_field":  3,
                            ...
                    }
            }
    }
    ]
    
    This patch calls btf_dumper introduced in previous patch to accomplish
    the above. Indeed, btf-ful info is only displayed if btf data for the
    given map is available. Otherwise existing output is displayed as-is.
    Signed-off-by: default avatarOkash Khawaja <osk@fb.com>
    Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
    Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    2d3feca8
map.c 22.1 KB