private List <StackInfo> GetStackInfo() { _stackFrames = DebugApi.GetCallstack(_cpuType); DebugState state = DebugApi.GetState(); switch (_cpuType) { case CpuType.Cpu: _programCounter = (uint)(state.Cpu.K << 16) | state.Cpu.PC; break; case CpuType.Sa1: _programCounter = (uint)(state.Sa1.Cpu.K << 16) | state.Sa1.Cpu.PC; break; case CpuType.Spc: _programCounter = (uint)state.Spc.PC; break; case CpuType.Gameboy: _programCounter = (uint)state.Gameboy.Cpu.PC; break; default: throw new Exception("Invalid cpu type"); } int relDestinationAddr = -1; List <StackInfo> stack = new List <StackInfo>(); for (int i = 0, len = _stackFrames.Length; i < len; i++) { int relSubEntryAddr = i == 0 ? -1 : (int)_stackFrames[i - 1].Target; stack.Add(new StackInfo() { SubName = this.GetFunctionName(relSubEntryAddr, i == 0 ? StackFrameFlags.None : _stackFrames[i - 1].Flags), Address = _stackFrames[i].Source, }); relDestinationAddr = (int)_stackFrames[i].Target; } //Add current location stack.Add(new StackInfo() { SubName = this.GetFunctionName(relDestinationAddr, _stackFrames.Length == 0 ? StackFrameFlags.None : _stackFrames[_stackFrames.Length - 1].Flags), Address = _programCounter, }); return(stack); }
private List <StackInfo> GetStackInfo(CpuType cpuType) { _stackFrames = DebugApi.GetCallstack(cpuType); DebugState state = DebugApi.GetState(); if (cpuType == CpuType.Cpu) { _programCounter = (uint)(state.Cpu.K << 16) | state.Cpu.PC; } else { _programCounter = (uint)state.Spc.PC; } int relDestinationAddr = -1; List <StackInfo> stack = new List <StackInfo>(); for (int i = 0, len = _stackFrames.Length; i < len; i++) { int relSubEntryAddr = i == 0 ? -1 : (int)_stackFrames[i - 1].Target; stack.Add(new StackInfo() { SubName = this.GetFunctionName(relSubEntryAddr, i == 0 ? StackFrameFlags.None : _stackFrames[i - 1].Flags), Address = _stackFrames[i].Source, }); relDestinationAddr = (int)_stackFrames[i].Target; } //Add current location stack.Add(new StackInfo() { SubName = this.GetFunctionName(relDestinationAddr, _stackFrames.Length == 0 ? StackFrameFlags.None : _stackFrames[_stackFrames.Length - 1].Flags), Address = _programCounter, }); return(stack); }