bool CommandObjectFile::Execute ( CommandInterpreter &interpreter, Args& command, CommandReturnObject &result ) { const char *file_path = command.GetArgumentAtIndex(0); Timer scoped_timer(__PRETTY_FUNCTION__, "(dbg) file '%s'", file_path); const int argc = command.GetArgumentCount(); if (argc == 1) { FileSpec file_spec (file_path); if (! file_spec.Exists()) { result.AppendErrorWithFormat ("File '%s' does not exist.\n", file_path); result.SetStatus (eReturnStatusFailed); return result.Succeeded(); } TargetSP target_sp; ArchSpec arch; if (m_options.m_arch.IsValid()) arch = m_options.m_arch; else { arch = lldb_private::GetDefaultArchitecture (); if (!arch.IsValid()) arch = LLDB_ARCH_DEFAULT; } Debugger &debugger = interpreter.GetDebugger(); Error error = debugger.GetTargetList().CreateTarget (debugger, file_spec, arch, NULL, true, target_sp); if (error.Fail() && !m_options.m_arch.IsValid()) { if (arch == LLDB_ARCH_DEFAULT_32BIT) arch = LLDB_ARCH_DEFAULT_64BIT; else arch = LLDB_ARCH_DEFAULT_32BIT; error = debugger.GetTargetList().CreateTarget (debugger, file_spec, arch, NULL, true, target_sp); } if (target_sp) { debugger.GetTargetList().SetCurrentTarget(target_sp.get()); result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, arch.AsCString()); result.SetStatus (eReturnStatusSuccessFinishNoResult); } else { result.AppendError(error.AsCString()); result.SetStatus (eReturnStatusFailed); } } else { result.AppendErrorWithFormat("'%s' takes exactly one executable path argument.\n", m_cmd_name.c_str()); result.SetStatus (eReturnStatusFailed); } return result.Succeeded(); }
Error TargetList::CreateTarget ( Debugger &debugger, const FileSpec& file, const ArchSpec& arch, const UUID *uuid_ptr, bool get_dependent_files, TargetSP &target_sp ) { Timer scoped_timer (__PRETTY_FUNCTION__, "TargetList::CreateTarget (file = '%s/%s', arch = '%s', uuid = %p)", file.GetDirectory().AsCString(), file.GetFilename().AsCString(), arch.AsCString(), uuid_ptr); ModuleSP exe_module_sp; FileSpec resolved_file(file); if (!Host::ResolveExecutableInBundle (&resolved_file)) resolved_file = file; Error error = ModuleList::GetSharedModule(resolved_file, arch, uuid_ptr, NULL, 0, exe_module_sp, NULL, NULL); if (exe_module_sp) { target_sp.reset(new Target(debugger)); target_sp->SetExecutableModule (exe_module_sp, get_dependent_files); if (target_sp.get()) { Mutex::Locker locker(m_target_list_mutex); m_current_target_idx = m_target_list.size(); m_target_list.push_back(target_sp); } // target_sp.reset(new Target); // // Let the target resolve any funky bundle paths before we try and get // // the object file... // target_sp->SetExecutableModule (exe_module_sp, get_dependent_files); // if (exe_module_sp->GetObjectFile() == NULL) // { // error.SetErrorStringWithFormat("%s%s%s: doesn't contain architecture %s", // file.GetDirectory().AsCString(), // file.GetDirectory() ? "/" : "", // file.GetFilename().AsCString(), // arch.AsCString()); // } // else // { // if (target_sp.get()) // { // error.Clear(); // Mutex::Locker locker(m_target_list_mutex); // m_current_target_idx = m_target_list.size(); // m_target_list.push_back(target_sp); // } // } } else { target_sp.reset(); } return error; }