[suggestion] gdb interfacing with any-editor via GNU screen

Stephane CHAZELAS Stephane_CHAZELAS@yahoo.fr
Mon Mar 24 16:42:00 GMT 2003


[I first sent this to gdb-bug@gnu.org, then noticed this mailing
list, hope, it's the right place to send this, this time]

Being a vi user, I've long tried to interface it with GDB. I had
written once a kind of wrapper that opened two pseudo-ttys,
catched the \032\032 sequences sent by "gdb -f" and turned them
into ":e +line filename" sent to vi.

I recently noticed I could use GNU screen to do this.
screen provides a special control sequence which allows to run
arbitrary screen commands based on output from a command.

>From "info -f screen -n 'Control Sequences'":
I| ESC ] 83 ; cmd ^G       (A)     Execute screen command. This only works if
I|                                 multi-user support is compiled into screen.
I|                                 The pseudo-user ":window:" is used to check
I|                                 the access control list. Use "addacl :window:
I|                                 -rwx #?" to create a user with no rights and
I|                                 allow only the needed commands.

My idea was then, that gdb could send something like "\e]83;<a
screen command to have vi open the right file at the right
line>\a" instead of sending
"\032\032filename:line:char:mid:addr\n".

That's my suggestion: add a new -F/--annotation-format option to
GDB with one required argument only used when the
annotation_level is 1 (-f option). The default would be:
"\032\032%f:%l:%c:%m:%a\n".

Attached, you'll find a quick patch on GDB 5.3, with my
suggestion implemented. (%f, %l, %c, %m, %a are replaced by
filename, line#, char#, middle/beg, address in the annotation
format).

vim-gdb-screen is a GNU bash script that
sets up a screen environment with a splitted screen (vim above,
gdb below) to use this feature. This must be run from within
screen, with two optionnal arguments: the executable to debug
and its source directory.

screenshot.png is a screenshot of an example usage.

Tell me what you think of it and don't hesitate to ask more
details.

Best regards,
Stéphane
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screenshot.png
Type: image/png
Size: 20379 bytes
Desc: Screen shot VIM+GDB debugging screen-3.9.15
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20030324/baf69f3c/attachment.png>
-------------- next part --------------
diff -ur gdb-5.3/gdb/annotate.c gdb-5.3.N/gdb/annotate.c
--- gdb-5.3/gdb/annotate.c	Tue Mar  6 09:21:05 2001
+++ gdb-5.3.N/gdb/annotate.c	Sun Mar 23 13:52:10 2003
@@ -42,6 +42,7 @@
 void (*annotate_exited_hook) (void);
 
 static int ignore_count_changed = 0;
+char *annotation_format = "\032\032%f:%l:%c:%m:%a\n";
 
 static void
 print_value_flags (struct type *t)
@@ -415,16 +416,48 @@
 void
 annotate_source (char *filename, int line, int character, int mid, CORE_ADDR pc)
 {
-  if (annotation_level > 1)
+  if (annotation_level > 1) {
     printf_filtered ("\n\032\032source ");
-  else
-    printf_filtered ("\032\032");
-
-  printf_filtered ("%s:%d:%d:%s:0x", filename,
-		   line, character,
-		   mid ? "middle" : "beg");
-  print_address_numeric (pc, 0, gdb_stdout);
-  printf_filtered ("\n");
+    printf_filtered ("%s:%d:%d:%s:0x", filename,
+		     line, character,
+		     mid ? "middle" : "beg");
+    print_address_numeric (pc, 0, gdb_stdout);
+    printf_filtered ("\n");
+  } else {
+    char *p;
+    for (p = annotation_format; *p; p++) {
+      if (*p == '%')
+	switch (*++p) {
+	case 'a':
+	  puts_filtered("0x");
+	  print_address_numeric(pc, 0, gdb_stdout);
+	  break;
+	case 'f':
+	  puts_filtered(filename);
+	  break;
+	case 'l':
+	  printf_filtered("%d", line);
+	  break;
+	case 'c':
+	  printf_filtered("%d", character);
+	  break;
+	case '%':
+	  putchar_filtered('%');
+	  break;
+	case '\0':
+	  putchar_filtered('%');
+	  return;
+	case 'm':
+	  puts_filtered(mid ? "middle" : "beg");
+	  break;
+	default:
+	  putchar_filtered('%');
+	  putchar_filtered(*p);
+	}
+      else
+	putchar_filtered(*p);
+    }
+  }
 }
 
 void
diff -ur gdb-5.3/gdb/defs.h gdb-5.3.N/gdb/defs.h
--- gdb-5.3/gdb/defs.h	Thu Aug  1 19:18:32 2002
+++ gdb-5.3.N/gdb/defs.h	Sun Mar 23 12:00:28 2003
@@ -397,6 +397,7 @@
 

 /* Annotation stuff.  */
 
+extern char* annotation_format;
 extern int annotation_level;	/* in stack.c */
 

 extern void begin_line (void);
diff -ur gdb-5.3/gdb/main.c gdb-5.3.N/gdb/main.c
--- gdb-5.3/gdb/main.c	Sat Sep 28 17:10:31 2002
+++ gdb-5.3.N/gdb/main.c	Sun Mar 23 13:01:37 2003
@@ -233,6 +233,8 @@
        emacses which use --fullname.  */
       {"fullname", no_argument, 0, 'f'},
       {"f", no_argument, 0, 'f'},
+      {"annotation-format", required_argument, 0, 'F'},
+      {"F", required_argument, 0, 'F'},
 
       {"annotate", required_argument, 0, 12},
       {"help", no_argument, &print_help, 1},
@@ -314,6 +316,9 @@
 	    annotation_level = 1;
 /* We have probably been invoked from emacs.  Disable window interface.  */
 	    use_windows = 0;
+	    break;
+	  case 'F':
+	    annotation_format = optarg;
 	    break;
 	  case 's':
 	    symarg = optarg;
-------------- next part --------------
#! /bin/bash
: ${STY?Must be run from screen}
exec_file=${1-$PWD/a.out}
src_dir=${2-$PWD}
shift ${2+2}
export src_dir exec_file

screen -X addacl :window: +x process,stuff
screen -X register N "
"
screen -X only
screen -t VIM 1 sh -c 'cd "$2" && exec vim'
screen -t GDB 1 gdb -f -F \
  $'\e]83;focus\a\e]83;stuff ":e +/\%%%ll. %f"\a\e]83;process N\a\e]83;focus\a' \
  "$@" "$exec_file"
screen -p VIM -X stuff ":set hls
"
screen -p GDB -X stuff "directory $src_dir
"
screen -X split
screen -X select VIM
screen -X focus
screen -X select GDB



More information about the Gdb-patches mailing list