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