comparison gdb_remote.c @ 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).
author Michael Pavone <pavone@retrodev.com>
date Sat, 25 Jul 2015 18:22:07 -0700
parents 483f7e7926a6
children 092524bb2e8f
comparison
equal deleted inserted replaced
791:60686f8d5e48 792:724bbec47f86
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. 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.
5 */ 5 */
6 #include "gdb_remote.h" 6 #include "gdb_remote.h"
7 #include "68kinst.h" 7 #include "68kinst.h"
8 #include "debug.h" 8 #include "debug.h"
9 #include "util.h"
9 #include <unistd.h> 10 #include <unistd.h>
10 #include <fcntl.h> 11 #include <fcntl.h>
11 #include <stddef.h> 12 #include <stddef.h>
12 #include <stdlib.h> 13 #include <stdlib.h>
13 #include <stdio.h> 14 #include <stdio.h>
74 } 75 }
75 76
76 void write_or_die(int fd, const void *buf, size_t count) 77 void write_or_die(int fd, const void *buf, size_t count)
77 { 78 {
78 if (write(fd, buf, count) < count) { 79 if (write(fd, buf, count) < count) {
79 fputs("Error writing to stdout\n", stderr); 80 fatal_error("Error writing to stdout\n");
80 exit(1);
81 } 81 }
82 } 82 }
83 83
84 void gdb_send_command(char * command) 84 void gdb_send_command(char * command)
85 { 85 {
184 if (pc < 0x400000) { 184 if (pc < 0x400000) {
185 pc_ptr = cart + pc/2; 185 pc_ptr = cart + pc/2;
186 } else if(pc > 0xE00000) { 186 } else if(pc > 0xE00000) {
187 pc_ptr = ram + (pc & 0xFFFF)/2; 187 pc_ptr = ram + (pc & 0xFFFF)/2;
188 } else { 188 } else {
189 fprintf(stderr, "Entered gdb remote debugger stub at address %X\n", pc); 189 fatal_error("Entered gdb remote debugger stub at address %X\n", pc);
190 exit(1);
191 } 190 }
192 uint16_t * after_pc = m68k_decode(pc_ptr, &inst, pc & 0xFFFFFF); 191 uint16_t * after_pc = m68k_decode(pc_ptr, &inst, pc & 0xFFFFFF);
193 uint32_t after = pc + (after_pc-pc_ptr)*2; 192 uint32_t after = pc + (after_pc-pc_ptr)*2;
194 193
195 if (inst.op == M68K_RTS) { 194 if (inst.op == M68K_RTS) {
405 if (pc < 0x400000) { 404 if (pc < 0x400000) {
406 pc_ptr = cart + pc/2; 405 pc_ptr = cart + pc/2;
407 } else if(pc > 0xE00000) { 406 } else if(pc > 0xE00000) {
408 pc_ptr = ram + (pc & 0xFFFF)/2; 407 pc_ptr = ram + (pc & 0xFFFF)/2;
409 } else { 408 } else {
410 fprintf(stderr, "Entered gdb remote debugger stub at address %X\n", pc); 409 fatal_error("Entered gdb remote debugger stub at address %X\n", pc);
411 exit(1);
412 } 410 }
413 uint16_t * after_pc = m68k_decode(pc_ptr, &inst, pc & 0xFFFFFF); 411 uint16_t * after_pc = m68k_decode(pc_ptr, &inst, pc & 0xFFFFFF);
414 uint32_t after = pc + (after_pc-pc_ptr)*2; 412 uint32_t after = pc + (after_pc-pc_ptr)*2;
415 413
416 if (inst.op == M68K_RTS) { 414 if (inst.op == M68K_RTS) {
450 goto not_impl; 448 goto not_impl;
451 449
452 } 450 }
453 return; 451 return;
454 not_impl: 452 not_impl:
455 fprintf(stderr, "Command %s is not implemented, exiting...\n", command); 453 fatal_error("Command %s is not implemented, exiting...\n", command);
456 exit(1);
457 } 454 }
458 455
459 m68k_context * gdb_debug_enter(m68k_context * context, uint32_t pc) 456 m68k_context * gdb_debug_enter(m68k_context * context, uint32_t pc)
460 { 457 {
461 dfprintf(stderr, "Entered debugger at address %X\n", pc); 458 dfprintf(stderr, "Entered debugger at address %X\n", pc);
514 //TODO: verify checksum 511 //TODO: verify checksum
515 //Null terminate payload 512 //Null terminate payload
516 *curbuf = 0; 513 *curbuf = 0;
517 //send acknowledgement 514 //send acknowledgement
518 if (write(STDOUT_FILENO, "+", 1) < 1) { 515 if (write(STDOUT_FILENO, "+", 1) < 1) {
519 fputs("Error writing to stdout\n", stderr); 516 fatal_error("Error writing to stdout\n");
520 exit(1);
521 } 517 }
522 gdb_run_command(context, pc, start); 518 gdb_run_command(context, pc, start);
523 curbuf += 2; 519 curbuf += 2;
524 } 520 }
525 } else { 521 } else {