From bbbf5f8cd14458d25204ad886fdd8af86d92f5a8 Mon Sep 17 00:00:00 2001 From: Aaron Tomlin Date: Fri, 22 Nov 2013 15:03:02 +0000 Subject: [PATCH] Add STAP_ERROR macro Instead of CONTEXT->last_error = "foo"; goto out; in an embedded-C function, a newly defined macro STAP_ERROR(str) should be used. The script can catch the exception with try { } catch { }. Signed-off-by: Aaron Tomlin --- translate.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/translate.cxx b/translate.cxx index b52f4f154..f99e0d7aa 100644 --- a/translate.cxx +++ b/translate.cxx @@ -2119,6 +2119,7 @@ c_unparser::emit_function (functiondecl* v) o->newline() << retvalue.init(); } + o->newline() << "#define STAP_ERROR(...) do { snprintf(CONTEXT->error_buffer, MAXSTRINGLEN, __VA_ARGS__); CONTEXT->last_error = CONTEXT->error_buffer; goto out; } while (0)"; o->newline() << "#define return goto out"; // redirect embedded-C return v->body->visit (this); o->newline() << "#undef return"; @@ -2143,6 +2144,7 @@ c_unparser::emit_function (functiondecl* v) o->newline() << c_arg_undef(v->locals[i]->name); // #undef STAP_ARG_foo } o->newline() << "#undef STAP_RETVALUE"; + o->newline() << "#undef STAP_ERROR"; o->newline(-1) << "}\n"; } -- 2.43.5