Ejemplo n.º 1
0
uint32_t
PlatformRemoteiOS::FindFileInAllSDKs (const char *platform_file_path,
                                      FileSpecList &file_list)
{
    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST | LIBLLDB_LOG_VERBOSE);
    if (platform_file_path && platform_file_path[0] && UpdateSDKDirectoryInfosIfNeeded())
    {
        const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
        lldb_private::FileSpec local_file;
        // First try for an exact match of major, minor and update
        for (uint32_t sdk_idx=0; sdk_idx<num_sdk_infos; ++sdk_idx)
        {
            if (log)
            {
                log->Printf ("Searching for %s in sdk path %s", platform_file_path, m_sdk_directory_infos[sdk_idx].directory.GetPath().c_str());
            }
            if (GetFileInSDK (platform_file_path,
                              sdk_idx,
                              local_file))
            {
                file_list.Append(local_file);
            }
        }
    }
    return file_list.GetSize();
}
Ejemplo n.º 2
0
size_t
FileSpecList::GetFilesMatchingPartialPath (const char *path, bool dir_okay, FileSpecList &matches)
{
#if 0  // FIXME: Just sketching...
    matches.Clear();
    FileSpec path_spec = FileSpec (path);
    if (path_spec.Exists ())
    {
        FileSpec::FileType type = path_spec.GetFileType();
        if (type == FileSpec::eFileTypeSymbolicLink)
            // Shouldn't there be a Resolve on a file spec that real-path's it?
        {
        }

        if (type == FileSpec::eFileTypeRegular
            || (type == FileSpec::eFileTypeDirectory && dir_okay))
        {
            matches.Append (path_spec);
            return 1;
        }
        else if (type == FileSpec::eFileTypeDirectory)
        {
            // Fill the match list with all the files in the directory:

        }
        else
        {
            return 0;
        }

    }
    else
    {
        ConstString dir_name = path_spec.GetDirectory();
        Constring file_name = GetFilename();
        if (dir_name == NULL)
        {
            // Match files in the CWD.
        }
        else
        {
            // Match files in the given directory:

        }
    }
#endif
    return 0;
}
Ejemplo n.º 3
0
void SearchFilter::SerializeFileSpecList(
    StructuredData::DictionarySP &options_dict_sp, OptionNames name,
    FileSpecList &file_list) {
  size_t num_modules = file_list.GetSize();

  // Don't serialize empty lists.
  if (num_modules == 0)
    return;

  auto module_array_sp = std::make_shared<StructuredData::Array>();
  for (size_t i = 0; i < num_modules; i++) {
    module_array_sp->AddItem(std::make_shared<StructuredData::String>(
        file_list.GetFileSpecAtIndex(i).GetPath()));
  }
  options_dict_sp->AddItem(GetKey(name), module_array_sp);
}
Ejemplo n.º 4
0
lldb::SearchFilterSP SearchFilterByModuleListAndCU::CreateFromStructuredData(
    Target &target, const StructuredData::Dictionary &data_dict,
    Status &error) {
  StructuredData::Array *modules_array = nullptr;
  SearchFilterSP result_sp;
  bool success = data_dict.GetValueForKeyAsArray(GetKey(OptionNames::ModList),
                                                 modules_array);
  FileSpecList modules;
  if (success) {
    size_t num_modules = modules_array->GetSize();
    for (size_t i = 0; i < num_modules; i++) {
      llvm::StringRef module;
      success = modules_array->GetItemAtIndexAsString(i, module);
      if (!success) {
        error.SetErrorStringWithFormat(
            "SFBM::CFSD: filter module item %zu not a string.", i);
        return result_sp;
      }
      modules.Append(FileSpec(module));
    }
  }

  StructuredData::Array *cus_array = nullptr;
  success =
      data_dict.GetValueForKeyAsArray(GetKey(OptionNames::CUList), cus_array);
  if (!success) {
    error.SetErrorString("SFBM::CFSD: Could not find the CU list key.");
    return result_sp;
  }

  size_t num_cus = cus_array->GetSize();
  FileSpecList cus;
  for (size_t i = 0; i < num_cus; i++) {
    llvm::StringRef cu;
    success = cus_array->GetItemAtIndexAsString(i, cu);
    if (!success) {
      error.SetErrorStringWithFormat(
          "SFBM::CFSD: filter cu item %zu not a string.", i);
      return nullptr;
    }
    cus.Append(FileSpec(cu));
  }

  return std::make_shared<SearchFilterByModuleListAndCU>(
      target.shared_from_this(), modules, cus);
}
Ejemplo n.º 5
0
uint32_t
ObjectFileJIT::GetDependentModules (FileSpecList& files)
{
    // JIT modules don't have dependencies, but they could
    // if external functions are called and we know where they are
    files.Clear();
    return 0;
}
uint32_t PlatformRemoteDarwinDevice::FindFileInAllSDKs(const char *platform_file_path,
                                              FileSpecList &file_list) {
  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
  if (platform_file_path && platform_file_path[0] &&
      UpdateSDKDirectoryInfosIfNeeded()) {
    const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
    lldb_private::FileSpec local_file;
    // First try for an exact match of major, minor and update
    for (uint32_t sdk_idx = 0; sdk_idx < num_sdk_infos; ++sdk_idx) {
      LLDB_LOGV(log, "Searching for {0} in sdk path {1}", platform_file_path,
                m_sdk_directory_infos[sdk_idx].directory);
      if (GetFileInSDK(platform_file_path, sdk_idx, local_file)) {
        file_list.Append(local_file);
      }
    }
  }
  return file_list.GetSize();
}
Ejemplo n.º 7
0
uint32_t
PlatformRemoteiOS::FindFileInAllSDKs (const char *platform_file_path,
                                      FileSpecList &file_list)
{
    if (platform_file_path && platform_file_path[0] && UpdateSDKDirectoryInfosInNeeded())
    {
        const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
        lldb_private::FileSpec local_file;
        // First try for an exact match of major, minor and update
        for (uint32_t sdk_idx=0; sdk_idx<num_sdk_infos; ++sdk_idx)
        {
            if (GetFileInSDK (platform_file_path,
                              sdk_idx,
                              local_file))
            {
                file_list.Append(local_file);
            }
        }
    }
    return file_list.GetSize();
}
Ejemplo n.º 8
0
uint32_t
ObjectFileELF::GetDependentModules(FileSpecList &files)
{
    size_t num_modules = ParseDependentModules();
    uint32_t num_specs = 0;

    for (unsigned i = 0; i < num_modules; ++i)
    {
        if (files.AppendIfUnique(m_filespec_ap->GetFileSpecAtIndex(i)))
            num_specs++;
    }

    return num_specs;
}
Ejemplo n.º 9
0
SearchFilterSP SearchFilterByModuleList::CreateFromStructuredData(
    Target &target, const StructuredData::Dictionary &data_dict,
    Status &error) {
  StructuredData::Array *modules_array;
  bool success = data_dict.GetValueForKeyAsArray(GetKey(OptionNames::ModList),
                                                 modules_array);
  FileSpecList modules;
  if (success) {
    size_t num_modules = modules_array->GetSize();
    for (size_t i = 0; i < num_modules; i++) {
      llvm::StringRef module;
      success = modules_array->GetItemAtIndexAsString(i, module);
      if (!success) {
        error.SetErrorStringWithFormat(
            "SFBM::CFSD: filter module item %zu not a string.", i);
        return nullptr;
      }
      modules.Append(FileSpec(module));
    }
  }

  return std::make_shared<SearchFilterByModuleList>(target.shared_from_this(),
                                                    modules);
}
Ejemplo n.º 10
0
lldb::REPLSP
SwiftREPL::CreateInstance (Error &err, lldb::LanguageType language, Debugger *debugger, Target *target, const char *repl_options)
{
    if (language != eLanguageTypeSwift)
    {
        return lldb::REPLSP();
    }
    
    if (target)
    {
        // Sanity check the target to make sure a REPL would work here.
        if (!target->GetProcessSP() ||
            !target->GetProcessSP()->IsAlive())
        {
            err.SetErrorString ("can't launch a Swift REPL without a running process");
            return lldb::REPLSP();
        }
        
        SymbolContextList sc_list;
        target->GetImages().FindSymbolsWithNameAndType(ConstString("_swift_release"), eSymbolTypeAny, sc_list);
        
        if (!sc_list.GetSize())
        {
            err.SetErrorString ("can't launch a Swift REPL in a process that doesn't have the Swift standard library");
            return lldb::REPLSP();
        }
        
        // Sanity checks succeeded.  Go ahead.
        SwiftREPL *repl = new SwiftREPL(*target);
        REPLSP repl_sp(repl);
        repl->SetCompilerOptions(repl_options);
        return repl_sp;
    }
    else if (debugger)
    {
        const char *bp_name = "repl_main";
        
        FileSpec repl_executable;

        if (HostInfo::GetLLDBPath (ePathTypeSupportExecutableDir, repl_executable))
        {
            repl_executable.GetFilename().SetCString("repl_swift");
            std::string repl_exe_path(repl_executable.GetPath());
            if (repl_executable.Exists())
            {
                const char *target_triple = NULL;
                bool add_dependent_modules = true;
                TargetSP target_sp;
                err = debugger->GetTargetList().CreateTarget (*debugger,
                                                              repl_exe_path.c_str(),
                                                              target_triple,
                                                              add_dependent_modules,
                                                              NULL,
                                                              target_sp);
                if (err.Success())
                {
                    // Limit the breakpoint to our executable module
                    FileSpecList containingModules;
                    ModuleSP exe_module_sp (target_sp->GetExecutableModule());
                    if (exe_module_sp)
                    {
                        FileSpec exe_spec(exe_module_sp->GetFileSpec());
                        containingModules.Append(exe_spec);
                        BreakpointSP main_bp_sp = target_sp->CreateBreakpoint (&containingModules,      // Limit to these modules
                                                                               NULL,                    // Don't limit the breakpoint to any source files
                                                                               bp_name,                 // Function name
                                                                               eFunctionNameTypeAuto,   // Name type
                                                                               eLanguageTypeUnknown,    // Language
                                                                               0,                       // offset
                                                                               eLazyBoolYes,            // skip_prologue,
                                                                               true,                    // internal
                                                                               false);                  // request_hardware
                        
                        if (main_bp_sp->GetNumLocations() > 0)
                        {
                            main_bp_sp->SetBreakpointKind("REPL");
                            
                            assert (main_bp_sp->IsInternal()); // We made an internal breakpoint above, it better say it is internal
                            
                            lldb_private::ProcessLaunchInfo launch_info;
                            const char *target_settings_argv0 = target_sp->GetArg0();
                            
                            if (target_sp->GetDisableASLR())
                                launch_info.GetFlags().Set (eLaunchFlagDisableASLR);
                                
                            if (target_sp->GetDisableSTDIO())
                                launch_info.GetFlags().Set (eLaunchFlagDisableSTDIO);
                                    
                            if (target_settings_argv0)
                            {
                                launch_info.GetArguments().AppendArgument (target_settings_argv0);
                                launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), false);
                            }
                            else
                            {
                                launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), true);
                            }
                            
                            debugger->SetAsyncExecution(false);
                            err = target_sp->Launch(launch_info, nullptr);
                            debugger->SetAsyncExecution(true);
                            
                            if (err.Success())
                            {
                                ProcessSP process_sp (target_sp->GetProcessSP());
                                if (process_sp)
                                {
                                    // Start handling process events automatically
                                    debugger->StartEventHandlerThread();
                                    
                                    StateType state = process_sp->GetState();
                                    
                                    if (state == eStateStopped)
                                    {
                                        ThreadList &thread_list = process_sp->GetThreadList();
                                        const uint32_t num_threads = thread_list.GetSize();
                                        if (num_threads > 0)
                                        {
                                            ThreadSP thread_sp = thread_list.GetSelectedThread();
                                            if (!thread_sp)
                                            {
                                                thread_sp = thread_list.GetThreadAtIndex(0);
                                                thread_list.SetSelectedThreadByID(thread_sp->GetID());
                                            }
                                            if (thread_sp)
                                            {
                                                thread_sp->SetSelectedFrameByIndex(0);
                                                
                                                std::string swift_full_version(swift::version::getSwiftFullVersion());
                                                printf ("Welcome to %s. Type :help for assistance.\n",
                                                        swift_full_version.c_str());
                                                
                                                REPLSP repl_sp(new SwiftREPL(*target_sp));
                                                ((SwiftREPL*)repl_sp.get())->SetCompilerOptions(repl_options);
                                                target_sp->SetREPL(lldb::eLanguageTypeSwift, repl_sp);
                                                return repl_sp;
                                            }
                                        }
                                        else
                                        {
                                            err.SetErrorString ("process is not in valid state (no threads)");
                                        }
                                    }
                                    else
                                    {
                                        err.SetErrorString ("failed to stop process at REPL breakpoint");
                                    }
                                    
                                    process_sp->Destroy(false);
                                    
                                    debugger->StopEventHandlerThread();
                                }
                                else
                                {
                                    err.SetErrorString ("failed to launch REPL process");
                                }
                            }
                            else
                            {
                                err.SetErrorStringWithFormat ("failed to launch REPL process: %s", err.AsCString());
                            }
                        }
                        else
                        {
                            err.SetErrorStringWithFormat ("failed to resolve REPL breakpoint for '%s'", bp_name);
                        }
                    }
                    else
                    {
                        err.SetErrorString ("unable to resolve REPL executable module");
                        
                        target_sp->Destroy();
                    }
                }
                else
                {
                    err.SetErrorStringWithFormat ("failed to create REPL target: %s", err.AsCString());
                }
            }
            else
            {
                err.SetErrorStringWithFormat ("REPL executable does not exist: '%s'", repl_exe_path.c_str());
            }
        }
        else
        {
            err.SetErrorString ("unable to locate REPL executable");
        }
        
        return lldb::REPLSP();
    }
    else
    {
        err.SetErrorString ("must have a debugger or a target to create a REPL");
        return lldb::REPLSP();
    }
}