stapbpf PR23858 :: support sorting by value in foreach loop
Previously stapbpf's behaviour on this was wrong.
This slightly nightmarish bit of code handles more cases.
XXX Also need to take into account s->sort_aggr for statistics aggregates
-- currently unsupported.
To support nested foreach loops, map_get_next_key was changed to take & return
addresses-of string addresses rather than string addresses. Previously
we'd need to allocate and copy multiple string keys onto one tiny stack,
which is not feasible.
* bpf-internal.h (SORT_FLAGS): New define packs sort_column, sort_direction in one word.
(GET_SORT_COLUMN): New define unpacks sort_column from SORT_FLAGS.
(GET_SORT_DIRECTION): New define unpacks sort_direction from SORT_FLAGS.
* bpf-translate.cxx (bpf_unparser::visit_foreach_loop): String key/value iteration,
hardcode keysize on stack to 8bytes (either an int or an address of a string),
check for sort_aggr (UNSUPPORTED),
pack sort_column and sort_direction into sort_flags,
properly handle returned address of a string.
* stapbpf/bpfinterp.cxx (map_int_keys, map_str_keys): Remove typedefs.
(struct map_keys): Nightmare begins. Support 4 cases of int/str keys/values.
(convert_int_key, convert_str_key, convert_int_kp, convert_str_kp): More nightmare,
handle different cases of packing/unpacking BPF key/val into C++ key/val.
(convert_key, convert_kp): More nightmare. 'Overload' pack/unpack for ANY key/val.
(compute_key_size): More nightmare. Calculate memory required for a key.
(map_sort): New function handles initial sorting of map.
(map_next): New function handles retrieval from sorted map.
(map_get_next_key): Handle sorted int/str keys/values on different columns,
now takes strings to give a place to allocate returned str key/vals
that is not on the BPF stack.
(bpf_intepret): Pass strings to map_get_next_key.
* testsuite/systemtap.bpf/bpf_tests/foreach_string.stp: Enable full testcase.
* testsuite/systemtap.bpf/bpf_tests/foreach_pr23858.stp: New testcase.