John <kkxkkx@xxxxxxxxx> 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