2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * Copyright (c) 1990, 1993
31 * The Regents of the University of California. All rights reserved.
33 * This software was developed by the Computer Systems Engineering group
34 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
35 * contributed to Berkeley.
37 * All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by the University of
40 * California, Lawrence Berkeley Laboratories.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgement:
52 * This product includes software developed by the University of
53 * California, Berkeley and its contributors.
54 * 4. Neither the name of the University nor the names of its contributors
55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission.
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
74 * Copyright (c) 2001 The NetBSD Foundation, Inc.
75 * All rights reserved.
77 * This code is derived from software contributed to The NetBSD Foundation
80 * Redistribution and use in source and binary forms, with or without
81 * modification, are permitted provided that the following conditions
83 * 1. Redistributions of source code must retain the above copyright
84 * notice, this list of conditions and the following disclaimer.
85 * 2. Redistributions in binary form must reproduce the above copyright
86 * notice, this list of conditions and the following disclaimer in the
87 * documentation and/or other materials provided with the distribution.
88 * 3. All advertising materials mentioning features or use of this software
89 * must display the following acknowledgement:
90 * This product includes software developed by the NetBSD
91 * Foundation, Inc. and its contributors.
92 * 4. Neither the name of The NetBSD Foundation nor the names of its
93 * contributors may be used to endorse or promote products derived
94 * from this software without specific prior written permission.
96 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
97 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
98 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
99 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
100 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
101 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
102 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
103 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
104 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
105 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
106 * POSSIBILITY OF SUCH DAMAGE.
110 * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
114 * "Stub" to allow remote cpu to debug over a serial line using gdb.
117 #include <sys/signal.h>
123 #include "base/intmath.hh"
124 #include "base/kgdb.h"
125 #include "base/remote_gdb.hh"
126 #include "base/socket.hh"
127 #include "base/trace.hh"
128 #include "cpu/exec_context.hh"
129 #include "cpu/static_inst.hh"
130 #include "mem/functional/physical.hh"
131 #include "sim/system.hh"
132 #include "targetarch/vtophys.hh"
137 RemoteGDB
*theDebugger
= NULL
;
143 theDebugger
->trap(ALPHA_KENTRY_IF
);
147 ///////////////////////////////////////////////////////////
152 GDBListener::Event::Event(GDBListener
*l
, int fd
, int e
)
153 : PollEvent(fd
, e
), listener(l
)
157 GDBListener::Event::process(int revent
)
162 GDBListener::GDBListener(RemoteGDB
*g
, int p
)
163 : event(NULL
), gdb(g
), port(p
)
166 GDBListener::~GDBListener()
175 return gdb
->name() + ".listener";
179 GDBListener::listen()
181 while (!listener
.listen(port
, true)) {
182 DPRINTF(GDBMisc
, "Can't bind port %d\n", port
);
186 cerr
<< "Listening for remote gdb connection on port " << port
<< endl
;
187 event
= new Event(this, listener
.getfd(), POLLIN
);
188 pollQueue
.schedule(event
);
192 GDBListener::accept()
194 if (!listener
.islistening())
195 panic("GDBListener::accept(): cannot accept if we're not listening!");
197 int sfd
= listener
.accept(true);
200 if (gdb
->isattached())
207 ///////////////////////////////////////////////////////////
213 void mem2hex(void *, const void *, int);
214 const char *hex2mem(void *, const char *, int);
215 Addr
hex2i(const char **);
217 RemoteGDB::Event::Event(RemoteGDB
*g
, int fd
, int e
)
218 : PollEvent(fd
, e
), gdb(g
)
222 RemoteGDB::Event::process(int revent
)
225 gdb
->trap(ALPHA_KENTRY_IF
);
226 else if (revent
& POLLNVAL
)
230 RemoteGDB::RemoteGDB(System
*_system
, ExecContext
*c
)
231 : event(NULL
), fd(-1), active(false), attached(false),
232 system(_system
), pmem(_system
->physmem
), context(c
)
234 memset(gdbregs
, 0, sizeof(gdbregs
));
237 RemoteGDB::~RemoteGDB()
246 return system
->name() + ".remote_gdb";
250 RemoteGDB::isattached()
254 RemoteGDB::attach(int f
)
258 event
= new Event(this, fd
, POLLIN
);
259 pollQueue
.schedule(event
);
262 DPRINTFN("remote gdb attached\n");
275 pollQueue
.remove(event
);
276 DPRINTFN("remote gdb detached\n");
280 gdb_command(char cmd
)
283 case KGDB_SIGNAL
: return "KGDB_SIGNAL";
284 case KGDB_SET_BAUD
: return "KGDB_SET_BAUD";
285 case KGDB_SET_BREAK
: return "KGDB_SET_BREAK";
286 case KGDB_CONT
: return "KGDB_CONT";
287 case KGDB_ASYNC_CONT
: return "KGDB_ASYNC_CONT";
288 case KGDB_DEBUG
: return "KGDB_DEBUG";
289 case KGDB_DETACH
: return "KGDB_DETACH";
290 case KGDB_REG_R
: return "KGDB_REG_R";
291 case KGDB_REG_W
: return "KGDB_REG_W";
292 case KGDB_SET_THREAD
: return "KGDB_SET_THREAD";
293 case KGDB_CYCLE_STEP
: return "KGDB_CYCLE_STEP";
294 case KGDB_SIG_CYCLE_STEP
: return "KGDB_SIG_CYCLE_STEP";
295 case KGDB_KILL
: return "KGDB_KILL";
296 case KGDB_MEM_W
: return "KGDB_MEM_W";
297 case KGDB_MEM_R
: return "KGDB_MEM_R";
298 case KGDB_SET_REG
: return "KGDB_SET_REG";
299 case KGDB_READ_REG
: return "KGDB_READ_REG";
300 case KGDB_QUERY_VAR
: return "KGDB_QUERY_VAR";
301 case KGDB_SET_VAR
: return "KGDB_SET_VAR";
302 case KGDB_RESET
: return "KGDB_RESET";
303 case KGDB_STEP
: return "KGDB_STEP";
304 case KGDB_ASYNC_STEP
: return "KGDB_ASYNC_STEP";
305 case KGDB_THREAD_ALIVE
: return "KGDB_THREAD_ALIVE";
306 case KGDB_TARGET_EXIT
: return "KGDB_TARGET_EXIT";
307 case KGDB_BINARY_DLOAD
: return "KGDB_BINARY_DLOAD";
308 case KGDB_CLR_HW_BKPT
: return "KGDB_CLR_HW_BKPT";
309 case KGDB_SET_HW_BKPT
: return "KGDB_SET_HW_BKPT";
310 case KGDB_START
: return "KGDB_START";
311 case KGDB_END
: return "KGDB_END";
312 case KGDB_GOODP
: return "KGDB_GOODP";
313 case KGDB_BADP
: return "KGDB_BADP";
314 default: return "KGDB_UNKNOWN";
318 ///////////////////////////////////////////////////////////
321 // Determine if the mapping at va..(va+len) is valid.
324 RemoteGDB::acc(Addr va
, size_t len
)
328 va
= TheISA::TruncPage(va
);
329 last_va
= TheISA::RoundPage(va
+ len
);
332 if (TheISA::IsK0Seg(va
)) {
333 if (va
< (TheISA::K0SegBase
+ pmem
->size())) {
334 DPRINTF(GDBAcc
, "acc: Mapping is valid K0SEG <= "
335 "%#x < K0SEG + size\n", va
);
338 DPRINTF(GDBAcc
, "acc: Mapping invalid %#x > K0SEG + size\n",
345 * This code says that all accesses to palcode (instruction and data)
346 * are valid since there isn't a va->pa mapping because palcode is
347 * accessed physically. At some point this should probably be cleaned up
348 * but there is no easy way to do it.
351 if (AlphaISA::PcPAL(va
) || va
< 0x10000)
354 Addr ptbr
= context
->regs
.ipr
[AlphaISA::IPR_PALtemp20
];
355 TheISA::PageTableEntry pte
= kernel_pte_lookup(pmem
, ptbr
, va
);
357 DPRINTF(GDBAcc
, "acc: %#x pte is invalid\n", va
);
360 va
+= TheISA::PageBytes
;
361 } while (va
< last_va
);
363 DPRINTF(GDBAcc
, "acc: %#x mapping is valid\n", va
);
367 ///////////////////////////////////////////////////////////
370 // Translate a trap number into a Unix-compatible signal number.
371 // (GDB only understands Unix signal numbers.)
374 RemoteGDB::signal(int type
)
377 case ALPHA_KENTRY_INT
:
380 case ALPHA_KENTRY_UNA
:
383 case ALPHA_KENTRY_ARITH
:
386 case ALPHA_KENTRY_IF
:
389 case ALPHA_KENTRY_MM
:
393 panic("unknown signal type");
398 ///////////////////////////////////////////////////////////
399 // RemoteGDB::getregs
401 // Translate the kernel debugger register format into
402 // the GDB register format.
406 memset(gdbregs
, 0, sizeof(gdbregs
));
407 memcpy(&gdbregs
[KGDB_REG_V0
], context
->regs
.intRegFile
, 32 * sizeof(uint64_t));
409 memcpy(&gdbregs
[KGDB_REG_F0
], context
->regs
.floatRegFile
.q
,
410 32 * sizeof(uint64_t));
412 gdbregs
[KGDB_REG_PC
] = context
->regs
.pc
;
415 ///////////////////////////////////////////////////////////
416 // RemoteGDB::setregs
418 // Translate the GDB register format into the kernel
419 // debugger register format.
424 memcpy(context
->regs
.intRegFile
, &gdbregs
[KGDB_REG_V0
],
425 32 * sizeof(uint64_t));
427 memcpy(context
->regs
.floatRegFile
.q
, &gdbregs
[KGDB_REG_F0
],
428 32 * sizeof(uint64_t));
430 context
->regs
.pc
= gdbregs
[KGDB_REG_PC
];
434 RemoteGDB::setTempBreakpoint(TempBreakpoint
&bkpt
, Addr addr
)
436 DPRINTF(GDBMisc
, "setTempBreakpoint: addr=%#x\n", addr
);
439 insertHardBreak(addr
, 4);
443 RemoteGDB::clearTempBreakpoint(TempBreakpoint
&bkpt
)
445 DPRINTF(GDBMisc
, "setTempBreakpoint: addr=%#x\n",
449 removeHardBreak(bkpt
.address
, 4);
454 RemoteGDB::clearSingleStep()
456 DPRINTF(GDBMisc
, "clearSingleStep bt_addr=%#x nt_addr=%#x\n",
457 takenBkpt
.address
, notTakenBkpt
.address
);
459 if (takenBkpt
.address
!= 0)
460 clearTempBreakpoint(takenBkpt
);
462 if (notTakenBkpt
.address
!= 0)
463 clearTempBreakpoint(notTakenBkpt
);
467 RemoteGDB::setSingleStep()
469 Addr pc
= context
->regs
.pc
;
473 npc
= pc
+ sizeof(MachInst
);
475 // User was stopped at pc, e.g. the instruction at pc was not
477 MachInst inst
= read
<MachInst
>(pc
);
478 StaticInstPtr
<TheISA
> si(inst
);
479 if (si
->hasBranchTarget(pc
, context
, bpc
)) {
480 // Don't bother setting a breakpoint on the taken branch if it
481 // is the same as the next pc
486 DPRINTF(GDBMisc
, "setSingleStep bt_addr=%#x nt_addr=%#x\n",
487 takenBkpt
.address
, notTakenBkpt
.address
);
489 setTempBreakpoint(notTakenBkpt
, npc
);
492 setTempBreakpoint(takenBkpt
, bpc
);
495 /////////////////////////
508 RemoteGDB::putbyte(uint8_t b
)
513 // Send a packet to gdb
515 RemoteGDB::send(const char *bp
)
520 DPRINTF(GDBSend
, "send: %s\n", bp
);
525 for (csum
= 0; (c
= *p
); p
++) {
530 putbyte(i2digit(csum
>> 4));
531 putbyte(i2digit(csum
));
532 } while ((c
= getbyte() & 0x7f) == KGDB_BADP
);
535 // Receive a packet from gdb
537 RemoteGDB::recv(char *bp
, int maxlen
)
546 while ((c
= getbyte()) != KGDB_START
)
549 while ((c
= getbyte()) != KGDB_END
&& len
< maxlen
) {
563 csum
-= digit2i(getbyte()) * 16;
564 csum
-= digit2i(getbyte());
573 bcopy(bp
+ 3, bp
, len
);
580 DPRINTF(GDBRecv
, "recv: %s: %s\n", gdb_command(*bp
), bp
);
585 // Read bytes from kernel address space for debugger.
587 RemoteGDB::read(Addr vaddr
, size_t size
, char *data
)
589 static Addr lastaddr
= 0;
590 static size_t lastsize
= 0;
595 DPRINTF(GDBRead
, "read: reading memory location zero!\n");
596 vaddr
= lastaddr
+ lastsize
;
599 DPRINTF(GDBRead
, "read: addr=%#x, size=%d", vaddr
, size
);
608 size_t count
= min((Addr
)size
,
609 VMPageSize
- (vaddr
& (VMPageSize
- 1)));
611 maddr
= vtomem(context
, vaddr
, count
);
612 memcpy(data
, maddr
, count
);
618 while (size
>= VMPageSize
) {
619 maddr
= vtomem(context
, vaddr
, count
);
620 memcpy(data
, maddr
, VMPageSize
);
628 maddr
= vtomem(context
, vaddr
, count
);
629 memcpy(data
, maddr
, size
);
633 if (DTRACE(GDBRead
)) {
634 if (DTRACE(GDBExtra
)) {
637 DPRINTFNR(": %s\n", buf
);
646 // Write bytes to kernel address space for debugger.
648 RemoteGDB::write(Addr vaddr
, size_t size
, const char *data
)
650 static Addr lastaddr
= 0;
651 static size_t lastsize
= 0;
656 DPRINTF(GDBWrite
, "write: writing memory location zero!\n");
657 vaddr
= lastaddr
+ lastsize
;
660 if (DTRACE(GDBWrite
)) {
661 DPRINTFN("write: addr=%#x, size=%d", vaddr
, size
);
662 if (DTRACE(GDBExtra
)) {
664 mem2hex(buf
, data
, size
);
665 DPRINTFNR(": %s\n", buf
);
673 size_t count
= min((Addr
)size
,
674 VMPageSize
- (vaddr
& (VMPageSize
- 1)));
676 maddr
= vtomem(context
, vaddr
, count
);
677 memcpy(maddr
, data
, count
);
683 while (size
>= VMPageSize
) {
684 maddr
= vtomem(context
, vaddr
, count
);
685 memcpy(maddr
, data
, VMPageSize
);
693 maddr
= vtomem(context
, vaddr
, count
);
694 memcpy(maddr
, data
, size
);
705 PCEventQueue
*RemoteGDB::getPcEventQueue()
707 return &system
->pcEventQueue
;
711 RemoteGDB::HardBreakpoint::HardBreakpoint(RemoteGDB
*_gdb
, Addr pc
)
712 : PCEvent(_gdb
->getPcEventQueue(), "HardBreakpoint Event", pc
),
713 gdb(_gdb
), refcount(0)
715 DPRINTF(GDBMisc
, "creating hardware breakpoint at %#x\n", evpc
);
720 RemoteGDB::HardBreakpoint::process(ExecContext
*xc
)
722 DPRINTF(GDBMisc
, "handling hardware breakpoint at %#x\n", pc());
724 if (xc
== gdb
->context
)
725 gdb
->trap(ALPHA_KENTRY_INT
);
729 RemoteGDB::insertSoftBreak(Addr addr
, size_t len
)
731 if (len
!= sizeof(MachInst
))
732 panic("invalid length\n");
734 return insertHardBreak(addr
, len
);
738 RemoteGDB::removeSoftBreak(Addr addr
, size_t len
)
740 if (len
!= sizeof(MachInst
))
741 panic("invalid length\n");
743 return removeHardBreak(addr
, len
);
747 RemoteGDB::insertHardBreak(Addr addr
, size_t len
)
749 if (len
!= sizeof(MachInst
))
750 panic("invalid length\n");
752 DPRINTF(GDBMisc
, "inserting hardware breakpoint at %#x\n", addr
);
754 HardBreakpoint
*&bkpt
= hardBreakMap
[addr
];
756 bkpt
= new HardBreakpoint(this, addr
);
764 RemoteGDB::removeHardBreak(Addr addr
, size_t len
)
766 if (len
!= sizeof(MachInst
))
767 panic("invalid length\n");
769 DPRINTF(GDBMisc
, "removing hardware breakpoint at %#x\n", addr
);
771 break_iter_t i
= hardBreakMap
.find(addr
);
772 if (i
== hardBreakMap
.end())
775 HardBreakpoint
*hbp
= (*i
).second
;
776 if (--hbp
->refcount
== 0) {
778 hardBreakMap
.erase(i
);
788 case '0': return "software breakpoint";
789 case '1': return "hardware breakpoint";
790 case '2': return "write watchpoint";
791 case '3': return "read watchpoint";
792 case '4': return "access watchpoint";
793 default: return "unknown breakpoint/watchpoint";
797 // This function does all command processing for interfacing to a
798 // remote gdb. Note that the error codes are ignored by gdb at
799 // present, but might eventually become meaningful. (XXX) It might
800 // makes sense to use POSIX errno values, because that is what the
801 // gdb/remote.c functions want to return.
803 RemoteGDB::trap(int type
)
807 char data
[KGDB_BUFLEN
+ 1];
808 char buffer
[sizeof(gdbregs
) * 2 + 256];
809 char temp
[KGDB_BUFLEN
];
811 char command
, subcmd
;
818 DPRINTF(GDBMisc
, "trap: PC=%#x NPC=%#x\n",
819 context
->regs
.pc
, context
->regs
.npc
);
824 * The first entry to this function is normally through
825 * a breakpoint trap in kgdb_connect(), in which case we
826 * must advance past the breakpoint because gdb will not.
828 * On the first entry here, we expect that gdb is not yet
829 * listening to us, so just enter the interaction loop.
830 * After the debugger is "active" (connected) it will be
831 * waiting for a "signaled" message from us.
836 // Tell remote host that an exception has occurred.
837 snprintf((char *)buffer
, sizeof(buffer
), "S%02x", signal(type
));
840 // Stick frame regs into our reg cache.
844 datalen
= recv(data
, sizeof(data
));
845 data
[sizeof(data
) - 1] = 0; // Sentinel
852 // if this command came from a running gdb, answer it --
853 // the other guy has no way of knowing if we're in or out
854 // of this loop when he issues a "remote-signal".
855 snprintf((char *)buffer
, sizeof(buffer
), "S%02x", signal(type
));
860 if (2 * sizeof(gdbregs
) > sizeof(buffer
))
861 panic("buffer too small");
863 mem2hex(buffer
, gdbregs
, sizeof(gdbregs
));
868 p
= hex2mem(gdbregs
, p
, sizeof(gdbregs
));
869 if (p
== NULL
|| *p
!= '\0')
884 if (val
< 0 && val
>= KGDB_NUMREGS
) {
889 gdbregs
[val
] = hex2i(&p
);
907 if (len
> sizeof(buffer
)) {
911 if (!acc(val
, len
)) {
916 if (read(val
, (size_t)len
, (char *)buffer
)) {
917 mem2hex(temp
, buffer
, len
);
935 if (len
> datalen
- (p
- data
)) {
939 p
= hex2mem(buffer
, p
, sizeof(buffer
));
944 if (!acc(val
, len
)) {
948 if (write(val
, (size_t)len
, (char *)buffer
))
954 case KGDB_SET_THREAD
:
970 case KGDB_ASYNC_CONT
:
974 context
->regs
.pc
= val
;
975 context
->regs
.npc
= val
+ sizeof(MachInst
);
981 if (p
- data
< datalen
) {
983 context
->regs
.pc
= val
;
984 context
->regs
.npc
= val
+ sizeof(MachInst
);
989 case KGDB_ASYNC_STEP
:
993 context
->regs
.pc
= val
;
994 context
->regs
.npc
= val
+ sizeof(MachInst
);
1000 if (p
- data
< datalen
) {
1002 context
->regs
.pc
= val
;
1003 context
->regs
.npc
= val
+ sizeof(MachInst
);
1008 case KGDB_CLR_HW_BKPT
:
1010 if (*p
++ != ',') send("E0D");
1012 if (*p
++ != ',') send("E0D");
1015 DPRINTF(GDBMisc
, "clear %s, addr=%#x, len=%d\n",
1016 break_type(subcmd
), val
, len
);
1021 case '0': // software breakpoint
1022 ret
= removeSoftBreak(val
, len
);
1025 case '1': // hardware breakpoint
1026 ret
= removeHardBreak(val
, len
);
1029 case '2': // write watchpoint
1030 case '3': // read watchpoint
1031 case '4': // access watchpoint
1037 send(ret
? "OK" : "E0C");
1040 case KGDB_SET_HW_BKPT
:
1042 if (*p
++ != ',') send("E0D");
1044 if (*p
++ != ',') send("E0D");
1047 DPRINTF(GDBMisc
, "set %s, addr=%#x, len=%d\n",
1048 break_type(subcmd
), val
, len
);
1053 case '0': // software breakpoint
1054 ret
= insertSoftBreak(val
, len
);
1057 case '1': // hardware breakpoint
1058 ret
= insertHardBreak(val
, len
);
1061 case '2': // write watchpoint
1062 case '3': // read watchpoint
1063 case '4': // access watchpoint
1069 send(ret
? "OK" : "E0C");
1072 case KGDB_QUERY_VAR
:
1073 var
= string(p
, datalen
- 1);
1081 case KGDB_SET_BREAK
:
1083 case KGDB_CYCLE_STEP
:
1084 case KGDB_SIG_CYCLE_STEP
:
1088 case KGDB_THREAD_ALIVE
:
1089 case KGDB_TARGET_EXIT
:
1090 case KGDB_BINARY_DLOAD
:
1091 // Unsupported command
1092 DPRINTF(GDBMisc
, "Unsupported command: %s\n",
1093 gdb_command(command
));
1094 DDUMP(GDBMisc
, (uint8_t *)data
, datalen
);
1100 DPRINTF(GDBMisc
, "Unknown command: %c(%#x)\n",
1113 // Convert a hex digit into an integer.
1114 // This returns -1 if the argument passed is no valid hex digit.
1118 if (c
>= '0' && c
<= '9')
1120 else if (c
>= 'a' && c
<= 'f')
1121 return (c
- 'a' + 10);
1122 else if (c
>= 'A' && c
<= 'F')
1124 return (c
- 'A' + 10);
1129 // Convert the low 4 bits of an integer into an hex digit.
1133 return ("0123456789abcdef"[n
& 0x0f]);
1136 // Convert a byte array into an hex string.
1138 mem2hex(void *vdst
, const void *vsrc
, int len
)
1140 char *dst
= (char *)vdst
;
1141 const char *src
= (const char *)vsrc
;
1144 *dst
++ = i2digit(*src
>> 4);
1145 *dst
++ = i2digit(*src
++);
1150 // Convert an hex string into a byte array.
1151 // This returns a pointer to the character following the last valid
1152 // hex digit. If the string ends in the middle of a byte, NULL is
1155 hex2mem(void *vdst
, const char *src
, int maxlen
)
1157 char *dst
= (char *)vdst
;
1160 while (*src
&& maxlen
--) {
1161 msb
= digit2i(*src
++);
1164 lsb
= digit2i(*src
++);
1167 *dst
++ = (msb
<< 4) | lsb
;
1172 // Convert an hex string into an integer.
1173 // This returns a pointer to the character following the last valid
1176 hex2i(const char **srcp
)
1178 const char *src
= *srcp
;
1182 while ((nibble
= digit2i(*src
)) >= 0) {