Re: [PATCH bpf-next 2/3] bpf: btf: add btf json print functionality
From: Quentin Monnet
Date: Fri Jun 22 2018 - 06:39:26 EST
2018-06-22 11:24 UTC+0100 ~ Okash Khawaja <osk@xxxxxx>
> On Thu, Jun 21, 2018 at 11:42:59AM +0100, Quentin Monnet wrote:
>> Hi Okash,
> hi and sorry about delay in responding. the email got routed to
> incorrect folder.
>>
>> 2018-06-20 13:30 UTC-0700 ~ Okash Khawaja <osk@xxxxxx>
>>> This consumes functionality exported in the previous patch. It does the
>>> main job of printing with BTF data. This is used in the following patch
>>> to provide a more readable output of a map's dump. It relies on
>>> json_writer to do json printing. Below is sample output where map keys
>>> are ints and values are of type struct A:
>>>
>>> typedef int int_type;
>>> enum E {
>>> E0,
>>> E1,
>>> };
>>>
>>> struct B {
>>> int x;
>>> int y;
>>> };
>>>
>>> struct A {
>>> int m;
>>> unsigned long long n;
>>> char o;
>>> int p[8];
>>> int q[4][8];
>>> enum E r;
>>> void *s;
>>> struct B t;
>>> const int u;
>>> int_type v;
>>> unsigned int w1: 3;
>>> unsigned int w2: 3;
>>> };
>>>
>>> $ sudo bpftool map dump -p id 14
>>> [{
>>> "key": 0
>>> },{
>>> "value": {
>>> "m": 1,
>>> "n": 2,
>>> "o": "c",
>>> "p": [15,16,17,18,15,16,17,18
>>> ],
>>> "q": [[25,26,27,28,25,26,27,28
>>> ],[35,36,37,38,35,36,37,38
>>> ],[45,46,47,48,45,46,47,48
>>> ],[55,56,57,58,55,56,57,58
>>> ]
>>> ],
>>> "r": 1,
>>> "s": 0x7ffff6f70568,
>>
>> Hexadecimal values, without quotes, are not valid JSON. Please stick to
>> decimal values.
> ah sorry, i used a buggy json validator. this should be a quick fix.
> which would be better: pointers be output hex strings or integers?
I would go for integers. Although this is harder to read for humans, it
is easier to process for machines, which remain the primary targets for
JSON output.
Quentin