Mercurial > repos > blastem
annotate gdb_remote.c @ 2488:bfd09d3367ba
Fix crash when enabling VGM recording while running Pico or Copera software
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 15 Apr 2024 23:07:18 -0700 |
parents | 8445e814d495 |
children | d74d3998482c |
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 |
1949
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1945
diff
changeset
|
21 #include <unistd.h> |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
22 #endif |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
23 |
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
|
24 #include "gdb_remote.h" |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
25 #include "68kinst.h" |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
26 #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
|
27 #include "util.h" |
456
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 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
53 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
|
54 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
55 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
|
56 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
57 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
|
58 *(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
|
59 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
60 } |
1495179d6737
Initial GDB remote 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 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
|
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 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
|
65 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
66 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
|
67 *(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
|
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 } |
1495179d6737
Initial GDB remote 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 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
|
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 >> 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
|
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 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
|
76 *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
|
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 |
1495179d6737
Initial GDB remote 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 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
|
80 { |
1495179d6737
Initial GDB remote 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 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
|
82 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
|
83 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
84 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
|
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 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
|
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 |
1495179d6737
Initial GDB remote 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 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
|
90 { |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
91 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
|
92 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
|
93 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
94 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
95 |
1495179d6737
Initial GDB remote 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 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
|
97 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
106 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
107 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
|
108 { |
1495179d6737
Initial GDB remote 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 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
|
110 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
|
111 { |
1495179d6737
Initial GDB remote 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 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
|
113 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
|
114 } |
1495179d6737
Initial GDB remote 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 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
|
116 } |
1495179d6737
Initial GDB remote 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 |
526
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
118 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
|
119 { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
120 context->status = value >> 8; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
121 for (int i = 4; i >= 0; i--) |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
122 { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
123 context->flags[i] = value & 1; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
124 value >>= 1; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
125 } |
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 |
1965
3a46ff899fa6
More correct implementation of byte printing in builtin debugger. Fix GDB debugger to use helper in backend.c for reading bytes
Michael Pavone <pavone@retrodev.com>
parents:
1963
diff
changeset
|
128 static uint8_t m68k_read_byte(m68k_context *context, uint32_t address) |
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
|
129 { |
1965
3a46ff899fa6
More correct implementation of byte printing in builtin debugger. Fix GDB debugger to use helper in backend.c for reading bytes
Michael Pavone <pavone@retrodev.com>
parents:
1963
diff
changeset
|
130 //TODO: share this implementation with builtin debugger |
3a46ff899fa6
More correct implementation of byte printing in builtin debugger. Fix GDB debugger to use helper in backend.c for reading bytes
Michael Pavone <pavone@retrodev.com>
parents:
1963
diff
changeset
|
131 return read_byte(address, (void **)context->mem_pointers, &context->options->gen, context); |
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
|
132 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
133 |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
134 void m68k_write_byte(m68k_context * context, uint32_t address, uint8_t value) |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
135 { |
801
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
136 genesis_context *gen = context->system; |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
137 //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
|
138 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
|
139 if (word) { |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
140 if (address & 1) { |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
141 *word = (*word & 0xFF00) | value; |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
142 } else { |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
143 *word = (*word & 0xFF) | value << 8; |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
144 } |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
145 //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
|
146 if (address >= 0xE00000) { |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
147 m68k_handle_code_write(address, context); |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
148 } |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
149 return; |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
150 } |
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
151 if (address >= 0xA00000 && address < 0xA04000) { |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
804
diff
changeset
|
152 gen->zram[address & 0x1FFF] = value; |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
153 genesis_context * gen = context->system; |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
154 #if !defined(NO_Z80) && !defined(NEW_CORE) |
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
|
155 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
|
156 #endif |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
157 return; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
158 } else { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
159 return; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
160 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
161 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
162 |
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
|
163 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
|
164 { |
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
|
165 char send_buf[512]; |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
166 dfprintf(stderr, "Received command %s\n", command); |
2107
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
167 debug_root *root = find_root(context); |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
168 if (!root) { |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
169 fatal_error("Could not find debug root for CPU %p\n", context); |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
170 } |
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
|
171 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
|
172 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
173 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
174 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
|
175 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
|
176 //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
|
177 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
|
178 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
179 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
|
180 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
|
181 break; |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
182 case 's': { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
183 if (*(command+1) != 0) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
184 //TODO: implement resuming at an arbitrary address |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
185 goto not_impl; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
186 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
187 m68kinst inst; |
801
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
188 genesis_context *gen = context->system; |
2133
8554751f17b5
Remove use of get_native_pointer in 68K instruction decoding in preparation for word RAM interleaving
Michael Pavone <pavone@retrodev.com>
parents:
2107
diff
changeset
|
189 uint32_t after = m68k_decode(m68k_instruction_fetch, context, &inst, pc & 0xFFFFFF); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
190 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
191 if (inst.op == M68K_RTS) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
192 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
|
193 } 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
|
194 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
|
195 } else if(m68k_is_branch(&inst)) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
196 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { |
2107
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
197 root->branch_f = after; |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
198 root->branch_t = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
199 insert_breakpoint(context, root->branch_t, gdb_debug_enter); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
200 } else if(inst.op == M68K_DBCC && inst.extra.cond != COND_FALSE) { |
2107
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
201 root->branch_t = after; |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
202 root->branch_f = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
203 insert_breakpoint(context, root->branch_f, gdb_debug_enter); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
204 } else { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
205 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
|
206 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
207 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
208 insert_breakpoint(context, after, gdb_debug_enter); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
209 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
210 cont = 1; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
211 expect_break_response = 1; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
212 break; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
213 } |
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
|
214 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
|
215 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
|
216 //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
|
217 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
|
218 } 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
|
219 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
|
220 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
221 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
|
222 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
|
223 uint8_t type = command[1]; |
2397
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
224 char *after_address; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
225 uint32_t address = strtoul(command+3, &after_address, 16); |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
226 uint32_t kind = strtoul(after_address +1, NULL, 16); |
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
|
227 if (type < '2') { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
228 insert_breakpoint(context, address, gdb_debug_enter); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
229 bp_def *new_bp = malloc(sizeof(bp_def)); |
2107
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
230 new_bp->next = root->breakpoints; |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
231 new_bp->address = address; |
2361
3350b3c8faa8
Initial implementation of VDP register write breakpoints
Michael Pavone <pavone@retrodev.com>
parents:
2133
diff
changeset
|
232 new_bp->mask = 0xFFFFFF; |
3350b3c8faa8
Initial implementation of VDP register write breakpoints
Michael Pavone <pavone@retrodev.com>
parents:
2133
diff
changeset
|
233 new_bp->type = BP_TYPE_CPU; |
2107
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
234 new_bp->index = root->bp_index++; |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
235 root->breakpoints = new_bp; |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
236 gdb_send_command("OK"); |
2397
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
237 } else if (type == '2') { |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
238 m68k_add_watchpoint(context, address, kind); |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
239 bp_def *new_bp = malloc(sizeof(bp_def)); |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
240 new_bp->next = root->breakpoints; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
241 new_bp->address = address; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
242 new_bp->mask = kind; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
243 new_bp->type = BP_TYPE_CPU_WATCH; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
244 new_bp->index = root->bp_index++; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
245 root->breakpoints = new_bp; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
246 gdb_send_command("OK"); |
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
|
247 } else { |
2397
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
248 //read and access watchpoints are not currently supported |
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
|
249 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
|
250 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
251 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
|
252 } |
1495179d6737
Initial GDB remote 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 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
|
254 uint8_t type = command[1]; |
2397
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
255 char *after_address; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
256 uint32_t address = strtoul(command+3, &after_address, 16); |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
257 uint32_t kind = strtoul(after_address +1, NULL, 16); |
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
|
258 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
|
259 remove_breakpoint(context, address); |
2361
3350b3c8faa8
Initial implementation of VDP register write breakpoints
Michael Pavone <pavone@retrodev.com>
parents:
2133
diff
changeset
|
260 bp_def **found = find_breakpoint(&root->breakpoints, address, BP_TYPE_CPU); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
261 if (*found) |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
262 { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
263 bp_def * to_remove = *found; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
264 *found = to_remove->next; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
265 free(to_remove); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
266 } |
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
|
267 gdb_send_command("OK"); |
2397
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
268 } else if (type == '2') { |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
269 m68k_remove_watchpoint(context, address, kind); |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
270 bp_def **cur = &root->breakpoints; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
271 while (*cur) |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
272 { |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
273 if ((*cur)->type == BP_TYPE_CPU_WATCH && (*cur)->address == address && (*cur)->mask == kind) { |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
274 break; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
275 } |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
276 cur = &(*cur)->next; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
277 } |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
278 if (*cur) { |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
279 bp_def *to_remove = *cur; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
280 *cur = to_remove->next; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
281 free(to_remove); |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
282 } |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
283 gdb_send_command("OK"); |
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
|
284 } else { |
2397
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
285 //read and access watchpoints are not currently supported |
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
|
286 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
|
287 } |
1495179d6737
Initial GDB remote 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 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
|
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 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
|
291 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
|
292 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
|
293 { |
1495179d6737
Initial GDB remote 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 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
|
295 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
|
296 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
297 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
|
298 { |
1495179d6737
Initial GDB remote 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 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
|
300 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
|
301 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 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
|
306 *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
|
307 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
|
308 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
|
309 } |
2398
8445e814d495
Implement gdb remote kill command
Michael Pavone <pavone@retrodev.com>
parents:
2397
diff
changeset
|
310 case 'k': |
8445e814d495
Implement gdb remote kill command
Michael Pavone <pavone@retrodev.com>
parents:
2397
diff
changeset
|
311 exit(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
|
312 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
|
313 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
|
314 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
|
315 uint32_t size = strtoul(rest+1, NULL, 16); |
757
483f7e7926a6
More clang warning cleanup
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
316 if (size > (sizeof(send_buf)-1)/2) { |
483f7e7926a6
More clang warning cleanup
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
317 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
|
318 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
319 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
|
320 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
|
321 { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
322 hex_8(m68k_read_byte(context, address), cur); |
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
|
323 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
|
324 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
|
325 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
|
326 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
327 *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
|
328 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
|
329 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
|
330 } |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
331 case 'M': { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
332 char * rest; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
333 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
|
334 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
|
335 |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
336 char *cur = rest+1; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
337 while (size) |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
338 { |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
339 char tmp[3]; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
340 tmp[0] = *(cur++); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
341 tmp[1] = *(cur++); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
342 tmp[2] = 0; |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
343 m68k_write_byte(context, address, strtoul(tmp, NULL, 16)); |
530
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
344 address++; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
345 size--; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
346 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
347 gdb_send_command("OK"); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
348 break; |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
349 } |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
350 case 'X': |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
351 //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
|
352 gdb_send_command(""); |
92606a032d56
Implement memory writes in GDB remote debugging stub
Mike Pavone <pavone@retrodev.com>
parents:
526
diff
changeset
|
353 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
|
354 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
|
355 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
|
356 |
1495179d6737
Initial GDB remote 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 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
|
358 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
|
359 } 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
|
360 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
|
361 } 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
|
362 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
|
363 } 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
|
364 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
|
365 } 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
|
366 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
|
367 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
368 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
|
369 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
|
370 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
|
371 } |
526
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
372 case 'P': { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
373 char *after = NULL; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
374 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
|
375 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
|
376 |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
377 if (reg < 8) { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
378 context->dregs[reg] = value; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
379 } else if (reg < 16) { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
380 context->aregs[reg-8] = value; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
381 } else if (reg == 16) { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
382 update_status(context, value); |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
383 } else { |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
384 //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
|
385 gdb_send_command("E01"); |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
386 break; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
387 } |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
388 gdb_send_command("OK"); |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
389 break; |
6fe73296938a
Support setting registers in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
525
diff
changeset
|
390 } |
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
|
391 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
|
392 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
|
393 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
|
394 gdb_send_command(send_buf); |
1166
73e36dac5be7
Fix GDB remote protocol support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
395 } else if (!memcmp("Attached", command+1, strlen("Attached"))) { |
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
|
396 //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
|
397 //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
|
398 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
|
399 } 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
|
400 //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
|
401 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
|
402 } 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
|
403 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
|
404 } 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
|
405 //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
|
406 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
|
407 } 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
|
408 //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
|
409 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
|
410 } 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
|
411 //we only support a single thread currently, so send 1 |
1166
73e36dac5be7
Fix GDB remote protocol support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
412 gdb_send_command("QC1"); |
73e36dac5be7
Fix GDB remote protocol support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
413 } else if (!strcmp("fThreadInfo", command + 1)) { |
73e36dac5be7
Fix GDB remote protocol support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
414 //we only support a single thread currently, so send 1 |
73e36dac5be7
Fix GDB remote protocol support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
415 gdb_send_command("m1"); |
73e36dac5be7
Fix GDB remote protocol support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
416 } else if (!strcmp("sThreadInfo", command + 1)) { |
73e36dac5be7
Fix GDB remote protocol support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
417 gdb_send_command("l"); |
1963
495569c1dc61
Add support for printing a byte from memory in native debugger. Add stubs for GDB commands qThreadExtraInfo and qP
Eric Fry <yuv422@users.noreply.github.com>
parents:
1949
diff
changeset
|
418 } else if (!memcmp("ThreadExtraInfo", command+1, strlen("ThreadExtraInfo"))) { |
495569c1dc61
Add support for printing a byte from memory in native debugger. Add stubs for GDB commands qThreadExtraInfo and qP
Eric Fry <yuv422@users.noreply.github.com>
parents:
1949
diff
changeset
|
419 gdb_send_command(""); |
495569c1dc61
Add support for printing a byte from memory in native debugger. Add stubs for GDB commands qThreadExtraInfo and qP
Eric Fry <yuv422@users.noreply.github.com>
parents:
1949
diff
changeset
|
420 } else if (command[1] == 'P') { |
495569c1dc61
Add support for printing a byte from memory in native debugger. Add stubs for GDB commands qThreadExtraInfo and qP
Eric Fry <yuv422@users.noreply.github.com>
parents:
1949
diff
changeset
|
421 gdb_send_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
|
422 } 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
|
423 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
|
424 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
425 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
|
426 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
|
427 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
|
428 gdb_send_command("vCont;c;C;s;S"); |
1166
73e36dac5be7
Fix GDB remote protocol support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
429 } else if (!strcmp("MustReplyEmpty", command + 1)) { |
73e36dac5be7
Fix GDB remote protocol support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
430 gdb_send_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
|
431 } 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
|
432 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
|
433 { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
434 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
|
435 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
|
436 //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
|
437 //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
|
438 //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
|
439 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
|
440 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
|
441 break; |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
442 case 's': |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
443 case 'S': { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
444 m68kinst inst; |
801
092524bb2e8f
Fix GDB remote debugging support
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
445 genesis_context *gen = context->system; |
2133
8554751f17b5
Remove use of get_native_pointer in 68K instruction decoding in preparation for word RAM interleaving
Michael Pavone <pavone@retrodev.com>
parents:
2107
diff
changeset
|
446 uint32_t after = m68k_decode(m68k_instruction_fetch, context, &inst, pc & 0xFFFFFF); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
447 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
448 if (inst.op == M68K_RTS) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
449 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
|
450 } 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
|
451 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
|
452 } else if(m68k_is_branch(&inst)) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
453 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) { |
2107
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
454 root->branch_f = after; |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
455 root->branch_t = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
456 insert_breakpoint(context, root->branch_t, gdb_debug_enter); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
457 } else if(inst.op == M68K_DBCC && inst.extra.cond != COND_FALSE) { |
2107
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
458 root->branch_t = after; |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
459 root->branch_f = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF; |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
460 insert_breakpoint(context, root->branch_f, gdb_debug_enter); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
461 } else { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
462 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
|
463 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
464 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
465 insert_breakpoint(context, after, gdb_debug_enter); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
466 |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
467 cont = 1; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
468 expect_break_response = 1; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
469 break; |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
470 } |
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
|
471 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
|
472 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
|
473 } |
2398
8445e814d495
Implement gdb remote kill command
Michael Pavone <pavone@retrodev.com>
parents:
2397
diff
changeset
|
474 } else if (!memcmp("Kill;", command+1, strlen("Kill;"))) { |
8445e814d495
Implement gdb remote kill command
Michael Pavone <pavone@retrodev.com>
parents:
2397
diff
changeset
|
475 exit(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
|
476 } 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
|
477 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
|
478 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
479 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
|
480 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
|
481 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
|
482 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
|
483 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
|
484 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
|
485 |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
486 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
487 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
|
488 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
|
489 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
|
490 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
491 |
1329
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1245
diff
changeset
|
492 void gdb_debug_enter(m68k_context * context, uint32_t 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
|
493 { |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
494 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
|
495 if (expect_break_response) { |
2397
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
496 if (context->wp_hit) { |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
497 context->wp_hit = 0; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
498 char reply[128]; |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
499 snprintf(reply, sizeof(reply), "T05watch:%X;", context->wp_hit_address); |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
500 gdb_send_command(reply); |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
501 } else { |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
502 gdb_send_command("S05"); |
39a009aea113
Implement watchpoints in gdb remote protocol
Michael Pavone <pavone@retrodev.com>
parents:
2361
diff
changeset
|
503 } |
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
|
504 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
|
505 } |
2107
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
506 debug_root *root = find_root(context); |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
507 if (!root) { |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
508 fatal_error("Could not find debug root for CPU %p\n", context); |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
509 } |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
510 if ((pc & 0xFFFFFF) == root->branch_t) { |
2361
3350b3c8faa8
Initial implementation of VDP register write breakpoints
Michael Pavone <pavone@retrodev.com>
parents:
2133
diff
changeset
|
511 bp_def ** f_bp = find_breakpoint(&root->breakpoints, root->branch_f, BP_TYPE_CPU); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
512 if (!*f_bp) { |
2107
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
513 remove_breakpoint(context, root->branch_f); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
514 } |
2107
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
515 root->branch_t = root->branch_f = 0; |
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
516 } else if((pc & 0xFFFFFF) == root->branch_f) { |
2361
3350b3c8faa8
Initial implementation of VDP register write breakpoints
Michael Pavone <pavone@retrodev.com>
parents:
2133
diff
changeset
|
517 bp_def ** t_bp = find_breakpoint(&root->breakpoints, root->branch_t, BP_TYPE_CPU); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
518 if (!*t_bp) { |
2107
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
519 remove_breakpoint(context, root->branch_t); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
520 } |
2107
f80c6111e1ae
Move some debugger state to a per-CPU structure. Add m command for returning to main CPU from sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
1965
diff
changeset
|
521 root->branch_t = root->branch_f = 0; |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
522 } |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
523 //Check if this is a user set breakpoint, or just a temporary one |
2361
3350b3c8faa8
Initial implementation of VDP register write breakpoints
Michael Pavone <pavone@retrodev.com>
parents:
2133
diff
changeset
|
524 bp_def ** this_bp = find_breakpoint(&root->breakpoints, pc & 0xFFFFFF, BP_TYPE_CPU); |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
525 if (!*this_bp) { |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
526 remove_breakpoint(context, pc & 0xFFFFFF); |
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
527 } |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
528 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
|
529 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
|
530 uint8_t partial = 0; |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
531 while(!cont) |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
532 { |
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
|
533 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
|
534 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
|
535 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
|
536 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
|
537 } |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
538 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
|
539 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
|
540 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
|
541 } 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
|
542 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
|
543 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
|
544 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
|
545 } |
1245
42fb3ee1e92c
Fix direct usage of read rather than GDB_READ in gdb_remote.c
Michael Pavone <pavone@retrodev.com>
parents:
1189
diff
changeset
|
546 int numread = GDB_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
|
547 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
|
548 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
|
549 } |
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
|
550 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
|
551 { |
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
|
552 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
|
553 { |
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
|
554 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
|
555 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
|
556 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
|
557 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
|
558 } |
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
|
559 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
|
560 //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
|
561 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
|
562 //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
|
563 //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
|
564 *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
|
565 //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
|
566 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
|
567 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
|
568 } |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
569 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
|
570 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
|
571 } |
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
|
572 } 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
|
573 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
|
574 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
|
575 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
|
576 } |
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
|
577 } else { |
525
62860044337d
Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents:
515
diff
changeset
|
578 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
|
579 } |
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
|
580 } |
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
|
581 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
|
582 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
|
583 } |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
584 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
585 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
586 |
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
|
587 void gdb_remote_init(void) |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
588 { |
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
|
589 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
|
590 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
|
591 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
|
592 #ifdef _WIN32 |
1949
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1945
diff
changeset
|
593 socket_init(); |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
594 |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
595 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
|
596 memset(&request, 0, sizeof(request)); |
1189
75ba222877f7
Force IPV4 for GDB remote debugging on Windows. Bind to localhost instead of unspecified address since listening on external ports probably isn't a good idea in the general case
Michael Pavone <pavone@retrodev.com>
parents:
1166
diff
changeset
|
597 request.ai_family = AF_INET; |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
598 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
|
599 request.ai_flags = AI_PASSIVE; |
1189
75ba222877f7
Force IPV4 for GDB remote debugging on Windows. Bind to localhost instead of unspecified address since listening on external ports probably isn't a good idea in the general case
Michael Pavone <pavone@retrodev.com>
parents:
1166
diff
changeset
|
600 getaddrinfo("localhost", "1234", &request, &result); |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
601 |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
602 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
|
603 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
|
604 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
|
605 } |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
606 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
|
607 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
|
608 } |
1945
ba7231d2411c
Fix addrinfo leak in GDB remote debug support
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
609 freeaddrinfo(result); |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
610 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
|
611 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
|
612 } |
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
613 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
|
614 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
|
615 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
|
616 } |
1949
5a76a7373823
Get WIP net play code compiling on Windows and cleanup some unistd.h includes
Michael Pavone <pavone@retrodev.com>
parents:
1945
diff
changeset
|
617 socket_close(listen_sock); |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
618 #else |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
619 disable_stdout_messages(); |
802
6811f601008f
Old changes for GDB remote debugging on Windows I forgot to commit
Michael Pavone <pavone@retrodev.com>
parents:
565
diff
changeset
|
620 #endif |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
621 } |