Stack usage: nice graphical display similar to memory usage [Imported Thread]
Idea Originally Posted by Dave 20/04/2009
The idea is to have the debugger examine an area of memory, and search from the "end" back for a specific character, and report how far back it got before the character was not found. When compiled with INITIALIZE_STACKS this could be used to report, grap
Comments
15/01/2015 Mark
Ben, you don't need to do that. You can use these to prevent you from having to look at the map file extern uint8_t __stack_start__[]; extern uint8_t __stack_end__[];
09/01/2015 Ben
This would be good but I'm not sure of the implementation. I do this manually by reading the map file to find the stack start and end, do a fill function at the start of the program and then periodically check the change from the fill value to see my usage. But I have to re-do it every time I add something to the program. The compiler knows the stack size and position so could do the fill, the debugger could do the check on a pause fairly simply I'd have thought.
21/07/2009 Jonathan Elliott (Admin)
Ahh, that's much easier. I have a prototype set of tools to monitor stack depth for CTL, our own tasking library, but never really considered the necessity to have a GUI-based display system. I don't think there would be a lot to getting this working.
20/07/2009 Dave
Paul, I don't think we are on the same page here. The implementation I was thinking of is compiler independent. Think of how the 'tasks' window is implemented; the javascript reads a global variable and reports some info to the tasks window. I was thinking this would work the same way, the debugger would simply read a global variable (which happens to be an array of structures) and using that info, reads the stacks, and reports the usage. It is completely up to the developer to populate the global variable with the addresses of the stacks and the fill character. The global variable is an array of structures of the following type: struct MemoryInfo { char* name; // the name of the region as reported in the debugger. char* begin; // the address of the beginning of the memory area char* end; // the address of the end of the memory area char fillchar; // the fill character (or maybe word?) bool topdn; // T if memory fills from the end back, false otherwise } So, the debugger reads the global variable to get, lets say, one of these structures. Now it knows of a region of memory that should contain some fill character. It reads this memory from the end back until the fill character is not found. It now knows how much of the region is 'unused' and can report this with a nice indicator. I think you think I am looking for static analysis of stack depth, which I'm not (besides GCC and lint will do that for me); I'm looking for a debugger-implemented runtime stack checking feature like those implemented some OSs. The advantage of this solution is that it works properly under all conditions (nested interrupts, recursive functions, etc) where static analysis fails. Using this format, you can fill in the data structure with not just the built-in stacks, but with task stacks as well, no matter what OS. For that matter, you can use this same feature to examine how much heap, or any other pool of memory is used, as long as you know it's address and 'fill character' I'm super busy right now but I could probably implement this completely in the threads.js file (it would obviously just report the % it would not have the nice graphical display).
13/07/2009 Jonathan Elliott (Admin)
Ok, we've considered this for GCC and non-GCC compilers. In a way, it's easier with our own compilers because the stack adjustment is known on each instruction of a C-compiled file. For GCC, it seems that we need to run a static analysis of each function's code in order to glean this. In short, it's possible to do, but it will take a lot of effort.
Please sign in to leave a comment.
Comments
0 comments