Re: pointer address is physical or virtual.



Okay, I will post the thing which confussed me.

This is the program i am executing which used instrument-function
facility of GCC.
(it adds two function which are called automatically when any function
begins its execution and exits its execution.)

[Prasad@prasadjoshi test]$ cat instrument_functions.c
#include<stdio.h>

void __cyg_profile_func_enter (void *this_fn, void *call_site)
__attribute__ ((no_instrument_function)) ;
void __cyg_profile_func_exit (void *this_fn, void *call_site)
__attribute__ ((no_instrument_function)) ;

void afun ()
{
printf ( "In afun ().\n" );
}

int main ()
{
int i = 0;
printf ( "In Main.\n" ) ;
afun () ;
i = 10 ;
while (1) ;
}
void __cyg_profile_func_enter (void *this_fn, void *call_site)
{
printf ( "In Entry Function.\t" ) ;
printf ( "Pointer : %p\n", this_fn ) ;
}
void __cyg_profile_func_exit (void *this_fn, void *call_site)
{
printf ( "In Exit Function.\t" ) ;
printf ( "Pointer : %p\n", this_fn ) ;
}
[Prasad@prasadjoshi test]$ gcc instrument_functions.c -o
instrument_functions1 -finstrument-functions
[Prasad@prasadjoshi test]$ gcc instrument_functions.c -o
instrument_functions -finstrument-functions

Created two copies of it for simultaneous execution, ran them from two
different terminals

[Prasad@prasadjoshi test]$ ./instrument_functions
In Entry Function. Pointer : 0x804844e
In Main.
In Entry Function. Pointer : 0x8048414
In afun ().
In Exit Function. Pointer : 0x8048414

[Prasad@prasadjoshi test]$ ./instrument_functions1
In Entry Function. Pointer : 0x804844e
In Main.
In Entry Function. Pointer : 0x8048414
In afun ().
In Exit Function. Pointer : 0x8048414

Now, I am not getting how could these both processes where loaded in
the same memory as they are having same addresses for the functions?

To add to the confussion, i tried with nm utility.
[Prasad@prasadjoshi test]$ nm instrument_functions | grep -i 804844e
0804844e T main
[Prasad@prasadjoshi test]$ nm instrument_functions | grep -i 8048414
08048414 T afun

Now, I am not getting how could the main() and afun() addresses print
by nm utility are same as the one printed by executing process.

So finally I have two questions.
1. Whether addresses printed from user program are virtual one or
physicall one.
( if they are physicall then how could thes two processes are loaded in
same memory).
2. and what nm utility prints ==> virtyal addresses or physicall one.
( i know this is a disk file and whree the program is loaded does not
depend on it but, still. )

Thanks and regards.
Praasd

Hadron wrote:
"Prasad" <prasadjoshi124@xxxxxxxxx> writes:

Hi All,

When we create a pointer o say an integer variable or a function. And
then print it what it should print?

Address in the physical memory where it is stored or virtual address?

Thanks and regards,
Prasad.


It depends on what the reader needs.

You might convert it to text! "Pointer 1 is to the function Foo" for
example.

.



Relevant Pages

  • Re: pointer address is physical or virtual.
    ... begins its execution and exits its execution.) ... void afun ... Pointer: 0x804844e ... physicall one. ...
    (comp.os.linux.development.system)
  • Re: Passing execution to a memory address
    ... execution to this and execute the file. ... You can't assign a void pointer to a function ... Try to use the system function. ... or would the programmer need to put in some assembly code ...
    (comp.lang.c)
  • Re: __builtins__ magic behavior
    ... dictionary to create a weak form of restricted execution" not only ... globals() or with a copy of globals. ... The exec statement, when given a string source, compiles it and eventually calls PyEval_EvalCodeEx, which creates a new frame using PyFrame_New and finally executes it. ... A frame object contains a pointer to the previous frame, the code to be executed, a pointer to the current globals *and* a separate pointer to the current builtins. ...
    (comp.lang.python)
  • Re: Passing execution to a memory address
    ... execution to this and execute the file. ... You can't assign a void pointer to a function ... Try to use the system function. ...
    (comp.lang.c)
  • Re: finding the full path of the program which ran.
    ... generate the call graphs of it, the call graphs should be dynamic. ... To these instrument functions a pointer to ... void afun ... on trying to put executables and writable configuration files in ...
    (comp.unix.programmer)