Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "G. Helffrich" <george@gly.bris.ac.uk>
To: gdb-patches@sources.redhat.com
Subject: Proposed gdb patch
Date: Tue, 28 May 2002 05:15:00 -0000	[thread overview]
Message-ID: <200205281057.LAA00860@xterm1.gly.bris.ac.uk> (raw)


Dear GDBers -

     Here is a patch to gdb 5.1.1 that adds functionality to the gdb command
language.  It implements the "edit" command featured in Sun's dbx, which
invokes your favorite file editor on the active line of the program being
debugged.  ChangeLog entry and patches follow.

                                       George

----------

2002-04-26  George Helffrich <george@gly.bris.ac.uk>

        * cli/cli-cmds.c, defs.h, source.c, gdb.1: Add edit command.  This
	command mimics the behavior of Sun 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/ChangeLog
===================================================================
RCS file: /usr/src/local/cvsroot/gdb-5.1.1/src/gdb/ChangeLog,v
retrieving revision 1.5
retrieving revision 1.6
diff -c -r1.5 -r1.6
*** gdb-5.1.1/src/gdb/ChangeLog	2002/05/25 20:27:13	1.5
--- gdb-5.1.1/src/gdb/ChangeLog	2002/05/26 12:12:25	1.6
***************
*** 1,3 ****
--- 1,10 ----
+ 2002-04-26  George Helffrich <george@gly.bris.ac.uk>
+ 
+         * cli/cli-cmds.c, defs.h, source.c, gdb.1: Add edit command.  This
+ 	command mimics the behavior of Sun dbx, and invokes an editor at
+ 	the current line number.  Editor comes from EDITOR environment
+ 	variable, or defaults to /bin/ex.
+ 
  2002-04-25  George Helffrich <george@gly.bris.ac.uk>
  
          * source.c, symfile.c, symtab.c, symtab.h: Define mechanism to set
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/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
diff -c -r1.2 -r1.3
*** 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/05/26 12:12:26	1.3
***************
*** 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);
  }
  \f
+ 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);
+ }
+ \f
  /* Commands to search the source file for a regexp.  */
  
  /* ARGSUSED */
***************
*** 1727,1732 ****
--- 1842,1858 ----
  
    if (dbx_commands)
      add_com_alias ("file", "list", class_files, 1);
+ 
+   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));
  
    add_show_from_set
      (add_set_cmd ("listsize", class_support, var_uinteger,
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);
  \f
  /* 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


             reply	other threads:[~2002-05-28 10:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-28  5:15 G. Helffrich [this message]
2002-05-28  9:03 ` Daniel Jacobowitz
2002-05-28 11:41   ` Eli Zaretskii
2002-06-06 10:10 G. Helffrich
2002-06-07  6:55 ` Eli Zaretskii
2002-07-02  4:31 G. Helffrich
2002-07-02  8:47 ` Eli Zaretskii

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=200205281057.LAA00860@xterm1.gly.bris.ac.uk \
    --to=george@gly.bris.ac.uk \
    --cc=gdb-patches@sources.redhat.com \
    /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