zsh-users
 help / color / mirror / code / Atom feed
From: Chris Johnson <cjohnson@cs.utk.edu>
To: zsh-users@sunsite.dk
Subject: ZLE widget to run gdb on command line
Date: Fri, 6 Oct 2006 10:52:22 -0400	[thread overview]
Message-ID: <20061006145222.GA32307@namib.cs.utk.edu> (raw)

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


             reply	other threads:[~2006-10-06 14:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-06 14:52 Chris Johnson [this message]
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

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=20061006145222.GA32307@namib.cs.utk.edu \
    --to=cjohnson@cs.utk.edu \
    --cc=zsh-users@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).