2 * Copyright 2015 LabWare
3 * Copyright 2014 Google, Inc.
4 * Copyright (c) 2002-2005 The Regents of The University of Michigan
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met: redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer;
11 * redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution;
14 * neither the name of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * Authors: Nathan Binkert
35 * Copyright (c) 1990, 1993 The Regents of the University of California
38 * This software was developed by the Computer Systems Engineering group
39 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
40 * contributed to Berkeley.
42 * All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Lawrence Berkeley Laboratories.
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. All advertising materials mentioning features or use of this software
56 * must display the following acknowledgement:
57 * This product includes software developed by the University of
58 * California, Berkeley and its contributors.
59 * 4. Neither the name of the University nor the names of its contributors
60 * may be used to endorse or promote products derived from this software
61 * without specific prior written permission.
63 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
64 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
67 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
75 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
79 * Copyright (c) 2001 The NetBSD Foundation, Inc.
80 * All rights reserved.
82 * This code is derived from software contributed to The NetBSD Foundation
85 * Redistribution and use in source and binary forms, with or without
86 * modification, are permitted provided that the following conditions
88 * 1. Redistributions of source code must retain the above copyright
89 * notice, this list of conditions and the following disclaimer.
90 * 2. Redistributions in binary form must reproduce the above copyright
91 * notice, this list of conditions and the following disclaimer in the
92 * documentation and/or other materials provided with the distribution.
93 * 3. All advertising materials mentioning features or use of this software
94 * must display the following acknowledgement:
95 * This product includes software developed by the NetBSD
96 * Foundation, Inc. and its contributors.
97 * 4. Neither the name of The NetBSD Foundation nor the names of its
98 * contributors may be used to endorse or promote products derived
99 * from this software without specific prior written permission.
101 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
102 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
103 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
104 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
105 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
106 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
107 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
108 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
109 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
110 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
111 * POSSIBILITY OF SUCH DAMAGE.
115 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
119 * "Stub" to allow remote cpu to debug over a serial line using gdb.
122 #include "base/remote_gdb.hh"
124 #include <sys/signal.h>
131 #include "arch/vtophys.hh"
132 #include "base/intmath.hh"
133 #include "base/socket.hh"
134 #include "base/trace.hh"
135 #include "config/the_isa.hh"
136 #include "cpu/base.hh"
137 #include "cpu/static_inst.hh"
138 #include "cpu/thread_context.hh"
139 #include "debug/GDBAll.hh"
140 #include "mem/fs_translating_port_proxy.hh"
141 #include "mem/port.hh"
142 #include "mem/se_translating_port_proxy.hh"
143 #include "sim/full_system.hh"
144 #include "sim/system.hh"
147 using namespace TheISA
;
150 vector
<BaseRemoteGDB
*> debuggers
;
155 static int current_debugger
= -1;
156 if (current_debugger
>= 0 && current_debugger
< (int)debuggers
.size()) {
157 BaseRemoteGDB
*gdb
= debuggers
[current_debugger
];
158 if (!gdb
->isattached())
159 gdb
->listener
->accept();
160 if (gdb
->isattached())
166 ///////////////////////////////////////////////////////////
171 GDBListener::InputEvent::InputEvent(GDBListener
*l
, int fd
, int e
)
172 : PollEvent(fd
, e
), listener(l
)
176 GDBListener::InputEvent::process(int revent
)
181 GDBListener::GDBListener(BaseRemoteGDB
*g
, int p
)
182 : inputEvent(NULL
), gdb(g
), port(p
)
184 assert(!gdb
->listener
);
185 gdb
->listener
= this;
188 GDBListener::~GDBListener()
197 return gdb
->name() + ".listener";
201 GDBListener::listen()
203 if (ListenSocket::allDisabled()) {
204 warn_once("Sockets disabled, not accepting gdb connections");
208 while (!listener
.listen(port
, true)) {
209 DPRINTF(GDBMisc
, "Can't bind port %d\n", port
);
213 inputEvent
= new InputEvent(this, listener
.getfd(), POLLIN
);
214 pollQueue
.schedule(inputEvent
);
217 gdb
->number
= debuggers
.size();
218 debuggers
.push_back(gdb
);
222 ccprintf(cerr
, "%d: %s: listening for remote gdb #%d on port %d\n",
223 curTick(), name(), gdb
->number
, port
);
225 ccprintf(cerr
, "%d: %s: listening for remote gdb on port %d\n",
226 curTick(), name(), port
);
231 GDBListener::accept()
233 if (!listener
.islistening())
234 panic("GDBListener::accept(): cannot accept if we're not listening!");
236 int sfd
= listener
.accept(true);
239 if (gdb
->isattached())
246 BaseRemoteGDB::InputEvent::InputEvent(BaseRemoteGDB
*g
, int fd
, int e
)
247 : PollEvent(fd
, e
), gdb(g
)
251 BaseRemoteGDB::InputEvent::process(int revent
)
253 if (gdb
->trapEvent
.scheduled()) {
254 warn("GDB trap event has already been scheduled! "
255 "Ignoring this input event.");
259 if (revent
& POLLIN
) {
260 gdb
->trapEvent
.type(SIGILL
);
261 gdb
->scheduleInstCommitEvent(&gdb
->trapEvent
, 0);
262 } else if (revent
& POLLNVAL
) {
263 gdb
->descheduleInstCommitEvent(&gdb
->trapEvent
);
269 BaseRemoteGDB::TrapEvent::process()
275 BaseRemoteGDB::SingleStepEvent::process()
277 if (!gdb
->singleStepEvent
.scheduled())
278 gdb
->scheduleInstCommitEvent(&gdb
->singleStepEvent
, 1);
282 BaseRemoteGDB::BaseRemoteGDB(System
*_system
, ThreadContext
*c
) :
283 inputEvent(NULL
), trapEvent(this), listener(NULL
),
284 number(-1), fd(-1), active(false), attached(false), system(_system
),
285 context(c
), singleStepEvent(this)
289 BaseRemoteGDB::~BaseRemoteGDB()
296 BaseRemoteGDB::name()
298 return system
->name() + ".remote_gdb";
302 BaseRemoteGDB::isattached()
306 BaseRemoteGDB::attach(int f
)
310 inputEvent
= new InputEvent(this, fd
, POLLIN
);
311 pollQueue
.schedule(inputEvent
);
314 DPRINTFN("remote gdb attached\n");
318 BaseRemoteGDB::detach()
324 pollQueue
.remove(inputEvent
);
325 DPRINTFN("remote gdb detached\n");
329 BaseRemoteGDB::gdb_command(char cmd
)
332 case GDBSignal
: return "KGDB_SIGNAL";
333 case GDBSetBaud
: return "KGDB_SET_BAUD";
334 case GDBSetBreak
: return "KGDB_SET_BREAK";
335 case GDBCont
: return "KGDB_CONT";
336 case GDBAsyncCont
: return "KGDB_ASYNC_CONT";
337 case GDBDebug
: return "KGDB_DEBUG";
338 case GDBDetach
: return "KGDB_DETACH";
339 case GDBRegR
: return "KGDB_REG_R";
340 case GDBRegW
: return "KGDB_REG_W";
341 case GDBSetThread
: return "KGDB_SET_THREAD";
342 case GDBCycleStep
: return "KGDB_CYCLE_STEP";
343 case GDBSigCycleStep
: return "KGDB_SIG_CYCLE_STEP";
344 case GDBKill
: return "KGDB_KILL";
345 case GDBMemW
: return "KGDB_MEM_W";
346 case GDBMemR
: return "KGDB_MEM_R";
347 case GDBSetReg
: return "KGDB_SET_REG";
348 case GDBReadReg
: return "KGDB_READ_REG";
349 case GDBQueryVar
: return "KGDB_QUERY_VAR";
350 case GDBSetVar
: return "KGDB_SET_VAR";
351 case GDBReset
: return "KGDB_RESET";
352 case GDBStep
: return "KGDB_STEP";
353 case GDBAsyncStep
: return "KGDB_ASYNC_STEP";
354 case GDBThreadAlive
: return "KGDB_THREAD_ALIVE";
355 case GDBTargetExit
: return "KGDB_TARGET_EXIT";
356 case GDBBinaryDload
: return "KGDB_BINARY_DLOAD";
357 case GDBClrHwBkpt
: return "KGDB_CLR_HW_BKPT";
358 case GDBSetHwBkpt
: return "KGDB_SET_HW_BKPT";
359 case GDBStart
: return "KGDB_START";
360 case GDBEnd
: return "KGDB_END";
361 case GDBGoodP
: return "KGDB_GOODP";
362 case GDBBadP
: return "KGDB_BADP";
363 default: return "KGDB_UNKNOWN";
367 /////////////////////////
372 BaseRemoteGDB::getbyte()
375 if (::read(fd
, &b
, 1) != 1)
376 warn("could not read byte from debugger");
381 BaseRemoteGDB::putbyte(uint8_t b
)
383 if (::write(fd
, &b
, 1) != 1)
384 warn("could not write byte to debugger");
387 // Send a packet to gdb
389 BaseRemoteGDB::send(const char *bp
)
394 DPRINTF(GDBSend
, "send: %s\n", bp
);
398 //Start sending a packet
400 //Send the contents, and also keep a check sum.
401 for (csum
= 0; (c
= *p
); p
++) {
405 //Send the ending character.
408 putbyte(i2digit(csum
>> 4));
409 putbyte(i2digit(csum
));
410 //Try transmitting over and over again until the other end doesn't send an
412 } while ((c
= getbyte() & 0x7f) == GDBBadP
);
415 // Receive a packet from gdb
417 BaseRemoteGDB::recv(char *bp
, int maxlen
)
426 //Find the beginning of a packet
427 while ((c
= getbyte()) != GDBStart
)
430 //Read until you find the end of the data in the packet, and keep
431 //track of the check sum.
432 while ((c
= getbyte()) != GDBEnd
&& len
< maxlen
) {
439 //Mask the check sum, and terminate the command string.
443 //If the command was too long, report an error.
449 //Bring in the checksum. If the check sum matches, csum will be 0.
450 csum
-= digit2i(getbyte()) * 16;
451 csum
-= digit2i(getbyte());
453 //If the check sum was correct
455 //Report that the packet was received correctly
462 memcpy(bp
, bp
+3, len
);
466 //Otherwise, report that there was a mistake.
470 DPRINTF(GDBRecv
, "recv: %s: %s\n", gdb_command(*bp
), bp
);
475 // Read bytes from kernel address space for debugger.
477 BaseRemoteGDB::read(Addr vaddr
, size_t size
, char *data
)
479 static Addr lastaddr
= 0;
480 static size_t lastsize
= 0;
483 DPRINTF(GDBRead
, "read: reading memory location zero!\n");
484 vaddr
= lastaddr
+ lastsize
;
487 DPRINTF(GDBRead
, "read: addr=%#x, size=%d", vaddr
, size
);
490 FSTranslatingPortProxy
&proxy
= context
->getVirtProxy();
491 proxy
.readBlob(vaddr
, (uint8_t*)data
, size
);
493 SETranslatingPortProxy
&proxy
= context
->getMemProxy();
494 proxy
.readBlob(vaddr
, (uint8_t*)data
, size
);
498 if (DTRACE(GDBRead
)) {
499 if (DTRACE(GDBExtra
)) {
501 mem2hex(buf
, data
, size
);
502 DPRINTFNR(": %s\n", buf
);
511 // Write bytes to kernel address space for debugger.
513 BaseRemoteGDB::write(Addr vaddr
, size_t size
, const char *data
)
515 static Addr lastaddr
= 0;
516 static size_t lastsize
= 0;
519 DPRINTF(GDBWrite
, "write: writing memory location zero!\n");
520 vaddr
= lastaddr
+ lastsize
;
523 if (DTRACE(GDBWrite
)) {
524 DPRINTFN("write: addr=%#x, size=%d", vaddr
, size
);
525 if (DTRACE(GDBExtra
)) {
527 mem2hex(buf
, data
, size
);
528 DPRINTFNR(": %s\n", buf
);
533 FSTranslatingPortProxy
&proxy
= context
->getVirtProxy();
534 proxy
.writeBlob(vaddr
, (uint8_t*)data
, size
);
536 SETranslatingPortProxy
&proxy
= context
->getMemProxy();
537 proxy
.writeBlob(vaddr
, (uint8_t*)data
, size
);
544 BaseRemoteGDB::clearSingleStep()
546 descheduleInstCommitEvent(&singleStepEvent
);
550 BaseRemoteGDB::setSingleStep()
552 if (!singleStepEvent
.scheduled())
553 scheduleInstCommitEvent(&singleStepEvent
, 1);
556 PCEventQueue
*BaseRemoteGDB::getPcEventQueue()
558 return &system
->pcEventQueue
;
562 BaseRemoteGDB::getComInstEventQueue()
564 BaseCPU
*cpu
= context
->getCpuPtr();
565 return cpu
->comInstEventQueue
[context
->threadId()];
569 BaseRemoteGDB::scheduleInstCommitEvent(Event
*ev
, int delta
)
571 EventQueue
*eq
= getComInstEventQueue();
572 // Here "ticks" aren't simulator ticks which measure time, they're
573 // instructions committed by the CPU.
574 eq
->schedule(ev
, eq
->getCurTick() + delta
);
578 BaseRemoteGDB::descheduleInstCommitEvent(Event
*ev
)
581 getComInstEventQueue()->deschedule(ev
);
585 BaseRemoteGDB::checkBpLen(size_t len
)
587 return len
== sizeof(MachInst
);
590 BaseRemoteGDB::HardBreakpoint::HardBreakpoint(BaseRemoteGDB
*_gdb
, Addr pc
)
591 : PCEvent(_gdb
->getPcEventQueue(), "HardBreakpoint Event", pc
),
592 gdb(_gdb
), refcount(0)
594 DPRINTF(GDBMisc
, "creating hardware breakpoint at %#x\n", evpc
);
598 BaseRemoteGDB::HardBreakpoint::process(ThreadContext
*tc
)
600 DPRINTF(GDBMisc
, "handling hardware breakpoint at %#x\n", pc());
602 if (tc
== gdb
->context
)
607 BaseRemoteGDB::insertSoftBreak(Addr addr
, size_t len
)
609 if (!checkBpLen(len
))
610 panic("invalid length\n");
612 return insertHardBreak(addr
, len
);
616 BaseRemoteGDB::removeSoftBreak(Addr addr
, size_t len
)
618 if (!checkBpLen(len
))
619 panic("invalid length\n");
621 return removeHardBreak(addr
, len
);
625 BaseRemoteGDB::insertHardBreak(Addr addr
, size_t len
)
627 if (!checkBpLen(len
))
628 panic("invalid length\n");
630 DPRINTF(GDBMisc
, "inserting hardware breakpoint at %#x\n", addr
);
632 HardBreakpoint
*&bkpt
= hardBreakMap
[addr
];
634 bkpt
= new HardBreakpoint(this, addr
);
642 BaseRemoteGDB::removeHardBreak(Addr addr
, size_t len
)
644 if (!checkBpLen(len
))
645 panic("invalid length\n");
647 DPRINTF(GDBMisc
, "removing hardware breakpoint at %#x\n", addr
);
649 break_iter_t i
= hardBreakMap
.find(addr
);
650 if (i
== hardBreakMap
.end())
653 HardBreakpoint
*hbp
= (*i
).second
;
654 if (--hbp
->refcount
== 0) {
656 hardBreakMap
.erase(i
);
663 BaseRemoteGDB::setTempBreakpoint(Addr bkpt
)
665 DPRINTF(GDBMisc
, "setTempBreakpoint: addr=%#x\n", bkpt
);
666 insertHardBreak(bkpt
, sizeof(TheISA::MachInst
));
670 BaseRemoteGDB::clearTempBreakpoint(Addr
&bkpt
)
672 DPRINTF(GDBMisc
, "setTempBreakpoint: addr=%#x\n", bkpt
);
673 removeHardBreak(bkpt
, sizeof(TheISA::MachInst
));
678 BaseRemoteGDB::break_type(char c
)
681 case '0': return "software breakpoint";
682 case '1': return "hardware breakpoint";
683 case '2': return "write watchpoint";
684 case '3': return "read watchpoint";
685 case '4': return "access watchpoint";
686 default: return "unknown breakpoint/watchpoint";
690 // This function does all command processing for interfacing to a
691 // remote gdb. Note that the error codes are ignored by gdb at
692 // present, but might eventually become meaningful. (XXX) It might
693 // makes sense to use POSIX errno values, because that is what the
694 // gdb/remote.c functions want to return.
696 BaseRemoteGDB::trap(int type
)
700 char data
[GDBPacketBufLen
+ 1];
704 char command
, subcmd
;
711 unique_ptr
<BaseRemoteGDB::BaseGdbRegCache
> regCache(gdbRegs());
713 bufferSize
= regCache
->size() * 2 + 256;
714 buffer
= (char*)malloc(bufferSize
);
716 DPRINTF(GDBMisc
, "trap: PC=%s\n", context
->pcState());
721 * The first entry to this function is normally through
722 * a breakpoint trap in kgdb_connect(), in which case we
723 * must advance past the breakpoint because gdb will not.
725 * On the first entry here, we expect that gdb is not yet
726 * listening to us, so just enter the interaction loop.
727 * After the debugger is "active" (connected) it will be
728 * waiting for a "signaled" message from us.
733 // Tell remote host that an exception has occurred.
734 snprintf(buffer
, bufferSize
, "S%02x", type
);
738 // Stick frame regs into our reg cache.
739 regCache
->getRegs(context
);
742 datalen
= recv(data
, sizeof(data
));
743 data
[sizeof(data
) - 1] = 0; // Sentinel
750 // if this command came from a running gdb, answer it --
751 // the other guy has no way of knowing if we're in or out
752 // of this loop when he issues a "remote-signal".
753 snprintf(buffer
, bufferSize
,
759 if (2 * regCache
->size() > bufferSize
)
760 panic("buffer too small");
762 mem2hex(buffer
, regCache
->data(), regCache
->size());
767 p
= hex2mem(regCache
->data(), p
, regCache
->size());
768 if (p
== NULL
|| *p
!= '\0')
771 regCache
->setRegs(context
);
787 if (len
> bufferSize
) {
791 if (!acc(val
, len
)) {
796 if (read(val
, (size_t)len
, buffer
)) {
797 // variable length array would be nice, but C++ doesn't
798 // officially support those...
799 char *temp
= new char[2*len
+1];
800 mem2hex(temp
, buffer
, len
);
819 if (len
> datalen
- (p
- data
)) {
823 p
= hex2mem(buffer
, p
, bufferSize
);
828 if (!acc(val
, len
)) {
832 if (write(val
, (size_t)len
, buffer
))
858 context
->pcState(val
);
864 if (p
- data
< (ptrdiff_t)datalen
) {
866 context
->pcState(val
);
875 context
->pcState(val
);
881 if (p
- data
< (ptrdiff_t)datalen
) {
883 context
->pcState(val
);
890 if (*p
++ != ',') send("E0D");
892 if (*p
++ != ',') send("E0D");
895 DPRINTF(GDBMisc
, "clear %s, addr=%#x, len=%d\n",
896 break_type(subcmd
), val
, len
);
901 case '0': // software breakpoint
902 ret
= removeSoftBreak(val
, len
);
905 case '1': // hardware breakpoint
906 ret
= removeHardBreak(val
, len
);
909 case '2': // write watchpoint
910 case '3': // read watchpoint
911 case '4': // access watchpoint
917 send(ret
? "OK" : "E0C");
922 if (*p
++ != ',') send("E0D");
924 if (*p
++ != ',') send("E0D");
927 DPRINTF(GDBMisc
, "set %s, addr=%#x, len=%d\n",
928 break_type(subcmd
), val
, len
);
933 case '0': // software breakpoint
934 ret
= insertSoftBreak(val
, len
);
937 case '1': // hardware breakpoint
938 ret
= insertHardBreak(val
, len
);
941 case '2': // write watchpoint
942 case '3': // read watchpoint
943 case '4': // access watchpoint
949 send(ret
? "OK" : "E0C");
953 var
= string(p
, datalen
- 1);
964 case GDBSigCycleStep
:
971 // Unsupported command
972 DPRINTF(GDBMisc
, "Unsupported command: %s\n",
973 gdb_command(command
));
974 DDUMP(GDBMisc
, (uint8_t *)data
, datalen
);
980 DPRINTF(GDBMisc
, "Unknown command: %c(%#x)\n",
994 // Convert a hex digit into an integer.
995 // This returns -1 if the argument passed is no valid hex digit.
997 BaseRemoteGDB::digit2i(char c
)
999 if (c
>= '0' && c
<= '9')
1001 else if (c
>= 'a' && c
<= 'f')
1002 return (c
- 'a' + 10);
1003 else if (c
>= 'A' && c
<= 'F')
1005 return (c
- 'A' + 10);
1010 // Convert the low 4 bits of an integer into an hex digit.
1012 BaseRemoteGDB::i2digit(int n
)
1014 return ("0123456789abcdef"[n
& 0x0f]);
1017 // Convert a byte array into an hex string.
1019 BaseRemoteGDB::mem2hex(char *vdst
, const char *vsrc
, int len
)
1022 const char *src
= vsrc
;
1025 *dst
++ = i2digit(*src
>> 4);
1026 *dst
++ = i2digit(*src
++);
1031 // Convert an hex string into a byte array.
1032 // This returns a pointer to the character following the last valid
1033 // hex digit. If the string ends in the middle of a byte, NULL is
1036 BaseRemoteGDB::hex2mem(char *vdst
, const char *src
, int maxlen
)
1041 while (*src
&& maxlen
--) {
1042 msb
= digit2i(*src
++);
1045 lsb
= digit2i(*src
++);
1048 *dst
++ = (msb
<< 4) | lsb
;
1053 // Convert an hex string into an integer.
1054 // This returns a pointer to the character following the last valid
1057 BaseRemoteGDB::hex2i(const char **srcp
)
1059 const char *src
= *srcp
;
1063 while ((nibble
= digit2i(*src
)) >= 0) {