Beispiel #1
0
 def remote_init(self):
     """Initialize things related to the remote communication and back-end daemons."""
     self.comm = CommunicatorFE(True)  # Initialize with locking.
     # One of {pid} and {launcher, launcher_args} will not be none, based
     # upon the command line input parsing.
     ret = self.comm.init_lmon(self.lmon_attach,
                               pid=self.lmon_pid,
                               launcher=self.lmon_launcher,
                               launcher_args=self.lmon_launcher_argv,
                               host=self.lmon_host)
     if not ret:
         # Terminate. Note at this point main is still waiting on the remote_up event,
         # so we have to set it.
         self.remote_up.set()
         self.interrupt_main()
         return False
     ret = self.comm.init_mrnet(local=self.local_launch)
     if not ret:
         # Terminate. See prior comment about remote_up.
         self.remote_up.set()
         self.interrupt_main()
         return False
     self.varobjs = {}
     for rank in self.comm.get_mpiranks():
         self.varobjs[rank] = VariableObjectManager()
     self.init_handlers()
     self.pprinter = GDBMIPrettyPrinter()
     self.sleep_time = 0.1
     self.blocks = []
     try:
         self.blocks += gdbconf.default_blocks
     except AttributeError:
         pass
     # Initialize the SBD system if needed.
     if gdbconf.use_sbd:
         self.sbd = SBDFE(self.comm)
     else:
         self.sbd = None
     return True
Beispiel #2
0
    def init_gdb(self):
        """Initialize GDB-related things, and launch the GDB process."""
        # Indexed by MPI rank.
        self.varobjs = {}
        # Maps tokens to MPI rank.
        self.token_rank_map = {}
        self.record_handler = GDBMIRecordHandler()
        self.record_handler.add_type_handler(
            self._watch_thread_created,
            set([mi.gdbmi_records.ASYNC_NOTIFY_THREAD_CREATED]))
        self.startup_stop_hid = self.record_handler.add_type_handler(
            self._watch_startup_stop,
            set([mi.gdbmi_records.ASYNC_EXEC_STOPPED]))
        gdb_env = {}
        if gdbconf.use_sbd:
            self.sbd = SBDBE(self.comm)
            gdb_env["LD_PRELOAD"] = gdbconf.sbd_bin
        else:
            self.sbd = None

        enable_pprint_cmd = Command("enable-pretty-printing")
        enable_target_async_cmd = Command("gdb-set",
                                          args=["target-async", "on"])
        disable_pagination_cmd = Command("gdb-set", args=["pagination", "off"])
        enable_non_stop_cmd = Command("gdb-set", args=["non-stop", "on"])
        add_inferior_cmd = Command("add-inferior")
        self.gdb = GDBMachineInterface(gdb=gdbconf.gdb_path,
                                       gdb_args=["-x", gdbconf.gdb_init_path],
                                       env=gdb_env)
        procs = self.comm.get_proctab()
        # Set up GDB.
        if not self.run_gdb_command(enable_pprint_cmd):
            raise RuntimeError("Could not enable pretty printing!")
        if not self.run_gdb_command(enable_target_async_cmd):
            raise RuntimeError("Could not enable target-async!")
        if not self.run_gdb_command(disable_pagination_cmd):
            raise RuntimeError("Could not disable pagination!")
        if not self.run_gdb_command(enable_non_stop_cmd):
            raise RuntimeError("Could not enable non-stop!")

        # Create inferiors and set up MPI rank/inferior map.
        # First inferior is created by default.
        self.rank_inferior_map = {procs[0].mpirank: 'i1'}
        self.inferior_rank_map = {'i1': procs[0].mpirank}
        i = 2
        for proc in procs[1:]:
            # Hackish: Assume that the inferiors follow the iN naming scheme.
            self.rank_inferior_map[proc.mpirank] = 'i' + str(i)
            self.inferior_rank_map['i' + str(i)] = proc.mpirank
            i += 1
            if not self.run_gdb_command(add_inferior_cmd, no_thread=True):
                raise RuntimeError('Cound not add inferior i{0}!'.format(i -
                                                                         1))

        # Maps MPI ranks to associated threads and vice-versa.
        self.rank_thread_map = {}
        self.thread_rank_map = {}

        if self.sbd:
            # Set up the list of executables for load file checking.
            self.sbd.set_executable_names(
                [os.path.basename(proc.pd.executable_name) for proc in procs])

        # Attach processes.
        for proc in procs:
            if not self.run_gdb_command(Command(
                    "target-attach",
                    opts={
                        '--thread-group': self.rank_inferior_map[proc.mpirank]
                    },
                    args=[proc.pd.pid]),
                                        proc.mpirank,
                                        no_thread=True):
                raise RuntimeError("Could not attach to rank {0}!".format(
                    proc.mpirank))
            self.varobjs[proc.mpirank] = VariableObjectManager()
            # Cludge to fix GDB not outputting records for the i1 attach.
            if self.rank_inferior_map[proc.mpirank] == 'i1':
                time.sleep(0.1)