The compiler now generates MacsBug function names for debugging

This commit is contained in:
Wolfgang Thaller 2014-09-19 02:11:50 +02:00
parent 58b700e49e
commit fdec31a641
4 changed files with 73 additions and 22 deletions

View File

@ -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;
}
}

View File

@ -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 *);

View File

@ -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"

View File

@ -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)