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 "psymtab.h"
29#include "solib.h"
30#include "solist.h"
31#include "gdbsupport/gdb_regex.h"
32
33/* Return to the client the absolute path and line number of the
34 current file being executed. */
35
36void
37mi_cmd_file_list_exec_source_file (const char *command, char **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
68mi_cmd_file_list_exec_source_files (const char *command, char **argv, int argc)
69{
70 enum opt
71 {
72 GROUP_BY_OBJFILE_OPT,
73 MATCH_BASENAME_OPT,
74 MATCH_DIRNAME_OPT
75 };
76 static const struct mi_opt opts[] =
77 {
78 {"-group-by-objfile", GROUP_BY_OBJFILE_OPT, 0},
79 {"-basename", MATCH_BASENAME_OPT, 0},
80 {"-dirname", MATCH_DIRNAME_OPT, 0},
81 { 0, 0, 0 }
82 };
83
84 /* Parse arguments. */
85 int oind = 0;
86 char *oarg;
87
88 bool group_by_objfile = false;
89 bool match_on_basename = false;
90 bool match_on_dirname = false;
91
92 while (1)
93 {
94 int opt = mi_getopt ("-file-list-exec-source-files", argc, argv,
95 opts, &oind, &oarg);
96 if (opt < 0)
97 break;
98 switch ((enum opt) opt)
99 {
100 case GROUP_BY_OBJFILE_OPT:
101 group_by_objfile = true;
102 break;
103 case MATCH_BASENAME_OPT:
104 match_on_basename = true;
105 break;
106 case MATCH_DIRNAME_OPT:
107 match_on_dirname = true;
108 break;
109 }
110 }
111
112 if ((argc - oind > 1) || (match_on_basename && match_on_dirname))
113 error (_("-file-list-exec-source-files: Usage: [--group-by-objfile] [--basename | --dirname] [--] REGEXP"));
114
115 const char *regexp = nullptr;
116 if (argc - oind == 1)
117 regexp = argv[oind];
118
120 if (match_on_dirname)
122 else if (match_on_basename)
124 else
126
127 info_sources_filter filter (match_type, regexp);
128 info_sources_worker (current_uiout, group_by_objfile, filter);
129}
130
131/* See mi-cmds.h. */
132
133void
134mi_cmd_file_list_shared_libraries (const char *command, char **argv, int argc)
135{
136 struct ui_out *uiout = current_uiout;
137 const char *pattern;
138
139 switch (argc)
140 {
141 case 0:
142 pattern = NULL;
143 break;
144 case 1:
145 pattern = argv[0];
146 break;
147 default:
148 error (_("Usage: -file-list-shared-libraries [REGEXP]"));
149 }
150
151 if (pattern != NULL)
152 {
153 const char *re_err = re_comp (pattern);
154
155 if (re_err != NULL)
156 error (_("Invalid regexp: %s"), re_err);
157 }
158
160
161 /* Print the table header. */
162 ui_out_emit_list list_emitter (uiout, "shared-libraries");
163
164 for (struct so_list *so : current_program_space->solibs ())
165 {
166 if (so->so_name[0] == '\0')
167 continue;
168 if (pattern != NULL && !re_exec (so->so_name))
169 continue;
170
171 ui_out_emit_tuple tuple_emitter (uiout, NULL);
172 mi_output_solib_attribs (uiout, so);
173 }
174}
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_valid_noargs(const char *prefix, int argc, char **argv)
Definition mi-getopt.c:98
int mi_getopt(const char *prefix, int argc, char **argv, const struct mi_opt *opts, int *oind, char **oarg)
Definition mi-getopt.c:82
void mi_output_solib_attribs(ui_out *uiout, struct so_list *solib)
Definition mi-interp.c:1047
struct program_space * current_program_space
Definition progspace.c:39
void update_solib_list(int from_tty)
Definition solib.c:766
const char * symtab_to_fullname(struct symtab *s)
Definition source.c:1252
const char * symtab_to_filename_for_display(struct symtab *symtab)
Definition source.c:1287
struct symtab_and_line get_current_source_symtab_and_line(void)
Definition source.c:238
void set_default_source_symtab_and_line(void)
Definition source.c:261
struct macro_table * macro_table() const
Definition symtab.h:1818
so_list_range solibs() const
Definition progspace.h:256
struct symtab * symtab
Definition symtab.h:2263
struct compunit_symtab * compunit() const
Definition symtab.h:1603
void info_sources_worker(struct ui_out *uiout, bool group_by_objfile, const info_sources_filter &filter)
Definition symtab.c:4435
#define current_uiout
Definition ui-out.h:40