This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[PATCH v2] Add STAP_ERROR macro
- From: Aaron Tomlin <atomlin at redhat dot com>
- To: systemtap at sourceware dot org
- Cc: fche at redhat dot com, jistone at redhat dot com
- Date: Fri, 22 Nov 2013 15:03:02 +0000
- Subject: [PATCH v2] Add STAP_ERROR macro
- Authentication-results: sourceware.org; auth=none
Josh,
How about this version?
v2:
[Josh Stone]: Added support for formatted strings and #undef for STAP_ERROR
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 <atomlin@redhat.com>
---
translate.cxx | 2 ++
1 file changed, 2 insertions(+)
diff --git a/translate.cxx b/translate.cxx
index b52f4f1..f99e0d7 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";
}
--
1.8.1.4