]>
Commit | Line | Data |
---|---|---|
2b03b41d | 1 | /* MI Command Set - file commands. |
1d506c26 | 2 | Copyright (C) 2000-2024 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" |
1abaf70c BR |
23 | #include "ui-out.h" |
24 | #include "symtab.h" | |
25 | #include "source.h" | |
57c22c6c | 26 | #include "objfiles.h" |
51457a05 MAL |
27 | #include "solib.h" |
28 | #include "solist.h" | |
d322d6d6 | 29 | #include "gdbsupport/gdb_regex.h" |
1abaf70c BR |
30 | |
31 | /* Return to the client the absolute path and line number of the | |
2b03b41d | 32 | current file being executed. */ |
1abaf70c | 33 | |
ce8f13f8 | 34 | void |
9158e49a TT |
35 | mi_cmd_file_list_exec_source_file (const char *command, |
36 | const char *const *argv, int argc) | |
1abaf70c BR |
37 | { |
38 | struct symtab_and_line st; | |
79a45e25 | 39 | struct ui_out *uiout = current_uiout; |
1abaf70c | 40 | |
1b05df00 TT |
41 | if (!mi_valid_noargs ("-file-list-exec-source-file", argc, argv)) |
42 | error (_("-file-list-exec-source-file: Usage: No args")); | |
1abaf70c | 43 | |
2b03b41d | 44 | /* Set the default file and line, also get them. */ |
17784837 NR |
45 | set_default_source_symtab_and_line (); |
46 | st = get_current_source_symtab_and_line (); | |
1abaf70c | 47 | |
2b03b41d SS |
48 | /* We should always get a symtab. Apparently, filename does not |
49 | need to be tested for NULL. The documentation in symtab.h | |
50 | suggests it will always be correct. */ | |
1abaf70c | 51 | if (!st.symtab) |
1b05df00 | 52 | error (_("-file-list-exec-source-file: No symtab")); |
1abaf70c | 53 | |
2b03b41d | 54 | /* Print to the user the line, filename and fullname. */ |
381befee | 55 | uiout->field_signed ("line", st.line); |
112e8700 | 56 | uiout->field_string ("file", symtab_to_filename_for_display (st.symtab)); |
57c22c6c | 57 | |
112e8700 | 58 | uiout->field_string ("fullname", symtab_to_fullname (st.symtab)); |
1abaf70c | 59 | |
381befee | 60 | uiout->field_signed ("macro-info", |
c6159652 | 61 | st.symtab->compunit ()->macro_table () != NULL); |
1abaf70c | 62 | } |
57c22c6c | 63 | |
0e350a05 | 64 | /* Implement -file-list-exec-source-files command. */ |
ccefe4c4 | 65 | |
ce8f13f8 | 66 | void |
9158e49a TT |
67 | mi_cmd_file_list_exec_source_files (const char *command, |
68 | const char *const *argv, int argc) | |
57c22c6c | 69 | { |
0e350a05 AB |
70 | enum opt |
71 | { | |
1fb1ce02 | 72 | GROUP_BY_OBJFILE_OPT, |
0e350a05 AB |
73 | MATCH_BASENAME_OPT, |
74 | MATCH_DIRNAME_OPT | |
75 | }; | |
76 | static const struct mi_opt opts[] = | |
77 | { | |
1fb1ce02 | 78 | {"-group-by-objfile", GROUP_BY_OBJFILE_OPT, 0}, |
0e350a05 AB |
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; | |
9158e49a | 86 | const char *oarg; |
0e350a05 | 87 | |
1fb1ce02 | 88 | bool group_by_objfile = false; |
0e350a05 AB |
89 | bool match_on_basename = false; |
90 | bool match_on_dirname = false; | |
91 | ||
92 | while (1) | |
8b31193a | 93 | { |
0e350a05 AB |
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) | |
8b31193a | 99 | { |
1fb1ce02 AB |
100 | case GROUP_BY_OBJFILE_OPT: |
101 | group_by_objfile = true; | |
102 | break; | |
0e350a05 AB |
103 | case MATCH_BASENAME_OPT: |
104 | match_on_basename = true; | |
105 | break; | |
106 | case MATCH_DIRNAME_OPT: | |
107 | match_on_dirname = true; | |
108 | break; | |
8b31193a TT |
109 | } |
110 | } | |
57c22c6c | 111 | |
0e350a05 | 112 | if ((argc - oind > 1) || (match_on_basename && match_on_dirname)) |
1fb1ce02 | 113 | error (_("-file-list-exec-source-files: Usage: [--group-by-objfile] [--basename | --dirname] [--] REGEXP")); |
0e350a05 AB |
114 | |
115 | const char *regexp = nullptr; | |
116 | if (argc - oind == 1) | |
117 | regexp = argv[oind]; | |
118 | ||
119 | info_sources_filter::match_on match_type; | |
120 | if (match_on_dirname) | |
121 | match_type = info_sources_filter::match_on::DIRNAME; | |
122 | else if (match_on_basename) | |
123 | match_type = info_sources_filter::match_on::BASENAME; | |
124 | else | |
125 | match_type = info_sources_filter::match_on::FULLNAME; | |
57c22c6c | 126 | |
0e350a05 | 127 | info_sources_filter filter (match_type, regexp); |
1fb1ce02 | 128 | info_sources_worker (current_uiout, group_by_objfile, filter); |
57c22c6c | 129 | } |
51457a05 MAL |
130 | |
131 | /* See mi-cmds.h. */ | |
132 | ||
133 | void | |
9158e49a TT |
134 | mi_cmd_file_list_shared_libraries (const char *command, |
135 | const char *const *argv, int argc) | |
51457a05 MAL |
136 | { |
137 | struct ui_out *uiout = current_uiout; | |
138 | const char *pattern; | |
51457a05 MAL |
139 | |
140 | switch (argc) | |
141 | { | |
142 | case 0: | |
143 | pattern = NULL; | |
144 | break; | |
145 | case 1: | |
146 | pattern = argv[0]; | |
147 | break; | |
148 | default: | |
149 | error (_("Usage: -file-list-shared-libraries [REGEXP]")); | |
150 | } | |
151 | ||
152 | if (pattern != NULL) | |
153 | { | |
154 | const char *re_err = re_comp (pattern); | |
155 | ||
156 | if (re_err != NULL) | |
157 | error (_("Invalid regexp: %s"), re_err); | |
158 | } | |
159 | ||
160 | update_solib_list (1); | |
161 | ||
162 | /* Print the table header. */ | |
10f489e5 | 163 | ui_out_emit_list list_emitter (uiout, "shared-libraries"); |
51457a05 | 164 | |
7b323785 | 165 | for (const solib &so : current_program_space->solibs ()) |
51457a05 | 166 | { |
8971d278 | 167 | if (so.so_name.empty ()) |
51457a05 | 168 | continue; |
98107b0b | 169 | |
8971d278 | 170 | if (pattern != nullptr && !re_exec (so.so_name.c_str ())) |
51457a05 MAL |
171 | continue; |
172 | ||
76f9c9cf | 173 | ui_out_emit_tuple tuple_emitter (uiout, NULL); |
8971d278 | 174 | mi_output_solib_attribs (uiout, so); |
51457a05 | 175 | } |
51457a05 | 176 | } |