2019-05-04 09:33:28 -04:00
|
|
|
|
using Mesen.GUI.Debugger.Controls;
|
|
|
|
|
using Mesen.GUI.Debugger.Integration;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger.Code
|
|
|
|
|
{
|
2020-01-21 18:22:27 -05:00
|
|
|
|
public class SymbolCodeDataProvider : ICodeDataProvider
|
2019-05-04 09:33:28 -04:00
|
|
|
|
{
|
|
|
|
|
//private byte[] _prgRom;
|
|
|
|
|
private int _lineCount;
|
2020-01-21 18:22:27 -05:00
|
|
|
|
private SourceFileInfo _file;
|
2020-02-23 15:58:14 -05:00
|
|
|
|
private CpuType _cpuType;
|
2019-05-04 09:33:28 -04:00
|
|
|
|
private bool _isC;
|
2020-01-21 18:22:27 -05:00
|
|
|
|
private ISymbolProvider _symbolProvider;
|
2019-05-04 09:33:28 -04:00
|
|
|
|
|
2020-01-21 18:22:27 -05:00
|
|
|
|
public SymbolCodeDataProvider(CpuType type, ISymbolProvider symbolProvider, SourceFileInfo file)
|
2019-05-04 09:33:28 -04:00
|
|
|
|
{
|
|
|
|
|
//_prgRom = DebugApi.GetMemoryState(SnesMemoryType.PrgRom);
|
2020-02-23 15:58:14 -05:00
|
|
|
|
_cpuType = type;
|
2019-05-04 09:33:28 -04:00
|
|
|
|
_symbolProvider = symbolProvider;
|
|
|
|
|
_file = file;
|
|
|
|
|
_lineCount = file.Data.Length;
|
|
|
|
|
|
|
|
|
|
string filename = file.Name.ToLower();
|
|
|
|
|
_isC = filename.EndsWith(".h") || filename.EndsWith(".c");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CodeLineData GetCodeLineData(int lineIndex)
|
|
|
|
|
{
|
2020-02-22 19:33:40 -05:00
|
|
|
|
AddressInfo? address = _symbolProvider.GetLineAddress(_file, lineIndex);
|
2019-05-04 09:33:28 -04:00
|
|
|
|
|
2020-02-23 15:58:14 -05:00
|
|
|
|
CodeLineData data = new CodeLineData(_cpuType) {
|
2019-05-04 09:33:28 -04:00
|
|
|
|
Address = GetLineAddress(lineIndex),
|
2020-02-22 19:33:40 -05:00
|
|
|
|
AbsoluteAddress = address.HasValue ? address.Value.Address : -1,
|
2019-05-04 09:33:28 -04:00
|
|
|
|
EffectiveAddress = -1,
|
|
|
|
|
Flags = LineFlags.VerifiedCode
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
|
/*if(prgAddress >= 0) {
|
|
|
|
|
int opSize = DebugApi.GetDisassemblyOpSize(_prgRom[prgAddress]);
|
|
|
|
|
string byteCode = "";
|
|
|
|
|
for(int i = prgAddress, end = prgAddress + opSize; i < end && i < _prgRom.Length; i++) {
|
|
|
|
|
byteCode += "$" + _prgRom[i].ToString("X2") + " ";
|
|
|
|
|
}
|
|
|
|
|
data.ByteCode = byteCode;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
string text = _file.Data[lineIndex];
|
|
|
|
|
string trimmed = text.TrimStart();
|
|
|
|
|
data.CustomIndent = (text.Length - trimmed.Length) * 10;
|
|
|
|
|
|
|
|
|
|
int commentIndex;
|
|
|
|
|
if(_isC) {
|
|
|
|
|
commentIndex = trimmed.IndexOf("//");
|
|
|
|
|
} else {
|
|
|
|
|
commentIndex = trimmed.IndexOfAny(new char[] { ';', '.' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(commentIndex >= 0) {
|
|
|
|
|
data.Comment = trimmed.Substring(commentIndex);
|
|
|
|
|
data.Text = trimmed.Substring(0, commentIndex).TrimEnd();
|
|
|
|
|
} else {
|
2019-05-04 13:54:17 -04:00
|
|
|
|
data.Comment = "";
|
2019-05-04 09:33:28 -04:00
|
|
|
|
data.Text = trimmed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetLineAddress(int lineIndex)
|
|
|
|
|
{
|
2020-02-22 19:33:40 -05:00
|
|
|
|
AddressInfo? absAddress = _symbolProvider.GetLineAddress(_file, lineIndex);
|
|
|
|
|
if(absAddress != null) {
|
2020-02-23 15:58:14 -05:00
|
|
|
|
return DebugApi.GetRelativeAddress(absAddress.Value, _cpuType).Address;
|
2020-02-22 19:33:40 -05:00
|
|
|
|
} else {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2019-05-04 09:33:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetLineCount()
|
|
|
|
|
{
|
|
|
|
|
return _lineCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetLineIndex(uint cpuAddress)
|
|
|
|
|
{
|
2020-02-22 19:33:40 -05:00
|
|
|
|
AddressInfo absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)cpuAddress, Type = SnesMemoryType.CpuMemory });
|
2019-05-04 09:33:28 -04:00
|
|
|
|
for(int i = 0; i < _lineCount; i++) {
|
2020-02-22 19:33:40 -05:00
|
|
|
|
AddressInfo? lineAddr = _symbolProvider.GetLineAddress(_file, i);
|
|
|
|
|
if(lineAddr != null && lineAddr.Value.Address == absAddress.Address && lineAddr.Value.Type == absAddress.Type) {
|
2019-05-04 09:33:28 -04:00
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool UseOptimizedSearch { get { return false; } }
|
|
|
|
|
|
|
|
|
|
public int GetNextResult(string searchString, int startPosition, int endPosition, bool searchBackwards)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|