* ZLE widget to run gdb on command line
@ 2006-10-06 14:52 Chris Johnson
2006-10-06 15:23 ` DervishD
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Chris Johnson @ 2006-10-06 14:52 UTC (permalink / raw)
To: zsh-users
Hi. I just thought I'd share a widget that I find helpful. Invoking
gdb is something I need to do a lot lately, it seems, and I often think
I can pass the program's arguments as arguments to gdb:
gdb myprog arg1 arg2 arg3
But gdb doesn't accept this because it expects other unnamed arguments.
Treating the whole command as a single argument to gdb also fails:
gdb "myprog arg1 arg2 arg3"
The single argument is treated as a single executable name. The only
way I know of to pass arguments to the executable is with gdb's run
command at the interpreter. So, the following widget effectively
transforms the line
myprog arg1 arg2 arg3
into
gdb myprog
gdb-prompt> run arg1 arg2 arg3
. Any comments or alternative solutions are quite welcome. I don't
know zle or history expansion very well.
--------------------------
run-in-gdb() {
# This function is ZLE widget that runs the current command in gdb.
# Since gdb doesn't take the program's arguments as arguments to gdb
# itself but rather through the interpreter, a "run" command is
# printed
# out to a temporary file which is invoked as script for gdb to grab
# commands from at startup.
# Commit current command line to history, inset its words in a gdb
# command, expand history to bypass HIST_VERIFY, and run it.
print -s ${(z)BUFFER}
BUFFER="gdb !!0 -x =(echo run !!1*)"
zle expand-history
zle accept-line
}
zle -N run-in-gdb
bindkey "^X^G" run-in-gdb
--------------------------
--
Chris Johnson
cjohnson@cs.utk.edu
http://www.cs.utk.edu/~cjohnson
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ZLE widget to run gdb on command line
2006-10-06 14:52 ZLE widget to run gdb on command line Chris Johnson
@ 2006-10-06 15:23 ` DervishD
2006-10-06 15:36 ` Chris Johnson
2006-10-06 15:25 ` Drew Perttula
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: DervishD @ 2006-10-06 15:23 UTC (permalink / raw)
To: Chris Johnson; +Cc: zsh-users
Hi Chris :)
* Chris Johnson <cjohnson@cs.utk.edu> dixit:
> Hi. I just thought I'd share a widget that I find helpful. Invoking
> gdb is something I need to do a lot lately, it seems, and I often think
> I can pass the program's arguments as arguments to gdb:
>
> gdb myprog arg1 arg2 arg3
>
> But gdb doesn't accept this because it expects other unnamed arguments.
> Treating the whole command as a single argument to gdb also fails:
>
> gdb "myprog arg1 arg2 arg3"
>
> The single argument is treated as a single executable name.
Obvious, gdb gets it as just ONE argument ;)
Try this:
gdb --args myprog arg1 arg2 arg3
(if you don't use a core argument, of course)
BTW, the widget is quite useful, not only for gdb, but for other
interactive programs too where you ALWAYS run certain command at
startup. Thanks :))
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
It's my PC and I'll cry if I want to... RAmen!
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ZLE widget to run gdb on command line
2006-10-06 14:52 ZLE widget to run gdb on command line Chris Johnson
2006-10-06 15:23 ` DervishD
@ 2006-10-06 15:25 ` Drew Perttula
2006-10-06 17:04 ` Phil Pennock
2006-10-07 2:31 ` Bart Schaefer
3 siblings, 0 replies; 9+ messages in thread
From: Drew Perttula @ 2006-10-06 15:25 UTC (permalink / raw)
To: Chris Johnson; +Cc: zsh-users
Chris Johnson wrote:
> Hi. I just thought I'd share a widget that I find helpful. Invoking
> gdb is something I need to do a lot lately, it seems, and I often think
> I can pass the program's arguments as arguments to gdb:
>
> gdb myprog arg1 arg2 arg3
>
> But gdb doesn't accept this because it expects other unnamed arguments.
> Treating the whole command as a single argument to gdb also fails:
>
> gdb "myprog arg1 arg2 arg3"
>
gdb --args myprog arg1 arg2 arg3
works on my version of gdb, at least.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ZLE widget to run gdb on command line
2006-10-06 15:23 ` DervishD
@ 2006-10-06 15:36 ` Chris Johnson
2006-10-06 15:50 ` DervishD
0 siblings, 1 reply; 9+ messages in thread
From: Chris Johnson @ 2006-10-06 15:36 UTC (permalink / raw)
To: zsh-users
DervishD sent me the following 1.0K:
> > Hi. I just thought I'd share a widget that I find helpful. Invoking
> > gdb is something I need to do a lot lately, it seems, and I often think
> > I can pass the program's arguments as arguments to gdb:
>
> Try this:
>
> gdb --args myprog arg1 arg2 arg3
You think they'd document these things in the man pages. Or maybe my
man pages are out of date.
> (if you don't use a core argument, of course)
>
> BTW, the widget is quite useful, not only for gdb, but for other
> interactive programs too where you ALWAYS run certain command at
> startup. Thanks :))
Yep, you still need to type "run" with --args. Thanks for the heads-up.
--
Chris Johnson
cjohnson@cs.utk.edu
http://www.cs.utk.edu/~cjohnson
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ZLE widget to run gdb on command line
2006-10-06 15:36 ` Chris Johnson
@ 2006-10-06 15:50 ` DervishD
2006-10-06 16:38 ` John Eikenberry
0 siblings, 1 reply; 9+ messages in thread
From: DervishD @ 2006-10-06 15:50 UTC (permalink / raw)
To: Chris Johnson; +Cc: zsh-users
Hi Chris :)
* Chris Johnson <cjohnson@cs.utk.edu> dixit:
> DervishD sent me the following 1.0K:
This is the most funny attribution line I've ever seen XDDDD
> > > Hi. I just thought I'd share a widget that I find helpful. Invoking
> > > gdb is something I need to do a lot lately, it seems, and I often think
> > > I can pass the program's arguments as arguments to gdb:
> >
> > Try this:
> >
> > gdb --args myprog arg1 arg2 arg3
>
> You think they'd document these things in the man pages. Or maybe my
> man pages are out of date.
With GNU things, don't rely on manpages, rely on the info
documentation (yes, I hate that format too, but...). In the --help
output the "--args" option is slightly documented (being "slightly"
the keyword here...).
Unfortunately, not all software is as well documented as zsh,
specially GNU software.
> > (if you don't use a core argument, of course)
> >
> > BTW, the widget is quite useful, not only for gdb, but for other
> > interactive programs too where you ALWAYS run certain command at
> > startup. Thanks :))
>
> Yep, you still need to type "run" with --args. Thanks for the heads-up.
I'm using your widget right now with a friend's ftp server that
forces me to do "epsv4 off" in my ftpclient each time I connect. As I
said, this is quite useful :))
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
It's my PC and I'll cry if I want to... RAmen!
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ZLE widget to run gdb on command line
2006-10-06 15:50 ` DervishD
@ 2006-10-06 16:38 ` John Eikenberry
0 siblings, 0 replies; 9+ messages in thread
From: John Eikenberry @ 2006-10-06 16:38 UTC (permalink / raw)
To: zsh-users; +Cc: Chris Johnson
DervishD wrote:
> With GNU things, don't rely on manpages, rely on the info
> documentation (yes, I hate that format too, but...). In the --help
> output the "--args" option is slightly documented (being "slightly"
> the keyword here...).
If you don't already use it, check out pinfo. It is an ncurses info/man
page viewer that makes info docs much more tolerable.
--
John Eikenberry
[jae@zhar.net - http://zhar.net]
______________________________________________________________
"It is difficult to produce a television documentary that is both incisive
and probing when every twelve minutes one is interrupted by twelve dancing
rabbits singing about toilet paper." - Rod Serling
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ZLE widget to run gdb on command line
2006-10-06 14:52 ZLE widget to run gdb on command line Chris Johnson
2006-10-06 15:23 ` DervishD
2006-10-06 15:25 ` Drew Perttula
@ 2006-10-06 17:04 ` Phil Pennock
2006-10-07 2:10 ` Bart Schaefer
2006-10-07 2:31 ` Bart Schaefer
3 siblings, 1 reply; 9+ messages in thread
From: Phil Pennock @ 2006-10-06 17:04 UTC (permalink / raw)
To: Chris Johnson; +Cc: zsh-users
On 2006-10-06 at 10:52 -0400, Chris Johnson wrote:
> print -s ${(z)BUFFER}
> BUFFER="gdb !!0 -x =(echo run !!1*)"
If one of the args starts with - then won't that turn into an option to
echo?
Perhaps =(print -r -- run !!1*) would be more reliable? Or am I missing
something?
Also there's the matter of quoted strings, such as 'foo bar'.
=(print -r -- ${(Q):-"${(qqq):-run !!1*}"})
The nearest that I can get to preserving the quotes but passing things
through to the command is the above, but it seems a bit strange to be
immediately removing a level of quoting just applied, so I've probably
over-complicated it.
Regards,
-Phil
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ZLE widget to run gdb on command line
2006-10-06 17:04 ` Phil Pennock
@ 2006-10-07 2:10 ` Bart Schaefer
0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2006-10-07 2:10 UTC (permalink / raw)
To: zsh-users
On Oct 6, 7:04pm, Phil Pennock wrote:
} Subject: Re: ZLE widget to run gdb on command line
}
} On 2006-10-06 at 10:52 -0400, Chris Johnson wrote:
} > print -s ${(z)BUFFER}
} > BUFFER="gdb !!0 -x =(echo run !!1*)"
}
} If one of the args starts with - then won't that turn into an option to
} echo?
If $BUFFER starts with "-" it'll turn into an option to print -s, but
the placement of "run" after "echo" means nothing beyond that will be
treated as options. (For those who have been following the strange
discussion on the austin-group list, zsh is not a GNU program and it
does not in general interpret as options strings beginning with a "-"
that appear after non-option operands.)
Interpretation of various backslashed sequences in the arguments is
another matter. From that standpoint, print -r would be better.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ZLE widget to run gdb on command line
2006-10-06 14:52 ZLE widget to run gdb on command line Chris Johnson
` (2 preceding siblings ...)
2006-10-06 17:04 ` Phil Pennock
@ 2006-10-07 2:31 ` Bart Schaefer
3 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2006-10-07 2:31 UTC (permalink / raw)
To: zsh-users
On Oct 6, 10:52am, Chris Johnson wrote:
}
} print -s ${(z)BUFFER}
} BUFFER="gdb !!0 -x =(echo run !!1*)"
} zle expand-history
} zle accept-line
This is a useful idea, but you have a whole function scope to play with.
No need to resort to expanding strings from the history.
set -- "${(@z)BUFFER}"
BUFFER="gdb $argv[1] -x =(print -r run ${(q)argv[2-]})"
zle accept-line
If you want the original line to appear in the history, insert
print -s -- "$@"
after the "set" command.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2006-10-07 2:31 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-06 14:52 ZLE widget to run gdb on command line Chris Johnson
2006-10-06 15:23 ` DervishD
2006-10-06 15:36 ` Chris Johnson
2006-10-06 15:50 ` DervishD
2006-10-06 16:38 ` John Eikenberry
2006-10-06 15:25 ` Drew Perttula
2006-10-06 17:04 ` Phil Pennock
2006-10-07 2:10 ` Bart Schaefer
2006-10-07 2:31 ` Bart Schaefer
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).