GDB (xrefs)
Loading...
Searching...
No Matches
mi-cmd-file.c
Go to the documentation of this file.
1/* MI Command Set - file commands.
2 Copyright (C) 2000-2023 Free Software Foundation, Inc.
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 "mi-interp.h"
24#include "ui-out.h"
25#include "symtab.h"
26#include "source.h"
27#include "objfiles.h"
28#include "solib.h"
29#include "solist.h"
30#include "gdbsupport/gdb_regex.h"
31
32/* Return to the client the absolute path and line number of the
33 current file being executed. */
34
35void
37 const char *const *argv, int argc)
38{
39 struct symtab_and_line st;
40 struct ui_out *uiout = current_uiout;
41
42 if (!mi_valid_noargs ("-file-list-exec-source-file", argc, argv))
43 error (_("-file-list-exec-source-file: Usage: No args"));
44
45 /* Set the default file and line, also get them. */
48
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. */
52 if (!st.symtab)
53 error (_("-file-list-exec-source-file: No symtab"));
54
55 /* Print to the user the line, filename and fullname. */
56 uiout->field_signed ("line", st.line);
58
59 uiout->field_string ("fullname", symtab_to_fullname (st.symtab));
60
61 uiout->field_signed ("macro-info",
62 st.symtab->compunit ()->macro_table () != NULL);
63}
64
65/* Implement -file-list-exec-source-files command. */
66
67void
69 const char *const *argv, int argc)
70{
71 enum opt
72 {
73 GROUP_BY_OBJFILE_OPT,
74 MATCH_BASENAME_OPT,
75 MATCH_DIRNAME_OPT
76 };
77 static const struct mi_opt opts[] =
78 {
79 {"-group-by-objfile", GROUP_BY_OBJFILE_OPT, 0},
80 {"-basename", MATCH_BASENAME_OPT, 0},
81 {"-dirname", MATCH_DIRNAME_OPT, 0},
82 { 0, 0, 0 }
83 };
84
85 /* Parse arguments. */
86 int oind = 0;
87 const char *oarg;
88
89 bool group_by_objfile = false;
90 bool match_on_basename = false;
91 bool match_on_dirname = false;
92
93 while (1)
94 {
95 int opt = mi_getopt ("-file-list-exec-source-files", argc, argv,
96 opts, &oind, &oarg);
97 if (opt < 0)
98 break;
99 switch ((enum opt) opt)
100 {
101 case GROUP_BY_OBJFILE_OPT:
102 group_by_objfile = true;
103 break;
104 case MATCH_BASENAME_OPT:
105 match_on_basename = true;
106 break;
107 case MATCH_DIRNAME_OPT:
108 match_on_dirname = true;
109 break;
110 }
111 }
112
113 if ((argc - oind > 1) || (match_on_basename && match_on_dirname))
114 error (_("-file-list-exec-source-files: Usage: [--group-by-objfile] [--basename | --dirname] [--] REGEXP"));
115
116 const char *regexp = nullptr;
117 if (argc - oind == 1)
118 regexp = argv[oind];
119
121 if (match_on_dirname)
123 else if (match_on_basename)
125 else
127
128 info_sources_filter filter (match_type, regexp);
129 info_sources_worker (current_uiout, group_by_objfile, filter);
130}
131
132/* See mi-cmds.h. */
133
134void
136 const char *const *argv, int argc)
137{
138 struct ui_out *uiout = current_uiout;
139 const char *pattern;
140
141 switch (argc)
142 {
143 case 0:
144 pattern = NULL;
145 break;
146 case 1:
147 pattern = argv[0];
148 break;
149 default:
150 error (_("Usage: -file-list-shared-libraries [REGEXP]"));
151 }
152
153 if (pattern != NULL)
154 {
155 const char *re_err = re_comp (pattern);
156
157 if (re_err != NULL)
158 error (_("Invalid regexp: %s"), re_err);
159 }
160
162
163 /* Print the table header. */
164 ui_out_emit_list list_emitter (uiout, "shared-libraries");
165
166 for (struct so_list *so : current_program_space->solibs ())
167 {
168 if (so->so_name[0] == '\0')
169 continue;
170 if (pattern != NULL && !re_exec (so->so_name))
171 continue;
172
173 ui_out_emit_tuple tuple_emitter (uiout, NULL);
174 mi_output_solib_attribs (uiout, so);
175 }
176}
void field_string(const char *fldname, const char *string, const ui_file_style &style=ui_file_style())
Definition ui-out.c:511
void field_signed(const char *fldname, LONGEST value)
Definition ui-out.c:437
EXTERN_C char * re_comp(const char *)
mi_cmd_argv_ftype mi_cmd_file_list_exec_source_files
mi_cmd_argv_ftype mi_cmd_file_list_shared_libraries
mi_cmd_argv_ftype mi_cmd_file_list_exec_source_file
int mi_getopt(const char *prefix, int argc, const char *const *argv, const struct mi_opt *opts, int *oind, const char **oarg)
Definition mi-getopt.c:82
int mi_valid_noargs(const char *prefix, int argc, const char *const *argv)
Definition mi-getopt.c:100
void mi_output_solib_attribs(ui_out *uiout, struct so_list *solib)
Definition mi-interp.c:727
struct program_space * current_program_space
Definition progspace.c:40
void update_solib_list(int from_tty)
Definition solib.c:775
const char * symtab_to_fullname(struct symtab *s)
Definition source.c:1234
const char * symtab_to_filename_for_display(struct symtab *symtab)
Definition source.c:1269
struct symtab_and_line get_current_source_symtab_and_line(void)
Definition source.c:239
void set_default_source_symtab_and_line(void)
Definition source.c:262
struct macro_table * macro_table() const
Definition symtab.h:1882
so_list_range solibs() const
Definition progspace.h:260
struct symtab * symtab
Definition symtab.h:2328
struct compunit_symtab * compunit() const
Definition symtab.h:1677
void info_sources_worker(struct ui_out *uiout, bool group_by_objfile, const info_sources_filter &filter)
Definition symtab.c:4445
#define current_uiout
Definition ui-out.h:40