public MemoryBlockDescriptor(DwarfData dwarfData, MemoryProfile memoryProfile, string memoryName) { _dwarfData = dwarfData; _name = memoryName; _memoryProfile = memoryProfile; _sections = _memoryProfile.GetSectionsByMemoryEx(memoryName); }
public MemoryProfile(DwarfData dwData, MemoryDescriptor memoryDescriptor = null) { DwarfData = dwData; DetectSectionsRamType(memoryDescriptor); //build memory usage table memoryUsageTable = new Dictionary <string, MemoryUsage>(); var memories = GetMemoryNames(); if (memories != null) { foreach (var memory in memories) { var sections = GetSectionsByMemoryEx(memory); var mem = new MemoryUsage { Sections = sections }; if (sections != null && sections.Length != 0) { mem.BytesUsed = sections.Aggregate(0UL, (current, section) => current + section.Header.size); if (memoryDescriptor != null && memoryDescriptor.IsEntryExists(memory)) { var entry = memoryDescriptor.GetEntryByName(memory); mem.Base = (ulong)entry.Origin; mem.Length = (ulong)entry.Length; } else { } } memoryUsageTable[memory] = mem; } } }
static void Main(string[] args) { //string linkerScriptPath = @"C:/Users/Sergey/AppData/Local/VisualGDB/EmbeddedBSPs/arm-eabi/com.sysprogs.arm.stm32/STM32F4xxxx-HAL/LinkerScripts/STM32F439xI_flash.lds"; string elfFilePath = @"D:\MotionParallaxResearch\NMarker\V03\Software\ATmega328P\ATmega328P\ATmega328P\Debug\ATmega328P.elf"; MemoryDescriptor mem = null;// MemoryDescriptor.FromLinkerScript(linkerScriptPath); ElfFile elf = new ElfFile(File.ReadAllBytes(elfFilePath)); DwarfData dwData = new DwarfData(elf); MemoryProfile profile = new MemoryProfile(dwData, mem); var flashSections = profile.GetFlashSections(); var progSections = profile.GetProgramSections(); var memNames = profile.GetMemoryNames(); foreach (var name in memNames) { var sections = profile.GetSectionsByMemoryEx(name); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Memory: {0}", name); ulong totalSize = 0; foreach (var section in sections) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\t{0} : {1}", section.Name, section.Header.size); totalSize += section.Header.size; //print symbols var fileGroups = section.Items.GroupBy(v => Path.GetFileName(v.FileStr)).ToArray(); foreach (var fileGroup in fileGroups) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("\t\t{0} : ", fileGroup.Key); Console.ResetColor(); foreach (var item in fileGroup) { var p1 = string.Format("\t\t\t{0}:", item.Name); if (p1.Length < 14) { p1 += "\t"; } if (p1.Length < 25) { p1 += "\t"; } Console.WriteLine(p1 + string.Format("\t{0}:\t0x{1:x}", item.Size, item.Pc)); } } } Console.WriteLine("\tTotal size: {0}", totalSize); } var flashSize = flashSections.Aggregate <ElfSection, ulong>(0, (current, item) => current + item.Header.size); var prgSize = progSections.Aggregate <ElfSection, ulong>(0, (current, item) => current + item.Header.size); Console.ReadLine(); }
public void Reload(string elfFilePath, string linkerScrintFilePath) { _elfUri = new Uri(elfFilePath); try { File = new ElfFile(System.IO.File.ReadAllBytes(elfFilePath)); } catch (Exception ex) { Debug.WriteLine(ex.Message); return; } _dwarf = new DwarfData(_elfFile); _memoryDescriptor = System.IO.File.Exists(linkerScrintFilePath) ? MemoryDescriptor.FromLinkerScript(linkerScrintFilePath) : null; Profile = new MemoryProfile(_dwarf, _memoryDescriptor); Symbols.Clear(); foreach (var memoryName in Profile.MemoryNames) { var adapter = new MemoryTypeAdapter(Profile, memoryName); foreach (var section in adapter.Sections) { foreach (var symbol in section.Symbols) { if (symbol.Header.Info.SymbolType == Elf32SymbolType.STT_SECTION) { continue; } SymbolDescriptor desc = new SymbolDescriptor(); desc.Section = section; desc.Memory = adapter; desc.Symbol = symbol; desc.DwarfUnitItem = _dwarf.globalItems.FirstOrDefault(v => v.Name == symbol.Name); /*Uri address1 = new Uri("http://www.contoso.com/"); * * // Create a new Uri from a string. * Uri address2 = new Uri("http://www.contoso.com/index.htm?date=today"); * * // Determine the relative Uri. * Console.WriteLine("The difference is {0}", address1.MakeRelativeUri(address2));*/ if (!string.IsNullOrEmpty(desc.DwarfUnitItem?.FileStr)) { if (System.IO.File.Exists(desc.DwarfUnitItem.FileStr)) { Uri elfUri = new Uri(elfFilePath); Uri symbolUri = new Uri(desc.DwarfUnitItem.FileStr); Uri relativePath = elfUri.MakeRelativeUri(symbolUri); desc.DwarfUnitItem.FileStr = relativePath.ToString(); } } Symbols.Add(desc); } } } UpdateTitle(); }