@@ -141,6 +141,25 @@ SymbolLocator *SymbolLocatorDebuginfod::CreateInstance() {
141141 return new SymbolLocatorDebuginfod ();
142142}
143143
144+ static llvm::StringRef getFileName (const ModuleSpec &module_spec,
145+ std::string url_path) {
146+ // Check if the URL path requests an executable file or a symbol file
147+ bool is_executable = url_path.find (" debuginfo" ) == std::string::npos;
148+ if (is_executable) {
149+ return module_spec.GetFileSpec ().GetFilename ().GetStringRef ();
150+ }
151+ llvm::StringRef symbol_file =
152+ module_spec.GetSymbolFileSpec ().GetFilename ().GetStringRef ();
153+ // Remove llvmcache- prefix and hash, keep origin file name
154+ if (symbol_file.starts_with (" llvmcache-" )) {
155+ size_t pos = symbol_file.rfind (' -' );
156+ if (pos != llvm::StringRef::npos) {
157+ symbol_file = symbol_file.substr (pos + 1 );
158+ }
159+ }
160+ return symbol_file;
161+ }
162+
144163static std::optional<FileSpec>
145164GetFileForModule (const ModuleSpec &module_spec,
146165 std::function<std::string(llvm::object::BuildID)> UrlBuilder) {
@@ -166,9 +185,13 @@ GetFileForModule(const ModuleSpec &module_spec,
166185 // We're ready to ask the Debuginfod library to find our file.
167186 llvm::object::BuildID build_id (module_uuid.GetBytes ());
168187 std::string url_path = UrlBuilder (build_id);
169- std::string cache_key = llvm::getDebuginfodCacheKey (url_path);
188+ llvm::StringRef file_name = getFileName (module_spec, url_path);
189+ std::string cache_file_name = llvm::toHex (build_id, true );
190+ if (!file_name.empty ()) {
191+ cache_file_name += " -" + file_name.str ();
192+ }
170193 llvm::Expected<std::string> result = llvm::getCachedOrDownloadArtifact (
171- cache_key , url_path, cache_path, debuginfod_urls, timeout);
194+ cache_file_name , url_path, cache_path, debuginfod_urls, timeout);
172195 if (result)
173196 return FileSpec (*result);
174197
0 commit comments