I understand that
dash is a "model" shell - it was written recently and well and it only implements what is required of POSIX shell. I looked at the dash source code to understand how "tracing" of a program such as shell, is done.
"Tracing" of dash is performed by compiling it with
DEBUG defined and invoking with
-o debug. When you do that, a file
trace is opened up with
fopen to which information is dumped about what
dash is doing when it runs.
Except the whole mechanism, appears to me, does not work, even in this "perfectly written" shell. If I have this in a shell script:
immediately all information after that, is very likely no longer dumped to file
trace but winds up on
stdout. That is because
open and that likely returns file descriptor 3.
This is not a contrived example. There are real-world commonly used scripts that have lines like
(I saw that in 2 autotools
configure scripts: for IP Infusion and Kerberos software).
So how can a shell be debugged/traced, when it has to run scripts like these?
(I am not looking for tools outside shell - I want to know what is the correct way to trace, inside a program such as shell. Or is it not possible in general?)