26#include "llvm/ADT/SmallString.h" 
   27#include "llvm/Support/FileSystem.h" 
   33  static constexpr llvm::StringLiteral class_name(
"lldb.targetList");
 
 
   46                                llvm::StringRef user_exe_path,
 
   47                                llvm::StringRef triple_str,
 
   53      debugger, user_exe_path, triple_str, load_dependent_files,
 
   54      platform_options, target_sp);
 
   56  if (target_sp && result.Success())
 
 
   62                                llvm::StringRef user_exe_path,
 
   68      debugger, user_exe_path, specified_arch, load_dependent_files,
 
   69      platform_sp, target_sp);
 
   71  if (target_sp && result.Success())
 
 
   77    Debugger &debugger, llvm::StringRef user_exe_path,
 
   90  if (!triple_str.empty() && !arch.
IsValid()) {
 
   92                                              triple_str.str().c_str());
 
  102    const bool select_platform = 
true;
 
  110  bool prefer_platform_arch = 
false;
 
  111  auto update_platform_arch = [&](
const ArchSpec &module_arch) {
 
  116      prefer_platform_arch = 
true;
 
  117      platform_arch = module_arch;
 
  121  if (!user_exe_path.empty()) {
 
  127    if (platform_sp->IsHost() &&
 
  140        module_spec.
GetFileSpec(), file_offset, file_size, module_specs);
 
  145      if (num_specs == 1) {
 
  162                  "the specified architecture '%s' is not compatible with '%s' " 
  170            prefer_platform_arch = 
true;
 
  178                                                matching_module_spec))
 
  183        std::vector<PlatformSP> candidates;
 
  184        std::vector<ArchSpec> archs;
 
  186          archs.push_back(spec.GetArchitecture());
 
  188                platform_list.
GetOrCreate(archs, {}, candidates)) {
 
  189          platform_sp = platform_for_archs_sp;
 
  190        } 
else if (candidates.empty()) {
 
  192              "no matching platforms found for this file");
 
  197          std::set<llvm::StringRef> platform_set;
 
  199              "more than one platform supports this executable (");
 
  200          for (
const auto &candidate : candidates) {
 
  201            llvm::StringRef platform_name = candidate->GetName();
 
  202            if (platform_set.count(platform_name))
 
  204            if (!platform_set.empty())
 
  207            platform_set.insert(platform_name);
 
  209          error_strm.
Printf(
"), specify an architecture to disambiguate");
 
  219  if (!prefer_platform_arch && arch.
IsValid()) {
 
  220    if (!platform_sp->IsCompatibleArchitecture(
 
  222      platform_sp = platform_list.
GetOrCreate(arch, {}, &platform_arch);
 
  226  } 
else if (platform_arch.
IsValid()) {
 
  230    if (!platform_sp->IsCompatibleArchitecture(
 
  233          platform_list.
GetOrCreate(platform_arch, {}, &fixed_platform_arch);
 
  240    platform_arch = arch;
 
  243                                          platform_arch, load_dependent_files,
 
  244                                          platform_sp, target_sp);
 
 
  248                                        llvm::StringRef user_exe_path,
 
  254                     user_exe_path.str().c_str(),
 
  257  const bool is_dummy_target = 
false;
 
  262    if (!platform_sp || !platform_sp->IsCompatibleArchitecture(
 
  272    arch = specified_arch;
 
  278    llvm::SmallString<64> unglobbed_path;
 
  282    if (unglobbed_path.empty())
 
  285      file = 
FileSpec(unglobbed_path.c_str());
 
  288  bool user_exe_path_is_bundle = 
false;
 
  289  char resolved_bundle_exe_path[
PATH_MAX];
 
  290  resolved_bundle_exe_path[0] = 
'\0';
 
  293      user_exe_path_is_bundle = 
true;
 
  295    if (file.
IsRelative() && !user_exe_path.empty()) {
 
  296      llvm::SmallString<64> cwd;
 
  297      if (! llvm::sys::fs::current_path(cwd)) {
 
  310      error = platform_sp->ResolveExecutable(module_spec, exe_module_sp,
 
  311                                             executable_search_paths.
GetSize()
 
  312                                                 ? &executable_search_paths
 
  316    if (
error.Success() && exe_module_sp) {
 
  317      if (exe_module_sp->GetObjectFile() == 
nullptr) {
 
  320              "\"%s\" doesn't contain architecture %s", file.
GetPath().c_str(),
 
  324              "unsupported file type \"%s\"", file.
GetPath().c_str());
 
  328      target_sp.reset(
new Target(debugger, arch, platform_sp, is_dummy_target));
 
  330      target_sp->SetExecutableModule(exe_module_sp, load_dependent_files);
 
  331      if (user_exe_path_is_bundle)
 
  332        exe_module_sp->GetFileSpec().GetPath(resolved_bundle_exe_path,
 
  333                                             sizeof(resolved_bundle_exe_path));
 
  334      if (target_sp->GetPreloadSymbols())
 
  335        exe_module_sp->PreloadSymbols();
 
  340    target_sp.reset(
new Target(debugger, arch, platform_sp, is_dummy_target));
 
  350  if (!user_exe_path.empty()) {
 
  353    if (user_exe_path_is_bundle && resolved_bundle_exe_path[0]) {
 
  354      target_sp->SetArg0(resolved_bundle_exe_path);
 
  357      target_sp->SetArg0(file.
GetPath().c_str());
 
  363    target_sp->AppendExecutableSearchPaths(file_dir);
 
 
  385  auto it = llvm::find_if(
 
  387        Module *exe_module = item->GetExecutableModulePointer();
 
  392        return !exe_arch_ptr ||
 
 
  405    auto *process_ptr = item->GetProcessSP().get();
 
  406    return process_ptr && (process_ptr->GetID() == pid);
 
 
  422    return item->GetProcessSP().get() == process;
 
 
  434    return item->GetGloballyUniqueID() == 
id;
 
 
  450    return item.get() == target;
 
 
  459  uint32_t num_async_interrupts_sent = 0;
 
  464      Process *process = target_sp->GetProcessSP().get();
 
  467        ++num_async_interrupts_sent;
 
  476  return num_async_interrupts_sent;
 
 
  480  uint32_t num_signals_sent = 0;
 
  486      process = target_sp->GetProcessSP().get();
 
  487      if (process && process->
IsAlive()) {
 
  496      process = target_sp->GetProcessSP().get();
 
  497      if (process && process->
IsAlive()) {
 
  503  return num_signals_sent;
 
 
  529             "target already exists it the list");
 
 
  549  if (target_sp && target_sp->IsValid()) {
 
 
  566    if (target_sp->GetImages().FindModule(&module))
 
  570    if (target_sp->GetImages().FindModule(&module))
 
 
  578    [[maybe_unused]] 
bool was_added;
 
  579    std::tie(std::ignore, was_added) =
 
  581    assert(was_added && 
"Target pointer was left in the in-process map");
 
 
  586    [[maybe_unused]] 
bool was_present =
 
  588    assert(was_present && 
"Target pointer being removed was not registered");
 
 
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_SCOPED_TIMERF(...)
An architecture specification class.
bool IsValid() const
Tests if this ArchSpec is valid.
void DumpTriple(llvm::raw_ostream &s) const
bool IsCompatibleMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, CompatibleMatch).
bool TripleVendorWasSpecified() const
bool TripleOSWasSpecified() const
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Broadcaster(lldb::BroadcasterManagerSP manager_sp, std::string name)
Construct with a broadcaster with a name.
void BroadcastEvent(lldb::EventSP &event_sp)
Broadcast an event which has no associated data.
void CheckInWithManager()
CommandInterpreter & GetCommandInterpreter()
TargetList & GetTargetList()
Get accessor for the target list.
PlatformList & GetPlatformList()
Target & GetDummyTarget()
size_t GetSize() const
Get the number of files in the file list.
void AppendPathComponent(llvm::StringRef component)
void SetDirectory(ConstString directory)
Directory string set accessor.
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
bool IsRelative() const
Returns true if the filespec represents a relative path.
const ConstString & GetDirectory() const
Directory string const get accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
bool ResolveExecutableLocation(FileSpec &file_spec)
Call into the Host to see if it can help find the file.
static FileSystem & Instance()
static bool ResolveExecutableInBundle(FileSpec &file)
When executable files may live within a directory, where the directory represents an executable bundl...
ModuleSpecIterable ModuleSpecs()
bool GetModuleSpecAtIndex(size_t i, ModuleSpec &module_spec) const
bool FindMatchingModuleSpec(const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const
ArchSpec & GetArchitecture()
A class that describes an executable image and its associated object and symbol files.
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
static size_t GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, ModuleSpecList &specs, lldb::DataBufferSP data_sp=lldb::DataBufferSP())
A plug-in interface definition class for debugging a process.
void SendAsyncInterrupt(Thread *thread=nullptr)
Send an async interrupt request.
Status Signal(int signal)
Sends a process a UNIX signal signal.
virtual bool IsAlive()
Check if a process is still alive.
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
const char * GetData() const
llvm::StringRef GetString() const
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
void SetSelectedTargetInternal(uint32_t index)
static llvm::StringRef GetStaticBroadcasterClass()
lldb::TargetSP FindTargetWithProcessID(lldb::pid_t pid) const
Find the target that contains a process with process ID pid.
bool IsTargetInProcess(lldb::TargetSP target_sp)
lldb::TargetSP GetTargetAtIndex(uint32_t index) const
TargetList(Debugger &debugger)
Constructor.
std::recursive_mutex m_target_list_mutex
uint32_t GetIndexOfTarget(lldb::TargetSP target_sp) const
lldb::TargetSP GetTargetSP(Target *target) const
void UnregisterInProcessTarget(lldb::TargetSP target_sp)
void SetSelectedTarget(uint32_t index)
uint32_t SendAsyncInterrupt(lldb::pid_t pid=LLDB_INVALID_PROCESS_ID)
Send an async interrupt to one or all processes.
bool DeleteTarget(lldb::TargetSP &target_sp)
Delete a Target object from the list.
lldb::TargetSP FindTargetWithProcess(lldb_private::Process *process) const
void RegisterInProcessTarget(lldb::TargetSP target_sp)
Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path, llvm::StringRef triple_str, LoadDependentFiles get_dependent_modules, const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp)
Create a new Target.
lldb::TargetSP GetSelectedTarget()
void AddTargetInternal(lldb::TargetSP target_sp, bool do_select)
static Status CreateTargetInternal(Debugger &debugger, llvm::StringRef user_exe_path, llvm::StringRef triple_str, LoadDependentFiles load_dependent_files, const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp)
lldb::TargetSP FindTargetByGloballyUniqueID(lldb::user_id_t id) const
Find the target that has a globally unique ID that matches ID id.
bool AnyTargetContainsModule(Module &module)
Returns whether any module, including ones in the process of being added, contains this module.
size_t GetNumTargets() const
uint32_t SignalIfRunning(lldb::pid_t pid, int signo)
lldb::TargetSP FindTargetWithExecutableAndArchitecture(const FileSpec &exe_file_spec, const ArchSpec *exe_arch_ptr=nullptr) const
Find the target that contains has an executable whose path matches exe_file_spec, and whose architect...
std::unordered_set< lldb::TargetSP > m_in_process_target_list
uint32_t m_selected_target_idx
static FileSpecList GetDefaultExecutableSearchPaths()
bool ResolveFullPath(llvm::StringRef Expr, llvm::SmallVectorImpl< char > &Output)
Resolve an entire path that begins with a tilde expression, replacing the username portion with the m...
#define LLDB_INVALID_PROCESS_ID
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP