Mercurial > repos > blastem
annotate gdb_remote.c @ 1053:b86c3ce007d9
Implemented undocumented flag bits for rotate instructions
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 29 Jul 2016 09:23:59 -0700 |
parents | 59e664fa2da8 |
children | 22e87b739ad6 |
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 */ |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
6 #ifdef _WIN32 |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
7 #define WINVER 0x501 |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
8 #include <winsock2.h> |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
9 #include <ws2tcpip.h> |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
10 |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
11 int gdb_sock; |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
12 #define GDB_IN_FD gdb_sock |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
13 #define GDB_OUT_FD gdb_sock |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
14 #define GDB_READ(fd, buf, bufsize) recv(fd, buf, bufsize, 0) |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
15 #define GDB_WRITE(fd, buf, bufsize) send(fd, buf, bufsize, 0) |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
16 #else |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
17 #define GDB_IN_FD STDIN_FILENO |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
18 #define GDB_OUT_FD STDOUT_FILENO |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
19 #define GDB_READ read |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
20 #define GDB_WRITE write |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
21 #endif |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
22 |
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
|
23 #include "gdb_remote.h" |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
24 #include "68kinst.h" |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
25 #include "debug.h" |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
757
diff
changeset
|
26 #include "util.h" |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 #include <unistd.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 #include <fcntl.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 #include <stddef.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 #include <stdlib.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 #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
|
32 #include <string.h> |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
34 |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
35 |
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
|
36 #define INITIAL_BUFFER_SIZE (16*1024) |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
38 #ifdef DO_DEBUG_PRINT |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
39 #define dfprintf fprintf |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
40 #else |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
41 #define dfprintf |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
42 #endif |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
43 |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 char * buf = NULL; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 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
|
46 char * end = NULL; |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 size_t bufsize; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 int cont = 0; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 int expect_break_response=0; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 uint32_t resume_pc; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 |
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
|
52 |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
53 static uint16_t branch_t; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
54 static uint16_t branch_f; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
55 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
56 static bp_def * breakpoints = NULL; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
57 static uint32_t bp_index = 0; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
58 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
59 |
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
|
60 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
|
61 { |
1495179d6737
Initial GDB remote 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 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
|
63 { |
1495179d6737
Initial GDB remote 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 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
|
65 *(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
|
66 } |
1495179d6737
Initial GDB remote 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 |
1495179d6737
Initial GDB remote 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 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
|
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 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
|
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 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
|
74 *(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
|
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 } |
1495179d6737
Initial GDB remote 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 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
|
79 { |
1495179d6737
Initial GDB remote 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 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
|
81 *(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
|
82 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
|
83 *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
|
84 } |
1495179d6737
Initial GDB remote 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 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
|
87 { |
1495179d6737
Initial GDB remote 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 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
|
89 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
|
90 { |
1495179d6737
Initial GDB remote 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 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
|
92 } |
1495179d6737
Initial GDB remote 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 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
|
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 |
1495179d6737
Initial GDB remote 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 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
|
97 { |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
98 if (GDB_WRITE(fd, buf, count) < count) { |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
757
diff
changeset
|
99 fatal_error("Error writing to stdout\n"); |
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
|
100 } |
1495179d6737
Initial GDB remote 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 } |
1495179d6737
Initial GDB remote 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 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
|
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 char end[3]; |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
106 write_or_die(GDB_OUT_FD, "$", 1); |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
107 write_or_die(GDB_OUT_FD, command, strlen(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
|
108 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
|
109 gdb_calc_checksum(command, end+1); |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
110 write_or_die(GDB_OUT_FD, end, 3); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
111 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
|
112 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
113 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
114 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
|
115 { |
1495179d6737
Initial GDB remote 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 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
|
117 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
|
118 { |
1495179d6737
Initial GDB remote 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 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
|
120 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
|
121 } |
1495179d6737
Initial GDB remote 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 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
|
123 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
124 |
526
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
125 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
|
126 { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
127 context->status = value >> 8; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
128 for (int i = 4; i >= 0; i--) |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
129 { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
130 context->flags[i] = value & 1; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
131 value >>= 1; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
132 } |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
133 } |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
134 |
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
|
135 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
|
136 { |
801
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
137 |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
138 genesis_context *gen = context->system; |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
139 //TODO: Use generated read/write functions to support access to hardware that is not ROM or RAM |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
140 uint16_t * word = get_native_pointer(address & 0xFFFFFFFE, (void **)context->mem_pointers, &context->options->gen); |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
141 if (word) { |
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
|
142 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
|
143 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
|
144 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
145 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
|
146 } |
801
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
147 if (address >= 0xA00000 && address < 0xA04000) { |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
148 return gen->zram[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
|
149 } |
801
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
150 return 0; |
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
|
151 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
152 |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
153 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
|
154 { |
801
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
155 genesis_context *gen = context->system; |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
156 //TODO: Use generated read/write functions so that memory map is properly respected |
801
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
157 uint16_t * word = get_native_pointer(address & 0xFFFFFFFE, (void **)context->mem_pointers, &context->options->gen); |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
158 if (word) { |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
159 if (address & 1) { |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
160 *word = (*word & 0xFF00) | value; |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
161 } else { |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
162 *word = (*word & 0xFF) | value << 8; |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
163 } |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
164 //TODO: Deal with this more generally once m68k_handle_code_write can handle it |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
165 if (address >= 0xE00000) { |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
166 m68k_handle_code_write(address, context); |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
167 } |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
168 return; |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
169 } |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
170 if (address >= 0xA00000 && address < 0xA04000) { |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
171 z80_ram[address & 0x1FFF] = value; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
172 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
|
173 #ifndef NO_Z80 |
804
59e664fa2da8
Fix a search/replace bug from the old Win32 GDB remote debugging work and replace some more print+exit combos with fatal_error
Michael Pavone <pavone@retrodev.com>
parents:
803
diff
changeset
|
174 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
|
175 #endif |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
176 return; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
177 } else { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
178 return; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
179 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
180 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
181 |
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
|
182 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
|
183 { |
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
|
184 char send_buf[512]; |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
185 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
|
186 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
|
187 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
188 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
189 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
|
190 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
|
191 //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
|
192 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
|
193 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
194 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
|
195 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
|
196 break; |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
197 case 's': { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
198 if (*(command+1) != 0) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
199 //TODO: implement resuming at an arbitrary address |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
200 goto not_impl; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
201 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
202 m68kinst inst; |
801
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
203 genesis_context *gen = context->system; |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
204 uint16_t * pc_ptr = get_native_pointer(pc, (void **)context->mem_pointers, &context->options->gen); |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
205 if (!pc_ptr) { |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
757
diff
changeset
|
206 fatal_error("Entered gdb remote debugger stub at address %X\n", pc); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
207 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
208 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
|
209 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
|
210 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
211 if (inst.op == M68K_RTS) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
212 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
|
213 } 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
|
214 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
|
215 } else if(m68k_is_branch(&inst)) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
216 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
|
217 branch_f = after; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
218 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
|
219 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
|
220 } 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
|
221 branch_t = after; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
222 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
|
223 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
|
224 } else { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
225 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
|
226 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
227 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
228 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
|
229 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
230 cont = 1; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
231 expect_break_response = 1; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
232 break; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
233 } |
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
|
234 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
|
235 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
|
236 //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
|
237 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
|
238 } 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
|
239 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
|
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 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 new_bp->next = breakpoints; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
249 new_bp->address = address; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
250 new_bp->index = bp_index++; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
251 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
|
252 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
|
253 } 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
|
254 //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
|
255 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
|
256 } |
1495179d6737
Initial GDB remote 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 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
|
258 } |
1495179d6737
Initial GDB remote 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 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
|
260 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
|
261 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
|
262 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
|
263 remove_breakpoint(context, address); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
264 bp_def **found = find_breakpoint(&breakpoints, address); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
265 if (*found) |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
266 { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
267 bp_def * to_remove = *found; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
268 *found = to_remove->next; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
269 free(to_remove); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
270 } |
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
|
271 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
|
272 } 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
|
273 //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
|
274 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
|
275 } |
1495179d6737
Initial GDB remote 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 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
|
277 } |
1495179d6737
Initial GDB remote 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 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
|
279 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
|
280 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
|
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 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
|
283 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
|
284 } |
1495179d6737
Initial GDB remote 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 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
|
286 { |
1495179d6737
Initial GDB remote 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 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
|
288 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
|
289 } |
1495179d6737
Initial GDB remote 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 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
|
291 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
|
292 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
|
293 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
|
294 *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
|
295 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
|
296 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
|
297 } |
1495179d6737
Initial GDB remote 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 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
|
299 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
|
300 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
|
301 uint32_t size = strtoul(rest+1, NULL, 16); |
757
483f7e7926a6
More clang warning cleanup
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
302 if (size > (sizeof(send_buf)-1)/2) { |
483f7e7926a6
More clang warning cleanup
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
303 size = (sizeof(send_buf)-1)/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
|
304 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
305 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
|
306 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
|
307 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
308 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
|
309 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
|
310 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
|
311 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
|
312 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
313 *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
|
314 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
|
315 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
|
316 } |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
317 case 'M': { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
318 char * rest; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
319 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
|
320 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
|
321 |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
322 char *cur = rest+1; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
323 while (size) |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
324 { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
325 char tmp[3]; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
326 tmp[0] = *(cur++); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
327 tmp[1] = *(cur++); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
328 tmp[2] = 0; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
329 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
|
330 address++; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
331 size--; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
332 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
333 gdb_send_command("OK"); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
334 break; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
335 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
336 case 'X': |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
337 //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
|
338 gdb_send_command(""); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
343 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
|
344 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
|
345 } 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
|
346 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
|
347 } 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
|
348 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
|
349 } 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
|
350 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
|
351 } 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
|
352 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
|
353 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
354 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
|
355 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
|
356 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
|
357 } |
526
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
358 case 'P': { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
359 char *after = NULL; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
360 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
|
361 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
|
362 |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
363 if (reg < 8) { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
364 context->dregs[reg] = value; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
365 } else if (reg < 16) { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
366 context->aregs[reg-8] = value; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
367 } else if (reg == 16) { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
368 update_status(context, value); |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
369 } else { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
370 //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
|
371 gdb_send_command("E01"); |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
372 break; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
373 } |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
374 gdb_send_command("OK"); |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
375 break; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
376 } |
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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 } 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
|
382 //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
|
383 //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
|
384 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
|
385 } 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
|
386 //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
|
387 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
|
388 } 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
|
389 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
|
390 } 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
|
391 //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
|
392 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
|
393 } 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
|
394 //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
|
395 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
|
396 } 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
|
397 //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
|
398 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
|
399 } 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
|
400 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
|
401 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
402 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
|
403 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
|
404 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
|
405 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
|
406 } 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
|
407 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
|
408 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
409 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
|
410 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
|
411 //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
|
412 //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
|
413 //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
|
414 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
|
415 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
|
416 break; |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
417 case 's': |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
418 case 'S': { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
419 m68kinst inst; |
801
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
420 genesis_context *gen = context->system; |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
421 uint16_t * pc_ptr = get_native_pointer(pc, (void **)context->mem_pointers, &context->options->gen); |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
422 if (!pc_ptr) { |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
757
diff
changeset
|
423 fatal_error("Entered gdb remote debugger stub at address %X\n", pc); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
424 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
425 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
|
426 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
|
427 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
428 if (inst.op == M68K_RTS) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
429 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
|
430 } 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
|
431 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
|
432 } else if(m68k_is_branch(&inst)) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
433 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
|
434 branch_f = after; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
435 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
|
436 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
|
437 } 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
|
438 branch_t = after; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
439 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
|
440 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
|
441 } else { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
442 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
|
443 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
444 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
445 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
|
446 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
447 cont = 1; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
448 expect_break_response = 1; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
449 break; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
450 } |
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
|
451 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
|
452 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
|
453 } |
1495179d6737
Initial GDB remote 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 } 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
|
455 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
|
456 } |
1495179d6737
Initial GDB remote 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 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
|
458 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
|
459 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
|
460 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
|
461 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
|
462 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
|
463 |
1495179d6737
Initial GDB remote 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 } |
1495179d6737
Initial GDB remote 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 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
|
466 not_impl: |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
757
diff
changeset
|
467 fatal_error("Command %s is not implemented, exiting...\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
|
468 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
469 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
470 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
|
471 { |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
472 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
|
473 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
|
474 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
|
475 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
|
476 } |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
477 if ((pc & 0xFFFFFF) == branch_t) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
478 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
|
479 if (!*f_bp) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
480 remove_breakpoint(context, branch_f); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
481 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
482 branch_t = branch_f = 0; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
483 } else if((pc & 0xFFFFFF) == branch_f) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
484 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
|
485 if (!*t_bp) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
486 remove_breakpoint(context, branch_t); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
487 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
488 branch_t = branch_f = 0; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
489 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
490 //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
|
491 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
|
492 if (!*this_bp) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
493 remove_breakpoint(context, pc & 0xFFFFFF); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
494 } |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
495 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
|
496 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
|
497 uint8_t partial = 0; |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 while(!cont) |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 { |
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
|
500 if (!curbuf) { |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
501 int numread = GDB_READ(GDB_IN_FD, buf, bufsize); |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
502 if (numread < 0) { |
804
59e664fa2da8
Fix a search/replace bug from the old Win32 GDB remote debugging work and replace some more print+exit combos with fatal_error
Michael Pavone <pavone@retrodev.com>
parents:
803
diff
changeset
|
503 fatal_error("Failed to read on GDB input file descriptor\n"); |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
504 } |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
505 dfprintf(stderr, "read %d bytes\n", numread); |
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 = 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
|
507 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
|
508 } 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
|
509 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
|
510 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
|
511 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
|
512 } |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
513 int numread = read(GDB_IN_FD, end, bufsize - (end-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
|
514 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
|
515 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
|
516 } |
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 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
|
518 { |
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
|
519 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
|
520 { |
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
|
521 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
|
522 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
|
523 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
|
524 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
|
525 } |
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 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
|
527 //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
|
528 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
|
529 //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
|
530 //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
|
531 *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
|
532 //send acknowledgement |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
533 if (GDB_WRITE(GDB_OUT_FD, "+", 1) < 1) { |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
757
diff
changeset
|
534 fatal_error("Error writing to stdout\n"); |
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
|
535 } |
1495179d6737
Initial GDB remote 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 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
|
537 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
|
538 } |
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
|
539 } 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
|
540 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
|
541 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
|
542 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
|
543 } |
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
|
544 } else { |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
545 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
|
546 } |
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
|
547 } |
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
|
548 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
|
549 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
|
550 } |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
551 } |
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
|
552 return context; |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
553 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
554 |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
555 #ifdef _WIN32 |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
556 void gdb_cleanup(void) |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
557 { |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
558 WSACleanup(); |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
559 } |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
560 WSADATA wsa_data; |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
561 #endif |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
562 |
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
|
563 void gdb_remote_init(void) |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
564 { |
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
|
565 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
|
566 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
|
567 bufsize = INITIAL_BUFFER_SIZE; |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
568 #ifdef _WIN32 |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
569 WSAStartup(MAKEWORD(2,2), &wsa_data); |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
570 |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
571 struct addrinfo request, *result; |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
572 memset(&request, 0, sizeof(request)); |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
573 request.ai_family = AF_UNSPEC; |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
574 request.ai_socktype = SOCK_STREAM; |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
575 request.ai_flags = AI_PASSIVE; |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
576 getaddrinfo(NULL, "1234", &request, &result); |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
577 |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
578 int listen_sock = socket(result->ai_family, result->ai_socktype, result->ai_protocol); |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
579 if (listen_sock < 0) { |
804
59e664fa2da8
Fix a search/replace bug from the old Win32 GDB remote debugging work and replace some more print+exit combos with fatal_error
Michael Pavone <pavone@retrodev.com>
parents:
803
diff
changeset
|
580 fatal_error("Failed to open GDB remote debugging socket"); |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
581 } |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
582 if (bind(listen_sock, result->ai_addr, result->ai_addrlen) < 0) { |
804
59e664fa2da8
Fix a search/replace bug from the old Win32 GDB remote debugging work and replace some more print+exit combos with fatal_error
Michael Pavone <pavone@retrodev.com>
parents:
803
diff
changeset
|
583 fatal_error("Failed to bind GDB remote debugging socket"); |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
584 } |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
585 if (listen(listen_sock, 1) < 0) { |
804
59e664fa2da8
Fix a search/replace bug from the old Win32 GDB remote debugging work and replace some more print+exit combos with fatal_error
Michael Pavone <pavone@retrodev.com>
parents:
803
diff
changeset
|
586 fatal_error("Failed to listen on GDB remote debugging socket"); |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
587 } |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
588 gdb_sock = accept(listen_sock, NULL, NULL); |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
589 if (gdb_sock < 0) { |
804
59e664fa2da8
Fix a search/replace bug from the old Win32 GDB remote debugging work and replace some more print+exit combos with fatal_error
Michael Pavone <pavone@retrodev.com>
parents:
803
diff
changeset
|
590 fatal_error("accept returned an error while listening on GDB remote debugging socket"); |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
591 } |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
592 closesocket(listen_sock); |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
593 #endif |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
594 } |