diff 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
line wrap: on
line diff
--- a/gdb_remote.c	Sat Jul 25 18:19:00 2015 -0700
+++ b/gdb_remote.c	Sat Jul 25 18:22:07 2015 -0700
@@ -6,6 +6,7 @@
 #include "gdb_remote.h"
 #include "68kinst.h"
 #include "debug.h"
+#include "util.h"
 #include <unistd.h>
 #include <fcntl.h>
 #include <stddef.h>
@@ -76,8 +77,7 @@
 void write_or_die(int fd, const void *buf, size_t count)
 {
 	if (write(fd, buf, count) < count) {
-		fputs("Error writing to stdout\n", stderr);
-		exit(1);
+		fatal_error("Error writing to stdout\n");
 	}
 }
 
@@ -186,8 +186,7 @@
 		} else if(pc > 0xE00000) {
 			pc_ptr = ram + (pc & 0xFFFF)/2;
 		} else {
-			fprintf(stderr, "Entered gdb remote debugger stub at address %X\n", pc);
-			exit(1);
+			fatal_error("Entered gdb remote debugger stub at address %X\n", pc);
 		}
 		uint16_t * after_pc = m68k_decode(pc_ptr, &inst, pc & 0xFFFFFF);
 		uint32_t after = pc + (after_pc-pc_ptr)*2;
@@ -407,8 +406,7 @@
 				} else if(pc > 0xE00000) {
 					pc_ptr = ram + (pc & 0xFFFF)/2;
 				} else {
-					fprintf(stderr, "Entered gdb remote debugger stub at address %X\n", pc);
-					exit(1);
+					fatal_error("Entered gdb remote debugger stub at address %X\n", pc);
 				}
 				uint16_t * after_pc = m68k_decode(pc_ptr, &inst, pc & 0xFFFFFF);
 				uint32_t after = pc + (after_pc-pc_ptr)*2;
@@ -452,8 +450,7 @@
 	}
 	return;
 not_impl:
-	fprintf(stderr, "Command %s is not implemented, exiting...\n", command);
-	exit(1);
+	fatal_error("Command %s is not implemented, exiting...\n", command);
 }
 
 m68k_context *  gdb_debug_enter(m68k_context * context, uint32_t pc)
@@ -516,8 +513,7 @@
 						*curbuf = 0;
 						//send acknowledgement
 						if (write(STDOUT_FILENO, "+", 1) < 1) {
-							fputs("Error writing to stdout\n", stderr);
-							exit(1);
+							fatal_error("Error writing to stdout\n");
 						}
 						gdb_run_command(context, pc, start);
 						curbuf += 2;