[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] 'watch' in gawk debugger gives wrong NR
From: |
Joep van Delft |
Subject: |
Re: [bug-gawk] 'watch' in gawk debugger gives wrong NR |
Date: |
Wed, 25 Nov 2015 11:54:25 +0100 |
User-agent: |
XS4ALL Webmail |
Thanks for looking into this, Arnold. The suspicious behavior, however,
would be one or two "continue"s further. Please consider the following
run:
| % gawk --version
| GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.3-p4, GNU MP 6.1.0)
|
| % cat dgawk.commands
| list
| watch c "c>0"
| break 6
| display NR
| display nr
| display c
| display $0
| run
|
| % gawk -D -f script.awk tst.txt
| gawk> source dgawk.commands
| 1 #!/usr/bin/gawk -f
| 2 BEGIN {
| 3 c = 0
| 4 }
| 5
| 6 /apple/ {
| 7 nr=NR
| 8 c++
| 9 #printf "[c, NR] = [%s, %s]\n", c, NR
| 10 }
| 11
| 12 END {
| 13 print c
| 14 }
| Watchpoint 1: c
| Breakpoint 2 set at file `script.awk', line 6
| 1: NR = 0
| 2: nr = untyped variable
| 3: c = untyped variable
| 4: $0 = ""
| Starting program:
| Stopping in Rule ...
| Breakpoint 2, main() at `script.awk':6
| 6 /apple/ {
| 1: NR = 1
| 2: nr = untyped variable
| 3: c = 0
| 4: $0 = "1 1 pear"
|
| gawk> continue
| Breakpoint 2, main() at `script.awk':6
| 6 /apple/ {
| 1: NR = 2
| 2: nr = untyped variable
| 3: c = 0
| 4: $0 = "2 1 apple 4"
Here I would expect that the upcoming halt would be on the watchpoint c,
as $0 matches PATTERN. Not so. Notice that c has already been increased,
but that the next line is already processed (according to NR and 0):
| gawk> continue
| Breakpoint 2, main() at `script.awk':6
| 6 /apple/ {
| 1: NR = 3
| 2: nr = 2
| 3: c = 1
| 4: $0 = "3 2 pear"
While we are already in the next line, the watchpoint gets triggered,
and consequently has a wrong NR and 0:
| gawk> continue
| Watchpoint 1: c
| Old value: untyped variable
| New value: 1
| main() at `script.awk':6
| 6 /apple/ {
| 1: NR = 3
| 2: nr = 2
| 3: c = 1
| 4: $0 = "3 2 pear"
Kind regards,
Joep
Aharon Robbins schreef op 2015-11-23 20:05:
Hi.
Thanks for your note. Here is what I got when I tried your example
using the gawk-4.1-stable branch in git. I don't think there's
a bug.
Run gawk:
| Script started on Mon Nov 23 20:56:29 2015
| [aahz:pts/6 gawk.git]$ ./gawk -D -f testprog.awk data.in
List:
| gawk> list
| 1 #! /usr/bin/gawk -f
| 2 BEGIN {
| 3 c = 0
| 4 }
| 5
| 6 /apple/ {
| 7 nr = NR
| 8 c++
| 9 # printf "[c, NR] = [%s, %s]\n", c, NR
| 10 }
| 11
| 12 END {
| 13 print c
| 14 }
Setup watchpoints, display variables, and breakpoint:
| gawk> watch c
| Watchpoint 1: c
| gawk> display nr
| 1: nr = untyped variable
| gawk> display NR
| 2: NR = 0
| gawk> display c
| 3: c = untyped variable
| gawk> break 6
| Breakpoint 2 set at file `testprog.awk', line 6
Run!
| gawk> run
| Starting program:
| Stopping in Rule ...
| Breakpoint 2, main() at `testprog.awk':6
| 6 /apple/ {
| 1: nr = untyped variable
| 2: NR = 1
| 3: c = 0
| gawk> print $0
| $0 = "1 1 pear"
So far, so good. First record doesn't match, nr has not been assigned
to, and NR is correct.
| gawk> continue
| Watchpoint 1: c
| Old value: untyped variable
| New value: 0
Hmm. This is a little strange. Maybe I need to look at why the
watchpoint was triggered.
| main() at `testprog.awk':6
| 6 /apple/ {
| 1: nr = untyped variable
| 2: NR = 1
| 3: c = 0
| gawk> print $0
| $0 = "1 1 pear"
So, we're still in the first record. NR is ok.
| gawk> continue
| Breakpoint 2, main() at `testprog.awk':6
| 6 /apple/ {
| 1: nr = untyped variable
| 2: NR = 2
| 3: c = 0
| gawk> print $0
| $0 = "2 1 apple 4"
Continue on:
| gawk> continue
| Breakpoint 2, main() at `testprog.awk':6
| 6 /apple/ {
| 1: nr = 2
| 2: NR = 3
| 3: c = 1
| gawk> print $0
| $0 = "3 2 pear"
We're at record 3. It won't match, but NR is displayed correctly.
| gawk> exit
| error: unknown command - "exit", try help
| gawk> ^D
I think display of NR is OK. I probably need to figure out
why the watchpoint triggered.
Thanks,
Arnold