From: Frank Ch. Eigler Date: Sat, 14 Oct 2017 21:11:16 +0000 (-0400) Subject: bpf translation error handling: try tracking derived_probe token X-Git-Tag: release-3.2~16 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=96013fc837347fad3a8571bc2c2d4e45204cff88;p=systemtap.git bpf translation error handling: try tracking derived_probe token BPF translation internals involve data structures that do not track the staptree level entities they are based on. So when an error occurs, there's no quick way to mapping it back to the token, for an ideal error message. translate_bpf_pass() now tries to track a last-token* as it goes translating all the probe bodies to bpf, so that a semantic_error can be synthesized if needed. This is still far from ideal; a single exception causes giving up trying all the remaining probes; and all begin/end probes are translated into single larger bpf programs, so it's harder to narrow down the cause. Baby steps. --- diff --git a/bpf-translate.cxx b/bpf-translate.cxx index 7dfbf00e6..7491c647c 100644 --- a/bpf-translate.cxx +++ b/bpf-translate.cxx @@ -2225,6 +2225,7 @@ translate_bpf_pass (systemtap_session& s) BPF_Output eo(fd); globals glob; int ret = 0; + const token* t = 0; try { translate_globals(glob, s); @@ -2238,6 +2239,7 @@ translate_bpf_pass (systemtap_session& s) if (!init.empty()) { + t = begin_v[0]->tok; program p; translate_init_and_probe_v(p, glob, init, begin_v); p.generate(); @@ -2245,6 +2247,7 @@ translate_bpf_pass (systemtap_session& s) } else if (!begin_v.empty()) { + t = begin_v[0]->tok; program p; translate_probe_v(p, glob, begin_v); p.generate(); @@ -2253,6 +2256,7 @@ translate_bpf_pass (systemtap_session& s) if (!end_v.empty()) { + t = end_v[0]->tok; program p; translate_probe_v(p, glob, end_v); p.generate(); @@ -2267,6 +2271,7 @@ translate_bpf_pass (systemtap_session& s) for (auto i = kprobe_v.begin(); i != kprobe_v.end(); ++i) { + t = i->first->tok; program p; translate_probe(p, glob, i->first); p.generate(); @@ -2293,7 +2298,8 @@ translate_bpf_pass (systemtap_session& s) } catch (const std::runtime_error &e) { - std::cerr << "bpf translation internal error: " << e.what() << std::endl; + semantic_error er(ERR_SRC, _F("bpf translation failure: %s", e.what()), t); + s.print_error(er); ret = 1; } catch (...)