[Top][All Lists]

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

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

From: Jared Maddox
Subject: Re: [Tinycc-devel] Creating a debugger for my own language, in TinyCC?
Date: Mon, 5 Jan 2015 16:47:26 -0600

> Date: Sun, 4 Jan 2015 21:03:33 +0000
> From: John Smith <address@hidden>
> To: address@hidden
> Subject: [Tinycc-devel] Creating a debugger for my own language, in
>         TinyCC?
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=us-ascii
> 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 guess the question really simply is...
>         Q: How easy is it, to get from the stack pointer, to the local
>            variables... in TinyCC?

If debugger information is available (I simply don't recall) then you
could open that particular section (note that every OS has a different
procedure for this) and parse it for the info that you want.

Otherwise, TinyCC doesn't currently support anything noteworthy on this subject.

> That is... do they exist in a very simple and predictable format? Pretty much
> starting 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"?

Your language is going to be in complete control of the whole process,
correct? In that case, I suggest the following:

1) Add a global variable named something like "debug".

2) When a "piece" of translated code has been compiled, call a
specially inserted "debug-init" function that calls EVERY function
once for the singular purpose of allowing functions to initialize
their own debug information structure(s). Variable locations are an
obvious thing to include, but so are e.g. label addresses. Note: this
can later be expanded to implement "sleep to disk" behaviors.

3) Allow normal access to that piece of compiled code, as the needed
debug info is now available.

The best thing about this particular option is that it should work on
any compiler with relatively minor modifications (you could also make
a first pass with TCC, start execution immediately, use GCC to produce
an optimized dynamic library version, load that version, pause
execution of the TCC version, transfer the data from the TCC version
to the GCC version, and resume execution inside the GCC version).

reply via email to

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