comparison gdb_remote.c @ 1983:a7b753e260a2 mame_interp

Merge from default
author Michael Pavone <pavone@retrodev.com>
date Sat, 09 May 2020 23:39:44 -0700
parents 374a5ae694e8 3a46ff899fa6
children
comparison
equal deleted inserted replaced
1937:cafde1255ad3 1983:a7b753e260a2
16 #else 16 #else
17 #define GDB_IN_FD STDIN_FILENO 17 #define GDB_IN_FD STDIN_FILENO
18 #define GDB_OUT_FD STDOUT_FILENO 18 #define GDB_OUT_FD STDOUT_FILENO
19 #define GDB_READ read 19 #define GDB_READ read
20 #define GDB_WRITE write 20 #define GDB_WRITE write
21 #include <unistd.h>
21 #endif 22 #endif
22 23
23 #include "gdb_remote.h" 24 #include "gdb_remote.h"
24 #include "68kinst.h" 25 #include "68kinst.h"
25 #include "debug.h" 26 #include "debug.h"
26 #include "util.h" 27 #include "util.h"
27 #include <unistd.h>
28 #include <fcntl.h> 28 #include <fcntl.h>
29 #include <stddef.h> 29 #include <stddef.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <stdio.h> 31 #include <stdio.h>
32 #include <string.h> 32 #include <string.h>
130 context->flags[i] = value & 1; 130 context->flags[i] = value & 1;
131 value >>= 1; 131 value >>= 1;
132 } 132 }
133 } 133 }
134 134
135 static uint8_t m68k_read_byte(m68k_context * context, uint32_t address) 135 static uint8_t m68k_read_byte(m68k_context *context, uint32_t address)
136 { 136 {
137 137 //TODO: share this implementation with builtin debugger
138 genesis_context *gen = context->system; 138 return read_byte(address, (void **)context->mem_pointers, &context->options->gen, context);
139 //TODO: Use generated read/write functions to support access to hardware that is not ROM or RAM
140 uint16_t * word = get_native_pointer(address & 0xFFFFFFFE, (void **)context->mem_pointers, &context->options->gen);
141 if (word) {
142 if (address & 1) {
143 return *word;
144 }
145 return *word >> 8;
146 }
147 if (address >= 0xA00000 && address < 0xA04000) {
148 return gen->zram[address & 0x1FFF];
149 }
150 return 0;
151 } 139 }
152 140
153 static void m68k_write_byte(m68k_context * context, uint32_t address, uint8_t value) 141 static void m68k_write_byte(m68k_context * context, uint32_t address, uint8_t value)
154 { 142 {
155 genesis_context *gen = context->system; 143 genesis_context *gen = context->system;
399 } else if (!strcmp("fThreadInfo", command + 1)) { 387 } else if (!strcmp("fThreadInfo", command + 1)) {
400 //we only support a single thread currently, so send 1 388 //we only support a single thread currently, so send 1
401 gdb_send_command("m1"); 389 gdb_send_command("m1");
402 } else if (!strcmp("sThreadInfo", command + 1)) { 390 } else if (!strcmp("sThreadInfo", command + 1)) {
403 gdb_send_command("l"); 391 gdb_send_command("l");
392 } else if (!memcmp("ThreadExtraInfo", command+1, strlen("ThreadExtraInfo"))) {
393 gdb_send_command("");
394 } else if (command[1] == 'P') {
395 gdb_send_command("");
404 } else { 396 } else {
405 goto not_impl; 397 goto not_impl;
406 } 398 }
407 break; 399 break;
408 case 'v': 400 case 'v':
556 curbuf = NULL; 548 curbuf = NULL;
557 } 549 }
558 } 550 }
559 } 551 }
560 552
561 #ifdef _WIN32
562 void gdb_cleanup(void)
563 {
564 WSACleanup();
565 }
566 WSADATA wsa_data;
567 #endif
568
569 void gdb_remote_init(void) 553 void gdb_remote_init(void)
570 { 554 {
571 buf = malloc(INITIAL_BUFFER_SIZE); 555 buf = malloc(INITIAL_BUFFER_SIZE);
572 curbuf = NULL; 556 curbuf = NULL;
573 bufsize = INITIAL_BUFFER_SIZE; 557 bufsize = INITIAL_BUFFER_SIZE;
574 #ifdef _WIN32 558 #ifdef _WIN32
575 WSAStartup(MAKEWORD(2,2), &wsa_data); 559 socket_init();
576 560
577 struct addrinfo request, *result; 561 struct addrinfo request, *result;
578 memset(&request, 0, sizeof(request)); 562 memset(&request, 0, sizeof(request));
579 request.ai_family = AF_INET; 563 request.ai_family = AF_INET;
580 request.ai_socktype = SOCK_STREAM; 564 request.ai_socktype = SOCK_STREAM;
586 fatal_error("Failed to open GDB remote debugging socket"); 570 fatal_error("Failed to open GDB remote debugging socket");
587 } 571 }
588 if (bind(listen_sock, result->ai_addr, result->ai_addrlen) < 0) { 572 if (bind(listen_sock, result->ai_addr, result->ai_addrlen) < 0) {
589 fatal_error("Failed to bind GDB remote debugging socket"); 573 fatal_error("Failed to bind GDB remote debugging socket");
590 } 574 }
575 freeaddrinfo(result);
591 if (listen(listen_sock, 1) < 0) { 576 if (listen(listen_sock, 1) < 0) {
592 fatal_error("Failed to listen on GDB remote debugging socket"); 577 fatal_error("Failed to listen on GDB remote debugging socket");
593 } 578 }
594 gdb_sock = accept(listen_sock, NULL, NULL); 579 gdb_sock = accept(listen_sock, NULL, NULL);
595 if (gdb_sock < 0) { 580 if (gdb_sock < 0) {
596 fatal_error("accept returned an error while listening on GDB remote debugging socket"); 581 fatal_error("accept returned an error while listening on GDB remote debugging socket");
597 } 582 }
598 closesocket(listen_sock); 583 socket_close(listen_sock);
599 #else 584 #else
600 disable_stdout_messages(); 585 disable_stdout_messages();
601 #endif 586 #endif
602 } 587 }