+ /* Generate a (hopefully unique) qualified name using the first part
+ of the dll name, e.g. KERNEL32!AddAtomA. This matches the style
+ used by windbg from the "Microsoft Debugging Tools for Windows". */
+
+ std::string bare_name;
+ if (sym_name == NULL || *sym_name == '\0')
+ bare_name = string_printf ("#%d", ordinal);
+ else
+ bare_name = sym_name;
+
+ std::string qualified_name
+ = string_printf ("%s!%s", dll_name, bare_name.c_str ());
+
+ if ((section_data->ms_type == mst_unknown) && debug_coff_pe_read)
+ fprintf_unfiltered (gdb_stdlog , _("Unknown section type for \"%s\""
+ " for entry \"%s\" in dll \"%s\"\n"),
+ section_data->section_name.c_str (), sym_name,
+ dll_name);
+
+ reader.record_with_info (qualified_name.c_str (), vma, section_data->ms_type,
+ section_data->index);
+
+ /* Enter the plain name as well, which might not be unique. */
+ reader.record_with_info (bare_name.c_str (), vma, section_data->ms_type,
+ section_data->index);
+ if (debug_coff_pe_read > 1)
+ fprintf_unfiltered (gdb_stdlog, _("Adding exported symbol \"%s\""
+ " in dll \"%s\"\n"), sym_name, dll_name);
+}
+
+/* Create a minimal symbol entry for an exported forward symbol.
+ Return 1 if the forwarded function was found 0 otherwise.
+ SYM_NAME contains the exported name or NULL if exported by ordinal,
+ FORWARD_DLL_NAME is the name of the DLL in which the target symobl resides,
+ FORWARD_FUNC_NAME is the name of the target symbol in that DLL,
+ ORDINAL is the ordinal index value of the symbol,
+ DLL_NAME is the internal name of the DLL file,
+ OBJFILE is the objfile struct of DLL_NAME. */
+
+static int
+add_pe_forwarded_sym (minimal_symbol_reader &reader,
+ const char *sym_name, const char *forward_dll_name,
+ const char *forward_func_name, int ordinal,
+ const char *dll_name, struct objfile *objfile)
+{
+ CORE_ADDR vma, baseaddr;
+ struct bound_minimal_symbol msymbol;
+ enum minimal_symbol_type msymtype;
+ int forward_dll_name_len = strlen (forward_dll_name);
+ int forward_func_name_len = strlen (forward_func_name);
+ int forward_len = forward_dll_name_len + forward_func_name_len + 2;
+ char *forward_qualified_name = (char *) alloca (forward_len);
+ short section;
+
+ xsnprintf (forward_qualified_name, forward_len, "%s!%s", forward_dll_name,
+ forward_func_name);
+
+
+ msymbol = lookup_bound_minimal_symbol (forward_qualified_name);
+
+ if (!msymbol.minsym)
+ {
+ int i;
+
+ for (i = 0; i < forward_dll_name_len; i++)
+ forward_qualified_name[i] = tolower (forward_qualified_name[i]);
+ msymbol = lookup_bound_minimal_symbol (forward_qualified_name);
+ }
+
+ if (!msymbol.minsym)
+ {
+ if (debug_coff_pe_read)
+ fprintf_unfiltered (gdb_stdlog, _("Unable to find function \"%s\" in"
+ " dll \"%s\", forward of \"%s\" in dll \"%s\"\n"),
+ forward_func_name, forward_dll_name, sym_name,
+ dll_name);
+ return 0;
+ }
+
+ if (debug_coff_pe_read > 1)
+ fprintf_unfiltered (gdb_stdlog, _("Adding forwarded exported symbol"
+ " \"%s\" in dll \"%s\", pointing to \"%s\"\n"),
+ sym_name, dll_name, forward_qualified_name);
+
+ vma = BMSYMBOL_VALUE_ADDRESS (msymbol);
+ msymtype = MSYMBOL_TYPE (msymbol.minsym);
+ section = MSYMBOL_SECTION (msymbol.minsym);