This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: [PATCH] Add STAP_ERROR macro
- From: Josh Stone <jistone at redhat dot com>
- To: Aaron Tomlin <atomlin at redhat dot com>, systemtap at sourceware dot org
- Cc: fche at redhat dot com
- Date: Thu, 21 Nov 2013 16:11:20 -0800
- Subject: Re: [PATCH] Add STAP_ERROR macro
- Authentication-results: sourceware.org; auth=none
- References: <1385078082-12176-1-git-send-email-atomlin at redhat dot com>
Hi,
On 11/21/2013 03:54 PM, Aaron Tomlin wrote:
> 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 { }.
In PR10300, I had a similar idea, but allowed for formatted strings too.
Would you care to generalize your patch to fit? Some CPP hackery might
even be able to optimize for the direct string case, but since this is
an error path the performance doesn't matter much.
https://sourceware.org/bugzilla/show_bug.cgi?id=10300
The sketch I gave used comma operators, which probably doesn't actually
work with goto, but your do{}while(0) is fine.
I have no excuse why I never followed up after filing that, so thanks
for coming around to this again. :)
> Signed-off-by: Aaron Tomlin <atomlin@redhat.com>
> ---
> translate.cxx | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/translate.cxx b/translate.cxx
> index b52f4f1..6fc6877 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(str) do { CONTEXT->last_error=(str); goto out; } while (0)";
> o->newline() << "#define return goto out"; // redirect embedded-C return
> v->body->visit (this);
> o->newline() << "#undef return";
If we're going to localize the #define, then it should get #undef too.
Otherwise, STAP_ERROR/WARN might as well go in a real runtime/ header.
Thanks,
Josh