Beispiel #1
0
            protected ulong ReadRegister(int index)
            {
                if (gdbStub.Running)
                {
                    throw new NotSupportedException("Cannot read register while running");
                }

                string command  = "g";
                string response = gdbStub.Query(command);

                response = response.Substring(index * 8, 8);

                //string command = string.Format("p{0:x}", index);
                //string response = gdbStub.Query(command);

                byte[] buffer = new byte[response.Length / 2];
                for (int i = 0; i < buffer.Length; i++)
                {
                    buffer[i] = Convert.ToByte(response.Substring(i * 2, 2), 16);
                }

                switch (buffer.Length)
                {
                case 8: return(BitConverter.ToUInt64(buffer, 0));

                case 4: return(BitConverter.ToUInt32(buffer, 0));

                case 2: return(BitConverter.ToUInt16(buffer, 0));
                }

                throw new Exception("Could not find register size");
            }
Beispiel #2
0
            public int Read(ulong address, byte[] buffer, int offset, int count)
            {
                if (gdbStub.Running)
                {
                    throw new Exception("Cannot read memory while running");
                }

                string command  = string.Format("m{0:x},{1:x}", address, count);
                string response = gdbStub.Query(command);

                for (int i = 0; i < response.Length / 2; i++)
                {
                    buffer[offset + i] = Convert.ToByte(response.Substring(i * 2, 2), 16);
                }

                return(response.Length / 2);
            }
Beispiel #3
0
            public void Add(GdbBreakpoint breakpoint)
            {
                string command, response = null;

                breakpoints.Add(breakpoint);

                switch (breakpoint.Type)
                {
                case GdbBreakpointType.Memory:
                    command  = string.Format("Z0,{0:x},{1:x}", breakpoint.Address, breakpoint.Kind);
                    response = gdbStub.Query(command);
                    break;

                case GdbBreakpointType.Hardware:
                    command  = string.Format("Z1,{0:x},{1:x}", breakpoint.Address, breakpoint.Kind);
                    response = gdbStub.Query(command);
                    break;

                case GdbBreakpointType.Write:
                    command  = string.Format("Z2,{0:x},{1:x}", breakpoint.Address, breakpoint.Kind);
                    response = gdbStub.Query(command);
                    break;

                case GdbBreakpointType.Read:
                    command  = string.Format("Z3,{0:x},{1:x}", breakpoint.Address, breakpoint.Kind);
                    response = gdbStub.Query(command);
                    break;

                case GdbBreakpointType.Access:
                    command  = string.Format("Z4,{0:x},{1:x}", breakpoint.Address, breakpoint.Kind);
                    response = gdbStub.Query(command);
                    break;
                }

                if (response != "OK")
                {
                    throw new Exception("Could not add specified breakpoint");
                }
            }