]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/mi/mi-cmd-file.c
Use function view in quick_symbol_functions::map_symbol_filenames
[thirdparty/binutils-gdb.git] / gdb / mi / mi-cmd-file.c
CommitLineData
2b03b41d 1/* MI Command Set - file commands.
3666a048 2 Copyright (C) 2000-2021 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"
51457a05 23#include "mi-interp.h"
1abaf70c
BR
24#include "ui-out.h"
25#include "symtab.h"
26#include "source.h"
57c22c6c 27#include "objfiles.h"
ccefe4c4 28#include "psymtab.h"
51457a05
MAL
29#include "solib.h"
30#include "solist.h"
31#include "gdb_regex.h"
1abaf70c
BR
32
33/* Return to the client the absolute path and line number of the
2b03b41d 34 current file being executed. */
1abaf70c 35
ce8f13f8 36void
9f33b8b7 37mi_cmd_file_list_exec_source_file (const char *command, char **argv, int argc)
1abaf70c
BR
38{
39 struct symtab_and_line st;
79a45e25 40 struct ui_out *uiout = current_uiout;
1abaf70c 41
1b05df00
TT
42 if (!mi_valid_noargs ("-file-list-exec-source-file", argc, argv))
43 error (_("-file-list-exec-source-file: Usage: No args"));
1abaf70c 44
2b03b41d 45 /* Set the default file and line, also get them. */
17784837
NR
46 set_default_source_symtab_and_line ();
47 st = get_current_source_symtab_and_line ();
1abaf70c 48
2b03b41d
SS
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. */
1abaf70c 52 if (!st.symtab)
1b05df00 53 error (_("-file-list-exec-source-file: No symtab"));
1abaf70c 54
2b03b41d 55 /* Print to the user the line, filename and fullname. */
381befee 56 uiout->field_signed ("line", st.line);
112e8700 57 uiout->field_string ("file", symtab_to_filename_for_display (st.symtab));
57c22c6c 58
112e8700 59 uiout->field_string ("fullname", symtab_to_fullname (st.symtab));
1abaf70c 60
381befee
TT
61 uiout->field_signed ("macro-info",
62 COMPUNIT_MACRO_TABLE (SYMTAB_COMPUNIT (st.symtab)) != NULL);
1abaf70c 63}
57c22c6c 64
ccefe4c4 65/* A callback for map_partial_symbol_filenames. */
2b03b41d 66
ccefe4c4 67static void
f4655dee 68print_partial_file_name (const char *filename, const char *fullname)
ccefe4c4 69{
79a45e25
PA
70 struct ui_out *uiout = current_uiout;
71
112e8700 72 uiout->begin (ui_out_type_tuple, NULL);
ccefe4c4 73
112e8700 74 uiout->field_string ("file", filename);
ccefe4c4
TT
75
76 if (fullname)
112e8700 77 uiout->field_string ("fullname", fullname);
ccefe4c4 78
112e8700 79 uiout->end (ui_out_type_tuple);
ccefe4c4
TT
80}
81
ce8f13f8 82void
9f33b8b7 83mi_cmd_file_list_exec_source_files (const char *command, char **argv, int argc)
57c22c6c 84{
79a45e25 85 struct ui_out *uiout = current_uiout;
57c22c6c 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 93 /* Look at all of the file symtabs. */
2030c079 94 for (objfile *objfile : current_program_space->objfiles ())
8b31193a 95 {
b669c953 96 for (compunit_symtab *cu : objfile->compunits ())
8b31193a
TT
97 {
98 for (symtab *s : compunit_filetabs (cu))
99 {
100 uiout->begin (ui_out_type_tuple, NULL);
101
102 uiout->field_string ("file", symtab_to_filename_for_display (s));
103 uiout->field_string ("fullname", symtab_to_fullname (s));
104
105 uiout->end (ui_out_type_tuple);
106 }
107 }
108 }
57c22c6c 109
f4655dee 110 map_symbol_filenames (print_partial_file_name, true /*need_fullname*/);
57c22c6c 111
112e8700 112 uiout->end (ui_out_type_list);
57c22c6c 113}
51457a05
MAL
114
115/* See mi-cmds.h. */
116
117void
9f33b8b7 118mi_cmd_file_list_shared_libraries (const char *command, char **argv, int argc)
51457a05
MAL
119{
120 struct ui_out *uiout = current_uiout;
121 const char *pattern;
51457a05
MAL
122
123 switch (argc)
124 {
125 case 0:
126 pattern = NULL;
127 break;
128 case 1:
129 pattern = argv[0];
130 break;
131 default:
132 error (_("Usage: -file-list-shared-libraries [REGEXP]"));
133 }
134
135 if (pattern != NULL)
136 {
137 const char *re_err = re_comp (pattern);
138
139 if (re_err != NULL)
140 error (_("Invalid regexp: %s"), re_err);
141 }
142
143 update_solib_list (1);
144
145 /* Print the table header. */
10f489e5 146 ui_out_emit_list list_emitter (uiout, "shared-libraries");
51457a05 147
a1fd1ac9 148 for (struct so_list *so : current_program_space->solibs ())
51457a05
MAL
149 {
150 if (so->so_name[0] == '\0')
151 continue;
152 if (pattern != NULL && !re_exec (so->so_name))
153 continue;
154
76f9c9cf 155 ui_out_emit_tuple tuple_emitter (uiout, NULL);
51457a05 156 mi_output_solib_attribs (uiout, so);
51457a05 157 }
51457a05 158}