public virtual async Task <(SbModule, bool)> LoadBinaryAsync( SbModule lldbModule, TextWriter searchLog) { if (lldbModule == null) { throw new ArgumentNullException(nameof(lldbModule)); } searchLog = searchLog ?? TextWriter.Null; if (!moduleUtil.IsPlaceholderModule(lldbModule)) { return(lldbModule, true); } var binaryName = lldbModule.GetPlatformFileSpec()?.GetFilename(); if (string.IsNullOrEmpty(binaryName)) { await searchLog.WriteLineAsync(ErrorStrings.BinaryFileNameUnknown); Trace.WriteLine(ErrorStrings.BinaryFileNameUnknown); return(lldbModule, false); } var binaryPath = await moduleFileFinder.FindFileAsync( binaryName, new BuildId(lldbModule.GetUUIDString()), false, searchLog); if (binaryPath == null) { return(lldbModule, false); } PlaceholderModuleProperties properties = moduleUtil.GetPlaceholderProperties(lldbModule, lldbTarget); if (properties == null) { return(lldbModule, false); } RemoveModule(lldbModule); var newModule = AddModule(binaryPath, lldbModule.GetUUIDString(), searchLog); if (newModule == null) { return(lldbModule, false); } if (!moduleUtil.ApplyPlaceholderProperties(newModule, properties, lldbTarget)) { return(lldbModule, false); } LldbModuleReplaced?.Invoke(Self, new LldbModuleReplacedEventArgs(newModule, lldbModule)); return(newModule, true); }
public void SetUp() { searchLog = new StringWriter(); mockTarget = Substitute.For <RemoteTarget>(); moduleReplacedHandler = Substitute.For <EventHandler <LldbModuleReplacedEventArgs> >(); mockModuleFileFinder = Substitute.For <IModuleFileFinder>(); mockModuleFileFinder.FindFileAsync(BINARY_FILENAME, UUID, false, searchLog) .Returns(Task.FromResult(PATH_IN_STORE)); placeholderModule = Substitute.For <SbModule>(); placeholderModule.GetPlatformFileSpec().GetFilename().Returns(BINARY_FILENAME); placeholderModule.GetUUIDString().Returns(UUID.ToString()); placeholderProperties = new PlaceholderModuleProperties(MODULE_SLIDE, Substitute.For <SbFileSpec>()); mockModuleUtil = Substitute.For <ILldbModuleUtil>(); mockModuleUtil.IsPlaceholderModule(placeholderModule).Returns(true); mockModuleUtil.GetPlaceholderProperties(Arg.Any <SbModule>(), Arg.Any <RemoteTarget>()) .ReturnsForAnyArgs(placeholderProperties); mockModuleUtil.ApplyPlaceholderProperties( Arg.Any <SbModule>(), Arg.Any <PlaceholderModuleProperties>(), Arg.Any <RemoteTarget>()) .ReturnsForAnyArgs(true); binaryLoader = new BinaryLoader(mockModuleUtil, mockModuleFileFinder, mockTarget); binaryLoader.LldbModuleReplaced += moduleReplacedHandler; }
public virtual async Task <bool> LoadSymbolsAsync( SbModule lldbModule, TextWriter searchLog, bool useSymbolStores) { if (lldbModule == null) { throw new ArgumentNullException(nameof(lldbModule)); } searchLog = searchLog ?? TextWriter.Null; // Return early if symbols are already loaded if (moduleUtil.HasSymbolsLoaded(lldbModule)) { return(true); } var(symbolFileDir, symbolFileName) = await GetSymbolFileDirAndNameAsync(lldbModule, searchLog); if (string.IsNullOrEmpty(symbolFileName)) { await searchLog.WriteLineAsync(ErrorStrings.SymbolFileNameUnknown); Trace.WriteLine(ErrorStrings.SymbolFileNameUnknown); return(false); } BuildId uuid = new BuildId(lldbModule.GetUUIDString()); // If we have a search directory, let us look up the symbol file in there. if (!string.IsNullOrEmpty(symbolFileDir)) { string symbolFilePath = string.Empty; try { symbolFilePath = Path.Combine(symbolFileDir, symbolFileName); BuildId fileUUID = await binaryFileUtil.ReadBuildIdAsync(symbolFilePath); if (fileUUID == uuid) { return(AddSymbolFile(symbolFilePath, lldbModule, searchLog)); } } catch (Exception e) when(e is InvalidBuildIdException || e is BinaryFileUtilException || e is ArgumentException) { // Just ignore the symbol file path if we could not read the build Id. Trace.WriteLine($"Could not read build Id from {symbolFilePath} " + $"for module {lldbModule.GetFileSpec().GetFilename()} " + $"(Message: {e.Message})."); } } var filepath = useSymbolStores ? await moduleFileFinder.FindFileAsync( symbolFileName, uuid, true, searchLog) : null; if (filepath == null) { return(false); } return(AddSymbolFile(filepath, lldbModule, searchLog)); }