Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Why there are two implementations related to getGDBProcess() method in MIProcessAdapter class

Hi all,

I am migrating our existing debug launch configuration which internally
uses MIProcessAdapter.


My doubts are as follows :-


1. I found two different implementations for the method getGDBProcess() in
MIProcessAdapter() class. So, why there are two implementations ? Which one
is called when.
2.  I checked out the code from CDT 6 branch, it has the code which uses
thread but when I executed this plugin , then the method called is one
which is not the threaded. Why is it happening so ? When I looked at the
package names for each of them. They both are shown same.
3. The threaded one is much faster than the non-threaded one. And it seems
in earliar cdt version i.e. CDT 4, the threaded one was called. But as I
mentioned in my #2 question that when I tested with CDT 6, then the
non-threaded one is getting called. So, now which one is the latest code.
If it is non-threaded one then why the threaded one is replaced by
non-threaded as non-threaded takes lot of time.
4. And if non-threaded one is latest then where does that code exists. Why
checking out the code from CDT 6 branch still has threaded implementation ?

When I checked out the code from CVS for Branch CDT6_0, it shows the
following implementation for getGDBProcess() method in MIProcessAdapter
class

protected Process getGDBProcess(String[] args, int launchTimeout,
IProgressMonitor monitor) throws IOException {
            final Process pgdb = ProcessFactory.getFactory().exec(args);
            Thread syncStartup = new Thread("GDB Start") { //$NON-NLS-1$
                  public void run() {
                        try {
                              PushbackInputStream pb = new
PushbackInputStream(pgdb.getInputStream());
                              gdbInputStream = pb;
                              pb.unread(pb.read());  // actually read
something, then return it
                        } catch (Exception e) {
                              // Do nothing, ignore the errors
                        }
                  }
            };
            syncStartup.start();

            int timepass = 0;
            if (launchTimeout <= 0) {
                  // Simulate we are waiting forever.
                  launchTimeout = Integer.MAX_VALUE;
            }

            // To respect the IProgressMonitor we can not use wait/notify
            // instead we have to loop and check for the monitor to allow
to cancel the thread.
            // The monitor is check every 1 second delay;
            for (timepass = 0; timepass < launchTimeout; timepass +=
ONE_SECOND) {
                  if (syncStartup.isAlive() && !monitor.isCanceled()) {
                        try {
                              Thread.sleep(ONE_SECOND);
                        } catch (InterruptedException e) {
                              // ignore
                        }
                  } else {
                        break;
                  }
            }
            try {
                  syncStartup.interrupt();
                  syncStartup.join(ONE_SECOND);
            } catch (InterruptedException e) {
                  // ignore
            }
            if (monitor.isCanceled()) {
                  pgdb.destroy();
                  throw new OperationCanceledException();
            } else if (timepass > launchTimeout) {
                  pgdb.destroy();
                  String message =
MIPlugin.getResourceString("src.GDBDebugger.Error_launch_timeout");
//$NON-NLS-1$
                  throw new IOException(message);
            }
            return pgdb;
      }

However when I actually launch it and use the debugger to track it , it
actually executes the following method of getGDBProcess() in
MIAdapterClass.

protected Process getGDBProcess(String[] args , int launchTimeout,
IProgressMonitor monitor) throws IOException {
      final Process pgdb = ProcessFactory.getFactory().exec(args);
      int timepass = 0;
      if (launchTimeout <=0) {
            // Simulate we are waiting forever
            launchTimeout = Integer.MAX_VALUE;
      }

      InputStream stream = pgdb.getInputStream();
      for(timepass = 0; timepass < launchTimeout ; timeout += ONE_SECOND){
            if (stream.available()<=0 && !monitor.isCancelled()){
                  try {
                        Thread.sleep(ONE_SECOND);
                  } catch (InterruptedException e){
                        //ignore
                  }
            } else {
                  break;
            }
      }
      if (monitor.isCancelled()){
            pgdb.destroy();
            throw new OperationCancelledException();
      } else if (timepass > launchTimeout) {
            pgdb.destroy();
            String message =
MIPlugin.getResourceString("src.GDBDebugger.Error_launch_timeout");
            throw new IOException(message);
      }
      return pgdb;
}


Thanks & Regards,

Nayna Jain



Back to the top