dannykopping / b3

strace to json parser
MIT License
35 stars 3 forks source link

Inconsistent datatype in args #8

Open p8nut opened 4 years ago

p8nut commented 4 years ago

may be link with #5 seem that if there is more than one element in an array ints are not parsed (if there is only one int it is parsed) here a strace of a program with a select

 > ./strace a.out
select(255, [0], [1 2], [0 1 2], {tv_sec=0, tv_usec=962357}) = 2 (out [1 2], left {tv_sec=0, tv_usec=962344})

which will produce

{
   "syscall": "select",
   "args": [
      255,
      [
         0
      ],
      [
         "1",
         "2"
      ],
      [
         "0",
         "1",
         "2"
      ],
      {
         "tv_sec": 0,
         "tv_usec": 962357
      }
   ],
   "result": "2 (out [1 2], left {tv_sec=0, tv_usec=962344})",
   "timing": null,
   "pid": null,
   "type": "SYSCALL"
}

if we look at the args array, the second parameter is an array of integer but the third parameter is an array of strings.

Thanks for this module it's really useful.

p8nut commented 4 years ago

i might have find a solution but it's not really a nice one ...

in the select when you have an array, elements are not separated by comma. so in the grammar, i change that:

array_elements
  = (
    head:data_structure
    tail:(',' _ value:data_structure { return value; })*
    { return [head].concat(tail); }
  )?

by (replace ',' by ' ') :

array_elements
  = (
    head:data_structure
    tail:(' ' _ value:data_structure { return value; })*
    { return [head].concat(tail); }
  )?

and it seem to work, all the ints are parsed now. but i think there might have a lot of side effect with this way.