From 688b546281869f7e360381723c211edd44fd2212 Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Wed, 6 Jun 2018 21:37:19 -0400 Subject: [PATCH] Added debug support for M2-Planet output --- CHANGELOG.org | 3 + cc.c | 17 ++- test/common_x86/ELF-i386-debug.hex2 | 216 ++++++++++++++++++++++++++++ test/test.answers | 8 +- test/test100/proof.answer | 2 +- test/test21/cleanup.sh | 1 + test/test21/hello.sh | 20 ++- test/test21/stub.h | 31 ++++ test/test22/cleanup.sh | 1 + test/test22/hello.sh | 22 +-- test/test22/proof.answer | 2 +- test/test22/stub.h | 33 +++++ test/test23/cleanup.sh | 1 + test/test23/hello.sh | 20 ++- 14 files changed, 344 insertions(+), 33 deletions(-) create mode 100644 test/common_x86/ELF-i386-debug.hex2 create mode 100644 test/test21/stub.h create mode 100644 test/test22/stub.h diff --git a/CHANGELOG.org b/CHANGELOG.org index 7f5f6dd..388aac9 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -35,6 +35,7 @@ Added Blood-elf test Added Hex2_linker test Added M1-macro test Added prototypes to allow functions to be independently built +Added support for debug format output to help debugging ** Changed Improving Documentation to help new programmers get functional @@ -43,6 +44,8 @@ Enabled stand alone builds of calloc Unified bitwise operations Made string.c more independent Created a M1-macro stub file to simplify independent builds +Created a hex2_linker stub file to simplify independent builds +Created a blood-elf stub file to simplify independent builds ** Fixed Minor cleanup and removal of unneeded whitespace diff --git a/cc.c b/cc.c index 62a23cf..1c9cb87 100644 --- a/cc.c +++ b/cc.c @@ -31,6 +31,7 @@ char* parse_string(char* string); int main(int argc, char** argv) { + int DEBUG = FALSE; FILE* in = stdin; FILE* destination_file = stdout; int i = 1; @@ -40,7 +41,7 @@ int main(int argc, char** argv) { i = i + 1; } - else if(match(argv[i], "-f")) + else if(match(argv[i], "-f") || match(argv[i], "--file")) { char* name = argv[i + 1]; in = fopen(name, "r"); @@ -54,7 +55,7 @@ int main(int argc, char** argv) global_token = read_all_tokens(in, global_token, name); i = i + 2; } - else if(match(argv[i], "-o")) + else if(match(argv[i], "-o") || match(argv[i], "--output")) { destination_file = fopen(argv[i + 1], "w"); if(NULL == destination_file) @@ -66,12 +67,17 @@ int main(int argc, char** argv) } i = i + 2; } - else if(match(argv[i], "--help")) + else if(match(argv[i], "-g") || match(argv[i], "--debug")) + { + DEBUG = TRUE; + i = i + 1; + } + else if(match(argv[i], "-h") || match(argv[i], "--help")) { file_print(" -f input file\x0A -o output file\x0A --help for this message\x0A --version for file version\x0A", stdout); exit(EXIT_SUCCESS); } - else if(match(argv[i], "--version")) + else if(match(argv[i], "-V") || match(argv[i], "--version")) { file_print("Basic test version 0.0.0.1a\x0A", stderr); exit(EXIT_SUCCESS); @@ -102,10 +108,11 @@ int main(int argc, char** argv) /* Output the program we have compiled */ file_print("\n# Core program\n\n", destination_file); recursive_output(output_list, destination_file); + if(DEBUG) file_print("\n:ELF_data\n", destination_file); file_print("\n# Program global variables\n\n", destination_file); recursive_output(globals_list, destination_file); file_print("\n# Program strings\n\n", destination_file); recursive_output(strings_list, destination_file); - file_print("\n:ELF_end\n", destination_file); + if(!DEBUG) file_print("\n:ELF_end\n", destination_file); return EXIT_SUCCESS; } diff --git a/test/common_x86/ELF-i386-debug.hex2 b/test/common_x86/ELF-i386-debug.hex2 new file mode 100644 index 0000000..6149932 --- /dev/null +++ b/test/common_x86/ELF-i386-debug.hex2 @@ -0,0 +1,216 @@ +### Copyright (C) 2016 Jeremiah Orians +### Copyright (C) 2017 Jan Nieuwenhuizen +### This file is part of stage0. +### +### stage0 is free software: you an redistribute it and/or modify +### it under the terms of the GNU General Public License as published by +### the Free Software Foundation, either version 3 of the License, or +### (at your option) any later version. +### +### stage0 is distributed in the hope that it will be useful, +### but WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with stage0. If not, see . + +### stage0's hex2 format for x86 +### !