![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Heap and stack | naan | High Level Programming | 5 | 04-29-2008 11:40 PM |
| what is stack winding and stack unwinding | amitpansuria | High Level Programming | 2 | 08-07-2007 02:46 PM |
| get stack trace from C program on Solaris 8 | rydahl | Filesystems, Disks and Memory | 4 | 03-23-2007 10:53 AM |
| stack region | yakari | UNIX for Advanced & Expert Users | 2 | 12-29-2006 06:34 AM |
| finding duplicate files by size and finding pattern matching and its count | jerome Sukumar | Shell Programming and Scripting | 2 | 12-01-2006 01:20 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
finding stack location in C using program
Is there a way to find the address of stack memory writing a program? Please guide me
|
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
If the general area will do, you can just take the address of a local variable.
If you want the stack pointer itself, you can get that through assembly language. If you need the top of it, on my system at least, it counts down from one system page less than the highest address. Depending on your system, you might be able to see the memory arrangement by processing /proc/<processid>/maps. |
|
#3
|
|||
|
|||
|
What i am doing is the following...
#include<stdio.h> //#include<conio.h> Last edited by jacques83; 10-21-2006 at 09:07 PM. |
|
#4
|
|||
|
|||
|
Debuggers like gdb (assuming you are on Linux) will show you all of the stack in either a core dump or a running program.
If you are on Linux, the source code for va_start() and va_arg() (part of stdarg.h) will show you how to walk the current stack frame. The same is true for other compilers that are open source. Note that each implmentation of this is specific to the hardware it runs on. There is no "general" solution. /proc/<pid>/maps is very much your friend as Corona says... |
|
#5
|
|||
|
|||
|
Quote:
In some configurations, the stack won't overflow, it will just grow indefinitely, which case an infinite recursion will bring down the entire system instead of crashing. On some compilers, an infinite recursion will be optimized into an infinite loop, which will just sit there and do nothing forever. In general, one never tries to make his own program crash on purpose. That's for actual errors. To get the maximum stack size, see 'man getrlimit'. To get the starting stack position, if you are on linux, take a look at /proc/<pid>/maps like I already suggested. |
|
#6
|
|||
|
|||
|
Hi,
But in my case, I am getting a list of around a couple of thousand or nore addresses, and then an eventual segmentation fault. I am running my program on linux. Isnt this a possible way? I am not allowed to use any system command, and am supposed to report my findings obtained empirically. Please comment... |
|
#7
|
|||
|
|||
|
Quote:
Quote:
Quote:
|
|||
| Google The UNIX and Linux Forums |