Skip to contentSkip to conversation

trace-events: don't use dtrace reserved words in and next

PATCH In review Alon Levy 5 participants 16 messages Mar 28, 2012 – Mar 30, 2012

lore
Share & tools
lore

Alon Levy

author
#0 lore raw

PATCH 1/1 trace-events: don't use dtrace reserved words in and next

---
 trace-events |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
trace-events +2 -2
index 70f059d..0924666 100644
@@ -313,7 +313,7 @@ usb_host_set_interface(int bus, int addr, int interface, int alt) "dev %d:%d, in
 usb_host_claim_interfaces(int bus, int addr, int config, int nif) "dev %d:%d, config %d, nif %d"
 usb_host_release_interfaces(int bus, int addr) "dev %d:%d"
 usb_host_req_control(int bus, int addr, int req, int value, int index) "dev %d:%d, req 0x%x, value %d, index %d"
-usb_host_req_data(int bus, int addr, int in, int ep, int size) "dev %d:%d, in %d, ep %d, size %d"
+usb_host_req_data(int bus, int addr, int _in, int ep, int size) "dev %d:%d, in %d, ep %d, size %d"
 usb_host_req_complete(int bus, int addr, int status) "dev %d:%d, status %d"
 usb_host_urb_submit(int bus, int addr, void *aurb, int length, int more) "dev %d:%d, aurb %p, length %d, more %d"
 usb_host_urb_complete(int bus, int addr, void *aurb, int status, int length, int more) "dev %d:%d, aurb %p, status %d, length %d, more %d"
@@ -562,7 +562,7 @@ qemu_coroutine_terminate(void *co) "self %p"
 
 # qemu-coroutine-lock.c
 qemu_co_queue_next_bh(void) ""
-qemu_co_queue_next(void *next) "next %p"
+qemu_co_queue_next(void *_next) "next %p"
 qemu_co_mutex_lock_entry(void *mutex, void *self) "mutex %p self %p"
 qemu_co_mutex_lock_return(void *mutex, void *self) "mutex %p self %p"
 qemu_co_mutex_unlock_entry(void *mutex, void *self) "mutex %p self %p"
Signature · 1 line
1.7.9.3
#1 lore raw
Quoted 3 lines · Alon Levy

---
 trace-events |    4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)

We're always going to struggle with new trace events that add reserved keywords. Fixing up trace-events is going to be an ongoing task so I'd like to also see tracetool automatically modify keywords 'next' -> 'next_'. Do you want to send a patch to do that instead?

Stefan

author
#2 lore raw
Quoted 9 lines · Stefan Hajnoczi
Quoted 3 lines · Alon Levy

---
 trace-events |    4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)

We're always going to struggle with new trace events that add reserved keywords. Fixing up trace-events is going to be an ongoing task so I'd like to also see tracetool automatically modify keywords 'next' -> 'next_'. Do you want to send a patch to do that instead?

sure. For the new tracetool.py too ? :)

Quoted 3 lines

Stefan

author
#3 lore raw

PATCH 1/2 tracetool: dtrace: handle in and next reserved words

---
 scripts/tracetool |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/tracetool +3 -3
index 65bd0a1..e7cebf3 100755
@@ -494,9 +494,9 @@ EOF
     i=1
     for arg in $arglist
     do
-        # 'limit' is a reserved keyword
-        if [ "$arg" = "limit" ]; then
-          arg="_limit"
+        # 'limit', 'in' and 'next' are reserved keywords
+        if [ "$arg" = "limit" -o "$arg" = "in" -o "$arg" = "next" ]; then
+          arg="_$arg"
         fi
         cat <<EOF
   $arg = \$arg$i;
Signature · 1 line
1.7.9.3
author
#4 lore raw

PATCH 2/2 tracetool: dtrace: warn on reserved word usage

---
 scripts/tracetool |    1 +
 1 file changed, 1 insertion(+)
scripts/tracetool +1 -0
index e7cebf3..d011bb7 100755
@@ -496,6 +496,7 @@ EOF
     do
         # 'limit', 'in' and 'next' are reserved keywords
         if [ "$arg" = "limit" -o "$arg" = "in" -o "$arg" = "next" ]; then
+          echo "reserved word used in line: $1" 1>&2
           arg="_$arg"
         fi
         cat <<EOF
Signature · 1 line
1.7.9.3
author
#5 lore raw
In reply to Alon Levy
Quoted 11 lines · Alon Levy
Quoted 9 lines · Stefan Hajnoczi
Quoted 3 lines · Alon Levy

---
 trace-events |    4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)

We're always going to struggle with new trace events that add reserved keywords. Fixing up trace-events is going to be an ongoing task so I'd like to also see tracetool automatically modify keywords 'next' -> 'next_'. Do you want to send a patch to do that instead?

hmm, I changed to _next, not next_, if you'd like to change that and commit I don't mind.

Quoted 6 lines

sure. For the new tracetool.py too ? :)

Quoted 3 lines

Stefan

#6 lore raw
Quoted 7 lines · Alon Levy
Quoted 6 lines · Alon Levy
Quoted 5 lines · Stefan Hajnoczi
Quoted 3 lines · Alon Levy

---
 trace-events |    4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

We're always going to struggle with new trace events that add reserved keywords.  Fixing up trace-events is going to be an ongoing task so I'd like to also see tracetool automatically modify keywords 'next' -> 'next_'.  Do you want to send a patch to do that instead?

hmm, I changed to _next, not next_, if you'd like to change that and commit I don't mind.

Thanks. next_ can be a little safer when languages reserve identifiers starting with '_'. I can tweak it.

Stefan

author
#7 lore raw

PATCH 1/2 tracetool: dtrace: handle in and next reserved words

In reply to Alon Levy
---
 scripts/tracetool |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/tracetool +3 -3
index 65bd0a1..e7cebf3 100755
@@ -494,9 +494,9 @@ EOF
     i=1
     for arg in $arglist
     do
-        # 'limit' is a reserved keyword
-        if [ "$arg" = "limit" ]; then
-          arg="_limit"
+        # 'limit', 'in' and 'next' are reserved keywords
+        if [ "$arg" = "limit" -o "$arg" = "in" -o "$arg" = "next" ]; then
+          arg="_$arg"
         fi
         cat <<EOF
   $arg = \$arg$i;
Signature · 1 line
1.7.9.3
author
#8 lore raw

PATCH 2/2 tracetool: dtrace: warn on reserved word usage

---
 scripts/tracetool |    1 +
 1 file changed, 1 insertion(+)
scripts/tracetool +1 -0
index e7cebf3..d011bb7 100755
@@ -496,6 +496,7 @@ EOF
     do
         # 'limit', 'in' and 'next' are reserved keywords
         if [ "$arg" = "limit" -o "$arg" = "in" -o "$arg" = "next" ]; then
+          echo "reserved word used in line: $1" 1>&2
           arg="_$arg"
         fi
         cat <<EOF
Signature · 1 line
1.7.9.3
#9 lore raw

Re: [Qemu-devel] [PATCH 1/2] tracetool: dtrace: handle in and next reserved words

In reply to Alon Levy
Quoted 24 lines · Alon Levy

---
scripts/tracetool | 6 +++---

1 file changed, 3 insertions(+), 3 deletions(-)
scripts/tracetool +3 -3
index 65bd0a1..e7cebf3 100755
@@ -494,9 +494,9 @@ EOF
    i=1
    for arg in $arglist
    do
-        # 'limit' is a reserved keyword
-        if [ "$arg" = "limit" ]; then
-          arg="_limit"
+        # 'limit', 'in' and 'next' are reserved keywords
+        if [ "$arg" = "limit" -o "$arg" = "in" -o "$arg" = "next" ]; then
+          arg="_$arg"
        fi
        cat <<EOF
  $arg = \$arg$i;
Signature · 1 line
1.7.9.3

Could we add 'self' to this list?

Lee.

#10 lore raw

Re: [Qemu-devel] [PATCH 1/2] tracetool: dtrace: handle in and next reserved words

Quoted 2 lines · Lee Essen

scripts/tracetool EOF · line 498

Quoted 2 lines
scripts/tracetool +2 -0
+        # 'limit', 'in' and 'next' are reserved keywords
+        if [ "$arg" = "limit" -o "$arg" = "in" -o "$arg" = "next" ]; then

[ ... -o ... ] is not portable. POSIX says you must break it into:
[ ... ] || [ ... ]

or, more efficiently for this particular filtering, rewrite this as:

# munge reserved words
case $arg in
  limit | in | next ) arg=_$arg ;;
esac
Quoted 2 lines

Could we add 'self' to this list?

and using case makes it easier to add more reserved words:

case $arg in
limit | in | next | self ) arg=_$arg ;;
esac

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#11 lore raw

Re: [Qemu-devel] [PATCH 1/2] tracetool: dtrace: handle in and next reserved words

In reply to Alon Levy

2012/3/28 Alon Levy <[email protected]>:

Quoted 7 lines

-        # 'limit' is a reserved keyword
-        if [ "$arg" = "limit" ]; then
-          arg="_limit"
+        # 'limit', 'in' and 'next' are reserved keywords
+        if [ "$arg" = "limit" -o "$arg" = "in" -o "$arg" = "next" ]; then
+          arg="_$arg"
        fi

The test -a and -o options are obsolete in POSIX shell scripts (use "if [ foo ] && [ bar ]" instead).

In this case it would be neater to use 'case' anyway:

    case "$arg" in
        limit|in|next)
            arg="_$arg"
            ;;
    esac

-- PMM

author
#12 lore raw

PATCH v3 1/2 tracetool: dtrace: handle in and next reserved words

In reply to Alon Levy

---

I think I need a qemu-trivial-review too ;)

v3:
added self (Lee Essen)
use post '_' (Stefan Hajnoczi)
use case/esca (Eric Blake & Peter Maydell)

 scripts/tracetool |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
scripts/tracetool +6 -4
index 65bd0a1..ab788f2 100755
@@ -494,10 +494,12 @@ EOF
     i=1
     for arg in $arglist
     do
-        # 'limit' is a reserved keyword
-        if [ "$arg" = "limit" ]; then
-          arg="_limit"
-        fi
+        # postfix reserved words with '_'
+        case "$arg" in
+            limit|in|next|self)
+                arg="${arg}_"
+                ;;
+        esac
         cat <<EOF
   $arg = \$arg$i;
 EOF
Signature · 1 line
1.7.9.3
author
#13 lore raw

PATCH 2/2 tracetool: dtrace: warn on reserved word usage

---
 scripts/tracetool |    1 +
 1 file changed, 1 insertion(+)
scripts/tracetool +1 -0
index ab788f2..c2aed8f 100755
@@ -497,6 +497,7 @@ EOF
         # postfix reserved words with '_'
         case "$arg" in
             limit|in|next|self)
+                echo "reserved word used in line: $1" 1>&2
                 arg="${arg}_"
                 ;;
         esac
Signature · 1 line
1.7.9.3
#14 lore raw

Re: [Qemu-trivial] [PATCH 2/2] tracetool: dtrace: warn on reserved word usage

Quoted 4 lines · Alon Levy

---
 scripts/tracetool |    1 +

 1 file changed, 1 insertion(+)

I have not merged this patch because I don't want to avoid adding warnings that are only visible when using a specific backend.

The problem is that offending trace-events lines will be added and later on someone who uses dtrace will find a whole list of new warnings.

Stefan

#15 lore raw

Re: [Qemu-trivial] [PATCH v3 1/2] tracetool: dtrace: handle in and next reserved words

In reply to Alon Levy
Quoted 5 lines · Alon Levy

---

I think I need a qemu-trivial-review too ;)

Quoted 7 lines

v3:
 added self    (Lee Essen)
 use post '_'  (Stefan Hajnoczi)
 use case/esca (Eric Blake & Peter Maydell)

 scripts/tracetool |   10 ++++++----

 1 file changed, 6 insertions(+), 4 deletions(-)

Thanks, I have merged this patch.

Stefan