tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Creating a debugger for my own language, in TinyCC?


From: John Smith
Subject: [Tinycc-devel] Creating a debugger for my own language, in TinyCC?
Date: Sun, 4 Jan 2015 21:03:33 +0000

Hi people...

Is it possible to create a debugger, for my own (Secret) programming language 
using TinyCC?

I'll spare you the long details (unless you need it)...

but here goes as short as I can...

So... let's imagine... I'm converting high-level code into C code.

Then... in this C code... I want to insert 2 functions... into every 
"translated function"

        DB_GetStackPointer(int)
        DB_Line(int)

So... 

function Func(MyStringArray) {
    for (S in MyStringArray) {
        print_line S
    }
}

        -->

void Func(Type1* self, Type2* MyStringArray) {
   DB_GetStackPointer(1); // "DB_" means its a function for debugging the code
                          // So we save the current stack pointer to a global 
variable
                          // and tell the debugger that we are on line 1 of the 
current file's source code.
   int N = 0;
   while (N < length(MyStringArray)) {
       Type3* S = element(MyStringArray, N);
       DB_Line(2);        // Tell the debugger that we have advanced to line 2 
of our *original* source code.
       N++;
    };
    DB_Line(3);
}

All I need to do then... is implement DB_Line and DB_GetStackPointer. The idea 
is that DB_GetStackPointer will save the current stack pointer... and DB_Line 
will go to a func that lets me read the current variables off that stack 
pointer, and then send them via a socket/TCP-connection... to my debugger.

I tried something like this using __builtin_frame_address from Xcode... but the 
variables did not exist in a reliable location, relative to the stack pointer, 
even in debug builds...

I guess the question really simply is...


        Q: How easy is it, to get from the stack pointer, to the local 
variables... in TinyCC?

That is... do they exist in a very simple and predictable format? Pretty much 
starting from from function params... then going to any local variables still 
in scope? And simply listing them in order?

If so... perhaps I could use TinyCC for my project...

        Q: Or perhaps you have some better way of "scraping local variables" 
out of a "calling parent function"?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]