Mercurial > repos > blastem
annotate gdb_remote.c @ 522:6a14c5a95648
Adjust PSG and YM-2612 volume to be closer to the real console
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 11 Feb 2014 12:52:28 -0800 |
parents | b7b7a1cab44a |
children | 1495179d6737 |
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 */ |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "blastem.h" |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include <unistd.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include <fcntl.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include <stddef.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include <stdlib.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #include <stdio.h> |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #define INITIAL_BUFFER_SIZE 4096 |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 char * buf = NULL; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 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
|
17 char * end = NULL; |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 size_t bufsize; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 int cont = 0; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 int expect_break_response=0; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 uint32_t resume_pc; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 void gdb_debug_enter(genesis_context * gen, uint32_t pc) |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 { |
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
|
25 fcntl(STDIN_FILENO, FD_SETFL, 0); |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 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
|
27 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
|
28 uint8_t partial = 0; |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 while(!cont) |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 { |
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
|
31 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
|
32 int numread = read(STDIN_FILENO, buf, bufsize); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
33 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
|
34 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
|
35 } 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
|
36 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
|
37 memmove(curbuf, buf, 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
|
38 end -= cufbuf - 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
|
39 } |
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
|
40 int numread = read(STDIN_FILENO, end, bufsize - (end-buf)); |
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
41 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
|
42 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
|
43 } |
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
|
44 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
|
45 { |
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 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
|
47 { |
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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 } |
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
|
53 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
|
54 //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
|
55 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
|
56 //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
|
57 //Null terminate payload |
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
|
58 *curbuf = 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
|
59 //send acknowledgement |
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
|
60 write(FILENO_STDOUT, "+", 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
|
61 gdb_run_command(genesis_context * gen, start); |
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
|
62 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
|
63 } |
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
|
64 } 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
|
65 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
|
66 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
|
67 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
|
68 } |
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
|
69 } |
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
|
70 } |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 } |
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
|
72 fcntl(STDIN_FILENO, FD_SETFL, O_NONBLOCK); |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 void gdb_run_command(genesis_context * gen, char * command) |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 switch(*command) |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 case 'c': |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 if (*(command+1) != 0) { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 resume_pc = |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 cont = 1; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 expect_break_response = 1; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 break; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 case 's': |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 void gdb_run_commands(genesis_context * gen) |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 int enter_debugger = 0; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 char * cur = buf; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 while(cur < curbuf); |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 if(*cur == '$') { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 cur++ |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 char * start = cur; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 while (cur < curbuf && *cur != '#') { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 cur++; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 if (*cur == '#') { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 //check to make sure we've received the checksum bytes |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 if (curbuf-cur >= 2) { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 //TODO: verify checksum |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 //Null terminate payload |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 //send acknowledgement |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 write(FILENO_STDOUT, "+", 1); |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 gdb_run_command(genesis_context * gen, start); |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 cur += 2; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 } else { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 cur = start - 1; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 break; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 } else { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 cur = start - 1; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 break; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 } else { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 if (*cur == 0x03) { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 enter_debugger = 1; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 cur++; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 //FIXME |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 if (consumed == curbuf-buf) { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 curbuf = buf; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 } else if (consumed > 0) { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 memmove(buf, buf + consumed, curbuf - buf - consumed); |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 curbuf -= consumed; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 |
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
|
137 int gdb_command_poll(genesis_context * gen) |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 for(;;) |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 if (curbuf == buf + bufsize) { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 //buffer is full, expand it |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 bufsize *= 2; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 buf = realloc(buf, bufsize); |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 if (!buf) { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 fprintf(stderr, "Failed to grow GDB command buffer to %d bytes\n", (int)bufsize); |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 exit(1); |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 curbuf = buf + bufsize/2; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 } |
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
|
151 int numread = read(STDIN_FILENO, buf, bufsize); |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 if (numread < 0) { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 if (errno == EAGAIN || errno == EWOULDBLOCK) { |
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
|
154 return 0; |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 } else { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 fprintf(stderr, "Error %d while reading GDB commands from stdin", errno); |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 exit(1); |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 } else if (numread == 0) { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 exit(0); |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 } |
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
|
162 for (curbuf = buf, end = buf+numread; 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
|
163 { |
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
|
164 if (*curbuf = 0x03) |
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
|
165 { |
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
|
166 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
|
167 return 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
|
168 } |
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
|
169 } |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 } |
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
|
171 return 0; |
456
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 } |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 void gdb_remote_init() |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 { |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 fcntl(STDIN_FILENO, FD_SETFL, O_NONBLOCK); |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 buf = malloc(INITIAL_BUFFER_SIZE); |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 curbuf = buf; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 bufzie = INITIAL_BUFFER_SIZE; |
249d24973682
Initial work on GDB remote debugging support
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 } |