This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add STAP_ERROR macro


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]