public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to get LD_DEBUG of forked process
@ 2012-10-11  6:30 Ajeet Yadav
  2012-10-11 17:04 ` David Daney
  0 siblings, 1 reply; 3+ messages in thread
From: Ajeet Yadav @ 2012-10-11  6:30 UTC (permalink / raw)
  To: gcc-help

Dear All,
I wish to check the the LD_DEBUG=reloc for both parent and child process.

Code of parent process p1, that is forking the child process p2
[ajeet_y@localhost ajeet]$ cat main1.c
#include <stdio.h>
#include <unistd.h>
int main()
{
        pid_t pid;
        printf("In P1\n");
        pid = fork();
        if (pid){
                sleep(1);
        } else {
                execve("./p2",NULL,NULL);
        }
}

Code of the child process p2
[ajeet_y@localhost ajeet]$ cat main2.c
#include <stdio.h>
int main()
{
        printf("In P2\n");
}

[ajeet_y@localhost ajeet]$ gcc main1.c -o p1
[ajeet_y@localhost ajeet]$ gcc main2.c -o p2

When I run it normally
[ajeet_y@localhost ajeet]$ ./p1
In P1
In P2


Now when I run it with LD_DEBUG=reloc, I get relocation information of p1 only
[ajeet_y@localhost ajeet]$ export LD_DEBUG=reloc
[ajeet_y@localhost ajeet]$ ./p1
     12259:
     12259:     relocation processing: /lib/libc.so.6
     12259:
     12259:     relocation processing: ./p1 (lazy)
     12259:
     12259:     relocation processing: /lib/ld-linux.so.2
     12259:
     12259:     calling init: /lib/libc.so.6
     12259:
     12259:
     12259:     initialize program: ./p1
     12259:
     12259:
     12259:     transferring control: ./p1
     12259:
In P1
In P2
     12259:
     12259:     calling fini: ./p1 [0]
     12259:
     12259:
     12259:     calling fini: /lib/libc.so.6 [0]
     12259:
[ajeet_y@localhost ajeet]$ unset LD_DEBUG


Can anyone help me why I am not getting the relocation information of
process P2, and how to get it ?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to get LD_DEBUG of forked process
  2012-10-11  6:30 How to get LD_DEBUG of forked process Ajeet Yadav
@ 2012-10-11 17:04 ` David Daney
  2012-10-12  4:37   ` Ajeet Yadav
  0 siblings, 1 reply; 3+ messages in thread
From: David Daney @ 2012-10-11 17:04 UTC (permalink / raw)
  To: Ajeet Yadav, gcc-help

On 10/10/2012 11:30 PM, Ajeet Yadav wrote:
> Dear All,
> I wish to check the the LD_DEBUG=reloc for both parent and child process.
>
> Code of parent process p1, that is forking the child process p2
> [ajeet_y@localhost ajeet]$ cat main1.c
> #include <stdio.h>
> #include <unistd.h>
> int main()
> {
>          pid_t pid;
>          printf("In P1\n");
>          pid = fork();
>          if (pid){
>                  sleep(1);
>          } else {
>                  execve("./p2",NULL,NULL);

Here you completely replace the Environment of the process execing p2.

>          }
> }
[...]

>
>
> Can anyone help me why I am not getting the relocation information of
> process P2,

You are not getting the LD_DEBUG=reloc information because that 
environment variable is not set in P2 due to your elimination of the 
entire environment.

>  and how to get it ?

Pass LD_DEBUG=reloc in the environment of any process for which you wish 
to see the dumps.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to get LD_DEBUG of forked process
  2012-10-11 17:04 ` David Daney
@ 2012-10-12  4:37   ` Ajeet Yadav
  0 siblings, 0 replies; 3+ messages in thread
From: Ajeet Yadav @ 2012-10-12  4:37 UTC (permalink / raw)
  To: David Daney; +Cc: gcc-help

On Thu, Oct 11, 2012 at 10:33 PM, David Daney <ddaney.cavm@gmail.com> wrote:
> On 10/10/2012 11:30 PM, Ajeet Yadav wrote:
>>
>> Dear All,
>> I wish to check the the LD_DEBUG=reloc for both parent and child process.
>>
>> Code of parent process p1, that is forking the child process p2
>> [ajeet_y@localhost ajeet]$ cat main1.c
>> #include <stdio.h>
>> #include <unistd.h>
>> int main()
>> {
>>          pid_t pid;
>>          printf("In P1\n");
>>          pid = fork();
>>          if (pid){
>>                  sleep(1);
>>          } else {
>>                  execve("./p2",NULL,NULL);
>
>
> Here you completely replace the Environment of the process execing p2.
>
>>          }
>> }
>
> [...]
>
>
>>
>>
>> Can anyone help me why I am not getting the relocation information of
>> process P2,
>
>
> You are not getting the LD_DEBUG=reloc information because that environment
> variable is not set in P2 due to your elimination of the entire environment.
>
>
>>  and how to get it ?
>
>
> Pass LD_DEBUG=reloc in the environment of any process for which you wish to
> see the dumps.
>
Thanks, I did the same with system("p2") in this case I get the
LD_DEBUG=reloc information for both, knowing that system() works, I
checked its fork:exec implementation. As you suggested, I did
execve("./p2", NULL, __environ), in this case also I did not get p2
information, finally I did

char *argv={"./p2",NULL};
execve("./p2", argv, __environ); now this works perfect.

3 arg is mandatory, but I did not understand, Why I need to pass 2nd arg ?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-10-12  4:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-11  6:30 How to get LD_DEBUG of forked process Ajeet Yadav
2012-10-11 17:04 ` David Daney
2012-10-12  4:37   ` Ajeet Yadav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).