Skip to content

Commit

Permalink
Debugger: Source View - Improve active line highlight logic for C files
Browse files Browse the repository at this point in the history
Highlight the C line of code if any of the CPU instructions contained inside of it is the current CPU instruction
  • Loading branch information
SourMesen committed Dec 7, 2024
1 parent 962a144 commit 47c1231
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
15 changes: 12 additions & 3 deletions UI/Debugger/Disassembly/SourceViewStyleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@ public SourceViewStyleProvider(CpuType cpuType, SourceViewViewModel model) : bas

public override bool IsLineActive(CodeLineData line, int lineIndex)
{
lineIndex += _model.ScrollPosition;

if(_model.ActiveAddress.HasValue && !line.IsAddressHidden) {
if(_model.ActiveAddress.Value == line.Address) {
return true;
} else if(line.AbsoluteAddress.Address > 0) {
AddressInfo relActiveAddr = new AddressInfo() { Address = _model.ActiveAddress.Value, Type = _model.CpuType.ToMemoryType() };
AddressInfo absAddr = DebugApi.GetAbsoluteAddress(relActiveAddr);
if(line.AbsoluteAddress.Address == absAddr.Address && line.AbsoluteAddress.Type == absAddr.Type) {
//Relative address doesn't match but the absolute address does - different mirror, mark it as active
return true;
if(absAddr.Address > 0) {
if(line.AbsoluteAddress.Address == absAddr.Address && line.AbsoluteAddress.Type == absAddr.Type) {
//Relative address doesn't match but the absolute address does - different mirror, mark it as active
return true;
} else if(_model.SymbolProvider.GetSourceCodeLineInfo(absAddr)?.LineNumber == lineIndex) {
//Current line number is associated with this address, mark it as active
//This allows C code mappings to display as "active" for each CPU instruction
//that's part of a single line of C code
return true;
}
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions UI/Debugger/Integration/PceasSymbolImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,23 +328,31 @@ public void Import(string path, bool showResult)

AddressInfo absAddr = GetLabelAddress(bank, addr);
if(absAddr.Address >= 0) {
long lengthFlags = long.Parse(m.Groups[3].Value, System.Globalization.NumberStyles.HexNumber);
int length = (int)(lengthFlags & ~0xC0000000);

if(absAddr.Type == MemoryType.PcePrgRom) {
//Build CDL data based on the extra flags present in the mappings
long lengthFlags = long.Parse(m.Groups[3].Value, System.Globalization.NumberStyles.HexNumber);
if((lengthFlags & 0x40000000) != 0) {
cdlData[absAddr.Address] |= (byte)CdlFlags.SubEntryPoint;
}

byte cdlFlags = (lengthFlags & 0x80000000) != 0 ? (byte)CdlFlags.Code : (byte)CdlFlags.Data;
for(long j = 0, len = (lengthFlags & ~0xC0000000); j < len; j++) {
for(long j = 0; j < length; j++) {
if(absAddr.Address + j < cdlData.Length) {
cdlData[absAddr.Address + j] |= cdlFlags;
} else {
break;
}
}
}

_addressByLine[_sourceFiles[fileId].Name + "_" + lineNumber.ToString()] = absAddr;
_linesByAddress[absAddr.Type.ToString() + absAddr.Address.ToString()] = new SourceCodeLocation(_sourceFiles[fileId], lineNumber);
SourceCodeLocation loc = new SourceCodeLocation(_sourceFiles[fileId], lineNumber);
for(int j = 0; j < length; j++) {
//Map this line of code to every address it represents
_linesByAddress[absAddr.Type.ToString() + (absAddr.Address + j).ToString()] = loc;
}
}
}
} else {
Expand Down

0 comments on commit 47c1231

Please sign in to comment.