Upgrade GDB from 7.4.1 to 7.6.1 on the vendor branch
[dragonfly.git] / contrib / gdb-7 / gdb / mi / mi-cmd-file.c
CommitLineData
ef5ccd6c
JM
1/* MI Command Set - file commands.
2 Copyright (C) 2000-2013 Free Software Foundation, Inc.
5796c8dc
SS
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"
cf7f2e2d 27#include "psymtab.h"
5796c8dc
SS
28
29/* Return to the client the absolute path and line number of the
ef5ccd6c 30 current file being executed. */
5796c8dc
SS
31
32void
33mi_cmd_file_list_exec_source_file (char *command, char **argv, int argc)
34{
35 struct symtab_and_line st;
a45ae5f8 36 struct ui_out *uiout = current_uiout;
5796c8dc 37
c50c785c
JM
38 if (!mi_valid_noargs ("-file-list-exec-source-file", argc, argv))
39 error (_("-file-list-exec-source-file: Usage: No args"));
5796c8dc 40
ef5ccd6c 41 /* Set the default file and line, also get them. */
5796c8dc
SS
42 set_default_source_symtab_and_line ();
43 st = get_current_source_symtab_and_line ();
44
ef5ccd6c
JM
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. */
5796c8dc 48 if (!st.symtab)
c50c785c 49 error (_("-file-list-exec-source-file: No symtab"));
5796c8dc 50
ef5ccd6c 51 /* Print to the user the line, filename and fullname. */
5796c8dc 52 ui_out_field_int (uiout, "line", st.line);
ef5ccd6c
JM
53 ui_out_field_string (uiout, "file",
54 symtab_to_filename_for_display (st.symtab));
5796c8dc 55
ef5ccd6c 56 ui_out_field_string (uiout, "fullname", symtab_to_fullname (st.symtab));
5796c8dc
SS
57
58 ui_out_field_int (uiout, "macro-info", st.symtab->macro_table ? 1 : 0);
59}
60
cf7f2e2d 61/* A callback for map_partial_symbol_filenames. */
ef5ccd6c 62
cf7f2e2d
JM
63static void
64print_partial_file_name (const char *filename, const char *fullname,
65 void *ignore)
66{
a45ae5f8
JM
67 struct ui_out *uiout = current_uiout;
68
cf7f2e2d
JM
69 ui_out_begin (uiout, ui_out_type_tuple, NULL);
70
71 ui_out_field_string (uiout, "file", filename);
72
73 if (fullname)
74 ui_out_field_string (uiout, "fullname", fullname);
75
76 ui_out_end (uiout, ui_out_type_tuple);
77}
78
5796c8dc
SS
79void
80mi_cmd_file_list_exec_source_files (char *command, char **argv, int argc)
81{
a45ae5f8 82 struct ui_out *uiout = current_uiout;
5796c8dc 83 struct symtab *s;
5796c8dc
SS
84 struct objfile *objfile;
85
c50c785c
JM
86 if (!mi_valid_noargs ("-file-list-exec-source-files", argc, argv))
87 error (_("-file-list-exec-source-files: Usage: No args"));
5796c8dc 88
ef5ccd6c 89 /* Print the table header. */
5796c8dc
SS
90 ui_out_begin (uiout, ui_out_type_list, "files");
91
ef5ccd6c 92 /* Look at all of the symtabs. */
5796c8dc
SS
93 ALL_SYMTABS (objfile, s)
94 {
95 ui_out_begin (uiout, ui_out_type_tuple, NULL);
96
ef5ccd6c
JM
97 ui_out_field_string (uiout, "file", symtab_to_filename_for_display (s));
98 ui_out_field_string (uiout, "fullname", symtab_to_fullname (s));
5796c8dc
SS
99
100 ui_out_end (uiout, ui_out_type_tuple);
101 }
102
a45ae5f8
JM
103 map_partial_symbol_filenames (print_partial_file_name, NULL,
104 1 /*need_fullname*/);
5796c8dc
SS
105
106 ui_out_end (uiout, ui_out_type_list);
107}