Checking the Memory regions

N

new

Hi Experts,
How can I check the memory regions occupied by the c program in gcc
compiler?
Any commands?
My intention is to check for the variables defined in the
program,whether it is in text,data,stack or heap regions.

Thanks for the help.
 
K

Kenny McCormack

Hi Experts,
How can I check the memory regions occupied by the c program in gcc
compiler?
Any commands?
My intention is to check for the variables defined in the
program,whether it is in text,data,stack or heap regions.

Thanks for the help.

Beavis/Butthead: He said the "S" word. Har har har.
 
B

Ben Bacarisse

new said:
Hi Experts,
How can I check the memory regions occupied by the c program in gcc
compiler?
Any commands?
My intention is to check for the variables defined in the
program,whether it is in text,data,stack or heap regions.

....or nowhere.

This is a system-specific question and you will get better help is
group discusses the tools you use. For example, if you use a
unix-like system, comp.unix.programmer can tell you all about programs
like nm that let you see what the compiler has done with your
program. There are similar active groups for Windows programming.
 
N

new

...or nowhere.

This is a system-specific question and you will get better help is
group discusses the tools you use.  For example, if you use a
unix-like system, comp.unix.programmer can tell you all about programs
like nm that let you see what the compiler has done with your
program.  There are similar active groups for Windows programming.

Am trying to find out in Linux machine
 
K

Keith Thompson

new said:
Am trying to find out in Linux machine

Then try comp.unix.programmer. If your question turns out to be
Linux-specific, they can direct you to a Linux newsgroup.
 
K

kid joe

Am trying to find out in Linux machine

Hi new,

You can use nm to find out about variables compiled into your object file
(static/global variables) as Ben said.

At runtime, of course malloc()d variables will be on the heap, local
variables on the stack. One way is to use gdb and set a breakpoint. You
can then type "info frame" to find out the current program counter and
where the locals start. The stack grows down, so look at the address
of the variable youre interested in. If its just below the "locals at"
address from "info frame", its on the stack. If its a much much lower
memory address then its on the heap.

Cheers,
Joe
 
F

Flash Gordon

kid said:
Hi new,

You can use nm to find out about variables compiled into your object file
(static/global variables) as Ben said.

At runtime, of course malloc()d variables will be on the heap, local
variables on the stack.

That is inaccurate. Often local variables are only in a register on some
processors.
One way is to use gdb and set a breakpoint. You
can then type "info frame" to find out the current program counter and
where the locals start. The stack grows down, so look at the address
of the variable youre interested in. If its just below the "locals at"
address from "info frame", its on the stack. If its a much much lower
memory address then its on the heap.

Have you checked on all of the processors Linux have been ported to? No,
I thought not.

As Ben said, finding a system specific news group (either one of the gnu
ones, a linux one, or comp.unix.programmer would be better.
 
C

cr88192

Flash Gordon said:
That is inaccurate. Often local variables are only in a register on some
processors.


Have you checked on all of the processors Linux have been ported to? No, I
thought not.

As Ben said, finding a system specific news group (either one of the gnu
ones, a linux one, or comp.unix.programmer would be better.


FWIW, it is almost assured that whatever the OP is using is probably x86, or
maybe x86-64...
other possibilities are sufficiently unlikely as to be assumed, by default,
not to be the case.

(or... maybe... one can start making a fuss that these groups are not easily
accessible to non-English speakers... and the illiterate...).


thus, there is no need to use that sort of attitude when responding...

 
J

James Dow Allen

Flash Gordon said:
kid said:
On Thu, 28 May 2009 08:01:11 -0700, new wrote:
Hi Experts,
Am trying to find out in Linux machine
Hi new,
You can use nm ...
That is inaccurate. ... on some
processors.
Have you checked on all of the processors Linux
have[sic] been ported to? No, I
thought not.

FWIW, it is almost assured that whatever the OP is
using is probably x86, or maybe x86-64...
other possibilities are sufficiently unlikely as to be
assumed, by default, not to be the case.

Note moreover, that the chance OP is not using
x86 is even smaller than the (small) a priori chance.
This is because even a relatively naive user would
be aware any non-x86 machine is somewhat "unusual"
and therefore would have mentioned it.

In the (unlikely) event that further evidence were
needed of excessive pedantry in c.l.c, these continual
topicality debates would prove it!

Although in this case c.u.p might be a good bet,
some of the ng recommendations here are often absurd,
of a ng with a name that makes it appear topical
but which is actually devoted to discussions about
sodomizing pigs, or some such.

James
 
F

Flash Gordon

cr88192 said:
FWIW, it is almost assured that whatever the OP is using is probably x86, or
maybe x86-64...
other possibilities are sufficiently unlikely as to be assumed, by default,
not to be the case.

I agree that it is the most likely, but it is by no means the only
processor hobiest are using Linux on. It is also used in the old non-x86
Macs and the last time I checked the TiVo (for which there certainly
used to be a large hacking community).
(or... maybe... one can start making a fuss that these groups are not easily
accessible to non-English speakers... and the illiterate...).

I do not see what that has got to do with it.
thus, there is no need to use that sort of attitude when responding...

The post did not says something like, "on the x86 which you are probably
using..." and was also in direct response to a post which suggested a
more appropriate group for the discussion. So I do think that pointing
out that not all the world is an x86 and that more appropriate groups
had been suggested was appropriate.
 
K

Kenny McCormack

James Dow Allen said:
Although in this case c.u.p might be a good bet,
some of the ng recommendations here are often absurd,
of a ng with a name that makes it appear topical
but which is actually devoted to discussions about
sodomizing pigs, or some such.

Kewl!

Note that this is true of CLC itself, as well.

I.e., although a superficial analysis might conclude that this is
a newsgroup for dicussion of C programming, in fact, nothing could be
further from the truth. Any discussion of real C programming is, of
course, off-topic - and will draw a quick rebuke from those in control.
But discussions of just about everything and anything else, such as
Fortran compilers, PL/1 compilers, Shakespeare, English history, the
correct and proper term to use to refer to residents of the United
States of America, dirty underwear, data structures (Just make sure to
avoid using the "S word" when doing so!), the histories (and relative
market shares over time) of computer companies, and so on, is all OK and
will get nary a comment from the "mods".
 
K

Kenny McCormack

cr88192 said:
FWIW, it is almost assured that whatever the OP is using is probably
x86, or maybe x86-64... other possibilities are sufficiently unlikely
as to be assumed, by default, not to be the case.

Indeed. Quite.
(or... maybe... one can start making a fuss that these groups are not
easily accessible to non-English speakers... and the illiterate...).

Not quite sure what you mean by this.
thus, there is no need to use that sort of attitude when responding...

It's what they live for. For many of them, it is quite literally, their
only reason to get out of bed each day.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top