diff --git a/src/Microsoft.Diagnostics.Runtime/src/DataReaders/Core/CoreDumpReader.cs b/src/Microsoft.Diagnostics.Runtime/src/DataReaders/Core/CoreDumpReader.cs index 51c39b761..4f8e0ec25 100644 --- a/src/Microsoft.Diagnostics.Runtime/src/DataReaders/Core/CoreDumpReader.cs +++ b/src/Microsoft.Diagnostics.Runtime/src/DataReaders/Core/CoreDumpReader.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using Microsoft.Diagnostics.Runtime.Linux; @@ -142,23 +141,8 @@ public bool GetThreadContext(uint threadID, uint contextFlags, Span contex public unsafe void GetVersionInfo(ulong baseAddress, out VersionInfo version) { ElfLoadedImage image = _core.LoadedImages.First(image => (ulong)image.BaseAddress == baseAddress); - - long loadAddress = 0; - long loadSize = 0; - foreach (ElfProgramHeader programHeader in image.Open().ProgramHeaders) - { - if (programHeader.Type == ElfProgramHeaderType.Load && programHeader.IsWritable) - { - loadAddress = programHeader.VirtualAddress; - loadSize = programHeader.VirtualSize; - break; - } - } - - Debug.Assert(loadAddress != 0); - Debug.Assert(loadSize != 0); - - LinuxFunctions.GetVersionInfo(this, baseAddress + (ulong)loadAddress, (ulong)loadSize, out version); + ElfFile file = image.Open(); + LinuxFunctions.GetVersionInfo(this, baseAddress, file, out version); } public uint ReadDwordUnsafe(ulong addr) diff --git a/src/Microsoft.Diagnostics.Runtime/src/Linux/LinuxLiveDataReader.cs b/src/Microsoft.Diagnostics.Runtime/src/Linux/LinuxLiveDataReader.cs index 46529bff3..219045c8d 100644 --- a/src/Microsoft.Diagnostics.Runtime/src/Linux/LinuxLiveDataReader.cs +++ b/src/Microsoft.Diagnostics.Runtime/src/Linux/LinuxLiveDataReader.cs @@ -136,23 +136,7 @@ public unsafe void GetVersionInfo(ulong baseAddress, out VersionInfo version) { MemoryVirtualAddressSpace memoryAddressSpace = new MemoryVirtualAddressSpace(this); ElfFile file = new ElfFile(new Reader(memoryAddressSpace), (long)baseAddress); - - long loadAddress = 0; - long loadSize = 0; - foreach (ElfProgramHeader programHeader in file.ProgramHeaders) - { - if (programHeader.Type == ElfProgramHeaderType.Load && programHeader.IsWritable) - { - loadAddress = programHeader.VirtualAddress; - loadSize = programHeader.VirtualSize; - break; - } - } - - Debug.Assert(loadAddress != 0); - Debug.Assert(loadSize != 0); - - LinuxFunctions.GetVersionInfo(this, baseAddress + (ulong)loadAddress, (ulong)loadSize, out version); + LinuxFunctions.GetVersionInfo(this, baseAddress, file, out version); } public bool ReadMemory(ulong address, Span span, out int bytesRead) diff --git a/src/Microsoft.Diagnostics.Runtime/src/Utilities/Platform/LinuxFunctions.cs b/src/Microsoft.Diagnostics.Runtime/src/Utilities/Platform/LinuxFunctions.cs index 4998f6abf..c305f1dfb 100644 --- a/src/Microsoft.Diagnostics.Runtime/src/Utilities/Platform/LinuxFunctions.cs +++ b/src/Microsoft.Diagnostics.Runtime/src/Utilities/Platform/LinuxFunctions.cs @@ -87,6 +87,22 @@ public LinuxFunctions() } } + internal static void GetVersionInfo(IDataReader dataReader, ulong baseAddress, ElfFile loadedFile, out VersionInfo version) + { + foreach (ElfProgramHeader programHeader in loadedFile.ProgramHeaders) + { + if (programHeader.Type == ElfProgramHeaderType.Load && programHeader.IsWritable) + { + long loadAddress = programHeader.VirtualAddress; + long loadSize = programHeader.VirtualSize; + GetVersionInfo(dataReader, baseAddress + (ulong)loadAddress, (ulong)loadSize, out version); + return; + } + } + + version = default; + } + internal static unsafe void GetVersionInfo(IDataReader dataReader, ulong address, ulong size, out VersionInfo version) { Span buffer = stackalloc byte[s_versionLength];