/
ExtractMapFromElfFile.cs
98 lines (76 loc) · 2.67 KB
/
ExtractMapFromElfFile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using IL2CPU.Debug.Symbols;
using static Cosmos.Build.Tasks.OperatingSystem;
namespace Cosmos.Build.Tasks
{
public class ExtractMapFromElfFile : ToolTask
{
[Required]
public string InputFile { get; set; }
[Required]
public string MapFile { get; set; }
[Required]
public string DebugInfoFile { get; set; }
[Required]
public string ActualToolPath { get; set; }
protected override string ToolName => IsWindows() ? "objdump.bat" : "sh";
protected override MessageImportance StandardErrorLoggingImportance => MessageImportance.High;
protected override MessageImportance StandardOutputLoggingImportance => MessageImportance.High;
protected override bool ValidateParameters()
{
if (!File.Exists(InputFile))
{
Log.LogError(nameof(InputFile) + " doesn't exist!");
}
return !Log.HasLoggedErrors;
}
protected override string GenerateFullPathToTool()
{
if (String.IsNullOrWhiteSpace(ToolExe))
{
return null;
}
if (String.IsNullOrWhiteSpace(ToolPath))
{
return Path.Combine(Directory.GetCurrentDirectory(), ToolExe);
}
return Path.Combine(Path.GetFullPath(ToolPath), ToolExe);
}
protected override string GenerateCommandLineCommands()
{
var xBuilder = new CommandLineBuilder();
string xPathToTool = Path.GetDirectoryName(GenerateFullPathToTool());
if (!IsWindows())
{
xBuilder.AppendFileNameIfNotNull(ActualToolPath + "/objdump.sh");
}
xBuilder.AppendFileNameIfNotNull(xPathToTool);
xBuilder.AppendFileNameIfNotNull(InputFile);
xBuilder.AppendFileNameIfNotNull(MapFile);
return xBuilder.ToString();
}
public override bool Execute()
{
Log.LogMessage(MessageImportance.High, "Extracting Map file...");
var xSW = Stopwatch.StartNew();
try
{
if (!base.Execute())
{
return false;
}
ObjDump.ExtractMapSymbolsForElfFile(DebugInfoFile, MapFile);
return true;
}
finally
{
xSW.Stop();
Log.LogMessage(MessageImportance.High, "Extracting Map file took {0}", xSW.Elapsed);
}
}
}
}