aboutsummaryrefslogtreecommitdiff
path: root/gdb/symtab.h
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2021-05-18 13:46:19 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2021-06-25 20:54:29 +0100
commit0e350a054bbeb4d00f2c430c4815c82d5ffb47a7 (patch)
tree079b2ed8a2344ef2b6b7c854b9ccfe8450d34137 /gdb/symtab.h
parent4a0788e08cbf9e7b90640475b17afbbf5423ea9d (diff)
downloadgdb-0e350a054bbeb4d00f2c430c4815c82d5ffb47a7.zip
gdb-0e350a054bbeb4d00f2c430c4815c82d5ffb47a7.tar.gz
gdb-0e350a054bbeb4d00f2c430c4815c82d5ffb47a7.tar.bz2
gdb/mi: add regexp filtering to -file-list-exec-source-files
This commit extends the existing MI command -file-list-exec-source-files to provide the same regular expression based filtering that the equivalent CLI command "info sources" provides. The new command syntax is: -file-list-exec-source-files [--basename | --dirname] [--] [REGEXP] All options are optional, which ensures the command is backward compatible. As part of this work I have unified the CLI and MI code. As a result of the unified code I now provide additional information in the MI command output, there is now a new field 'debug-fully-read' included with each source file. This field which has the values 'true' or 'false', indicates if the source file is from a compilation unit that has had its debug information fully read. However, as this is additional information, a well written front-end should just ignore this field if it doesn't understand it, so things should still be backward compatible. gdb/ChangeLog: * NEWS: Mention additions to -file-list-exec-source-files. * mi/mi-cmd-file.c (print_partial_file_name): Delete. (mi_cmd_file_list_exec_source_files): Rewrite to handle command options, and make use of info_sources_worker. * symtab.c (struct info_sources_filter): Moved to symtab.h. (info_sources_filter::print): Take uiout argument, produce output through uiout. (struct output_source_filename_data) <output_source_filename_data>: Take uiout argument, store into m_uiout. <output>: Rewrite comment, add additional arguments to declaration. <operator()>: Send more arguments to output. <m_uiout>: New member variable. (output_source_filename_data::output): Take extra arguments, produce output through m_uiout, and structure for MI. (output_source_filename_data::print_header): Produce output through m_uiout. (info_sources_worker): New function, the implementation is taken from info_sources_command, but modified so produce output through a ui_out. (info_sources_command): The second half of this function has gone to become info_sources_worker. * symtab.h (struct info_sources_filter): Moved from symtab.c, add extra parameter to print member function. (info_sources_worker): Declare. gdb/doc/ChangeLog: * gdb.texinfo (GDB/MI File Commands): Document extensions to -file-list-exec-source-files. gdb/testsuite/ChangeLog: * gdb.dwarf2/dw2-filename.exp: Update expected results. * gdb.mi/mi-file.exp: Likewise. * gdb.mi/mi-info-sources-base.c: New file. * gdb.mi/mi-info-sources.c: New file. * gdb.mi/mi-info-sources.exp: New file.
Diffstat (limited to 'gdb/symtab.h')
-rw-r--r--gdb/symtab.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/gdb/symtab.h b/gdb/symtab.h
index a5d0168..db0df5c 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2385,4 +2385,67 @@ private:
std::vector<bound_minimal_symbol> m_minimal_symbols;
};
+/* Class used to encapsulate the filename filtering for the "info sources"
+ command. */
+
+struct info_sources_filter
+{
+ /* If filename filtering is being used (see M_C_REGEXP) then which part
+ of the filename is being filtered against? */
+ enum class match_on
+ {
+ /* Match against the full filename. */
+ FULLNAME,
+
+ /* Match only against the directory part of the full filename. */
+ DIRNAME,
+
+ /* Match only against the basename part of the full filename. */
+ BASENAME
+ };
+
+ /* Create a filter of MATCH_TYPE using regular expression REGEXP. If
+ REGEXP is nullptr then all files will match the filter and MATCH_TYPE
+ is ignored.
+
+ The string pointed too by REGEXP must remain live and unchanged for
+ this lifetime of this object as the object only retains a copy of the
+ pointer. */
+ info_sources_filter (match_on match_type, const char *regexp);
+
+ DISABLE_COPY_AND_ASSIGN (info_sources_filter);
+
+ /* Does FULLNAME match the filter defined by this object, return true if
+ it does, otherwise, return false. If there is no filtering defined
+ then this function will always return true. */
+ bool matches (const char *fullname) const;
+
+ /* Print a single line describing this filter to UIOUT, used as part of
+ the "info sources" command output. If there is no filter in place
+ then nothing is printed. */
+ void print (struct ui_out *uiout) const;
+
+private:
+
+ /* The type of filtering in place. */
+ match_on m_match_type;
+
+ /* Points to the original regexp used to create this filter. */
+ const char *m_regexp;
+
+ /* A compiled version of M_REGEXP. This object is only given a value if
+ M_REGEXP is not nullptr and is not the empty string. */
+ gdb::optional<compiled_regex> m_c_regexp;
+};
+
+/* Perform the core of the 'info sources' command.
+
+ FILTER is used to perform regular expression based filtering on the
+ source files that will be displayed.
+
+ Output is written to UIOUT in CLI or MI style as appropriate. */
+
+extern void info_sources_worker (struct ui_out *uiout,
+ const info_sources_filter &filter);
+
#endif /* !defined(SYMTAB_H) */