]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/mi/mi-cmd-file.c
gdb/amd64-linux-tdep: add missing space
[thirdparty/binutils-gdb.git] / gdb / mi / mi-cmd-file.c
CommitLineData
2b03b41d 1/* MI Command Set - file commands.
d01e8234 2 Copyright (C) 2000-2025 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 19
1abaf70c
BR
20#include "mi-cmds.h"
21#include "mi-getopt.h"
51457a05 22#include "mi-interp.h"
378cefb4 23#include "progspace.h"
1abaf70c
BR
24#include "ui-out.h"
25#include "symtab.h"
26#include "source.h"
51457a05 27#include "solib.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
9158e49a
TT
33mi_cmd_file_list_exec_source_file (const char *command,
34 const char *const *argv, int argc)
1abaf70c 35{
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 42 set_default_source_symtab_and_line ();
3bae94c0
SM
43 symtab_and_line st
44 = get_current_source_symtab_and_line (current_program_space);
1abaf70c 45
2b03b41d
SS
46 /* We should always get a symtab. Apparently, filename does not
47 need to be tested for NULL. The documentation in symtab.h
48 suggests it will always be correct. */
1abaf70c 49 if (!st.symtab)
1b05df00 50 error (_("-file-list-exec-source-file: No symtab"));
1abaf70c 51
2b03b41d 52 /* Print to the user the line, filename and fullname. */
381befee 53 uiout->field_signed ("line", st.line);
112e8700 54 uiout->field_string ("file", symtab_to_filename_for_display (st.symtab));
57c22c6c 55
112e8700 56 uiout->field_string ("fullname", symtab_to_fullname (st.symtab));
1abaf70c 57
381befee 58 uiout->field_signed ("macro-info",
c6159652 59 st.symtab->compunit ()->macro_table () != NULL);
1abaf70c 60}
57c22c6c 61
0e350a05 62/* Implement -file-list-exec-source-files command. */
ccefe4c4 63
ce8f13f8 64void
9158e49a
TT
65mi_cmd_file_list_exec_source_files (const char *command,
66 const char *const *argv, int argc)
57c22c6c 67{
0e350a05
AB
68 enum opt
69 {
1fb1ce02 70 GROUP_BY_OBJFILE_OPT,
0e350a05
AB
71 MATCH_BASENAME_OPT,
72 MATCH_DIRNAME_OPT
73 };
74 static const struct mi_opt opts[] =
75 {
1fb1ce02 76 {"-group-by-objfile", GROUP_BY_OBJFILE_OPT, 0},
0e350a05
AB
77 {"-basename", MATCH_BASENAME_OPT, 0},
78 {"-dirname", MATCH_DIRNAME_OPT, 0},
79 { 0, 0, 0 }
80 };
81
82 /* Parse arguments. */
83 int oind = 0;
9158e49a 84 const char *oarg;
0e350a05 85
1fb1ce02 86 bool group_by_objfile = false;
0e350a05
AB
87 bool match_on_basename = false;
88 bool match_on_dirname = false;
89
90 while (1)
8b31193a 91 {
0e350a05
AB
92 int opt = mi_getopt ("-file-list-exec-source-files", argc, argv,
93 opts, &oind, &oarg);
94 if (opt < 0)
95 break;
96 switch ((enum opt) opt)
8b31193a 97 {
1fb1ce02
AB
98 case GROUP_BY_OBJFILE_OPT:
99 group_by_objfile = true;
100 break;
0e350a05
AB
101 case MATCH_BASENAME_OPT:
102 match_on_basename = true;
103 break;
104 case MATCH_DIRNAME_OPT:
105 match_on_dirname = true;
106 break;
8b31193a
TT
107 }
108 }
57c22c6c 109
0e350a05 110 if ((argc - oind > 1) || (match_on_basename && match_on_dirname))
1fb1ce02 111 error (_("-file-list-exec-source-files: Usage: [--group-by-objfile] [--basename | --dirname] [--] REGEXP"));
0e350a05
AB
112
113 const char *regexp = nullptr;
114 if (argc - oind == 1)
115 regexp = argv[oind];
116
117 info_sources_filter::match_on match_type;
118 if (match_on_dirname)
119 match_type = info_sources_filter::match_on::DIRNAME;
120 else if (match_on_basename)
121 match_type = info_sources_filter::match_on::BASENAME;
122 else
123 match_type = info_sources_filter::match_on::FULLNAME;
57c22c6c 124
0e350a05 125 info_sources_filter filter (match_type, regexp);
1fb1ce02 126 info_sources_worker (current_uiout, group_by_objfile, filter);
57c22c6c 127}
51457a05
MAL
128
129/* See mi-cmds.h. */
130
131void
9158e49a
TT
132mi_cmd_file_list_shared_libraries (const char *command,
133 const char *const *argv, int argc)
51457a05
MAL
134{
135 struct ui_out *uiout = current_uiout;
136 const char *pattern;
51457a05
MAL
137
138 switch (argc)
139 {
140 case 0:
141 pattern = NULL;
142 break;
143 case 1:
144 pattern = argv[0];
145 break;
146 default:
147 error (_("Usage: -file-list-shared-libraries [REGEXP]"));
148 }
149
150 if (pattern != NULL)
151 {
152 const char *re_err = re_comp (pattern);
153
154 if (re_err != NULL)
155 error (_("Invalid regexp: %s"), re_err);
156 }
157
158 update_solib_list (1);
159
160 /* Print the table header. */
10f489e5 161 ui_out_emit_list list_emitter (uiout, "shared-libraries");
51457a05 162
7b323785 163 for (const solib &so : current_program_space->solibs ())
51457a05 164 {
6896e625 165 if (so.name.empty ())
51457a05 166 continue;
98107b0b 167
6896e625 168 if (pattern != nullptr && !re_exec (so.name.c_str ()))
51457a05
MAL
169 continue;
170
76f9c9cf 171 ui_out_emit_tuple tuple_emitter (uiout, NULL);
8971d278 172 mi_output_solib_attribs (uiout, so);
51457a05 173 }
51457a05 174}