Processes That Use exec()

Set $catchexecs to 1 to instruct the debugger to stop the process and notify you when an exec occurs. The process stops before executing any user program code or static initializations. You can debug the newly executed process. The debugger keeps a history of the progression of the executed files.

In the following scenario, you set the predefined variables $catchforks and $catchexecs to 1. The debugger will notify you when an execution occurs. Because $catchforks is set, you will also be tracking the child process and, therefore, you will be notified of any exec in the child process.

The following example shows an exec occurring on the current context and the child process stopped on the run-time loader entry point:

 

(idb) set $catchforks = 1

(idb) set $catchexecs = 1

(idb) run

Process 14839 forked.  The child process is 14835.

Process 14835 stopped on fork.

stopped at [int main(void):8 0x1200011f8]

      8   if ((pid = fork()) == 0)

x_exec.c: I am the parent.

Process has exited with status 0

(idb) show process

>localhost:14918 (x_exec) loaded.

 localhost:14835 (x_exec) paused.

(idb) process $childprocess

(idb) list 6:13

      6   int pid;

      7

>     8   if ((pid = fork()) == 0)

      9       {

     10       printf("About to exec \n");

     11       fflush(stdout);  /* Make sure the output gets out! */

     12       execlp("announcer", "announcer", NULL);

     13       printf("After exec \n");

     14       }

     15   else

     16      {

     17       printf("x_exec.c: I am the parent.\n");

     18      }

(idb) cont

About to exec

The process 14835 has execed the image "./announcer".

Reading symbolic information ...done

stopped at [ 0x3ff8001bf48]

      5     printf("announcer.c: I am here!! \n");

 

Note the following: