Add a better diagnostic message in mi_gdb_test
[deliverable/binutils-gdb.git] / gdb / mi / mi-cmd-file.c
CommitLineData
2b03b41d 1/* MI Command Set - file commands.
61baf725 2 Copyright (C) 2000-2017 Free Software Foundation, Inc.
1abaf70c
BR
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
1abaf70c
BR
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1abaf70c
BR
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"
57c22c6c 26#include "objfiles.h"
ccefe4c4 27#include "psymtab.h"
1abaf70c
BR
28
29/* Return to the client the absolute path and line number of the
2b03b41d 30 current file being executed. */
1abaf70c 31
ce8f13f8 32void
17784837 33mi_cmd_file_list_exec_source_file (char *command, char **argv, int argc)
1abaf70c
BR
34{
35 struct symtab_and_line st;
79a45e25 36 struct ui_out *uiout = current_uiout;
1abaf70c 37
1b05df00
TT
38 if (!mi_valid_noargs ("-file-list-exec-source-file", argc, argv))
39 error (_("-file-list-exec-source-file: Usage: No args"));
1abaf70c 40
2b03b41d 41 /* Set the default file and line, also get them. */
17784837
NR
42 set_default_source_symtab_and_line ();
43 st = get_current_source_symtab_and_line ();
1abaf70c 44
2b03b41d
SS
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. */
1abaf70c 48 if (!st.symtab)
1b05df00 49 error (_("-file-list-exec-source-file: No symtab"));
1abaf70c 50
2b03b41d 51 /* Print to the user the line, filename and fullname. */
112e8700
SM
52 uiout->field_int ("line", st.line);
53 uiout->field_string ("file", symtab_to_filename_for_display (st.symtab));
57c22c6c 54
112e8700 55 uiout->field_string ("fullname", symtab_to_fullname (st.symtab));
1abaf70c 56
112e8700
SM
57 uiout->field_int ("macro-info",
58 COMPUNIT_MACRO_TABLE (SYMTAB_COMPUNIT (st.symtab)) != NULL);
1abaf70c 59}
57c22c6c 60
ccefe4c4 61/* A callback for map_partial_symbol_filenames. */
2b03b41d 62
ccefe4c4
TT
63static void
64print_partial_file_name (const char *filename, const char *fullname,
65 void *ignore)
66{
79a45e25
PA
67 struct ui_out *uiout = current_uiout;
68
112e8700 69 uiout->begin (ui_out_type_tuple, NULL);
ccefe4c4 70
112e8700 71 uiout->field_string ("file", filename);
ccefe4c4
TT
72
73 if (fullname)
112e8700 74 uiout->field_string ("fullname", fullname);
ccefe4c4 75
112e8700 76 uiout->end (ui_out_type_tuple);
ccefe4c4
TT
77}
78
ce8f13f8 79void
57c22c6c
BR
80mi_cmd_file_list_exec_source_files (char *command, char **argv, int argc)
81{
79a45e25 82 struct ui_out *uiout = current_uiout;
43f3e411 83 struct compunit_symtab *cu;
57c22c6c 84 struct symtab *s;
57c22c6c
BR
85 struct objfile *objfile;
86
1b05df00
TT
87 if (!mi_valid_noargs ("-file-list-exec-source-files", argc, argv))
88 error (_("-file-list-exec-source-files: Usage: No args"));
57c22c6c 89
2b03b41d 90 /* Print the table header. */
112e8700 91 uiout->begin (ui_out_type_list, "files");
57c22c6c 92
43f3e411
DE
93 /* Look at all of the file symtabs. */
94 ALL_FILETABS (objfile, cu, s)
57c22c6c 95 {
112e8700 96 uiout->begin (ui_out_type_tuple, NULL);
57c22c6c 97
112e8700
SM
98 uiout->field_string ("file", symtab_to_filename_for_display (s));
99 uiout->field_string ("fullname", symtab_to_fullname (s));
57c22c6c 100
112e8700 101 uiout->end (ui_out_type_tuple);
57c22c6c
BR
102 }
103
bb4142cf
DE
104 map_symbol_filenames (print_partial_file_name, NULL,
105 1 /*need_fullname*/);
57c22c6c 106
112e8700 107 uiout->end (ui_out_type_list);
57c22c6c 108}
This page took 1.18912 seconds and 4 git commands to generate.