void ParseRegisters(Registers pRegisters, string pString)
        {
            var matches = _regexRegisters.Matches(pString);

            foreach (Match match in matches)
            {
                try
                {
                    pRegisters[match.Groups["register"].Value] = Convert.Parse(match.Groups["value"].Value, isHex: true);
                }
                catch
                {
                    // ignore
                }
            }

            matches = _regexFlags.Matches(pString);
            foreach (Match match in matches)
            {
                // match.Groups["register"].Value
                // match.Groups["s"].Value
                // match.Groups["z"].Value
                // match.Groups["bit5"].Value
                // match.Groups["h"].Value
                // match.Groups["bit3"].Value
                // match.Groups["n"].Value
                // match.Groups["c"].Value
            }
        }
        public override int ReadMemory(ushort address, byte[] bytes, int start = 0, int length = 0)
        {
            if (length == 0)
            {
                length = bytes.Length - start;
            }

            var memory = SendAndReceiveSingle("read-memory " + address + " " + length);

            for (var i = 0; i < length; i++)
            {
                bytes[i + start] = (byte)((Convert.FromHex(memory[i * 2]) << 4) | Convert.FromHex(memory[i * 2 + 1]));
            }

            return(length);
        }
Exemple #3
0
        void HandleMessage(string msg, dynamic args, Request request)
        {
            LogDebug("(in)  " + request.type + " " + msg);
            LogVerbose("... " + JsonConvert.SerializeObject(request));

            args = args ?? new { };

            try
            {
                switch (msg)
                {
                case "initialize":
                    var cap = new Capabilities();
                    InitializeEvent?.Invoke(request, cap);
                    Send(request, cap);
                    Initialized();
                    break;

                case "configurationDone":
                    ConfigurationDoneEvent?.Invoke(request);
                    break;

                case "launch":
                    LaunchEvent?.Invoke(request, JsonConvert.SerializeObject(args));
                    break;

                case "attach":
                    AttachEvent?.Invoke(request, JsonConvert.SerializeObject(args));
                    break;

                case "disconnect":
                    DisconnectEvent?.Invoke(request);
                    break;

                case "next":
                    StepOverEvent?.Invoke(request);
                    break;

                case "continue":
                    ContinueEvent?.Invoke(request);
                    break;

                case "stepIn":
                    StepInEvent?.Invoke(request);
                    break;

                case "stepOut":
                    StepOutEvent?.Invoke(request);
                    break;

                case "pause":
                    PauseEvent?.Invoke(request);
                    break;

                case "threads":
                    GetThreadsEvent?.Invoke(request);
                    break;

                case "scopes":
                    GetScopesEvent?.Invoke(request, (int)args.frameId);
                    break;

                case "stackTrace":
                    GetStackTraceEvent?.Invoke(request);
                    break;

                case "variables":
                    _tempVariables.Clear();
                    GetVariablesEvent?.Invoke(request, (int)args.variablesReference, _tempVariables);
                    Send(request, new VariablesResponseBody(_tempVariables));
                    break;

                case "setVariable":

                    var variable = new Variable((string)args.name, (string)args.value, "", (int)args.variablesReference);

                    SetVariableEvent?.Invoke(
                        request, variable
                        );

                    Send(
                        request,
                        new SetVariableResponseBody(variable.value, variable.variablesReference)
                        );

                    break;

                case "loadedSources":
                    GetLoadedSourcesEvent?.Invoke(request);
                    break;

                case "source":
                    GetSourceEvent?.Invoke(request);
                    break;

                case "evaluate":

                    string resultEval = "";
                    EvaluateEvent?.Invoke(
                        request, (int)args.frameId, (string)args.context, (string)args.expression, (bool)(args.format?.hex ?? false),
                        ref resultEval
                        );

                    Send(
                        request,
                        new EvaluateResponseBody(
                            resultEval
                            )
                        );

                    break;

                case "completions":
                    GetCompletionsEvent?.Invoke(
                        request, (int)args.frameId, (int)args.line, (int)args.column, (string )args.text
                        );
                    break;


                case "setBreakpoints":
                    SetBreakpointsEvent?.Invoke(request);
                    break;


//                    case "runInTerminal":
//                        OnRunInTerminal?.Invoke( pRequest );
//                        break;


//                    case "setFunctionBreakpoints":
//                        SetFunctionBreakpoints( pResponse, pArgs );
//                        break;

//                    case "setExceptionBreakpoints":
//                        SetExceptionBreakpoints( pResponse, pArgs );
//                        break;

                default:

                    CustomRequestEvent?.Invoke(request);

                    if (!request.responded)
                    {
                        Log(
                            Logging.Severity.Error,
                            string.Format("Request not handled: '{0}' [{1}]", msg, Convert.Encode(request.arguments.ToString()))
                            );
                    }

                    break;
                }
            }
            catch (Exception e)
            {
                Log(
                    Logging.Severity.Error,
                    $"Error during request '{Convert.Encode( request.arguments.ToString() )}' [{msg}] (exception: {e.Message})\n{e}"
                    );

                Send(new Response(request, errorMsg: e.Message));
            }
        }
        public override bool ReadMemoryConfiguration(Memory memory)
        {
            var currentPages       = SendAndReceiveSingle("get-memory-pages");
            var currentPagingState = SendAndReceiveSingle("get-paging-state");

            // don't get verbose page list if the simple page lists haven't changed
            if (_lastGetMemoryPages == currentPages && _lastGetPagingState == currentPagingState)
            {
                return(false);
            }

            _lastGetMemoryPages = currentPages;
            _lastGetPagingState = currentPagingState;

            memory.ClearConfiguration();
            memory.PagingEnabled = true;

            // now get the verbose page lists
            var lines = SendAndReceive("get-memory-pages verbose", _tempMemoryConfig);

            int    count        = 0;
            string indexStr     = null;
            string typeStr      = null;
            string numberStr    = null;
            string shortnameStr = null;
            string startAddrStr = null;
            string endAddrStr   = null;

            foreach (var line in lines)
            {
                var match = _regexPages.Match(line);

                if (!match.Success)
                {
                    continue;
                }

                count += UpdateFromRegexGroup(match.Groups, "index", ref indexStr);
                count += UpdateFromRegexGroup(match.Groups, "type", ref typeStr);
                count += UpdateFromRegexGroup(match.Groups, "number", ref numberStr);
                count += UpdateFromRegexGroup(match.Groups, "shortname", ref shortnameStr);
                count += UpdateFromRegexGroup(match.Groups, "startaddr", ref startAddrStr);
                count += UpdateFromRegexGroup(match.Groups, "endaddr", ref endAddrStr);

                if (count != 6)
                {
                    continue;
                }

                if (typeStr == "System")
                {
                    typeStr   = numberStr;
                    numberStr = "0";
                }

                var number    = int.Parse(numberStr);
                var startAddr = Convert.Parse(startAddrStr);
                var endAddr   = Convert.Parse(endAddrStr);
                var length    = (ushort)(endAddr - startAddr + 1);

                var bankID = new BankID(typeStr, number, BankID.PartEnum.All);
                memory.SetAddressBank(startAddr, length, memory.Bank(bankID));

                indexStr = typeStr = numberStr = shortnameStr = startAddrStr = endAddrStr = null;
                count    = 0;
            }

            return(true);
        }
        void WriteDisasmLines(TextWriter stream, DisasmBank bank, ushort bankOffset, ref int line)
        {
            if (bank.ID.Type != BankID.TypeEnum.All)
            {
                line++;

                var memBank = Memory.Bank(bank.ID);

                if (memBank.IsPagedIn)
                {
                    stream.WriteLine("  {0}:", memBank.ID);
                }
                else
                {
                    stream.WriteLine("  {0} ({1}):", memBank.ID, memBank.PagedAddress.ToHex());
                }
            }

            var prev = bank.SortedLines[0].Offset;

            foreach (var disasmLine in bank.SortedLines)
            {
                var doneBlank = false;

                if (disasmLine.Offset - prev > 1)
                {
                    line++;
                    stream.WriteLine();
                    doneBlank = true;
                }

                prev = (ushort)(disasmLine.Offset + disasmLine.Instruction.Length);

                var labelledItem = GetLabels(bank.ID, (ushort)(disasmLine.Offset + bankOffset));

                if (labelledItem != null)
                {
                    var doneComment = false;

                    foreach (var label in labelledItem.Labels)
                    {
                        _tempLabel.Append(' ', 4);
                        _tempLabel.Append(label.Name);
                        _tempLabel.Append(':');

                        if (!doneComment)
                        {
                            if (!string.IsNullOrWhiteSpace(label.Comment))
                            {
                                // line up comment with start of mnemonics at col 21
                                _tempLabel.Append(' ', Math.Max(20 - _tempLabel.Length, 0));
                                _tempLabel.Append(';');
                            }

                            if (!string.IsNullOrWhiteSpace(label.Comment))
                            {
                                _tempLabel.Append(' ');
                                _tempLabel.Append(label.Comment);
                            }

                            doneComment = true;
                        }

                        if (_tempLabel.Length > 0)
                        {
                            if (!doneBlank && Disassembler.Settings.BlankLineBeforeLabel)
                            {
                                line++;
                                stream.WriteLine();
                                doneBlank = true;
                            }

                            line++;
                            stream.WriteLine(_tempLabel.ToString());

                            _tempLabel.Clear();
                        }
                    }
                }

                stream.WriteLine("      {0:X4} {1,-8} {2}",
                                 disasmLine.Offset + bankOffset,
                                 Convert.ToHex(disasmLine.Instruction.Bytes),
                                 FormatInstruction(disasmLine, bank.ID, bankOffset)
                                 );

                disasmLine.FileLine = line;

                _linesToDisasm[line++] = disasmLine;
            }
        }