+/* Return the name of a domain_enum. */
+
+const char *
+domain_name (domain_enum e)
+{
+ switch (e)
+ {
+ case UNDEF_DOMAIN: return "UNDEF_DOMAIN";
+ case VAR_DOMAIN: return "VAR_DOMAIN";
+ case STRUCT_DOMAIN: return "STRUCT_DOMAIN";
+ case LABEL_DOMAIN: return "LABEL_DOMAIN";
+ case COMMON_BLOCK_DOMAIN: return "COMMON_BLOCK_DOMAIN";
+ default: gdb_assert_not_reached ("bad domain_enum");
+ }
+}
+
+/* Return the name of a search_domain . */
+
+const char *
+search_domain_name (enum search_domain e)
+{
+ switch (e)
+ {
+ case VARIABLES_DOMAIN: return "VARIABLES_DOMAIN";
+ case FUNCTIONS_DOMAIN: return "FUNCTIONS_DOMAIN";
+ case TYPES_DOMAIN: return "TYPES_DOMAIN";
+ case ALL_DOMAIN: return "ALL_DOMAIN";
+ default: gdb_assert_not_reached ("bad search_domain");
+ }
+}
+
+/* See whether FILENAME matches SEARCH_NAME using the rule that we
+ advertise to the user. (The manual's description of linespecs
+ describes what we advertise). Returns true if they match, false
+ otherwise. */
+
+int
+compare_filenames_for_search (const char *filename, const char *search_name)
+{
+ int len = strlen (filename);
+ size_t search_len = strlen (search_name);
+
+ if (len < search_len)
+ return 0;
+
+ /* The tail of FILENAME must match. */
+ if (FILENAME_CMP (filename + len - search_len, search_name) != 0)
+ return 0;
+
+ /* Either the names must completely match, or the character
+ preceding the trailing SEARCH_NAME segment of FILENAME must be a
+ directory separator.
+
+ The check !IS_ABSOLUTE_PATH ensures SEARCH_NAME "/dir/file.c"
+ cannot match FILENAME "/path//dir/file.c" - as user has requested
+ absolute path. The sama applies for "c:\file.c" possibly
+ incorrectly hypothetically matching "d:\dir\c:\file.c".
+
+ The HAS_DRIVE_SPEC purpose is to make FILENAME "c:file.c"
+ compatible with SEARCH_NAME "file.c". In such case a compiler had
+ to put the "c:file.c" name into debug info. Such compatibility
+ works only on GDB built for DOS host. */
+ return (len == search_len
+ || (!IS_ABSOLUTE_PATH (search_name)
+ && IS_DIR_SEPARATOR (filename[len - search_len - 1]))
+ || (HAS_DRIVE_SPEC (filename)
+ && STRIP_DRIVE_SPEC (filename) == &filename[len - search_len]));
+}
+
+/* Check for a symtab of a specific name by searching some symtabs.
+ This is a helper function for callbacks of iterate_over_symtabs.
+
+ If NAME is not absolute, then REAL_PATH is NULL
+ If NAME is absolute, then REAL_PATH is the gdb_realpath form of NAME.
+
+ The return value, NAME, REAL_PATH, CALLBACK, and DATA
+ are identical to the `map_symtabs_matching_filename' method of
+ quick_symbol_functions.
+
+ FIRST and AFTER_LAST indicate the range of symtabs to search.
+ AFTER_LAST is one past the last symtab to search; NULL means to
+ search until the end of the list. */
+
+int
+iterate_over_some_symtabs (const char *name,
+ const char *real_path,
+ int (*callback) (struct symtab *symtab,
+ void *data),
+ void *data,
+ struct symtab *first,
+ struct symtab *after_last)
+{
+ struct symtab *s = NULL;
+ const char* base_name = lbasename (name);
+
+ for (s = first; s != NULL && s != after_last; s = s->next)
+ {
+ if (compare_filenames_for_search (s->filename, name))
+ {
+ if (callback (s, data))
+ return 1;
+ continue;
+ }
+
+ /* Before we invoke realpath, which can get expensive when many
+ files are involved, do a quick comparison of the basenames. */
+ if (! basenames_may_differ
+ && FILENAME_CMP (base_name, lbasename (s->filename)) != 0)
+ continue;
+
+ if (compare_filenames_for_search (symtab_to_fullname (s), name))
+ {
+ if (callback (s, data))
+ return 1;
+ continue;
+ }
+
+ /* If the user gave us an absolute path, try to find the file in
+ this symtab and use its absolute path. */
+ if (real_path != NULL)
+ {
+ const char *fullname = symtab_to_fullname (s);
+
+ gdb_assert (IS_ABSOLUTE_PATH (real_path));
+ gdb_assert (IS_ABSOLUTE_PATH (name));
+ if (FILENAME_CMP (real_path, fullname) == 0)
+ {
+ if (callback (s, data))
+ return 1;
+ continue;
+ }
+ }
+ }
+
+ return 0;
+}
+