This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Adding -file-list-exec-source-file command to GDB/MI
- From: Bob Rossi <bob_rossi at cox dot net>
- To: gdb-patches at sources dot redhat dot com
- Date: Mon, 10 Feb 2003 17:15:57 -0500
- Subject: Adding -file-list-exec-source-file command to GDB/MI
Hi,
This is a patch to add -file-list-exec-source-file to GDB. The command
returns to the client the absolute path and line number of the current
executable. It is a replacement for the old way of getting the line
and file using annotations 1 or 2. It is nice because the client doesn't
have to call the -interpreter-exec command and parse the output of the CLI.
I ran the testsuite and there were no errors. I tested the feature from
GDB when there was not an program being debugged and when GDB had to
find the main file ( before running the exe ).
Both of these cases worked properly.
I tested it on:
uname -a='Linux 2.4.18 #2 Mon Nov 4 18:23:35 EST 2002 i686 unknown'
gdb -v|tail -n1='This GDB was configured as "i386-linux".'
This patch can be applied from src/gdb using patch -p1.
I added a file called mi-cmd-file.c. I was following the pattern created
by the designers of GDB/MI. I was imagining that all of the
unimplemented function -file will go in it when they are ready.
The file is attached.
Index: gdb/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.328
diff -c -r1.328 Makefile.in
*** gdb/Makefile.in 7 Feb 2003 05:33:44 -0000 1.328
--- gdb/Makefile.in 10 Feb 2003 20:51:47 -0000
***************
*** 168,181 ****
SUBDIR_MI_OBS = \
mi-out.o mi-console.o \
mi-cmds.o mi-cmd-env.o mi-cmd-var.o mi-cmd-break.o mi-cmd-stack.o \
! mi-cmd-disas.o \
mi-interp.o \
mi-main.o mi-parse.o mi-getopt.o
SUBDIR_MI_SRCS = \
mi/mi-out.c mi/mi-console.c \
mi/mi-cmds.c mi/mi-cmd-env.c \
mi/mi-cmd-var.c mi/mi-cmd-break.c mi/mi-cmd-stack.c \
! mi/mi-cmd-disas.c \
mi/mi-interp.c \
mi/mi-main.c mi/mi-parse.c mi/mi-getopt.c
SUBDIR_MI_DEPS =
--- 168,181 ----
SUBDIR_MI_OBS = \
mi-out.o mi-console.o \
mi-cmds.o mi-cmd-env.o mi-cmd-var.o mi-cmd-break.o mi-cmd-stack.o \
! mi-cmd-file.o mi-cmd-disas.o \
mi-interp.o \
mi-main.o mi-parse.o mi-getopt.o
SUBDIR_MI_SRCS = \
mi/mi-out.c mi/mi-console.c \
mi/mi-cmds.c mi/mi-cmd-env.c \
mi/mi-cmd-var.c mi/mi-cmd-break.c mi/mi-cmd-stack.c \
! mi/mi-cmd-file.c mi/mi-cmd-disas.c \
mi/mi-interp.c \
mi/mi-main.c mi/mi-parse.c mi/mi-getopt.c
SUBDIR_MI_DEPS =
***************
*** 2494,2499 ****
--- 2494,2503 ----
$(ui_out_h) $(mi_out_h) $(breakpoint_h) $(gdb_string_h) \
$(mi_getopt_h) $(gdb_events_h) $(gdb_h)
$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-cmd-break.c
+ mi-cmd-file.o: $(srcdir)/mi/mi-cmd-file.c $(defs_h) $(mi_cmds_h) \
+ $(ui_out_h) $(mi_out_h) $(breakpoint_h) $(gdb_string_h) \
+ $(mi_getopt_h) $(gdb_events_h) $(gdb_h)
+ $(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-cmd-file.c
mi-cmd-disas.o: $(srcdir)/mi/mi-cmd-disas.c $(defs_h) $(target_h) $(value_h) \
$(mi_cmds_h) $(mi_getopt_h) $(ui_out_h) $(gdb_string_h) $(disasm_h)
$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-cmd-disas.c
Index: gdb/mi/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/mi/ChangeLog,v
retrieving revision 1.92
diff -c -r1.92 ChangeLog
*** gdb/mi/ChangeLog 9 Feb 2003 10:47:37 -0000 1.92
--- gdb/mi/ChangeLog 10 Feb 2003 20:51:51 -0000
***************
*** 1,3 ****
--- 1,10 ----
+ 2003-02-10 Bob Rossi <bob_rossi@cox.net>
+
+ * mi-cmd-file.c: added file to implement mi file commands.
+ * mi-cmds.c: Add -file-list-exec-source-file command.
+ * mi-cmds.h: Add -file-list-exec-source-file to proto list.
+ * gdbmi.texinfo: Document -file-list-exec-source-file.
+
2003-02-09 Andrew Cagney <ac131313@redhat.com>
* mi-interp.c (mi_remove_notify_hooks): Convert function
Index: gdb/mi/gdbmi.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/mi/gdbmi.texinfo,v
retrieving revision 1.33
diff -c -r1.33 gdbmi.texinfo
*** gdb/mi/gdbmi.texinfo 4 Feb 2003 18:41:29 -0000 1.33
--- gdb/mi/gdbmi.texinfo 10 Feb 2003 20:51:55 -0000
***************
*** 2340,2345 ****
--- 2340,2355 ----
@subsubheading Example
N.A.
+ @subheading The @code{-file-list-exec-source-file} Command
+ @findex -file-list-exec-source-file
+
+ @subsubheading Synopsis
+
+ @example
+ -file-list-exec-source-file
+ @end example
+
+ List the current source file and line for the current executable.
@subheading The @code{-file-list-exec-source-files} Command
@findex -file-list-exec-source-files
Index: gdb/mi/mi-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.c,v
retrieving revision 1.10
diff -c -r1.10 mi-cmds.c
*** gdb/mi/mi-cmds.c 6 Feb 2003 01:19:12 -0000 1.10
--- gdb/mi/mi-cmds.c 10 Feb 2003 20:51:55 -0000
***************
*** 80,85 ****
--- 80,86 ----
{"file-exec-and-symbols", "file %s", 0},
{"file-exec-file", "exec-file %s", 0},
{"file-list-exec-sections", 0, 0},
+ {"file-list-exec-source-file", 0, 0, mi_cmd_file_list_exec_source_file},
{"file-list-exec-source-files", 0, 0},
{"file-list-shared-libraries", 0, 0},
{"file-list-symbol-files", 0, 0},
Index: gdb/mi/mi-cmds.h
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.h,v
retrieving revision 1.7
diff -c -r1.7 mi-cmds.h
*** gdb/mi/mi-cmds.h 6 Feb 2003 01:19:12 -0000 1.7
--- gdb/mi/mi-cmds.h 10 Feb 2003 20:51:55 -0000
***************
*** 80,85 ****
--- 80,86 ----
extern mi_cmd_args_ftype mi_cmd_exec_step_instruction;
extern mi_cmd_args_ftype mi_cmd_exec_until;
extern mi_cmd_args_ftype mi_cmd_exec_interrupt;
+ extern mi_cmd_argv_ftype mi_cmd_file_list_exec_source_file;
extern mi_cmd_argv_ftype mi_cmd_gdb_exit;
extern mi_cmd_argv_ftype mi_cmd_interpreter_exec;
extern mi_cmd_argv_ftype mi_cmd_stack_info_depth;
#include "defs.h"
#include "mi-cmds.h"
#include "ui-out.h"
#include "symtab.h"
#include "source.h"
/* Return to the client the absolute path and line number of the
current file being executed. */
enum mi_cmd_result
mi_cmd_file_list_exec_source_file(char *command, char **argv, int argc)
{
struct symtab_and_line st;
if (argc != 0)
error ("mi_cmd_file_list_exec_source_file: Usage: No args");
/* Set the default file and line, also get them */
set_default_source_symtab_and_line();
st = get_current_source_symtab_and_line();
/* We should always get a symtab. */
if (!st.symtab)
error ("mi_cmd_file_list_exec_source_file: No symtab");
/* Extract the fullname if it is not known yet */
if (st.symtab->fullname == NULL)
symtab_to_filename (st.symtab);
/* We may not be able to open the file (not available). */
if (st.symtab->fullname == NULL)
error ("mi_cmd_file_list_exec_source_file: File not found");
/* Print to the user the line and absolute file name */
ui_out_field_int (uiout, "line", st.line);
ui_out_field_string (uiout, "file", st.symtab->fullname);
return MI_CMD_DONE;
}