From fdec31a64153ba2f3cb53bddad2a6ba11e0e9ea4 Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Fri, 19 Sep 2014 02:11:50 +0200 Subject: [PATCH] The compiler now generates MacsBug function names for debugging --- ASFilter/asfilter.cc | 65 ++++++++++++++++++++----------- gcc/gcc/config/m68k/m68k-protos.h | 2 + gcc/gcc/config/m68k/m68k.c | 18 +++++++++ gcc/gcc/config/m68k/m68k.h | 10 +++++ 4 files changed, 73 insertions(+), 22 deletions(-) diff --git a/ASFilter/asfilter.cc b/ASFilter/asfilter.cc index 21accaf264..749ebc293c 100644 --- a/ASFilter/asfilter.cc +++ b/ASFilter/asfilter.cc @@ -68,11 +68,12 @@ int main(int argc, char *argv[]) std::string wordS = "[0-9a-f][0-9a-f][0-9a-f][0-9a-f]"; rx::regex jsr("\tjsr __magic_inline_(" + wordS + "(_" + wordS + ")*)"); rx::regex word(wordS); - //std::regex size("\t\\.size\t([a-zA-Z0-9_]+), \\.-([a-zA-Z0-9_]+)"); - rx::regex globl("\t\\.globl\t([a-zA-Z0-9_]+)"); rx::regex rts("\trts"); - - std::string function_name = "__unknown"; + rx::regex instruction("\t[a-z]+.*"); + rx::regex macsbug("# macsbug symbol"); + + bool hadRts = false; + bool macsbugSymbol = false, macsbugSymbol1; while(in) { std::string line; @@ -80,40 +81,60 @@ int main(int argc, char *argv[]) if(!in) break; + macsbugSymbol1 = false; + rx::smatch match; + // ******* 1. __magic_inline hack for Toolbox calls + // + // PrepareHeaders.hs converts calls to ONEWORDINLINE, TWOWORDINLINE etc. functions + // into "jsr __magic_inline_a123" or "jsr __magic_inline_1234_5678", etc. + // This is converted to a series of dc.w if(rx::regex_match(line, match, jsr)) { - const rx::sregex_token_iterator end; - for (rx::sregex_token_iterator p(line.cbegin(), line.cend(), word); + const rx::sregex_iterator end; + for (rx::sregex_iterator p(line.cbegin(), line.cend(), word); p != end; ++p) { out << "\tdc.w 0x" << *p << std::endl; } } - /*else if(rx::regex_match(line, match, size) && match[1] == match[2]) - { - out << "\tdc.b 0x8e\n"; - out << "\t.string \"" << match[1] << "\"\n"; - out << "\t.align 2\n"; - out << line << std::endl; - }*/ - else if(rx::regex_match(line, match, globl)) + + // ******* 2. strip unneeded extra rts from "# macsbug symbol" paragraphs + // + // GCC is patche to add something like this to the end of every function: + // # macsbug symbol + // rts + // .byte 132 + // .ascii "main" + // .align 2,0 + // .short 0 + // .size main, .-main + // + // The rts is usually redundant as most functions already end in RTS. + // The following removes the RTS if there has already been an RTS immediately before. + else if(rx::regex_match(line, macsbug)) { out << line << std::endl; - function_name = match[1]; + macsbugSymbol1 = true; } - /*else if(rx::regex_match(line, rts)) + else if(rx::regex_match(line, rts)) { + if(!macsbugSymbol || !hadRts) + out << line << std::endl; + hadRts = true; + } + else if(rx::regex_match(line, instruction)) + { + hadRts = false; out << line << std::endl; - out << "\tdc.b 0x8e\n"; - out << "\t.string \"" << function_name << "\"\n"; - out << "\tdc.b 0x00\n"; - out << "\tdc.b 0x00\n"; - out << "\t.align 2\n"; - }*/ + } + + // Pass through everything else. else out << line << std::endl; + + macsbugSymbol = macsbugSymbol1; } } diff --git a/gcc/gcc/config/m68k/m68k-protos.h b/gcc/gcc/config/m68k/m68k-protos.h index df1888628c..fdab475080 100644 --- a/gcc/gcc/config/m68k/m68k-protos.h +++ b/gcc/gcc/config/m68k/m68k-protos.h @@ -100,3 +100,5 @@ extern void init_68881_table (void); extern rtx m68k_legitimize_call_address (rtx); extern rtx m68k_legitimize_sibcall_address (rtx); extern int m68k_hard_regno_rename_ok(unsigned int, unsigned int); + +extern void m68k_write_macsbug_name(FILE *, const char *); diff --git a/gcc/gcc/config/m68k/m68k.c b/gcc/gcc/config/m68k/m68k.c index fe20a87f4b..6e5d5b1547 100644 --- a/gcc/gcc/config/m68k/m68k.c +++ b/gcc/gcc/config/m68k/m68k.c @@ -6563,4 +6563,22 @@ m68k_init_sync_libfuncs (void) init_sync_libfuncs (UNITS_PER_WORD); } +void +m68k_write_macsbug_name(FILE *file, const char *name) +{ + int len = strlen(name); + if(len > 255) + len = 255; + + fprintf(file, "# macsbug symbol\n"); + fprintf(file, "\trts\n"); + if(len < 32) + fprintf(file, "\t.byte %d\n", len | 0x80); + else + fprintf(file, "\t.byte 0x80\n\t.byte %d\n", len); + + ASM_OUTPUT_ASCII(file, name, len); + fprintf(file, "\t.align 2,0\n\t.short 0\n", len); +} + #include "gt-m68k.h" diff --git a/gcc/gcc/config/m68k/m68k.h b/gcc/gcc/config/m68k/m68k.h index 69626486c1..00cb54fd75 100644 --- a/gcc/gcc/config/m68k/m68k.h +++ b/gcc/gcc/config/m68k/m68k.h @@ -986,3 +986,13 @@ extern int m68k_sched_address_bypass_p (rtx, rtx); extern int m68k_sched_indexed_address_bypass_p (rtx, rtx); #define CPU_UNITS_QUERY 1 + +#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \ + do \ + { \ + m68k_write_macsbug_name(FILE, FNAME); \ + if (!flag_inhibit_size_directive) \ + ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME); \ + } \ + while (0) +