This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: How to modify GCC so to insert some code for debug?
- From: Ian Lance Taylor <iant at google dot com>
- To: John <kkxkkx at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: 23 Mar 2007 09:20:34 -0700
- Subject: Re: How to modify GCC so to insert some code for debug?
- References: <2311f6f10703230638g3e1c12c9rf5526f86146eaa@mail.gmail.com>
John <kkxkkx@gmail.com> writes:
> I use GCC to compile the code that runs in a very resouse-limited embed system,
> so I can't use the usual debug tools, such as GDB. And there are thousands of
> lagacy code already, in which there is no debug code, sth like
> PRINT(__FILE__, __LINE__).
>
> So I want to modify the GCC to meet the requirement below:
> 1. In each funtion entry and exit, print out some info, such as the
> funtion name, time, etc.
Look at the profiling support enabled by -pg, which does something
similar at function entry. It inserts a call to _mcount.
> 2. Before each loop(for/while/until) and branch selection, print out
> the condition info.
> For exmaple:
> for(i = ...) while(j < ...), if(i > ...), print out the value of i.
Painful but possible.
> 3. More advanced, when a variable is accessed, its value is printed.
> Like the watch command in GDB.
Look at the -fmudflap support.
> Could some gurus give me some suggestions? Such as is there a project
> aimed at this? How long/difficult
> does it take if I make it from scratch?
I don't know of anybody trying these ideas, because the result is
going to run quite slowly. You might want to look into setting up a
gdb stub as described in the gdb manual, and using the remote
protocol. I've successfully used gdb on resource constrainted
embedded systems that way. It's not easy to set up, but it's much
much simpler than changing the compiler as you propose.
Ian