zsh-workers
 help / color / mirror / code / Atom feed
From: "Rocky Bernstein" <rocky.bernstein@gmail.com>
To: "Zsh hackers list" <zsh-workers@sunsite.dk>
Subject: DEBUG_CMD_LINE (Was Re: PATCH: skip command from debug trap)
Date: Wed, 6 Aug 2008 17:19:14 -0400	[thread overview]
Message-ID: <6cd6de210808061419q2a81856cv62969490069e8f3e@mail.gmail.com> (raw)

On Wed, Aug 6, 2008 at 3:49 PM, Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
> "Rocky Bernstein" wrote:
>> But given the choice of adding
>>    1) an option in the return statement everywhere that is specific to
>> just "trap DEBUG" or
>>    2) specifying what specific numbers do when on a return from "trap DEBUG",
>>
>> isn't 2) simpler and more consistent with programming in shell
>> languages work? I take it as a given that every function or command is
>> going to have error codes that are somewhat arbitrary and that I'm not
>> going to intuit.
>
> I'm in two minds about this.

Ok. I'm sure you'll do what's best and let us know what is decided.

> If we didn't have the existing rule that
> any non-zero return status from TRAPDEBUG, or any explicit return from
> within an inline trap, forced an immediate return, then I'd agree simply
> adding to the set of useful statuses was cleaner and more natural.  As
> it is, we're now forced to pick some numeric value the user wouldn't
> naturally want to return from am enclosing context (since the return
> value is propagated).
>
> The option to return seems to me natural enough, because as "return"
> means "just return", so "return with an option" means "return but with
> slightly different semantics".  Having a different return status meaning
> to execute different code (rather than simply provide a different test
> for the caller, as normal) is an unusual enough effect that it doesn't
> strike me as the unequivocal answer.
>
> But, whatever.  If there's a number we all really like to mean "skip",
> we can go with that.  It's already working, is easy to document, and
> doesn't need any changes to parsing.
>
> (By the way, it wouldn't be too hard, if not completely trivial, to pass
> down the code about to be executed in a variable, say DEBUG_CMD_LINE, as
> reconstructed text, i.e. the same sort of format as what you get if you
> get the shell to output a shell function that's already loaded.  But
> it's messy enough that I won't unless it's definitely useful.)

My secret plan was to get the debugger working enough for folks to realize this
would be useful. In bash the variable $BASH_COMMAND holds the command that
is up for execution next. It is not the "line"  (as suggested in the
name DEBUG_CMD_LINE)
 but the last command or statement.

And  although DEBUG_CMD_LINE can be used in debugging, there's nothing
about it that
strictly needs to be so. For example suppose I wanted to get statistics on how
many commands are run that start with the letter A.

Anyway, in debugging where it's most useful are places where there are
statement
lines for example

   [[ -z $FOO ]] && bar || baz
   temp=x; x=y; y=temp

If one is is stepping along it can be useful to know in which part of
the line you
are about to run. The hueristic that bashdb uses is that if the line
number is the
same as the last line number that it stopped at but the command string changes,
then it's probably a good idea to show not just the line but also the command
that is about to be executed. In practice this means that one can assume that
whenever you see a line with more than one statement and no statement is
explicitly printed, then one can assume that the statement that is about to be
run is the first one shown. And if one is not sure one can just run a
print $BASH_COMMAND
debugger command.

>
> --
> Peter Stephenson <p.w.stephenson@ntlworld.com>
> Web page now at http://homepage.ntlworld.com/p.w.stephenson/
>


             reply	other threads:[~2008-08-06 21:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-06 21:19 Rocky Bernstein [this message]
2008-08-07  8:54 ` Peter Stephenson
2008-08-07  9:31   ` Stephane Chazelas
2008-08-07 10:14     ` Peter Stephenson
2008-08-07 10:40       ` Stephane Chazelas
2008-08-07 12:06         ` Peter Stephenson
2008-08-07 13:37           ` Rocky Bernstein
2008-08-07 15:10             ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6cd6de210808061419q2a81856cv62969490069e8f3e@mail.gmail.com \
    --to=rocky.bernstein@gmail.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).