zsh-users
 help / color / mirror / code / Atom feed
* 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

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).