]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Adding -file-list-exec-source-file command to MI
authorBob Rossi <bob@brasko.net>
Wed, 2 Apr 2003 22:10:35 +0000 (22:10 +0000)
committerBob Rossi <bob@brasko.net>
Wed, 2 Apr 2003 22:10:35 +0000 (22:10 +0000)
gdb/ChangeLog
gdb/Makefile.in
gdb/doc/gdb.texinfo
gdb/mi/mi-cmd-file.c [new file with mode: 0644]
gdb/mi/mi-cmds.c
gdb/mi/mi-cmds.h
gdb/mi/mi-getopt.c
gdb/mi/mi-getopt.h
gdb/testsuite/gdb.mi/mi-file.exp [new file with mode: 0644]

index 2f28c9e2d5e16237300bbb5ae2f5cec157acff81..16339df49f73ed914c42f491b47182c3c8667fd8 100644 (file)
@@ -1,3 +1,14 @@
+2003-04-02  Bob Rossi  <bob_rossi@cox.net>
+
+       * mi-cmd-file.c: Added file to implement mi file commands.
+       * mi-getopt.c: Added mi_valid_noargs to verify if a set of 
+       parameters passed to an MI function has no arguments
+       * mi-getopt.h: Prototyped mi_valid_noargs
+       * mi-cmds.c: Added -file-list-exec-source-file command.
+       * mi-cmds.h: Added -file-list-exec-source-file to proto list.
+       * doc/gdb.texinfo: Document -file-list-exec-source-file.
+       * mi-file.exp: Added testcase to test -file-list-exec-source-file.
+
 2003-04-01  Kevin Buettner  <kevinb@redhat.com>
 
        * mips-tdep.c (mips_dwarf_dwarf2_ecoff_reg_to_regnum)
index e09bd7bf6e88f5b925130b25303d0d8b0a05d5a8..c5ba5d84218cbbffe0cec0c882d4de2a2afe9fe2 100644 (file)
@@ -168,14 +168,14 @@ SUBDIR_CLI_UNINSTALL=
 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-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-disas.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 =
@@ -2546,6 +2546,10 @@ mi-cmd-break.o: $(srcdir)/mi/mi-cmd-break.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-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 5c4eb95e6b337e2d1a0dd5bb8151bbc04c5a2d93..f00cf2b287cb7e4030e6c9096685d2ec52bbafe4 100644 (file)
@@ -16337,6 +16337,32 @@ information as this command.  @code{gdbtk} has a corresponding command
 N.A.
 
 
+@subheading The @code{-file-list-exec-source-file} Command
+@findex -file-list-exec-source-file
+
+@subsubheading Synopsis
+
+@smallexample
+ -file-list-exec-source-file
+@end smallexample
+
+List the line number, the current source file, and the absolute path 
+to the current source file for the current executable.
+
+@subsubheading @value{GDBN} Command
+
+There's no @value{GDBN} command which directly corresponds to this one.
+
+@subsubheading Example
+
+@smallexample
+(@value{GDBP})
+123-file-list-exec-source-file
+123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
+(@value{GDBP})
+@end smallexample
+
+
 @subheading The @code{-file-list-exec-source-files} Command
 @findex -file-list-exec-source-files
 
diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c
new file mode 100644 (file)
index 0000000..eb1d67a
--- /dev/null
@@ -0,0 +1,67 @@
+/* MI Command Set - breakpoint and watchpoint commands.
+   Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
+   Contributed by Cygnus Solutions (a Red Hat company).
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include "defs.h"
+#include "mi-cmds.h"
+#include "mi-getopt.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;
+  int optind = 0;
+  char *optarg;
+  
+  if ( !mi_valid_noargs("mi_cmd_file_list_exec_source_file", argc, argv) )
+    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. 
+     Apparently, filename does not need to be tested for NULL.
+     The documentation in symtab.h suggests it will always be correct */
+  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, filename and fullname */
+  ui_out_field_int (uiout, "line", st.line);
+  ui_out_field_string (uiout, "file", st.symtab->filename);
+  ui_out_field_string (uiout, "fullname", st.symtab->fullname);
+
+  return MI_CMD_DONE;
+}
index 5a0bf50754edb678c31e31b34996afb204dffc72..d6778421339ef0c21b4a5f4d1cdaedf005a5f09d 100644 (file)
@@ -80,6 +80,7 @@ struct mi_cmd mi_cmds[] =
   {"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 3eb6153694e56b32b6d7d754ea2664af4f216bc7..47e1bbf17a7f5330c02943d07ef9049342c8d006 100644 (file)
@@ -80,6 +80,7 @@ extern mi_cmd_args_ftype mi_cmd_exec_step;
 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;
index 59ccdf3efd06dbe1cecee89c3b353bd3ab66ade5..3f2a9021002586cb62b06151e3d71a39e206e4b2 100644 (file)
@@ -74,3 +74,19 @@ mi_getopt (const char *prefix,
     }
   error ("%s: Unknown option ``%s''", prefix, arg + 1);
 }
+
+int 
+mi_valid_noargs (const char *prefix, int argc, char **argv) 
+{
+  int optind = 0;
+  char *optarg;
+  static struct mi_opt opts[] =
+  {
+    0
+  };
+
+  if (mi_getopt (prefix, argc, argv, opts, &optind, &optarg) == -1)
+    return 1;
+  else
+    return 0;
+}
index 6b31adf029a86a6403763ec7cad70bca220414df..17d66fb265433b2cf53e6c65789c93c6a15b1372 100644 (file)
@@ -57,4 +57,24 @@ struct mi_opt
 
 struct mi_opt;
 
+/* mi_valid_noargs
+   
+   Determines if ARGC/ARGV are a valid set of parameters to satisfy 
+   an MI function that is not supposed to recieve any arguments.
+   
+   An MI function that should not recieve arguments can still be 
+   passed parameters after the special option '--' such as below.
+
+   Example: The MI function -exec-run takes no args.
+   However, the client may pass '-exec-run -- -a ...'
+   See PR-783
+
+   PREFIX is passed to mi_getopt for an error message.
+    
+   This function Returns 1 if the parameter pair ARGC/ARGV are valid
+   for an MI function that takes no arguments. Otherwise, it returns 0
+   and the appropriate error message is displayed by mi_getopt.  */
+
+extern int mi_valid_noargs (const char *prefix, int argc, char **argv);
+                               
 #endif
diff --git a/gdb/testsuite/gdb.mi/mi-file.exp b/gdb/testsuite/gdb.mi/mi-file.exp
new file mode 100644 (file)
index 0000000..2ffdcbf
--- /dev/null
@@ -0,0 +1,65 @@
+#   Copyright 1999 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+#
+# Test essential Machine interface (MI) operations
+#
+# Verify that, using the MI, we can run a simple program and perform basic
+# debugging activities like: insert breakpoints, run the program,
+# step, next, continue until it ends and, last but not least, quit.
+#
+# The goal is not to test gdb functionality, which is done by other tests,
+# but to verify the correct output response to MI operations.
+#
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+gdb_exit
+if [mi_gdb_start] {
+    continue
+}
+
+set testfile "basics"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+mi_delete_breakpoints
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_load ${binfile}
+
+proc test_tbreak_creation_and_listing {} {
+    global srcfile
+    global srcdir
+    global subdir
+    set srcfilepath [string_to_regexp ${srcdir}/${subdir}/${srcfile}]
+
+    # get the path and absolute path to the current executable
+    mi_gdb_test "111-file-list-exec-source-file" \
+           "111\\\^done,line=\"23\",file=\"${srcfilepath}\",fullname=\"/.*/${srcfile}\"" \
+               "request path info of current source file (${srcfile})"
+}
+
+test_tbreak_creation_and_listing
+
+mi_gdb_exit
+return 0