예제 #1
0
        private void OnGDBPaused(StopReply response)
        {
            this.CurrentBreakpoint = null;
            this.CurrentObjectFile = null;

            // Update Registers
            this.registers = this.connector.ReadRegisters();
            var regs       = this.registers.Keys.ToArray();
            var trues      = regs.Select((_) => true).ToArray();
            this.Registers = new RegisterSet(regs, trues, new bool[regs.Length]);

            // Fire event
            if (this.RefreshRegisters != null)
            {
                // Do a batch update of all regs
                this.RefreshRegisters(this, new RegistersChangedEventArgs(
                    this.registers.Keys.Select((reg) => reg.Name).ToArray()));
            }

            // Update current address
            foreach (var pair in this.registers)
            {
                if (pair.Key.Type == RegisterType.InstructionPointer)
                {
                    this.CurrentAddress = Utils.LongFromBytes(pair.Value);
                    break;
                }
            }

            // Update breakpoint
            foreach (Breakpoint bp in this.breakpoints)
            {
                if (bp.Address == this.CurrentAddress)
                {
                    this.CurrentBreakpoint = bp; break;
                }
            }

            // Update object file
            foreach (ObjectCodeFile file in Application.Session.LoadedImages)
            {
                if (file.Sections[0].LoadMemoryAddress <= this.CurrentAddress &&
                    file.Sections[0].LoadMemoryAddress + file.Size > this.CurrentAddress)
                {
                    this.CurrentObjectFile = file; break;
                }
            }

            // If object file found, try and load current code unit
            if (this.CurrentObjectFile != null)
            {
                this.CurrentCodeUnit = this.CurrentObjectFile.GetCode(this.CurrentAddress);
            }

            // Fire stepped event
            if (this.Suspended != null) this.Suspended(this, null);

            // Qemu gets stuck on the current line unless the breakpoint is disabled
            if (this.CurrentBreakpoint != null)
            {
                this.ClearBreakpoint(this.CurrentBreakpoint.Address);
            }
        }
예제 #2
0
        private void HandleStopReply(Message msg)
        {
            if (msg.Data[0] == 'O')
            {
                // It's actually just console output
                if (this.ConsoleOutput != null)
                {
                    // Use ThreadPool so that we don't interrupt the message loop thread
                    ThreadPool.QueueUserWorkItem((o) =>
                        this.ConsoleOutput(msg.Data.Remove(0, 1)));
                }
            }
            else if (msg.Data[0] == 'F')
            {
                return; // Ignore system call requests
            }
            else // We have an actual stop reply
            {
                StopReply reply = new StopReply(msg.Data);

                if (reply.Reason == StopReason.Trap || reply.Reason == StopReason.Watchpoint)
                {
                    if (this.Paused != null)
                    {
                        // Use ThreadPool so that we don't interrupt the message loop thread
                        ThreadPool.QueueUserWorkItem((o) => this.Paused(reply));
                    }
                }
                else if (reply.Reason == StopReason.Termination)
                {
                    if (this.Terminated != null)
                    {
                        // Use ThreadPool so that we don't interrupt the message loop thread
                        ThreadPool.QueueUserWorkItem((o) => this.Terminated());
                    }
                }
            }
        }