From: Tim Wescott on 11 May 2010 14:27 Grant Edwards wrote: > On 2010-05-11, John Speth <johnspeth(a)yahoo.com> wrote: >>>> What is the GCC method for getting the stack top and bottom pointers at >>>> runtime? >>> The first place that I'd look would be the linker command file >>> (something_or_other.ld) -- if you're lucky they'll be called something >>> like __stack_top and __stack_bottom. Failing that, look in the map file >>> from your link for things called "stack". Failing that, grep. >> You're right but it needs to be a run time operation. > > Oh for pete's sake: > > > extern char __stack_top, __stack_bottom; > > > [...] > > printf("Stack top = %p, bottom = %p\n",&__stack_top,&__stack_bottom); Pete has a lot to answer for. -- Tim Wescott Control system and signal processing consulting www.wescottdesign.com
From: Tim Wescott on 11 May 2010 14:29 John Speth wrote: >>> What is the GCC method for getting the stack top and bottom pointers at >>> runtime? > >> The first place that I'd look would be the linker command file >> (something_or_other.ld) -- if you're lucky they'll be called something >> like __stack_top and __stack_bottom. Failing that, look in the map file >> from your link for things called "stack". Failing that, grep. > > You're right but it needs to be a run time operation. Do you mean you need to know the limits at run time, or that you need to know how much of the stack is used at run time? If it's the former, see Grant's response. If it's the latter, then fill the stack with all zeros, or 0xDEADBEEF, or something, and test for how much is overwritten when you need to know how much of the stack's been used. -- Tim Wescott Control system and signal processing consulting www.wescottdesign.com
From: John Speth on 11 May 2010 15:24 >>>> What is the GCC method for getting the stack top and bottom pointers at >>>> runtime? >> >>> The first place that I'd look would be the linker command file >>> (something_or_other.ld) -- if you're lucky they'll be called something >>> like __stack_top and __stack_bottom. Failing that, look in the map file >>> from your link for things called "stack". Failing that, grep. >> >> You're right but it needs to be a run time operation. > > Do you mean you need to know the limits at run time, or that you need to > know how much of the stack is used at run time? > > If it's the former, see Grant's response. > > If it's the latter, then fill the stack with all zeros, or 0xDEADBEEF, or > something, and test for how much is overwritten when you need to know how > much of the stack's been used. It's the latter. My problem is NOT the mechanics of filling the stack and reading it to uncover used stack. My problem is how to identify the stack start and end in my C code. There's a simple solution that eludes me. I'm hoping somebody just knows. Google doesn't seem to give it up. The map file has two likely variables that I read (__alt_stack_base and __alt_stack_limit) but they both evaluate to 0. The code compiles and links without errors: extern int __alt_stack_base; extern int __alt_stack_limit; printf("%08X %08X\n",__alt_stack_base,__alt_stack_limit); John Speth --- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: D Yuniskis on 11 May 2010 16:08 Hi John, John Speth wrote: > I'm building a NIOS2 project which uses GCC tools and I'd like to write a C > function that needs to know the stack top and stack bottom pointers at > runtime. > > What is the GCC method for getting the stack top and bottom pointers at > runtime? What is your goal? Do you want to know how much stack has been set aside by the linkage editor for your application? Or, do you want to know how much of that you are actually *using* (in various contexts)? Presumably, your OS doesn't dynamically grow the stack to fit your needs?
From: Grant Edwards on 11 May 2010 16:02 On 2010-05-11, John Speth <johnspeth(a)yahoo.com> wrote: >>>>> What is the GCC method for getting the stack top and bottom pointers at >>>>> runtime? >>> >>>> The first place that I'd look would be the linker command file >>>> (something_or_other.ld) -- if you're lucky they'll be called something >>>> like __stack_top and __stack_bottom. Failing that, look in the map file >>>> from your link for things called "stack". Failing that, grep. >>> >>> You're right but it needs to be a run time operation. >> >> Do you mean you need to know the limits at run time, or that you need to >> know how much of the stack is used at run time? >> >> If it's the former, see Grant's response. >> >> If it's the latter, then fill the stack with all zeros, or 0xDEADBEEF, or >> something, and test for how much is overwritten when you need to know how >> much of the stack's been used. > > It's the latter. My problem is NOT the mechanics of filling the stack and > reading it to uncover used stack. My problem is how to identify the stack > start and end in my C code. Then that's the "former", not the "latter". > There's a simple solution that eludes me. I'm hoping somebody just > knows. Google doesn't seem to give it up. > > The map file has two likely variables that I read (__alt_stack_base and > __alt_stack_limit) but they both evaluate to 0. The code compiles and links > without errors: > > extern int __alt_stack_base; > extern int __alt_stack_limit; > printf("%08X %08X\n",__alt_stack_base,__alt_stack_limit); As I posted earlier, try this: extern char __alt_stack_base, __alt_stack_limit; printf("%p %p\n", &__alt_stack_base, &__alt_stack_limit; -- Grant Edwards grant.b.edwards Yow! Somewhere in Tenafly, at New Jersey, a chiropractor gmail.com is viewing "Leave it to Beaver"!
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Seeking TAS151 Manual desperately Next: How to find memory data width (x16 or x32?) |