From: Alfredo Ortega <ortegaalfredo@gmail.com>
To: gdb-patches@sourceware.org
Subject: Use external editor in 'commands' command
Date: Wed, 14 Jan 2009 21:48:00 -0000 [thread overview]
Message-ID: <e598931c0901141347j4d159f16he23ad164760518ff@mail.gmail.com> (raw)
In-Reply-To: <e598931c0901141343j79164cf6we2bc5307f41f41da@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 624 bytes --]
Hi all,
I have made a small patch to the 'commands' command to allow the use
of an external editor to add or modify commands. This is convenient if
you are dealing with many commands per breakpoint.
The editor follows the behavior of the 'edit' command (/bin/ex by
default, or the 'EDITOR' environment variable)
Tested on i686-pc-linux-gnu, please tell me what do you think about it.
2009-01-14 Alfredo Ortega <ortegaalfredo@gmail.com>
* breakpoint.c (commands_command,_initialize_breakpoint):
Add the 'edit' keyword to the 'commands' command to allow the
use of an external editor to add or modify commands.
[-- Attachment #2: commands.diff --]
[-- Type: text/x-patch, Size: 3633 bytes --]
--- OLD/gdb/breakpoint.c 2009-01-14 17:46:26.000000000 -0200
+++ NEW/gdb/breakpoint.c 2009-01-14 19:32:40.000000000 -0200
@@ -585,14 +585,20 @@ condition_command (char *arg, int from_t
error (_("No breakpoint number %d."), bnum);
}
+#define COMMANDS_EDCOMMAND "edit"
+
static void
commands_command (char *arg, int from_tty)
{
struct breakpoint *b;
char *p;
- int bnum;
+ int bnum,fsize;
struct command_line *l;
-
+ char vitmp[50];
+ char cmdline[100];
+ FILE *tmpstream=NULL;
+ char *editor;
+
/* If we allowed this, we would have problems with when to
free the storage, if we change the commands currently
being read from. */
@@ -602,6 +608,41 @@ commands_command (char *arg, int from_tt
p = arg;
bnum = get_number (&p);
+ vitmp[0]=0;
+ /* Edit commands with external editor */
+ if (!strcmp(COMMANDS_EDCOMMAND,p)) {
+ /* Generates the temporal file name*/
+ /* vitmp = tempnam(NULL,".gdb"); this is more secure according to man mkstemp, but gcc complains... */
+ p=NULL;
+ strcpy(vitmp,"/tmp/.gdbXXXXXX");
+ if (mkstemp(vitmp)<0) return;
+ ALL_BREAKPOINTS (b)
+ if (b->number == bnum)
+ {
+ if (&b->commands) {
+ /* commands exists, must dump them to the temporal file */
+ tmpstream=fopen(vitmp,"w");
+ l = b->commands;
+ while(l) {
+ fsize=0;
+ fsize+=fwrite(l->line,1,strlen(l->line),tmpstream);
+ fsize+=fwrite("\n",1,strlen("\n"),tmpstream);
+ if (fsize<strlen(l->line)+1) {
+ fclose(tmpstream);
+ unlink(vitmp);
+ return;
+ };
+ l = l->next;
+ }
+ fclose(tmpstream);
+ }
+ /* Edit the file */
+ if ((editor = (char *) getenv ("EDITOR")) == NULL)
+ editor = "/bin/ex";
+ snprintf(cmdline,sizeof(cmdline),"%s \"%s\"",editor,vitmp);
+ if (system(cmdline)<0) return;
+ }
+ }
if (p && *p)
error (_("Unexpected extra arguments following breakpoint number."));
@@ -609,17 +650,31 @@ commands_command (char *arg, int from_tt
ALL_BREAKPOINTS (b)
if (b->number == bnum)
{
- char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
+ if(vitmp[0]) {
+ /* redirect instream */
+ tmpstream=instream;
+ instream=fopen(vitmp,"r");
+ l = read_command_lines (NULL, from_tty, 1);
+ }
+ else {
+ char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
bnum);
- struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
- l = read_command_lines (tmpbuf, from_tty, 1);
- do_cleanups (cleanups);
+ struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
+ l = read_command_lines (tmpbuf, from_tty, 1);
+ do_cleanups (cleanups);
+ }
free_command_lines (&b->commands);
b->commands = l;
breakpoints_changed ();
observer_notify_breakpoint_modified (b->number);
+ if(vitmp[0]) {
+ /* restore instream */
+ instream=tmpstream;
+ /* erase temporal file */
+ unlink(vitmp);
+ }
return;
- }
+ }
error (_("No breakpoint number %d."), bnum);
}
@@ -8103,6 +8158,9 @@ Usage is `ignore N COUNT'."));
add_com ("commands", class_breakpoint, commands_command, _("\
Set commands to be executed when a breakpoint is hit.\n\
Give breakpoint number as argument after \"commands\".\n\
+After the command number you can enter the `edit' keyword, and then you can \n\
+use the external editor to add or modify commands.\n\
+Uses EDITOR environment variable contents as editor (or ex as default).\n\
With no argument, the targeted breakpoint is the last one set.\n\
The commands themselves follow starting on the next line.\n\
Type a line containing \"end\" to indicate the end of them.\n\
next parent reply other threads:[~2009-01-14 21:48 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <e598931c0901141343j79164cf6we2bc5307f41f41da@mail.gmail.com>
2009-01-14 21:48 ` Alfredo Ortega [this message]
2009-01-14 22:38 ` Eli Zaretskii
2009-01-15 1:55 ` Alfredo Ortega
2009-01-22 3:25 ` dgutson
[not found] ` <e598931c0901141632m4f124d85l2452f7e2870cad91@mail.gmail.com>
2009-01-15 4:21 ` Eli Zaretskii
2009-01-16 7:39 ` Alfredo Ortega
2009-01-16 9:07 ` Eli Zaretskii
2009-01-16 22:08 ` Alfredo Ortega
2009-01-16 23:38 ` Daniel Jacobowitz
2009-01-16 23:58 ` Tom Tromey
2009-01-17 9:27 ` Eli Zaretskii
2009-01-16 23:56 ` Tom Tromey
2009-01-17 9:29 ` Eli Zaretskii
2009-01-19 11:45 ` Alfredo Ortega
2009-02-02 22:18 ` Tom Tromey
2009-02-19 20:05 ` Alfredo Ortega
2009-02-19 20:26 ` Alfredo Ortega
2009-02-24 20:20 ` Tom Tromey
2009-08-28 23:17 ` Alfredo Ortega
2009-09-18 21:05 ` Tom Tromey
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=e598931c0901141347j4d159f16he23ad164760518ff@mail.gmail.com \
--to=ortegaalfredo@gmail.com \
--cc=gdb-patches@sourceware.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox