Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Alfredo Ortega <ortegaalfredo@gmail.com>
To: gdb-patches@sourceware.org
Subject: Re: Use external editor in 'commands' command
Date: Fri, 16 Jan 2009 07:39:00 -0000	[thread overview]
Message-ID: <e598931c0901152338l2b1bde20r7e242167e038ea8f@mail.gmail.com> (raw)
In-Reply-To: <uab9tw67k.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1837 bytes --]

2009/1/15 Eli Zaretskii <eliz@gnu.org>:
>> Date: Wed, 14 Jan 2009 22:32:03 -0200
>> From: Alfredo Ortega <ortegaalfredo@gmail.com>
>>
>> I see. This updated patch contains my proposed documentation changes
>> to gdb.texinfo and refcard.tex. I hope that the patch format is
>> adequate.
>
> Thanks you.
>
> First, please also submit ChangeLog entries for your changes, both in
> code and in documentation.
>
>> +@item commands @r{[}@var{bnum}@r{]} edit
>> +This spawns an external editor for adding or editing commands. the final  @code{end} is not necessary in this case. @xref{Choosing your Editor}.
>                                                                  ^^^
> Capital "T" here.
>
> Also, please leave 2 blanks after a period that ends a sentence.
>
>> +@node Choosing your Editor
>>  @subsection Choosing your Editor
>
> Adding a @node requires that you also modify the @menu in its parent
> node, otherwise makeinfo will barf.
>
>> +\qquad {\it command-list}&execute GDB {\it command-list} every time breakpoint {\it n} is reached. \opt{{\tt silent} suppresses default display}  \opt{{\tt edit} use external editor for commands}
>                                                                   ^^^
> A period missing here.
>

Thanks for the corrections. Here are are both changelogs and the
updated diff, I hope there are less errors now...
I promise that my next patches will be better!

2009-01-16 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.

2009-01-16 Alfredo Ortega <ortegaalfredo@gmail.com>
    * gdb.texinfo, refcard.tex (breakpoint commands): Added
documentation of the edit option, for editing commands with an
external editor.

[-- Attachment #2: commands.diff --]
[-- Type: text/x-patch, Size: 5844 bytes --]

diff -upr OLD/gdb/breakpoint.c NEW/gdb/breakpoint.c
--- 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\
diff -upr OLD/gdb/doc/gdb.texinfo NEW/gdb/doc/gdb.texinfo
--- OLD/gdb/doc/gdb.texinfo	2009-01-14 17:46:18.000000000 -0200
+++ NEW/gdb/doc/gdb.texinfo	2009-01-16 03:54:37.000000000 -0200
@@ -3976,6 +3976,8 @@ follow it immediately with @code{end}; t
 With no @var{bnum} argument, @code{commands} refers to the last
 breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
 recently encountered).
+@item commands @r{[}@var{bnum}@r{]} edit
+This spawns an external editor for adding or editing commands.  The final  @code{end} is not necessary in this case.  @xref{Choosing your Editor}.
 @end table
 
 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
@@ -5384,6 +5386,7 @@ prefer to use Emacs facilities to view s
 * List::                        Printing source lines
 * Specify Location::            How to specify code locations
 * Edit::                        Editing source files
+* Choosing your Editor::        Specifying your text editor
 * Search::                      Searching source files
 * Source Path::                 Specifying source directories
 * Machine Code::                Source and machine code
@@ -5587,6 +5590,7 @@ Edit the file containing @var{function} 
 
 @end table
 
+@node Choosing your Editor
 @subsection Choosing your Editor
 You can customize @value{GDBN} to use any editor you want
 @footnote{
diff -upr OLD/gdb/doc/refcard.tex NEW/gdb/doc/refcard.tex
--- OLD/gdb/doc/refcard.tex	2009-01-14 17:46:18.000000000 -0200
+++ NEW/gdb/doc/refcard.tex	2009-01-16 03:54:44.000000000 -0200
@@ -355,10 +355,9 @@ delete when reached
 ignore {\it n} {\it count}&ignore breakpoint {\it n}, {\it count}
 times\cr
 \cr
-commands {\it n}\par
+commands {\it n} \opt{{\it edit}} \par
 \qquad \opt{\tt silent}\par
-\qquad {\it command-list}&execute GDB {\it command-list} every time breakpoint {\it n} is reached. \opt{{\tt silent} suppresses default
-display}\cr
+\qquad {\it command-list}&execute GDB {\it command-list} every time breakpoint {\it n} is reached  \opt{{\tt edit} using external editor}. \opt{{\tt silent} suppresses default display} \cr
 end&end of {\it command-list}\cr
 \endsec
 

  reply	other threads:[~2009-01-16  7:39 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
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 [this message]
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=e598931c0901152338l2b1bde20r7e242167e038ea8f@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