1*ef5ccd6cSJohn Marino /* MI Command Set - file commands.
2*ef5ccd6cSJohn Marino Copyright (C) 2000-2013 Free Software Foundation, Inc.
35796c8dcSSimon Schubert Contributed by Cygnus Solutions (a Red Hat company).
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert This file is part of GDB.
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert (at your option) any later version.
115796c8dcSSimon Schubert
125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155796c8dcSSimon Schubert GNU General Public License for more details.
165796c8dcSSimon Schubert
175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
195796c8dcSSimon Schubert
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "mi-cmds.h"
225796c8dcSSimon Schubert #include "mi-getopt.h"
235796c8dcSSimon Schubert #include "ui-out.h"
245796c8dcSSimon Schubert #include "symtab.h"
255796c8dcSSimon Schubert #include "source.h"
265796c8dcSSimon Schubert #include "objfiles.h"
27cf7f2e2dSJohn Marino #include "psymtab.h"
285796c8dcSSimon Schubert
295796c8dcSSimon Schubert /* Return to the client the absolute path and line number of the
305796c8dcSSimon Schubert current file being executed. */
315796c8dcSSimon Schubert
325796c8dcSSimon Schubert void
mi_cmd_file_list_exec_source_file(char * command,char ** argv,int argc)335796c8dcSSimon Schubert mi_cmd_file_list_exec_source_file (char *command, char **argv, int argc)
345796c8dcSSimon Schubert {
355796c8dcSSimon Schubert struct symtab_and_line st;
36a45ae5f8SJohn Marino struct ui_out *uiout = current_uiout;
375796c8dcSSimon Schubert
38c50c785cSJohn Marino if (!mi_valid_noargs ("-file-list-exec-source-file", argc, argv))
39c50c785cSJohn Marino error (_("-file-list-exec-source-file: Usage: No args"));
405796c8dcSSimon Schubert
41*ef5ccd6cSJohn Marino /* Set the default file and line, also get them. */
425796c8dcSSimon Schubert set_default_source_symtab_and_line ();
435796c8dcSSimon Schubert st = get_current_source_symtab_and_line ();
445796c8dcSSimon Schubert
45*ef5ccd6cSJohn Marino /* We should always get a symtab. Apparently, filename does not
46*ef5ccd6cSJohn Marino need to be tested for NULL. The documentation in symtab.h
47*ef5ccd6cSJohn Marino suggests it will always be correct. */
485796c8dcSSimon Schubert if (!st.symtab)
49c50c785cSJohn Marino error (_("-file-list-exec-source-file: No symtab"));
505796c8dcSSimon Schubert
51*ef5ccd6cSJohn Marino /* Print to the user the line, filename and fullname. */
525796c8dcSSimon Schubert ui_out_field_int (uiout, "line", st.line);
53*ef5ccd6cSJohn Marino ui_out_field_string (uiout, "file",
54*ef5ccd6cSJohn Marino symtab_to_filename_for_display (st.symtab));
555796c8dcSSimon Schubert
56*ef5ccd6cSJohn Marino ui_out_field_string (uiout, "fullname", symtab_to_fullname (st.symtab));
575796c8dcSSimon Schubert
585796c8dcSSimon Schubert ui_out_field_int (uiout, "macro-info", st.symtab->macro_table ? 1 : 0);
595796c8dcSSimon Schubert }
605796c8dcSSimon Schubert
61cf7f2e2dSJohn Marino /* A callback for map_partial_symbol_filenames. */
62*ef5ccd6cSJohn Marino
63cf7f2e2dSJohn Marino static void
print_partial_file_name(const char * filename,const char * fullname,void * ignore)64cf7f2e2dSJohn Marino print_partial_file_name (const char *filename, const char *fullname,
65cf7f2e2dSJohn Marino void *ignore)
66cf7f2e2dSJohn Marino {
67a45ae5f8SJohn Marino struct ui_out *uiout = current_uiout;
68a45ae5f8SJohn Marino
69cf7f2e2dSJohn Marino ui_out_begin (uiout, ui_out_type_tuple, NULL);
70cf7f2e2dSJohn Marino
71cf7f2e2dSJohn Marino ui_out_field_string (uiout, "file", filename);
72cf7f2e2dSJohn Marino
73cf7f2e2dSJohn Marino if (fullname)
74cf7f2e2dSJohn Marino ui_out_field_string (uiout, "fullname", fullname);
75cf7f2e2dSJohn Marino
76cf7f2e2dSJohn Marino ui_out_end (uiout, ui_out_type_tuple);
77cf7f2e2dSJohn Marino }
78cf7f2e2dSJohn Marino
795796c8dcSSimon Schubert void
mi_cmd_file_list_exec_source_files(char * command,char ** argv,int argc)805796c8dcSSimon Schubert mi_cmd_file_list_exec_source_files (char *command, char **argv, int argc)
815796c8dcSSimon Schubert {
82a45ae5f8SJohn Marino struct ui_out *uiout = current_uiout;
835796c8dcSSimon Schubert struct symtab *s;
845796c8dcSSimon Schubert struct objfile *objfile;
855796c8dcSSimon Schubert
86c50c785cSJohn Marino if (!mi_valid_noargs ("-file-list-exec-source-files", argc, argv))
87c50c785cSJohn Marino error (_("-file-list-exec-source-files: Usage: No args"));
885796c8dcSSimon Schubert
89*ef5ccd6cSJohn Marino /* Print the table header. */
905796c8dcSSimon Schubert ui_out_begin (uiout, ui_out_type_list, "files");
915796c8dcSSimon Schubert
92*ef5ccd6cSJohn Marino /* Look at all of the symtabs. */
935796c8dcSSimon Schubert ALL_SYMTABS (objfile, s)
945796c8dcSSimon Schubert {
955796c8dcSSimon Schubert ui_out_begin (uiout, ui_out_type_tuple, NULL);
965796c8dcSSimon Schubert
97*ef5ccd6cSJohn Marino ui_out_field_string (uiout, "file", symtab_to_filename_for_display (s));
98*ef5ccd6cSJohn Marino ui_out_field_string (uiout, "fullname", symtab_to_fullname (s));
995796c8dcSSimon Schubert
1005796c8dcSSimon Schubert ui_out_end (uiout, ui_out_type_tuple);
1015796c8dcSSimon Schubert }
1025796c8dcSSimon Schubert
103a45ae5f8SJohn Marino map_partial_symbol_filenames (print_partial_file_name, NULL,
104a45ae5f8SJohn Marino 1 /*need_fullname*/);
1055796c8dcSSimon Schubert
1065796c8dcSSimon Schubert ui_out_end (uiout, ui_out_type_list);
1075796c8dcSSimon Schubert }
108