This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Re-posting of proposed patch


All -

     I posted this patch 2 July, and while the doc portions were approved
(Eli Zaretskii), the remainder doesn't appear to have been looked at.  In
the hope that it was simply overlooked in the beehive of other work evident
from the list's activity, I'm re-posting it to facilitate approval by those
responsible.

					 George Helffrich


2002-07-02  George Helffrich <george@gly.bris.ac.uk>

      * cli/cli-cmds.c, defs.h, source.c, gdb.1, doc/gdb.texinfo,
      doc/refcard.tex: Add edit command.  This command mimics the behavior
      of Sun and SGI dbx, and invokes an editor at the current line number.
      Editor comes from EDITOR environment variable, or defaults to /bin/ex.

Index: gdb-5.1.1/src/gdb/defs.h
===================================================================
RCS file: /usr/src/local/cvsroot/gdb-5.1.1/src/gdb/defs.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -c -r1.1.1.1 -r1.2
*** gdb-5.1.1/src/gdb/defs.h	2002/02/02 11:34:18	1.1.1.1
--- gdb-5.1.1/src/gdb/defs.h	2002/05/26 12:12:26	1.2
***************
*** 751,756 ****
--- 751,760 ----
  
  extern void print_address (CORE_ADDR, struct ui_file *);
  
+ /* From command.c */
+ 
+ extern void shell_escape (char *, int);
+ 
  /* From source.c */
  
  extern int openp (const char *, int, const char *, int, int, char **);
Index: gdb-5.1.1/src/gdb/gdb.1
===================================================================
RCS file: /usr/src/local/cvsroot/gdb-5.1.1/src/gdb/gdb.1,v
retrieving revision 1.2
retrieving revision 1.3
diff -c -r1.2 -r1.3
*** gdb-5.1.1/src/gdb/gdb.1	2002/05/22 12:25:15	1.2
--- gdb-5.1.1/src/gdb/gdb.1	2002/05/26 12:16:34	1.3
***************
*** 1,6 ****
  .\" Copyright 1991, 1999 Free Software Foundation, Inc.
  .\" See section COPYING for conditions for redistribution
! .\" $Id: gdb.1,v 1.2 2002/05/22 12:25:15 george Exp $
  .TH gdb 1 "22may2002" "GNU Tools" "GNU Tools"
  .SH NAME
  gdb \- The GNU Debugger
--- 1,6 ----
  .\" Copyright 1991, 1999 Free Software Foundation, Inc.
  .\" See section COPYING for conditions for redistribution
! .\" $Id: gdb.1,v 1.3 2002/05/26 12:16:34 george Exp $
  .TH gdb 1 "22may2002" "GNU Tools" "GNU Tools"
  .SH NAME
  gdb \- The GNU Debugger
***************
*** 148,153 ****
--- 148,156 ----
  .I over\c
  \& any
  function calls in the line.
+ .TP
+ .B edit \fR[\|\fIfile\fB:\fR\|]\fIfunction
+ look at the program line where it is presently stopped.
  .TP
  .B list \fR[\|\fIfile\fB:\fR\|]\fIfunction
  type the text of the program in the vicinity of where it is presently stopped.
Index: gdb-5.1.1/src/gdb/cli/cli-cmds.c
===================================================================
RCS file: /usr/src/local/cvsroot/gdb-5.1.1/src/gdb/cli/cli-cmds.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -c -r1.1.1.1 -r1.2
*** gdb-5.1.1/src/gdb/cli/cli-cmds.c	2002/02/02 11:34:57	1.1.1.1
--- gdb-5.1.1/src/gdb/cli/cli-cmds.c	2002/05/26 12:13:00	1.2
***************
*** 77,84 ****
  
  static void make_command (char *, int);
  
- static void shell_escape (char *, int);
- 
  void apropos_command (char *, int);
  
  /* Define all cmd_list_elements.  */
--- 77,82 ----
***************
*** 427,433 ****
  }
  
  /* ARGSUSED */
! static void
  shell_escape (char *arg, int from_tty)
  {
  #ifdef CANT_FORK
--- 425,431 ----
  }
  
  /* ARGSUSED */
! void
  shell_escape (char *arg, int from_tty)
  {
  #ifdef CANT_FORK
Index: gdb-5.1.1/src/gdb/doc/refcard.tex
===================================================================
RCS file: /usr/src/local/cvsroot/gdb-5.1.1/src/gdb/doc/refcard.tex,v
retrieving revision 1.1
retrieving revision 1.2
diff -c -r1.1 -r1.2
*** gdb-5.1.1/src/gdb/doc/refcard.tex	2002/02/02 11:35:11	1.1
--- gdb-5.1.1/src/gdb/doc/refcard.tex	2002/06/06 10:36:31	1.2
***************
*** 598,603 ****
--- 598,605 ----
  \quad{\tt -\it off}&{\it off} lines previous to last printed\cr
  \quad{\tt*\it address}&line containing {\it address}\cr
  list {\it f},{\it l}&from line {\it f} to line {\it l}\cr
+ edit&edit program at active line (editor used is EDITOR env. variable or /bin/ex)\cr
+ edit {\it line}&line specification as for list command\cr
  info line {\it num}&show starting, ending addresses of compiled code for
  source line {\it num}\cr
  info source&show name of current source file\cr
Index: gdb-5.1.1/src/gdb/doc/ChangeLog
===================================================================
RCS file: /usr/src/local/cvsroot/gdb-5.1.1/src/gdb/doc/ChangeLog,v
retrieving revision 1.1
retrieving revision 1.2
diff -c -r1.1 -r1.2
*** gdb-5.1.1/src/gdb/doc/ChangeLog	2002/02/02 11:35:10	1.1
--- gdb-5.1.1/src/gdb/doc/ChangeLog	2002/06/06 10:38:31	1.2
***************
*** 1,3 ****
--- 1,7 ----
+ 2002-06-06  George Helffrich <george@gly.bris.ac.uk>
+ 
+ 	* gdb.texinfo, refcard.dvi: Document edit command.
+ 
  2002-01-27  Eli Zaretskii  <eliz@is.elta.co.il>
  
  	* gdb.texinfo: Fix typos and markup.  From Dmitry Sivachenko
Index: gdb-5.1.1/src/gdb/doc/gdb.texinfo
===================================================================
RCS file: /usr/src/local/cvsroot/gdb-5.1.1/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.1
retrieving revision 1.2.2.1
diff -c -r1.1 -r1.2.2.1
*** gdb-5.1.1/src/gdb/doc/gdb.texinfo	2002/02/02 11:35:11	1.1
--- gdb-5.1.1/src/gdb/doc/gdb.texinfo	2002/07/02 10:21:44	1.2.2.1
***************
*** 31,38 ****
  @set EDITION Ninth
  
  @c !!set GDB manual's revision date
! @set DATE January 2002
  
  @c THIS MANUAL REQUIRES TEXINFO 3.12 OR LATER.
  
  @c This is a dir.info fragment to support semi-automated addition of
--- 31,41 ----
  @set EDITION Ninth
  
  @c !!set GDB manual's revision date
! @set DATE June 2002
  
+ @c !!set GDB edit command default editor
+ @set EDITOR /bin/ex
+ 
  @c THIS MANUAL REQUIRES TEXINFO 3.12 OR LATER.
  
  @c This is a dir.info fragment to support semi-automated addition of
***************
*** 3965,3971 ****
  
  After such a printout, the @code{list} command with no arguments
  prints ten lines centered on the point of execution in the frame.
! @xref{List, ,Printing source lines}.
  
  @table @code
  @kindex down-silently
--- 3968,3977 ----
  
  After such a printout, the @code{list} command with no arguments
  prints ten lines centered on the point of execution in the frame.
! You can also edit the program at the point of execution with your favorite
! editing program by typing @code{edit}.
! @xref{List, ,Printing source lines},
! for details.
  
  @table @code
  @kindex down-silently
***************
*** 4072,4077 ****
--- 4078,4084 ----
  
  @menu
  * List::                        Printing source lines
+ * Edit::                        Editing source files
  * Search::                      Searching source files
  * Source Path::                 Specifying source directories
  * Machine Code::                Source and machine code
***************
*** 4193,4198 ****
--- 4200,4270 ----
  Specifies the line containing the program address @var{address}.
  @var{address} may be any expression.
  @end table
+ 
+ @node Edit
+ @section Editing source files
+ @cindex editing source files
+ 
+ @kindex edit
+ @kindex e @r{(@code{edit})}
+ To edit the lines in a source file, use the @code{edit} command.
+ The editing program of your choice
+ is invoked with the current line set to
+ the active line in the program.
+ Alternatively, there are several ways to specify what part of the file you
+ want to print if you want to see other parts of the program.
+ 
+ Here are the forms of the @code{edit} command most commonly used:
+ 
+ @table @code
+ @item edit
+ Edit the current source file at the active line number in the program.
+ 
+ @item edit @var{number}
+ Edit the current source file with @var{number} as the active line number.
+ 
+ @item edit @var{function}
+ Edit the file containing @var{function} at the beginning of its definition.
+ 
+ @item edit @var{filename}:@var{number}
+ Specifies line @var{number} in the source file @var{filename}.
+ 
+ @item edit @var{filename}:@var{function}
+ Specifies the line that begins the body of the
+ function @var{function} in the file @var{filename}.  You only need the
+ file name with a function name to avoid ambiguity when there are
+ identically named functions in different source files.
+ 
+ @item edit *@var{address}
+ Specifies the line containing the program address @var{address}.
+ @var{address} may be any expression.
+ @end table
+ 
+ @subsection Choosing your editor
+ You can customize @value{GDBN} to use any editor you want
+ @footnote{
+ The only restriction is that your editor (say @code{ex}), recognizes the
+ following command-line syntax:
+ @example
+ ex +@var{number} file
+ @end example
+ The optional numeric value +@var{number} designates the active line in the file.
+ }.
+ By default, it is @value{EDITOR}, but you can change this by setting the
+ environment variable @code{EDITOR} before using
+ @value{GDBN}.
+ For example, to configure @value{GDBN} to use the @code{vi} editor, you
+ could use these commands with the @code{sh} shell:
+ @example
+ EDITOR=/usr/bin/vi
+ export EDITOR
+ gdb ...
+ @end example
+ or in the @code{csh} shell,
+ @example
+ setenv EDITOR /usr/bin/vi
+ gdb ...
+ @end example
  
  @node Search
  @section Searching source files
Index: gdb-5.1.1/src/gdb/source.c
===================================================================
RCS file: /usr/src/local/cvsroot/gdb-5.1.1/src/gdb/source.c,v
retrieving revision 1.2
retrieving revision 1.3.2.2
diff -c -r1.2 -r1.3.2.2
*** gdb-5.1.1/src/gdb/source.c	2002/05/25 20:27:13	1.2
--- gdb-5.1.1/src/gdb/source.c	2002/07/02 10:32:21	1.3.2.2
***************
*** 82,87 ****
--- 82,91 ----
  
  static void list_command (char *, int);
  
+ static void edit_command (char *, int);
+ 
+ static void do_edit (struct symtab *, int, int);
+ 
  static void ambiguous_line_spec (struct symtabs_and_lines *);
  
  static void source_info (char *, int);
***************
*** 1443,1448 ****
--- 1447,1563 ----
    xfree (sals.sals);
  }
  
+ static void
+ edit_command (char *arg, int from_tty)
+ {
+   struct symtabs_and_lines sals, sals_end;
+   struct symtab_and_line sal, sal_end;
+   struct symbol *sym;
+   char *arg1;
+ 
+   if (!have_full_symbols () && !have_partial_symbols())
+     error ("No symbol table is loaded.  Use the \"file\" command.");
+ 
+   /* Pull in a current source symtab if necessary */
+   if (current_source_symtab == 0 &&
+       (arg == 0 || arg[0] == '+' || arg[0] == '-'))
+     select_source_symtab (0);
+ 
+   /* bare "edit" edits file with present line.  */
+ 
+   if (arg == 0)
+     {
+       if (current_source_symtab == 0)
+ 	error ("No default source file yet.  Do \"help edit\".");
+       do_edit (current_source_symtab,
+                current_source_line + lines_to_list/2, from_tty);
+       return;
+     }
+ 
+   /* Now should only be one argument -- decode it in SAL */
+ 
+   arg1 = arg;
+   sals = decode_line_1 (&arg1, 0, 0, 0, 0);
+ 
+   if (! sals.nelts) return;  /*  C++  */
+   if (sals.nelts > 1) {
+     ambiguous_line_spec (&sals);
+     free (sals.sals);
+     return;
+   }
+ 
+   sal = sals.sals[0];
+   free (sals.sals);
+ 
+   if (*arg1)
+     error ("Junk at end of line specification.");
+ 
+   /* if line was specified by address,
+      first print exactly which line, and which file.
+      In this case, sal.symtab == 0 means address is outside
+      of all known source files, not that user failed to give a filename.  */
+   if (*arg == '*')
+     {
+       if (sal.symtab == 0)
+ 	/* FIXME-32x64--assumes sal.pc fits in long.  */
+ 	error ("No source file for address %s.",
+ 		local_hex_string((unsigned long) sal.pc));
+       sym = find_pc_function (sal.pc);
+       if (sym)
+ 	{
+ 	  print_address_numeric (sal.pc, 1, gdb_stdout);
+ 	  printf_filtered (" is in ");
+ 	  fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
+ 	  printf_filtered (" (%s:%d).\n", sal.symtab->filename, sal.line);
+ 	}
+       else
+ 	{
+ 	  print_address_numeric (sal.pc, 1, gdb_stdout);
+ 	  printf_filtered (" is at %s:%d.\n",
+ 			   sal.symtab->filename, sal.line);
+ 	}
+     }
+ 
+   /* If what was given does not imply a symtab, it must be an undebuggable
+      symbol which means no source code.  */
+ 
+   if (sal.symtab == 0)
+     error ("No line number known for %s.", arg);
+ 
+   do_edit(sal.symtab, sal.line, from_tty);
+ }
+ 
+ static void
+ do_edit (struct symtab *symtb, int line, int from_tty)
+ {
+   int cmdlen, log10;
+   unsigned m;
+   char *editor;
+   char *p;
+ 
+   if ((editor = (char *) getenv ("EDITOR")) == NULL)
+       editor = "/bin/ex";
+   
+   /* Approximate base-10 log of line to 1 unit for digit count */
+   for(log10=32, m=0x80000000; !(line & m) && log10>0; log10--, m=m>>1);
+   log10 = 1 + (int)((log10 + (0 == ((m-1)&line)))/3.32192809);
+ 
+   cmdlen = strlen(editor) + 1
+          + (NULL == symtb->dirname ? 0 : strlen(symtb->dirname) + 1)
+ 	 + (NULL == symtb->filename? 0 : strlen(symtb->filename)+ 1)
+ 	 + log10 + 2;
+   
+   p = xmalloc(cmdlen);
+   sprintf(p,"%s +%d %s%s",editor,line,
+      (NULL == symtb->dirname ? "./" :
+         (NULL != symtb->filename && *(symtb->filename) != '/') ?
+ 	   symtb->dirname : ""),
+      (NULL == symtb->filename ? "unknown" : symtb->filename)
+   );
+   shell_escape(p, from_tty);
+   free(p);
+ }
+ 
  /* Commands to search the source file for a regexp.  */
  
  /* ARGSUSED */
***************
*** 1727,1732 ****
--- 1842,1860 ----
  
    if (dbx_commands)
      add_com_alias ("file", "list", class_files, 1);
+ 
+   c = add_com ("edit", class_files, edit_command,
+            concat ("Edit specified file or function.\n\
+ With no argument, edits file containing most recent line listed.\n\
+ ", "\
+ Editing targets can be specified in these ways:\n\
+   FILE:LINENUM, to edit at that line in that file,\n\
+   FUNCTION, to edit at the beginning of that function,\n\
+   FILE:FUNCTION, to distinguish among like-named static functions.\n\
+   *ADDRESS, to edit at the line containing that address.\n\
+ Uses EDITOR environment variable contents as editor (or ex as default).",NULL));
+ 
+   c->completer = location_completer;
  
    add_show_from_set
      (add_set_cmd ("listsize", class_support, var_uinteger,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]