Tip 2. How to Synchronize Processes

If the processes become unsynchronized in the debugging session (for example, if you use the focus command on a subset of the total set and then use a next or some other motion command), the easiest way to get the processes back together is to use a cont to a future location where all processes have to go. The following example shows how the output from processes is not identical because different processes are at different locations in the program. Using the cont to command synchronizes the processes and aggregates the messages.

 

(idb) next

(idb)    [4:5,12] stopped at [int feedbackToDebugger(int, int, char*):17 0x120006bf4]

   [0:3,6:11] [3] stopped at [int feedbackToDebugger(int, int, char*):15 0x120006bf0]

   [4:5,12]      17   int pathSize = 1000;

   [0:3,6:11]      15   int i = 0;

(idb) l

(idb)    [0:3,6:11]      16   char path[1000];

   [4:5,12]      18   char hostname[1000];

   [0:3,6:11]      17   int pathSize = 1000;

   [4:5,12]      19   int hostnameSize = 1000;

   [0:3,6:11]      18   char hostname[1000];

   [4:5,12]      20

   [0:3,6:11]      19   int hostnameSize = 1000;

   [4:5,12]      21   volatile int debuggerAttached = 0;

   [0:3,6:11]      20

   [4:5,12]      22

   [0:3,6:11]      21   volatile int debuggerAttached = 0;

   [4:5,12]      23   gethostname(hostname,hostnameSize);

%3 [0:12]      [22;24]

   [0:3,6:11]      23   gethostname(hostname,hostnameSize);

   [4:5,12]      25   getcwd(path,pathSize);

   [0:3,6:11]      24

   [4:5,12]      26   strcat(path,"/");

   [0:3,6:11]      25   getcwd(path,pathSize);

   [4:5,12]      27   strcat(path,name);

   [0:3,6:11]      26   strcat(path,"/");

   [4:5,12]      28

   [0:3,6:11]      27   strcat(path,name);

   [4:5,12]      29   // Print myid pid into idbAttach.myid

   [0:3,6:11]      28

   [4:5,12]      30   sprintf(filename,"idbAttach.%d",myid);

   [0:3,6:11]      29   // Print myid pid into idbAttach.myid

   [4:5,12]      31   file = fopen(filename,"w");

   [0:3,6:11]      30   sprintf(filename,"idbAttach.%d",myid);

   [4:5,12]      32   if (file == NULL) {

   [0:3,6:11]      31   file = fopen(filename,"w");

   [4:5,12]      33     fprintf(stderr,"smg98: can't open %s for %s\n",filename, "w");

   [0:3,6:11]      32   if (file == NULL) {

   [4:5,12]      34     exit(1)

   [0:3,6:11]      33     fprintf(stderr,"smg98: can't open %s for %s\n",filename, "w");

   [4:5,12]      35   }

   [12]      36   fprintf(file," %ld %ld %s %s\n", myid, getpid(), hostname, path);

   [12]      37   fclose(file);

   [12]      38

   [4:5]      36   fprintf(file," %ld %ld %s %s\n", myid, getpid(), hostname, path);

   [0:3,6:11]      34     exit(1);

   [0:3,6:11]      35   }

   [4:5]      37   fclose(file);

   [0:3,6:11]      36   fprintf(file," %ld %ld %s %s\n", myid, getpid(), hostname, path);

   [4:5]      38

(idb) cont to 36

   [0:13] stopped at [int feedbackToDebugger(int, int, char*):36 0x120006cb8]

   [0:13]      36   fprintf(file," %ld %ld %s %s\n", myid, getpid(), hostname, path);

(idb) next

(idb)    [0:13] stopped at [int feedbackToDebugger(int, int, char*):37 0x120006d0c]

   [0:13]      37   fclose(file);