* elf64-ppc.c (dec_dynrel_count): Don't error when elf_gc_sweep_symbol
[external/binutils.git] / gdb / mi / mi-cmd-file.c
1 /* MI Command Set - file commands.
2    Copyright (C) 2000-2013 Free Software Foundation, Inc.
3    Contributed by Cygnus Solutions (a Red Hat company).
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include "defs.h"
21 #include "mi-cmds.h"
22 #include "mi-getopt.h"
23 #include "ui-out.h"
24 #include "symtab.h"
25 #include "source.h"
26 #include "objfiles.h"
27 #include "psymtab.h"
28
29 /* Return to the client the absolute path and line number of the 
30    current file being executed.  */
31
32 void
33 mi_cmd_file_list_exec_source_file (char *command, char **argv, int argc)
34 {
35   struct symtab_and_line st;
36   struct ui_out *uiout = current_uiout;
37   
38   if (!mi_valid_noargs ("-file-list-exec-source-file", argc, argv))
39     error (_("-file-list-exec-source-file: Usage: No args"));
40
41   /* Set the default file and line, also get them.  */
42   set_default_source_symtab_and_line ();
43   st = get_current_source_symtab_and_line ();
44
45   /* We should always get a symtab.  Apparently, filename does not
46      need to be tested for NULL.  The documentation in symtab.h
47      suggests it will always be correct.  */
48   if (!st.symtab)
49     error (_("-file-list-exec-source-file: No symtab"));
50
51   /* Print to the user the line, filename and fullname.  */
52   ui_out_field_int (uiout, "line", st.line);
53   ui_out_field_string (uiout, "file", st.symtab->filename);
54
55   ui_out_field_string (uiout, "fullname", symtab_to_fullname (st.symtab));
56
57   ui_out_field_int (uiout, "macro-info", st.symtab->macro_table ? 1 : 0);
58 }
59
60 /* A callback for map_partial_symbol_filenames.  */
61
62 static void
63 print_partial_file_name (const char *filename, const char *fullname,
64                          void *ignore)
65 {
66   struct ui_out *uiout = current_uiout;
67
68   ui_out_begin (uiout, ui_out_type_tuple, NULL);
69
70   ui_out_field_string (uiout, "file", filename);
71
72   if (fullname)
73     ui_out_field_string (uiout, "fullname", fullname);
74
75   ui_out_end (uiout, ui_out_type_tuple);
76 }
77
78 void
79 mi_cmd_file_list_exec_source_files (char *command, char **argv, int argc)
80 {
81   struct ui_out *uiout = current_uiout;
82   struct symtab *s;
83   struct objfile *objfile;
84
85   if (!mi_valid_noargs ("-file-list-exec-source-files", argc, argv))
86     error (_("-file-list-exec-source-files: Usage: No args"));
87
88   /* Print the table header.  */
89   ui_out_begin (uiout, ui_out_type_list, "files");
90
91   /* Look at all of the symtabs.  */
92   ALL_SYMTABS (objfile, s)
93   {
94     ui_out_begin (uiout, ui_out_type_tuple, NULL);
95
96     ui_out_field_string (uiout, "file", s->filename);
97     ui_out_field_string (uiout, "fullname", symtab_to_fullname (s));
98
99     ui_out_end (uiout, ui_out_type_tuple);
100   }
101
102   map_partial_symbol_filenames (print_partial_file_name, NULL,
103                                 1 /*need_fullname*/);
104
105   ui_out_end (uiout, ui_out_type_list);
106 }