probe never {p <<< 1} global p results in ERROR: empty aggregate near identifier 'p' at <input>:1:28 but should result in p @count=0x0
The related code in tranlate.cxx // PR 2142+2610: empty aggregates 3757 o->newline() << "if (unlikely (" << agg.value() << " == NULL)" 3758 << " || " << agg.value() << "->count == 0) {"; 3759 o->newline(1) << "c->last_error = \"empty aggregate\";"; 3760 o->newline() << "goto out;"; I can't reproduce 2142 and 2610 when such code is commented. Then sensible result will be printed in the test case. Maybe some improvements on global were added since that commit. Guess we can weaken the checking of empty aggregrate.
If we wish to keep the status quo that @operators on empty aggregates are erroneous, then the code to change for this bug would be elaborate.cxx's synthesis of the printf (" @count=....@avg=..."), to fork it into one case where @count=0 and is printed alone, and another one where @count>1 and the other @values are printed.
Created attachment 3085 [details] patch for checking empty aggregate and adding default print Add checking empty aggregate and default print where @count==0. It's not necessary to check empty aggregate in Array case. The generated foreach can eliminate the possibly of printing empty aggregate. Sample script: $ sudo stap -ve 'global var; probe never{ var<<<2}' -p2 Pass 1: parsed user script and 47 library script(s) in 540usr/60sys/603real ms. # globals var:stats # probes never /* <- never */ (var) <<< (2) end /* <- end */ { if ((@count(var)) > (0)) printf("var @count=%#x @min=%#x @max=%#x @sum=%#x @avg=%#x\\n", @count(var), @min(var), @max(var), @sum(var), @avg(var)) else printf("var @count=0x0\\n") } Pass 2: analyzed script: 2 probe(s), 0 function(s), 0 embed(s), 1 global(s) in 10usr/20sys/26real ms.
Nice work, plase commit with a test case.
Seem commit 271d408e09e033857658c83cb722078fab02edda
patch already committed