Skip to content

Commit

Permalink
Better support for standalone map files. Don't use timer for progress…
Browse files Browse the repository at this point in the history
… indication
  • Loading branch information
govind-mukundan committed Dec 14, 2017
1 parent c98c2cc commit a61ee97
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 47 deletions.
15 changes: 14 additions & 1 deletion MapParser/MapParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ public Symbol(string sym, string file, UInt64 la, UInt32 siz, string section)
Match m2 = Regex.Match(file, @"[^\/\\(]+(\.o|\.c)$");
FileName = m2.ToString();
}

public void GetFileFromModuleName(string mod)
{
// Special for newlib, module name turns out to be of the form ..lib/libc.a(lib_a-rget.o), while dwarf file name = rget.c, so we takeout all "lib_a" prefix
if (mod.Contains("lib_a-"))
mod = mod.Replace("lib_a-", String.Empty);

Match m2 = Regex.Match(mod, @"[^\/\\(]+(\.o|\.c)$");
FileName = m2.ToString();
}
}

public class Module
Expand Down Expand Up @@ -147,7 +157,7 @@ public static MAPParser Instance
get { return _instance; }
}

public bool Run(string filePath)
public bool Run(string filePath, Action prog_ind)
{
Sections = new List<Section>();
AllSections = new string[C_TEXT_ID.Length + C_DATA_ID.Length + C_BSS_ID.Length];
Expand Down Expand Up @@ -194,6 +204,8 @@ public bool Run(string filePath)
bool valid_section = false;
foreach (string line in Map.GetRange(MMap_index, MMap_end - MMap_index))
{
prog_ind?.Invoke();

Section s; bool valid;

if (line == "") // A blank line indicates a break in the section
Expand Down Expand Up @@ -240,6 +252,7 @@ public bool Run(string filePath)
//if (sym.SymbolName.Contains("*fill*"))
// Debug.Write("oops");
sym.ModuleName = mod.ModuleName;
sym.GetFileFromModuleName(mod.ModuleName);
uint siz = 0;
// update the size of the previous symbol, given that we know the address of the current symbol
if (mod.Symbols != null && mod.Symbols.Count > 0)
Expand Down
18 changes: 4 additions & 14 deletions MapParser/SymParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ public static SymParser Instance
{
get { return _instance; }
}
MapViewer MapViewerObj = null;
public void Run(string nmPath, string elfPath, MapViewer ownerForm)

public void Run(string nmPath, string elfPath, Action prog_ind)
{
this.MapViewerObj = ownerForm;
string result = "";
Symbols = new List<Symbol>();
if (nmPath == "" || elfPath == "" || !File.Exists(nmPath) || !File.Exists(elfPath)) return;
Expand All @@ -75,17 +74,8 @@ public void Run(string nmPath, string elfPath, MapViewer ownerForm)
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;
//}
{
prog_ind?.Invoke();

// Split using spaces - note that the module path may itself contain spaces
string[] entries = line.Split(new char[0], 4, StringSplitOptions.RemoveEmptyEntries);
Expand Down
66 changes: 34 additions & 32 deletions MapParser/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,25 @@ private void btn_Analyze_Click(object sender, EventArgs e)
});
}

bool _flip;
int _flip;
public void Progress_indication()
{
string text = "";
if (_flip == 0)
{
text = "Analyze" + " +";
_flip = 1;
_timer.Start();
}

else if (_flip == 1)
{
text = "Analyze" + " -";
_flip = 0;
_timer.Start();
}
Button_status_text(text);
}
public void Button_status(bool val)
{
if (InvokeRequired)
Expand All @@ -259,33 +277,7 @@ public void Button_status(bool val)
else
{
this.btn_Analyze.Enabled = val;
if (!val)
{
// Use a timer to have a single update for more than one "text changed" event, better UX
_timer.Stop(); // Stop an existing timer
_timer.AutoReset = true; // restart
_timer.Enabled = true;
_timer.Interval = 50;
_timer.Elapsed += (object s, ElapsedEventArgs e1) =>
{
if (_flip)
{
Button_status_text("Analyze" + " +");
_flip = false;
}
else
{
Button_status_text("Analyze" + " -");
_flip = true;
}
};
_timer.Start();
}
else
{
Button_status_text("Analyze");
_timer.Stop();
}
if (val) Button_status_text("Analyze");
}
}

Expand Down Expand Up @@ -379,7 +371,7 @@ void AnalyzeSymbols()
{
_UIUpdateInProgress = true;
// Parse the MAP file alone
if (!MAPParser.Instance.Run(txtBx_MapFilepath.Text)) return;
if (!MAPParser.Instance.Run(txtBx_MapFilepath.Text, Progress_indication)) return;
// Update the ListView for Modules
AddSumRow(MAPParser.Instance.ModuleMap);
PopulateModuleLV(MAPParser.Instance.ModuleMap);
Expand All @@ -402,7 +394,7 @@ void AnalyzeSymbols()
DwarfParser.Instance.Run(BINUTIL_READ_ELF, txtBx_ElfFilepath.Text);
// Extract the symbols using NM
_syms = SymParser.Instance;
_syms.Run(BINUTIL_NM, txtBx_ElfFilepath.Text, this);
_syms.Run(BINUTIL_NM, txtBx_ElfFilepath.Text, Progress_indication);

// Update symbols present in MAP but missing in NM output
// FIXME: The size of these "hidden" symbols may not be accurate as of now..
Expand Down Expand Up @@ -505,6 +497,7 @@ private void olv_ModuleView_SelectionChanged(object sender, EventArgs e)
if (_syms == null || _UIUpdateInProgress) return;

Button_status(false);
_flip = 0;
var list = olv_ModuleView.SelectedObjects.Cast<Module>().ToList();

// Move the processing into the non-UI context
Expand Down Expand Up @@ -628,13 +621,15 @@ List<Symbol> FilterSymbols(List<Module> mods)
// Go through all the symbols and select those that match the currently selected modules
List<Symbol> syms = mods.SelectMany(m => _syms.Symbols.Where(s =>
{
Progress_indication(); // Update UI

string mod = m.ModuleName;
// Special for newlib, module name turns out to be of the form ..lib/libc.a(lib_a-rget.o), while dwarf file name = rget.c, so we takeout all "lib_a" prefix
if (m.ModuleName.Contains("lib_a-"))
mod = mod.Replace("lib_a-", String.Empty);

Match m2 = Regex.Match(mod, @"[^\/\\(]+(?=.o\)?$)");
Match m1 = Regex.Match(s.ModuleName, @"[^\/\\(]+(?=.c\)?$)");
Match m1 = Regex.Match(s.ModuleName, @"[^\/\\(]+(?=.[co]\)?$)"); /* look for modules with .c (nm) and .o (standalone map files) */

if (m1.ToString() == m2.ToString() && ((filtGlobal == false) || (Symbol.TYPE_GLOBAL == s.GlobalScope)))
{
Expand Down Expand Up @@ -668,7 +663,12 @@ private List<CrefNode> tlv_Init(string root_node_module)
/* Verify that the we have at least some entries that match our root */
//string root_node_module = "impure.o";
CrefEntry cr = cref.CrefTable.Where(x => x.SouceModule.Contains(root_node_module)).ToList().FirstOrDefault();
if (cr == null) return null;
if (cr == null)
{
Debug.WriteLineIf(DEBUG, "Nothing to build " + root_node_module);
return null;

}

var cref_tree = new List<CrefNode>();
cref_tree.Add(new CrefNode(root_node_module));
Expand All @@ -684,6 +684,8 @@ void Build(CrefNode n, int depth)
{
if (TotalNodeCnt++ > CREF_TOTAL_ELEMENT_COUNT) return;

Progress_indication(); // Update UI

depth--;
if ((depth == 0))
{
Expand Down

0 comments on commit a61ee97

Please sign in to comment.