]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/mi/mi-cmd-file.c
cf7991f9892032985b22bc348060be59197940ab
1 /* MI Command Set - file commands.
2 Copyright (C) 2000-2025 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions (a Red Hat company).
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "mi-getopt.h"
22 #include "mi-interp.h"
23 #include "progspace.h"
29 /* Return to the client the absolute path and line number of the
30 current file being executed. */
33 mi_cmd_file_list_exec_source_file (const char *command
,
34 const char *const *argv
, int argc
)
36 struct ui_out
*uiout
= current_uiout
;
38 if (!mi_valid_noargs ("-file-list-exec-source-file", argc
, argv
))
39 error (_("-file-list-exec-source-file: Usage: No args"));
41 /* Set the default file and line, also get them. */
42 set_default_source_symtab_and_line ();
44 = get_current_source_symtab_and_line (current_program_space
);
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. */
50 error (_("-file-list-exec-source-file: No symtab"));
52 /* Print to the user the line, filename and fullname. */
53 uiout
->field_signed ("line", st
.line
);
54 uiout
->field_string ("file", symtab_to_filename_for_display (st
.symtab
));
56 uiout
->field_string ("fullname", symtab_to_fullname (st
.symtab
));
58 uiout
->field_signed ("macro-info",
59 st
.symtab
->compunit ()->macro_table () != NULL
);
62 /* Implement -file-list-exec-source-files command. */
65 mi_cmd_file_list_exec_source_files (const char *command
,
66 const char *const *argv
, int argc
)
74 static const struct mi_opt opts
[] =
76 {"-group-by-objfile", GROUP_BY_OBJFILE_OPT
, 0},
77 {"-basename", MATCH_BASENAME_OPT
, 0},
78 {"-dirname", MATCH_DIRNAME_OPT
, 0},
82 /* Parse arguments. */
86 bool group_by_objfile
= false;
87 bool match_on_basename
= false;
88 bool match_on_dirname
= false;
92 int opt
= mi_getopt ("-file-list-exec-source-files", argc
, argv
,
96 switch ((enum opt
) opt
)
98 case GROUP_BY_OBJFILE_OPT
:
99 group_by_objfile
= true;
101 case MATCH_BASENAME_OPT
:
102 match_on_basename
= true;
104 case MATCH_DIRNAME_OPT
:
105 match_on_dirname
= true;
110 if ((argc
- oind
> 1) || (match_on_basename
&& match_on_dirname
))
111 error (_("-file-list-exec-source-files: Usage: [--group-by-objfile] [--basename | --dirname] [--] REGEXP"));
113 const char *regexp
= nullptr;
114 if (argc
- oind
== 1)
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
;
123 match_type
= info_sources_filter::match_on::FULLNAME
;
125 info_sources_filter
filter (match_type
, regexp
);
126 info_sources_worker (current_uiout
, group_by_objfile
, filter
);
132 mi_cmd_file_list_shared_libraries (const char *command
,
133 const char *const *argv
, int argc
)
135 struct ui_out
*uiout
= current_uiout
;
147 error (_("Usage: -file-list-shared-libraries [REGEXP]"));
152 const char *re_err
= re_comp (pattern
);
155 error (_("Invalid regexp: %s"), re_err
);
158 update_solib_list (1);
160 /* Print the table header. */
161 ui_out_emit_list
list_emitter (uiout
, "shared-libraries");
163 for (const solib
&so
: current_program_space
->solibs ())
165 if (so
.name
.empty ())
168 if (pattern
!= nullptr && !re_exec (so
.name
.c_str ()))
171 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
172 mi_output_solib_attribs (uiout
, so
);