Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Function call tracing

Function call tracing

2011-01-15 by Chuck Hackett

While I was tracking down my 'clobbered stack' problem I implemented a couple of
function Enter/Exit macros that I placed in functions in an effort to isolate
exactly where the problem was occurring.

On entry I reported the function name as well as the stack pointer, on exit I just
reported that I was exiting "xyz".

I used the __func__ compiler symbol which worked fine, except, as far as I can tell
WinAVR insists on placing the function name in SRAM space as opposed to program
space and I am way shorter on SRAM space than I am on program space (ATMega32).

Is there a way to have WinAVR put the name in program space?  (without me having to
retype each name ...)

Is there another facility I should use?

As I type this, it occurred to me that I might be able to write a preprocessor macro
(w/variable args) that could wrap function declarations and returns.  For some
reason it strikes me as not a good idea.  Might it screw up readability,
'lint'/re-formatters, or confuse the IDE editor (Code::Blocks)?

I suppose another option would be a utility that knew how to parse C and add the
program-space function name as a function-scope variable for me ...

Or, maybe I should just hope I never have to do that again :-)
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844 http://www.whitetrout.net/Chuck

Re: Function call tracing

2011-01-15 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, "Chuck Hackett" <egroupscdh@...> wrote:
> I used the __func__ compiler symbol which worked fine, except,
> as far as I can tell WinAVR insists on placing the function
> name in SRAM space as opposed to program space [...]
Yes, all constant strings are RAM-based unless you specify otherwise.  The PSTR() macro defines a string residing in program space, e.g.

PSTR(__func__)

Of course, your code will need to be modified to read the string's characters from Flash, too.

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

RE: [AVR-Chat] Re: Function call tracing

2011-01-15 by Chuck Hackett

> From: Don Kinzer
> ....
> --- In AVR-Chat@yahoogroups.com, "Chuck Hackett" <egroupscdh@...> wrote:
> > I used the __func__ compiler symbol which worked fine, except,
> > as far as I can tell WinAVR insists on placing the function
> > name in SRAM space as opposed to program space [...]
>
> Yes, all constant strings are RAM-based unless you specify otherwise.  The
> PSTR() macro defines a string residing in program space, e.g.
> 
> PSTR(__func__)

All I can say is "Dah, why didn't I think of that ..." - sometimes one gets so
caught up in the details that one forgets the simple stuff ...

> Of course, your code will need to be modified to read the string's characters
> from Flash, too.

Yup, no problem there ...

Thanks again ...
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844 http://www.whitetrout.net/Chuck

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.