Patchwork tracetool: handle DTrace keywords 'in', 'next', 'self'

login
register
mail settings
Submitter Stefan Hajnoczi
Date April 16, 2012, 11:53 a.m.
Message ID <1334577238-22242-1-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/152818/
State New
Headers show

Comments

Stefan Hajnoczi - April 16, 2012, 11:53 a.m.
Language keywords cannot be used as argument names.  The DTrace backend
appends an underscore to the argument name in order to make the argument
name legal.

This patch adds 'in', 'next', and 'self' keywords to dtrace.py.

Also drop the unnecessary argument name lstrip() call.  The
Arguments.build() method already ensures there is no space around
argument names.  Furthermore it is misleading to do the lstrip() *after*
checking against keywords because the keyword check would not match if
spaces were in the name.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 scripts/tracetool/backend/dtrace.py |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Alon Levy - April 16, 2012, 12:51 p.m.
On Mon, Apr 16, 2012 at 12:53:58PM +0100, Stefan Hajnoczi wrote:
> Language keywords cannot be used as argument names.  The DTrace backend
> appends an underscore to the argument name in order to make the argument
> name legal.
> 
> This patch adds 'in', 'next', and 'self' keywords to dtrace.py.
> 
> Also drop the unnecessary argument name lstrip() call.  The
> Arguments.build() method already ensures there is no space around
> argument names.  Furthermore it is misleading to do the lstrip() *after*
> checking against keywords because the keyword check would not match if
> spaces were in the name.
> 

Reviewed-by: Alon Levy <alevy@redhat.com>

> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
>  scripts/tracetool/backend/dtrace.py |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py
> index cebbd57..9cab75c 100644
> --- a/scripts/tracetool/backend/dtrace.py
> +++ b/scripts/tracetool/backend/dtrace.py
> @@ -86,10 +86,10 @@ def stap(events):
>          i = 1
>          if len(e.args) > 0:
>              for name in e.args.names():
> -                # 'limit' is a reserved keyword
> -                if name == 'limit':
> -                    name = '_limit'
> -                out('  %s = $arg%d;' % (name.lstrip(), i))
> +                # Append underscore to reserved keywords
> +                if name in ('limit', 'in', 'next', 'self'):
> +                    name += '_'
> +                out('  %s = $arg%d;' % (name, i))
>                  i += 1
>  
>          out('}')
> -- 
> 1.7.9.5
> 
>
Stefan Hajnoczi - April 16, 2012, 3:06 p.m.
On Mon, Apr 16, 2012 at 12:53:58PM +0100, Stefan Hajnoczi wrote:
> Language keywords cannot be used as argument names.  The DTrace backend
> appends an underscore to the argument name in order to make the argument
> name legal.
> 
> This patch adds 'in', 'next', and 'self' keywords to dtrace.py.
> 
> Also drop the unnecessary argument name lstrip() call.  The
> Arguments.build() method already ensures there is no space around
> argument names.  Furthermore it is misleading to do the lstrip() *after*
> checking against keywords because the keyword check would not match if
> spaces were in the name.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
>  scripts/tracetool/backend/dtrace.py |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Applied to the tracing patches tree:
https://github.com/stefanha/qemu/commits/tracing

Stefan
Lluís Vilanova - April 16, 2012, 5:22 p.m.
Stefan Hajnoczi writes:

> Language keywords cannot be used as argument names.  The DTrace backend
> appends an underscore to the argument name in order to make the argument
> name legal.

> This patch adds 'in', 'next', and 'self' keywords to dtrace.py.

> Also drop the unnecessary argument name lstrip() call.  The
> Arguments.build() method already ensures there is no space around
> argument names.  Furthermore it is misleading to do the lstrip() *after*
> checking against keywords because the keyword check would not match if
> spaces were in the name.

> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Reviewed-by: Lluís Vilanova <vilanova@ac.upc.edu>

> ---
>  scripts/tracetool/backend/dtrace.py |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

> diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py
> index cebbd57..9cab75c 100644
> --- a/scripts/tracetool/backend/dtrace.py
> +++ b/scripts/tracetool/backend/dtrace.py
> @@ -86,10 +86,10 @@ def stap(events):
>          i = 1
>          if len(e.args) > 0:
>              for name in e.args.names():
> -                # 'limit' is a reserved keyword
> -                if name == 'limit':
> -                    name = '_limit'
> -                out('  %s = $arg%d;' % (name.lstrip(), i))
> +                # Append underscore to reserved keywords
> +                if name in ('limit', 'in', 'next', 'self'):
> +                    name += '_'
> +                out('  %s = $arg%d;' % (name, i))
>                  i += 1
 
>          out('}')
> -- 
> 1.7.9.5

Patch

diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py
index cebbd57..9cab75c 100644
--- a/scripts/tracetool/backend/dtrace.py
+++ b/scripts/tracetool/backend/dtrace.py
@@ -86,10 +86,10 @@  def stap(events):
         i = 1
         if len(e.args) > 0:
             for name in e.args.names():
-                # 'limit' is a reserved keyword
-                if name == 'limit':
-                    name = '_limit'
-                out('  %s = $arg%d;' % (name.lstrip(), i))
+                # Append underscore to reserved keywords
+                if name in ('limit', 'in', 'next', 'self'):
+                    name += '_'
+                out('  %s = $arg%d;' % (name, i))
                 i += 1
 
         out('}')