1 /* MI Command Set - file commands.
2 Copyright (C) 2000-2017 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions (a Red Hat company).
5 This file is part of GDB.
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.
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.
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/>. */
22 #include "mi-getopt.h"
23 #include "mi-interp.h"
31 #include "gdb_regex.h"
33 /* Return to the client the absolute path and line number of the
34 current file being executed. */
37 mi_cmd_file_list_exec_source_file (char *command, char **argv, int argc)
39 struct symtab_and_line st;
40 struct ui_out *uiout = current_uiout;
42 if (!mi_valid_noargs ("-file-list-exec-source-file", argc, argv))
43 error (_("-file-list-exec-source-file: Usage: No args"));
45 /* Set the default file and line, also get them. */
46 set_default_source_symtab_and_line ();
47 st = get_current_source_symtab_and_line ();
49 /* We should always get a symtab. Apparently, filename does not
50 need to be tested for NULL. The documentation in symtab.h
51 suggests it will always be correct. */
53 error (_("-file-list-exec-source-file: No symtab"));
55 /* Print to the user the line, filename and fullname. */
56 uiout->field_int ("line", st.line);
57 uiout->field_string ("file", symtab_to_filename_for_display (st.symtab));
59 uiout->field_string ("fullname", symtab_to_fullname (st.symtab));
61 uiout->field_int ("macro-info",
62 COMPUNIT_MACRO_TABLE (SYMTAB_COMPUNIT (st.symtab)) != NULL);
65 /* A callback for map_partial_symbol_filenames. */
68 print_partial_file_name (const char *filename, const char *fullname,
71 struct ui_out *uiout = current_uiout;
73 uiout->begin (ui_out_type_tuple, NULL);
75 uiout->field_string ("file", filename);
78 uiout->field_string ("fullname", fullname);
80 uiout->end (ui_out_type_tuple);
84 mi_cmd_file_list_exec_source_files (char *command, char **argv, int argc)
86 struct ui_out *uiout = current_uiout;
87 struct compunit_symtab *cu;
89 struct objfile *objfile;
91 if (!mi_valid_noargs ("-file-list-exec-source-files", argc, argv))
92 error (_("-file-list-exec-source-files: Usage: No args"));
94 /* Print the table header. */
95 uiout->begin (ui_out_type_list, "files");
97 /* Look at all of the file symtabs. */
98 ALL_FILETABS (objfile, cu, s)
100 uiout->begin (ui_out_type_tuple, NULL);
102 uiout->field_string ("file", symtab_to_filename_for_display (s));
103 uiout->field_string ("fullname", symtab_to_fullname (s));
105 uiout->end (ui_out_type_tuple);
108 map_symbol_filenames (print_partial_file_name, NULL,
109 1 /*need_fullname*/);
111 uiout->end (ui_out_type_list);
117 mi_cmd_file_list_shared_libraries (char *command, char **argv, int argc)
119 struct ui_out *uiout = current_uiout;
121 struct so_list *so = NULL;
122 struct gdbarch *gdbarch = target_gdbarch ();
133 error (_("Usage: -file-list-shared-libraries [REGEXP]"));
138 const char *re_err = re_comp (pattern);
141 error (_("Invalid regexp: %s"), re_err);
144 update_solib_list (1);
146 /* Print the table header. */
147 struct cleanup *cleanup
148 = make_cleanup_ui_out_list_begin_end (uiout, "shared-libraries");
152 if (so->so_name[0] == '\0')
154 if (pattern != NULL && !re_exec (so->so_name))
157 struct cleanup *tuple_clean_up
158 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
159 mi_output_solib_attribs (uiout, so);
161 do_cleanups (tuple_clean_up);
164 do_cleanups (cleanup);