Mercurial > repos > blastem
annotate gdb_remote.c @ 735:539d12fa6a4d
Add a define in both the source and Makefile for enabling logging of z80 instruction address/cycle counts. Fix Z80 in/out instructions to eliminate assumptions about which registers are stored in native regs. Fix read_16 to not corrupt the low byte when the read has to call into a C function.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 25 May 2015 18:56:22 -0700 |
parents | 9324f721efa6 |
children | 483f7e7926a6 6811f601008f |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
456
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
456
diff
changeset
|
2 Copyright 2013 Michael Pavone |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
3 This file is part of BlastEm. |
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
456
diff
changeset
|
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
456
diff
changeset
|
5 */ |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
6 #include "gdb_remote.h" |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
7 #include "68kinst.h" |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
8 #include "debug.h" |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include <unistd.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include <fcntl.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #include <stddef.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 #include <stdlib.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #include <stdio.h> |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
14 #include <string.h> |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
16 #define INITIAL_BUFFER_SIZE (16*1024) |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
18 #ifdef DO_DEBUG_PRINT |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
19 #define dfprintf fprintf |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
20 #else |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
21 #define dfprintf |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
22 #endif |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
23 |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 char * buf = NULL; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 char * curbuf = NULL; |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
26 char * end = NULL; |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 size_t bufsize; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 int cont = 0; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 int expect_break_response=0; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 uint32_t resume_pc; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
32 |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
33 static uint16_t branch_t; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
34 static uint16_t branch_f; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
35 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
36 static bp_def * breakpoints = NULL; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
37 static uint32_t bp_index = 0; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
38 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
39 |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
40 void hex_32(uint32_t num, char * out) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
41 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
42 for (int32_t shift = 28; shift >= 0; shift -= 4) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
43 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
44 uint8_t nibble = num >> shift & 0xF; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
45 *(out++) = nibble > 9 ? nibble - 0xA + 'A' : nibble + '0'; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
46 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
47 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
48 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
49 void hex_16(uint16_t num, char * out) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
50 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
51 for (int16_t shift = 14; shift >= 0; shift -= 4) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
52 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
53 uint8_t nibble = num >> shift & 0xF; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
54 *(out++) = nibble > 9 ? nibble - 0xA + 'A' : nibble + '0'; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
55 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
56 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
57 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
58 void hex_8(uint8_t num, char * out) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
59 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
60 uint8_t nibble = num >> 4; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
61 *(out++) = nibble > 9 ? nibble - 0xA + 'A' : nibble + '0'; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
62 nibble = num & 0xF; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
63 *out = nibble > 9 ? nibble - 0xA + 'A' : nibble + '0'; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
64 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
65 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
66 void gdb_calc_checksum(char * command, char *out) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
67 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
68 uint8_t checksum = 0; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
69 while (*command) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
70 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
71 checksum += *(command++); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
72 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
73 hex_8(checksum, out); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
74 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
75 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
76 void write_or_die(int fd, const void *buf, size_t count) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
77 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
78 if (write(fd, buf, count) < count) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
79 fputs("Error writing to stdout\n", stderr); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
80 exit(1); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
81 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
82 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
83 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
84 void gdb_send_command(char * command) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
85 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
86 char end[3]; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
87 write_or_die(STDOUT_FILENO, "$", 1); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
88 write_or_die(STDOUT_FILENO, command, strlen(command)); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
89 end[0] = '#'; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
90 gdb_calc_checksum(command, end+1); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
91 write_or_die(STDOUT_FILENO, end, 3); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
92 dfprintf(stderr, "Sent $%s#%c%c\n", command, end[1], end[2]); |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
93 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
94 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
95 uint32_t calc_status(m68k_context * context) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
96 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
97 uint32_t status = context->status << 3; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
98 for (int i = 0; i < 5; i++) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
99 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
100 status <<= 1; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
101 status |= context->flags[i]; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
102 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
103 return status; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
104 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
105 |
526
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
106 void update_status(m68k_context * context, uint16_t value) |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
107 { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
108 context->status = value >> 8; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
109 for (int i = 4; i >= 0; i--) |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
110 { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
111 context->flags[i] = value & 1; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
112 value >>= 1; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
113 } |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
114 } |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
115 |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
116 uint8_t read_byte(m68k_context * context, uint32_t address) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
117 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
118 uint16_t * word; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
119 //TODO: Use generated read/write functions so that memory map is properly respected |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
120 if (address < 0x400000) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
121 word = context->mem_pointers[0] + address/2; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
122 } else if (address >= 0xE00000) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
123 word = context->mem_pointers[1] + (address & 0xFFFF)/2; |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
124 } else if (address >= 0xA00000 && address < 0xA04000) { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
125 return z80_ram[address & 0x1FFF]; |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
126 } else { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
127 return 0; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
128 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
129 if (address & 1) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
130 return *word; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
131 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
132 return *word >> 8; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
133 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
134 |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
135 void write_byte(m68k_context * context, uint32_t address, uint8_t value) |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
136 { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
137 uint16_t * word; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
138 //TODO: Use generated read/write functions so that memory map is properly respected |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
139 if (address < 0x400000) { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
140 //TODO: Invalidate translated code |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
141 word = context->mem_pointers[0] + address/2; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
142 } else if (address >= 0xE00000) { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
143 m68k_handle_code_write(address & 0xFFFF, context); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
144 word = context->mem_pointers[1] + (address & 0xFFFF)/2; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
145 } else if (address >= 0xA00000 && address < 0xA04000) { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
146 z80_ram[address & 0x1FFF] = value; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
147 genesis_context * gen = context->system; |
565
9324f721efa6
Add a separate flag/define for disabling the Z80 at compile time to ease refactoring
Michael Pavone <pavone@retrodev.com>
parents:
548
diff
changeset
|
148 #ifndef NO_Z80 |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
149 z80_handle_code_write(address & 0x1FFF, gen->z80); |
548
a3afee2271ce
Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents:
530
diff
changeset
|
150 #endif |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
151 return; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
152 } else { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
153 return; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
154 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
155 if (address & 1) { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
156 *word = (*word & 0xFF00) | value; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
157 } else { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
158 *word = (*word & 0xFF) | value << 8; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
159 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
160 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
161 |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
162 void gdb_run_command(m68k_context * context, uint32_t pc, char * command) |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 { |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
164 char send_buf[512]; |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
165 dfprintf(stderr, "Received command %s\n", command); |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
166 switch(*command) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
167 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
168 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
169 case 'c': |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
170 if (*(command+1) != 0) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
171 //TODO: implement resuming at an arbitrary address |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
172 goto not_impl; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
173 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
174 cont = 1; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
175 expect_break_response = 1; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
176 break; |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
177 case 's': { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
178 if (*(command+1) != 0) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
179 //TODO: implement resuming at an arbitrary address |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
180 goto not_impl; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
181 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
182 m68kinst inst; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
183 uint16_t * pc_ptr; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
184 if (pc < 0x400000) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
185 pc_ptr = cart + pc/2; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
186 } else if(pc > 0xE00000) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
187 pc_ptr = ram + (pc & 0xFFFF)/2; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
188 } else { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
189 fprintf(stderr, "Entered gdb remote debugger stub at address %X\n", pc); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
190 exit(1); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
191 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
192 uint16_t * after_pc = m68k_decode(pc_ptr, &inst, pc & 0xFFFFFF); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
193 uint32_t after = pc + (after_pc-pc_ptr)*2; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
194 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
195 if (inst.op == M68K_RTS) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
196 after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
197 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
198 after = (read_dma_value((context->aregs[7]+2)/2) << 16) | read_dma_value((context->aregs[7]+2)/2 + 1); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
199 } else if(m68k_is_branch(&inst)) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
200 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
201 branch_f = after; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
202 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
203 insert_breakpoint(context, branch_t, (uint8_t *)gdb_debug_enter); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
204 } else if(inst.op == M68K_DBCC && inst.extra.cond != COND_FALSE) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
205 branch_t = after; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
206 branch_f = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
207 insert_breakpoint(context, branch_f, (uint8_t *)gdb_debug_enter); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
208 } else { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
209 after = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
210 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
211 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
212 insert_breakpoint(context, after, (uint8_t *)gdb_debug_enter); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
213 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
214 cont = 1; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
215 expect_break_response = 1; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
216 break; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
217 } |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
218 case 'H': |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
219 if (command[1] == 'g' || command[1] == 'c') {; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
220 //no thread suport, just acknowledge |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
221 gdb_send_command("OK"); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
222 } else { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
223 goto not_impl; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
224 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
225 break; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
226 case 'Z': { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
227 uint8_t type = command[1]; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
228 if (type < '2') { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
229 uint32_t address = strtoul(command+3, NULL, 16); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
230 insert_breakpoint(context, address, (uint8_t *)gdb_debug_enter); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
231 bp_def *new_bp = malloc(sizeof(bp_def)); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
232 new_bp->next = breakpoints; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
233 new_bp->address = address; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
234 new_bp->index = bp_index++; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
235 breakpoints = new_bp; |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
236 gdb_send_command("OK"); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
237 } else { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
238 //watchpoints are not currently supported |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
239 gdb_send_command(""); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
240 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
241 break; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
242 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
243 case 'z': { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
244 uint8_t type = command[1]; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
245 if (type < '2') { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
246 uint32_t address = strtoul(command+3, NULL, 16); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
247 remove_breakpoint(context, address); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
248 bp_def **found = find_breakpoint(&breakpoints, address); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
249 if (*found) |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
250 { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
251 bp_def * to_remove = *found; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
252 *found = to_remove->next; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
253 free(to_remove); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
254 } |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
255 gdb_send_command("OK"); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
256 } else { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
257 //watchpoints are not currently supported |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
258 gdb_send_command(""); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
259 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
260 break; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
261 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
262 case 'g': { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
263 char * cur = send_buf; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
264 for (int i = 0; i < 8; i++) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
265 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
266 hex_32(context->dregs[i], cur); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
267 cur += 8; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
268 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
269 for (int i = 0; i < 8; i++) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
270 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
271 hex_32(context->aregs[i], cur); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
272 cur += 8; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
273 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
274 hex_32(calc_status(context), cur); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
275 cur += 8; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
276 hex_32(pc, cur); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
277 cur += 8; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
278 *cur = 0; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
279 gdb_send_command(send_buf); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
280 break; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
281 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
282 case 'm': { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
283 char * rest; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
284 uint32_t address = strtoul(command+1, &rest, 16); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
285 uint32_t size = strtoul(rest+1, NULL, 16); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
286 if (size > sizeof(send_buf-1)/2) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
287 size = sizeof(send_buf-1)/2; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
288 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
289 char *cur = send_buf; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
290 while (size) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
291 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
292 hex_8(read_byte(context, address), cur); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
293 cur += 2; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
294 address++; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
295 size--; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
296 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
297 *cur = 0; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
298 gdb_send_command(send_buf); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
299 break; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
300 } |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
301 case 'M': { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
302 char * rest; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
303 uint32_t address = strtoul(command+1, &rest, 16); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
304 uint32_t size = strtoul(rest+1, &rest, 16); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
305 |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
306 char *cur = rest+1; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
307 while (size) |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
308 { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
309 char tmp[3]; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
310 tmp[0] = *(cur++); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
311 tmp[1] = *(cur++); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
312 tmp[2] = 0; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
313 write_byte(context, address, strtoul(tmp, NULL, 16)); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
314 address++; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
315 size--; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
316 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
317 gdb_send_command("OK"); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
318 break; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
319 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
320 case 'X': |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
321 //binary transfers aren't supported currently as I don't feel like dealing with the escaping |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
322 gdb_send_command(""); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
323 break; |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
324 case 'p': { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
325 unsigned long reg = strtoul(command+1, NULL, 16); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
326 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
327 if (reg < 8) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
328 hex_32(context->dregs[reg], send_buf); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
329 } else if (reg < 16) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
330 hex_32(context->aregs[reg-8], send_buf); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
331 } else if (reg == 16) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
332 hex_32(calc_status(context), send_buf); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
333 } else if (reg == 17) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
334 hex_32(pc, send_buf); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
335 } else { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
336 send_buf[0] = 0; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
337 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
338 send_buf[8] = 0; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
339 gdb_send_command(send_buf); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
340 break; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
341 } |
526
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
342 case 'P': { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
343 char *after = NULL; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
344 unsigned long reg = strtoul(command+1, &after, 16); |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
345 uint32_t value = strtoul(after+1, NULL, 16); |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
346 |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
347 if (reg < 8) { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
348 context->dregs[reg] = value; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
349 } else if (reg < 16) { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
350 context->aregs[reg-8] = value; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
351 } else if (reg == 16) { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
352 update_status(context, value); |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
353 } else { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
354 //supporting updates to PC is going to be a pain |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
355 gdb_send_command("E01"); |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
356 break; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
357 } |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
358 gdb_send_command("OK"); |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
359 break; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
360 } |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
361 case 'q': |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
362 if (!memcmp("Supported", command+1, strlen("Supported"))) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
363 sprintf(send_buf, "PacketSize=%X", (int)bufsize); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
364 gdb_send_command(send_buf); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
365 } else if (!memcmp("Attached", command+1, strlen("Supported"))) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
366 //not really meaningful for us, but saying we spawned a new process |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
367 //is probably closest to the truth |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
368 gdb_send_command("0"); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
369 } else if (!memcmp("Offsets", command+1, strlen("Offsets"))) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
370 //no relocations, so offsets are all 0 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
371 gdb_send_command("Text=0;Data=0;Bss=0"); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
372 } else if (!memcmp("Symbol", command+1, strlen("Symbol"))) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
373 gdb_send_command(""); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
374 } else if (!memcmp("TStatus", command+1, strlen("TStatus"))) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
375 //TODO: actual tracepoint support |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
376 gdb_send_command("T0;tnotrun:0"); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
377 } else if (!memcmp("TfV", command+1, strlen("TfV")) || !memcmp("TfP", command+1, strlen("TfP"))) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
378 //TODO: actual tracepoint support |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
379 gdb_send_command(""); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
380 } else if (command[1] == 'C') { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
381 //we only support a single thread currently, so send 1 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
382 gdb_send_command("1"); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
383 } else { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
384 goto not_impl; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
385 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
386 break; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
387 case 'v': |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
388 if (!memcmp("Cont?", command+1, strlen("Cont?"))) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
389 gdb_send_command("vCont;c;C;s;S"); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
390 } else if (!memcmp("Cont;", command+1, strlen("Cont;"))) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
391 switch (*(command + 1 + strlen("Cont;"))) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
392 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
393 case 'c': |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
394 case 'C': |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
395 //might be interesting to have continue with signal fire a |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
396 //trap exception or something, but for no we'll treat it as |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
397 //a normal continue |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
398 cont = 1; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
399 expect_break_response = 1; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
400 break; |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
401 case 's': |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
402 case 'S': { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
403 m68kinst inst; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
404 uint16_t * pc_ptr; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
405 if (pc < 0x400000) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
406 pc_ptr = cart + pc/2; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
407 } else if(pc > 0xE00000) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
408 pc_ptr = ram + (pc & 0xFFFF)/2; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
409 } else { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
410 fprintf(stderr, "Entered gdb remote debugger stub at address %X\n", pc); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
411 exit(1); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
412 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
413 uint16_t * after_pc = m68k_decode(pc_ptr, &inst, pc & 0xFFFFFF); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
414 uint32_t after = pc + (after_pc-pc_ptr)*2; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
415 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
416 if (inst.op == M68K_RTS) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
417 after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
418 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
419 after = (read_dma_value((context->aregs[7]+2)/2) << 16) | read_dma_value((context->aregs[7]+2)/2 + 1); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
420 } else if(m68k_is_branch(&inst)) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
421 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
422 branch_f = after; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
423 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
424 insert_breakpoint(context, branch_t, (uint8_t *)gdb_debug_enter); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
425 } else if(inst.op == M68K_DBCC && inst.extra.cond != COND_FALSE) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
426 branch_t = after; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
427 branch_f = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
428 insert_breakpoint(context, branch_f, (uint8_t *)gdb_debug_enter); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
429 } else { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
430 after = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
431 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
432 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
433 insert_breakpoint(context, after, (uint8_t *)gdb_debug_enter); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
434 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
435 cont = 1; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
436 expect_break_response = 1; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
437 break; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
438 } |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
439 default: |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
440 goto not_impl; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
441 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
442 } else { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
443 goto not_impl; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
444 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
445 break; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
446 case '?': |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
447 gdb_send_command("S05"); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
448 break; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
449 default: |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
450 goto not_impl; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
451 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
452 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
453 return; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
454 not_impl: |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
455 fprintf(stderr, "Command %s is not implemented, exiting...\n", command); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
456 exit(1); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
457 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
458 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
459 m68k_context * gdb_debug_enter(m68k_context * context, uint32_t pc) |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
460 { |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
461 dfprintf(stderr, "Entered debugger at address %X\n", pc); |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
462 if (expect_break_response) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
463 gdb_send_command("S05"); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
464 expect_break_response = 0; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
465 } |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
466 if ((pc & 0xFFFFFF) == branch_t) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
467 bp_def ** f_bp = find_breakpoint(&breakpoints, branch_f); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
468 if (!*f_bp) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
469 remove_breakpoint(context, branch_f); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
470 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
471 branch_t = branch_f = 0; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
472 } else if((pc & 0xFFFFFF) == branch_f) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
473 bp_def ** t_bp = find_breakpoint(&breakpoints, branch_t); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
474 if (!*t_bp) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
475 remove_breakpoint(context, branch_t); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
476 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
477 branch_t = branch_f = 0; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
478 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
479 //Check if this is a user set breakpoint, or just a temporary one |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
480 bp_def ** this_bp = find_breakpoint(&breakpoints, pc & 0xFFFFFF); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
481 if (!*this_bp) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
482 remove_breakpoint(context, pc & 0xFFFFFF); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
483 } |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 resume_pc = pc; |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
485 cont = 0; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
486 uint8_t partial = 0; |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 while(!cont) |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 { |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
489 if (!curbuf) { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
490 int numread = read(STDIN_FILENO, buf, bufsize); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
491 curbuf = buf; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
492 end = buf + numread; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
493 } else if (partial) { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
494 if (curbuf != buf) { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
495 memmove(curbuf, buf, end-curbuf); |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
496 end -= curbuf - buf; |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
497 } |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
498 int numread = read(STDIN_FILENO, end, bufsize - (end-buf)); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
499 end += numread; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
500 curbuf = buf; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
501 } |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
502 for (; curbuf < end; curbuf++) |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
503 { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
504 if (*curbuf == '$') |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
505 { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
506 curbuf++; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
507 char * start = curbuf; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
508 while (curbuf < end && *curbuf != '#') { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
509 curbuf++; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
510 } |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
511 if (*curbuf == '#') { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
512 //check to make sure we've received the checksum bytes |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
513 if (end-curbuf >= 2) { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
514 //TODO: verify checksum |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
515 //Null terminate payload |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
516 *curbuf = 0; |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
517 //send acknowledgement |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
518 if (write(STDOUT_FILENO, "+", 1) < 1) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
519 fputs("Error writing to stdout\n", stderr); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
520 exit(1); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
521 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
522 gdb_run_command(context, pc, start); |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
523 curbuf += 2; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
524 } |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
525 } else { |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
526 curbuf--; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
527 partial = 1; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
528 break; |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
529 } |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
530 } else { |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
531 dfprintf(stderr, "Ignoring character %c\n", *curbuf); |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
532 } |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
533 } |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
534 if (curbuf == end) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
535 curbuf = NULL; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
536 } |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
537 } |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
538 return context; |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
539 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
540 |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
541 void gdb_remote_init(void) |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
542 { |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
543 buf = malloc(INITIAL_BUFFER_SIZE); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
544 curbuf = NULL; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
545 bufsize = INITIAL_BUFFER_SIZE; |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
546 } |