/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { using (MapViewer game = new MapViewer()) { game.Run(); } }
public void Run(string nmPath, string elfPath, MapViewer ownerForm) { this.MapViewerObj = ownerForm; string result = ""; Symbols = new List <Symbol>(); if (nmPath == "" || elfPath == "") { return; } ProcessAdapter.Execute(ref result, nmPath, "--demangle --print-size --size-sort " + Quote(elfPath)); //--line-numbers // Parse the resultant table // 00800744 00000004 b LoaderIPMode --> b means static BSS symbol, B beans global BSS symbol, same for d/D data // 00006364 00000018 T vTaskSuspendAll /cygdrive/d/Freelance/Study/FTDI/VFWLoaderDemo/lib/FreeRTOS/Source/tasks.c:1632 string[] symTable = result.Split(new[] { '\r', '\n' }); bool flip = false; foreach (string line in symTable) { if (flip) { this.MapViewerObj.Button_status_text("Analyze" + " +"); flip = false; } else { this.MapViewerObj.Button_status_text("Analyze" + " -"); flip = true; } // Split using spaces - note that the module path may itself contain spaces string[] entries = line.Split(new char[0], 4, StringSplitOptions.RemoveEmptyEntries); if (entries.Length < 4) { continue; } string path = ""; int type = Symbol.TYPE_STATIC; string secName = "unknown"; // Extract the module path, we also take into account paths with spaces in between entries[3] = entries[3].TrimEnd(' '); // trim spaces from the end of function name if (UseDWARF) { // Extract module path from DARF info if (entries[2].ToLower() == "t") { // Subroutines path = DwarfParser.Instance.FindSubRoutineCUnit(entries[3], Convert.ToUInt32(entries[0], 16)); } else if (entries[2].ToLower() == "w") // Weak symbols could be either vars or subroutines { Debug.WriteLineIf(DEBUG, "Found a weak symbol " + entries[3]); path = DwarfParser.Instance.FindSubRoutineCUnit(entries[3], Convert.ToUInt32(entries[0], 16)); if (path != String.Empty) { Debug.WriteLineIf(DEBUG, "Is a subroutine " + path); } else { path = DwarfParser.Instance.FindSymbolCUnit(entries[3], Convert.ToUInt32(entries[0], 16) & (~RAM_ADDRESS_MASK)); if (path != String.Empty) { Debug.WriteLineIf(DEBUG, "Is a variable " + path); // FIXME: for now just assume all weak variable syms are in BSS entries[2] = "b"; } } } else { // variables path = DwarfParser.Instance.FindSymbolCUnit(entries[3], Convert.ToUInt32(entries[0], 16) & (~RAM_ADDRESS_MASK)); } } else { if (entries.Length > 4) { int end = line.IndexOf(':'); int j = 0; for (int i = 0; i < line.Length; i++) { // Find the index of 4th space if (line[i] == ' ' || line[i] == '\t') { j++; if (j == 4) { j = i + 1; break; } } } path = line.Substring(j, end - j); } } if (Regex.IsMatch(entries[2], @"[TDBGSR]")) { type = Symbol.TYPE_GLOBAL; } // Get the section if (entries[2].ToLower() == "t") { secName = SEC_NAME_TEXT; } if (entries[2].ToLower() == "d" || entries[2].ToLower() == "g" || entries[2].ToLower() == "r") { secName = SEC_NAME_DATA; } if (entries[2].ToLower() == "b" || entries[2].ToLower() == "s" || entries[2].ToLower() == "c") { secName = SEC_NAME_BSS; } Symbol sym = new Symbol(entries[3], path, Convert.ToUInt32(entries[0], 16), Convert.ToUInt32(entries[1], 16), secName); sym.GlobalScope = type; Symbols.Add(sym); } }