[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Debugging Script
From: |
arnold |
Subject: |
Re: [bug-gawk] Debugging Script |
Date: |
Mon, 08 Apr 2019 13:11:38 -0600 |
User-agent: |
Heirloom mailx 12.5 7/5/10 |
Hi.
I didn't see the original mail. It looks like I was temporarily unsubscribed
from the list for a few days.
> On Sat, Apr 06, 2019 at 08:13:00PM +0200, Holger Klene wrote:
> > I had to learn the hard way, that debugging requires a script file [1].
> >
> > So I tried being clever and thought I run this in bash:
> >
> > $ printf "%s\n" a b c \
> > | gawk -f <(echo '{ if ($1 == "b") { print "great" } }')
> >
> > From bash man page [2]:
> > > Process substitution allows a process's input or output to be referred
> > to using a filename.
> >
> > Well so far it works great. But on adding -D to start debugging, I get
> > an error requesting option -f ... somehow gawk caught me cheating :-(
Process substitution works by creating a pipeline from the command
inside the <(...) and hooking the output of the command (the read end
of the pipe) to a high-numbered file descriptor opened in the main
process, such as 63. It then places "/dev/fd/63" on the command line
as an argument.
Files in /dev/fd/ are special - opening them essentially does a dup(2)
of the original file descriptor, so gawk gets a file descriptor that is
open on a pipe, and NOT a regular file. (Note that this description is
approximate; different OSs handle /dev/fd differently.)
> gawk> list
> error: can't open source file `/dev/fd/63' for reading (No such file or
> directory)
I think this happens since gawk read its input and then closes the
file descriptor. Reopening /dev/fd/63 doesn't work, since the pipe
fd is no longer available.
> > My questions:
> > a) I don't get where my error is? Why doesn't my "workaround" just work?
See above - gawk isn't getting a regular file that it can open
and read.
> > b) Is there a bug tracker on this known limitation [1]? What's the plan?
> > Somebody working on it? ETA?
There is no bug tracker. There currently is no plan. Noone is working on it
at the moment. Thus there is no ETA.
> > How hard can it be to keep a few lines of
> > script in memory?
Not terribly hard, but it's not as simple as you might think, since
gawk allows multiple -e and -f options, as well as `-f -' to read source
code from standard input. Essentially, gawk would have to create a
temporary file, dump all the combined original source code into it, feed
that to the debugger, and remember to remove the temporary file upon exit.
> I'm not aware of any bug tracker. This sounds more like a feature request
> to me...
It is indeed a feature request. Not an unreasonable one, but one that
hasn't come up yet in the ~ 8 years since the debugger has been available.
Patches are welcome and will be reviewed.
HTH,
Arnold