gdb/mi/mi-cmd-file.c - gdb

Functions defined

Source code

  1. /* MI Command Set - file commands.
  2.    Copyright (C) 2000-2015 Free Software Foundation, Inc.
  3.    Contributed by Cygnus Solutions (a Red Hat company).

  4.    This file is part of GDB.

  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 3 of the License, or
  8.    (at your option) any later version.

  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.

  13.    You should have received a copy of the GNU General Public License
  14.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  15. #include "defs.h"
  16. #include "mi-cmds.h"
  17. #include "mi-getopt.h"
  18. #include "ui-out.h"
  19. #include "symtab.h"
  20. #include "source.h"
  21. #include "objfiles.h"
  22. #include "psymtab.h"

  23. /* Return to the client the absolute path and line number of the
  24.    current file being executed.  */

  25. void
  26. mi_cmd_file_list_exec_source_file (char *command, char **argv, int argc)
  27. {
  28.   struct symtab_and_line st;
  29.   struct ui_out *uiout = current_uiout;

  30.   if (!mi_valid_noargs ("-file-list-exec-source-file", argc, argv))
  31.     error (_("-file-list-exec-source-file: Usage: No args"));

  32.   /* Set the default file and line, also get them.  */
  33.   set_default_source_symtab_and_line ();
  34.   st = get_current_source_symtab_and_line ();

  35.   /* We should always get a symtab.  Apparently, filename does not
  36.      need to be tested for NULL.  The documentation in symtab.h
  37.      suggests it will always be correct.  */
  38.   if (!st.symtab)
  39.     error (_("-file-list-exec-source-file: No symtab"));

  40.   /* Print to the user the line, filename and fullname.  */
  41.   ui_out_field_int (uiout, "line", st.line);
  42.   ui_out_field_string (uiout, "file",
  43.                        symtab_to_filename_for_display (st.symtab));

  44.   ui_out_field_string (uiout, "fullname", symtab_to_fullname (st.symtab));

  45.   ui_out_field_int (uiout, "macro-info",
  46.                     COMPUNIT_MACRO_TABLE
  47.                       (SYMTAB_COMPUNIT (st.symtab)) != NULL);
  48. }

  49. /* A callback for map_partial_symbol_filenames.  */

  50. static void
  51. print_partial_file_name (const char *filename, const char *fullname,
  52.                          void *ignore)
  53. {
  54.   struct ui_out *uiout = current_uiout;

  55.   ui_out_begin (uiout, ui_out_type_tuple, NULL);

  56.   ui_out_field_string (uiout, "file", filename);

  57.   if (fullname)
  58.     ui_out_field_string (uiout, "fullname", fullname);

  59.   ui_out_end (uiout, ui_out_type_tuple);
  60. }

  61. void
  62. mi_cmd_file_list_exec_source_files (char *command, char **argv, int argc)
  63. {
  64.   struct ui_out *uiout = current_uiout;
  65.   struct compunit_symtab *cu;
  66.   struct symtab *s;
  67.   struct objfile *objfile;

  68.   if (!mi_valid_noargs ("-file-list-exec-source-files", argc, argv))
  69.     error (_("-file-list-exec-source-files: Usage: No args"));

  70.   /* Print the table header.  */
  71.   ui_out_begin (uiout, ui_out_type_list, "files");

  72.   /* Look at all of the file symtabs.  */
  73.   ALL_FILETABS (objfile, cu, s)
  74.   {
  75.     ui_out_begin (uiout, ui_out_type_tuple, NULL);

  76.     ui_out_field_string (uiout, "file", symtab_to_filename_for_display (s));
  77.     ui_out_field_string (uiout, "fullname", symtab_to_fullname (s));

  78.     ui_out_end (uiout, ui_out_type_tuple);
  79.   }

  80.   map_symbol_filenames (print_partial_file_name, NULL,
  81.                         1 /*need_fullname*/);

  82.   ui_out_end (uiout, ui_out_type_list);
  83. }