LLDB mainline
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
lldb_private::TargetList Class Reference

#include <TargetList.h>

Inheritance diagram for lldb_private::TargetList:
Inheritance graph
[legend]

Public Types

enum  { eBroadcastBitInterrupt = (1 << 0) }
 Broadcaster event bits definitions. More...
 
typedef std::vector< lldb::TargetSPcollection
 
typedef LockingAdaptedIterable< collection, lldb::TargetSP, vector_adapter, std::recursive_mutex > TargetIterable
 

Public Member Functions

ConstStringGetBroadcasterClass () const override
 This needs to be filled in if you are going to register the broadcaster with the broadcaster manager and do broadcaster class matching.
 
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.
 
Status CreateTarget (Debugger &debugger, llvm::StringRef user_exe_path, const ArchSpec &arch, LoadDependentFiles get_dependent_modules, lldb::PlatformSP &platform_sp, lldb::TargetSP &target_sp)
 Create a new Target.
 
bool DeleteTarget (lldb::TargetSP &target_sp)
 Delete a Target object from the list.
 
size_t GetNumTargets () const
 
lldb::TargetSP GetTargetAtIndex (uint32_t index) const
 
uint32_t GetIndexOfTarget (lldb::TargetSP target_sp) const
 
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 architecture matches arch_ptr if arch_ptr is not nullptr.
 
lldb::TargetSP FindTargetWithProcessID (lldb::pid_t pid) const
 Find the target that contains a process with process ID pid.
 
lldb::TargetSP FindTargetWithProcess (lldb_private::Process *process) const
 
lldb::TargetSP GetTargetSP (Target *target) const
 
uint32_t SendAsyncInterrupt (lldb::pid_t pid=LLDB_INVALID_PROCESS_ID)
 Send an async interrupt to one or all processes.
 
uint32_t SignalIfRunning (lldb::pid_t pid, int signo)
 
void SetSelectedTarget (uint32_t index)
 
void SetSelectedTarget (const lldb::TargetSP &target)
 
lldb::TargetSP GetSelectedTarget ()
 
bool AnyTargetContainsModule (Module &module)
 Returns whether any module, including ones in the process of being added, contains this module.
 
TargetIterable Targets ()
 
- Public Member Functions inherited from lldb_private::Broadcaster
 Broadcaster (lldb::BroadcasterManagerSP manager_sp, std::string name)
 Construct with a broadcaster with a name.
 
virtual ~Broadcaster ()
 Destructor.
 
void CheckInWithManager ()
 
void BroadcastEvent (lldb::EventSP &event_sp)
 Broadcast an event which has no associated data.
 
void BroadcastEventIfUnique (lldb::EventSP &event_sp)
 
void BroadcastEvent (uint32_t event_type, const lldb::EventDataSP &event_data_sp)
 
void BroadcastEvent (uint32_t event_type)
 
void BroadcastEventIfUnique (uint32_t event_type)
 
void Clear ()
 
virtual void AddInitialEventsToListener (const lldb::ListenerSP &listener_sp, uint32_t requested_events)
 
uint32_t AddListener (const lldb::ListenerSP &listener_sp, uint32_t event_mask)
 Listen for any events specified by event_mask.
 
const std::string & GetBroadcasterName ()
 Get this broadcaster's name.
 
bool GetEventNames (Stream &s, const uint32_t event_mask, bool prefix_with_broadcaster_name) const
 Get the event name(s) for one or more event bits.
 
void SetEventName (uint32_t event_mask, const char *name)
 Set the name for an event bit.
 
const char * GetEventName (uint32_t event_mask) const
 
bool EventTypeHasListeners (uint32_t event_type)
 
bool RemoveListener (const lldb::ListenerSP &listener_sp, uint32_t event_mask=UINT32_MAX)
 Removes a Listener from this broadcasters list and frees the event bits specified by event_mask that were previously acquired by listener (assuming listener was listening to this object) for other listener objects to use.
 
bool HijackBroadcaster (const lldb::ListenerSP &listener_sp, uint32_t event_mask=UINT32_MAX)
 Provides a simple mechanism to temporarily redirect events from broadcaster.
 
bool IsHijackedForEvent (uint32_t event_mask)
 
void RestoreBroadcaster ()
 Restore the state of the Broadcaster from a previous hijack attempt.
 
virtual ConstStringGetBroadcasterClass () const
 This needs to be filled in if you are going to register the broadcaster with the broadcaster manager and do broadcaster class matching.
 
lldb::BroadcasterManagerSP GetManager ()
 
void SetPrimaryListener (lldb::ListenerSP listener_sp)
 
lldb::ListenerSP GetPrimaryListener ()
 

Static Public Member Functions

static ConstStringGetStaticBroadcasterClass ()
 

Private Member Functions

 TargetList (Debugger &debugger)
 Constructor.
 
void RegisterInProcessTarget (lldb::TargetSP target_sp)
 
void UnregisterInProcessTarget (lldb::TargetSP target_sp)
 
bool IsTargetInProcess (lldb::TargetSP target_sp)
 
void AddTargetInternal (lldb::TargetSP target_sp, bool do_select)
 
void SetSelectedTargetInternal (uint32_t index)
 
 TargetList (const TargetList &)=delete
 
const TargetListoperator= (const TargetList &)=delete
 

Static Private Member Functions

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)
 
static Status CreateTargetInternal (Debugger &debugger, llvm::StringRef user_exe_path, const ArchSpec &arch, LoadDependentFiles get_dependent_modules, lldb::PlatformSP &platform_sp, lldb::TargetSP &target_sp)
 

Private Attributes

collection m_target_list
 
std::unordered_set< lldb::TargetSPm_in_process_target_list
 
std::recursive_mutex m_target_list_mutex
 
uint32_t m_selected_target_idx
 

Friends

class Debugger
 

Additional Inherited Members

- Protected Types inherited from lldb_private::Broadcaster
typedef std::shared_ptr< BroadcasterImplBroadcasterImplSP
 
typedef std::weak_ptr< BroadcasterImplBroadcasterImplWP
 
- Protected Member Functions inherited from lldb_private::Broadcaster
BroadcasterImplSP GetBroadcasterImpl ()
 
const char * GetHijackingListenerName ()
 

Detailed Description

Definition at line 21 of file TargetList.h.

Member Typedef Documentation

◆ collection

Definition at line 46 of file TargetList.h.

◆ TargetIterable

Definition at line 49 of file TargetList.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Broadcaster event bits definitions.

Enumerator
eBroadcastBitInterrupt 

Definition at line 36 of file TargetList.h.

Constructor & Destructor Documentation

◆ TargetList() [1/2]

TargetList::TargetList ( Debugger debugger)
private

Constructor.

The constructor for the target list is private. Clients can get ahold of the one and only target list through the lldb_private::Debugger::GetSharedInstance().GetTargetList().

See also
static TargetList& lldb_private::Debugger::GetTargetList().

Definition at line 38 of file TargetList.cpp.

References lldb_private::Broadcaster::CheckInWithManager().

◆ TargetList() [2/2]

lldb_private::TargetList::TargetList ( const TargetList )
privatedelete

Member Function Documentation

◆ AddTargetInternal()

void TargetList::AddTargetInternal ( lldb::TargetSP  target_sp,
bool  do_select 
)
private

◆ AnyTargetContainsModule()

bool TargetList::AnyTargetContainsModule ( Module module)

Returns whether any module, including ones in the process of being added, contains this module.

I don't want to give direct access to these not yet added target, but for interruption purposes, we might need to ask whether this target contains this module.

Definition at line 551 of file TargetList.cpp.

References m_in_process_target_list, m_target_list, and m_target_list_mutex.

◆ CreateTarget() [1/2]

Status TargetList::CreateTarget ( Debugger debugger,
llvm::StringRef  user_exe_path,
const ArchSpec arch,
LoadDependentFiles  get_dependent_modules,
lldb::PlatformSP platform_sp,
lldb::TargetSP target_sp 
)

Create a new Target.

Same as the function above, but used when you already know the platform you will be using

Definition at line 61 of file TargetList.cpp.

References AddTargetInternal(), CreateTargetInternal(), and m_target_list_mutex.

◆ CreateTarget() [2/2]

Status TargetList::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.

Clients must use this function to create a Target. This allows a global list of targets to be maintained in a central location so signal handlers and other global functions can use it to locate an appropriate target to deliver asynchronous information to.

Parameters
[in]debuggerThe debugger to associate this target with
[in]user_exe_pathThe main executable file for a debug target. This value can be empty and the file can be set later using: Target::SetExecutableModule (ModuleSP&)
[in]triple_strA target triple string to be used for the target. This can be nullptr if the triple is not known or when attaching to a process.
[in]get_dependent_modulesTrack down the dependent modules for an executable and load those into the module list.
[in]platform_optionsA pointer to the platform options to use when creating this target. If this value is nullptr, then the currently selected platform will be used.
[out]target_spA shared pointer to a target that will be filled in if this call is successful.
Returns
An error object that indicates success or failure

Definition at line 45 of file TargetList.cpp.

References AddTargetInternal(), CreateTargetInternal(), and m_target_list_mutex.

Referenced by PlatformPOSIX::Attach(), lldb_private::PlatformWindows::Attach(), lldb_private::platform_gdb_server::PlatformRemoteGDBServer::Attach(), lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::CreateEmptyProcess(), lldb_private::Platform::DoConnectProcess(), CommandObjectProcessAttach::DoExecute(), and CommandObjectTargetCreate::DoExecute().

◆ CreateTargetInternal() [1/2]

Status TargetList::CreateTargetInternal ( Debugger debugger,
llvm::StringRef  user_exe_path,
const ArchSpec arch,
LoadDependentFiles  get_dependent_modules,
lldb::PlatformSP platform_sp,
lldb::TargetSP target_sp 
)
staticprivate

◆ CreateTargetInternal() [2/2]

Status TargetList::CreateTargetInternal ( Debugger debugger,
llvm::StringRef  user_exe_path,
llvm::StringRef  triple_str,
LoadDependentFiles  load_dependent_files,
const OptionGroupPlatform platform_options,
lldb::TargetSP target_sp 
)
staticprivate

Definition at line 76 of file TargetList.cpp.

References lldb_private::Stream::AsRawOstream(), lldb_private::ArchSpec::CompatibleMatch, lldb_private::OptionGroupPlatform::CreatePlatformWithOptions(), CreateTargetInternal(), lldb_private::ArchSpec::DumpTriple(), error(), lldb_private::FileSystem::Exists(), lldb_private::ModuleSpecList::FindMatchingModuleSpec(), lldb_private::ModuleSpec::GetArchitecture(), lldb_private::Debugger::GetCommandInterpreter(), lldb_private::StreamString::GetData(), lldb_private::ModuleSpec::GetFileSpec(), lldb_private::ModuleSpecList::GetModuleSpecAtIndex(), lldb_private::ObjectFile::GetModuleSpecifications(), lldb_private::PlatformList::GetOrCreate(), lldb_private::FileSpec::GetPath(), lldb_private::Debugger::GetPlatformList(), lldb_private::PlatformList::GetSelectedPlatform(), lldb_private::StreamString::GetString(), lldb_private::FileSystem::Instance(), lldb_private::ArchSpec::IsCompatibleMatch(), lldb_private::ArchSpec::IsValid(), lldb_private::ModuleSpecList::ModuleSpecs(), lldb_private::OptionGroupPlatform::PlatformMatches(), lldb_private::OptionGroupPlatform::PlatformWasSpecified(), lldb_private::Stream::Printf(), lldb_private::Stream::PutCString(), lldb_private::FileSystem::Resolve(), lldb_private::Host::ResolveExecutableInBundle(), lldb_private::FileSystem::ResolveExecutableLocation(), lldb_private::PlatformList::SetSelectedPlatform(), lldb_private::ArchSpec::TripleOSWasSpecified(), and lldb_private::ArchSpec::TripleVendorWasSpecified().

Referenced by CreateTarget(), and CreateTargetInternal().

◆ DeleteTarget()

bool TargetList::DeleteTarget ( lldb::TargetSP target_sp)

Delete a Target object from the list.

When clients are done with the Target objects, this function should be called to release the memory associated with a target object.

Parameters
[in]target_spThe shared pointer to a target.
Returns
Returns true if the target was successfully removed from from this target list, false otherwise. The client will be left with the last remaining shared pointer to the target in target_sp which can then be properly released.

Definition at line 371 of file TargetList.cpp.

References m_target_list, and m_target_list_mutex.

Referenced by CommandObjectTargetDelete::DoExecute(), and lldb_private::trace_intel_pt::TraceIntelPTBundleLoader::LoadBundle().

◆ FindTargetWithExecutableAndArchitecture()

TargetSP TargetList::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 architecture matches arch_ptr if arch_ptr is not nullptr.

Parameters
[in]exe_file_specA file spec containing a basename, or a full path (directory and basename). If exe_file_spec contains only a filename (empty GetDirectory() value) then matching will be done solely based on the filenames and directories won't be compared. If exe_file_spec contains a filename and a directory, then both must match.
[in]exe_arch_ptrIf not nullptr then the architecture also needs to match, else the architectures will be compared.
Returns
A shared pointer to a target object. The returned shared pointer will contain nullptr if no target objects have a executable whose full or partial path matches with a matching process ID.

Definition at line 381 of file TargetList.cpp.

References m_target_list, and m_target_list_mutex.

◆ FindTargetWithProcess()

TargetSP TargetList::FindTargetWithProcess ( lldb_private::Process process) const

Definition at line 415 of file TargetList.cpp.

References m_target_list, and m_target_list_mutex.

◆ FindTargetWithProcessID()

TargetSP TargetList::FindTargetWithProcessID ( lldb::pid_t  pid) const

Find the target that contains a process with process ID pid.

Parameters
[in]pidThe process ID to search our target list for.
Returns
A shared pointer to a target object. The returned shared pointer will contain nullptr if no target objects own a process with a matching process ID.

Definition at line 401 of file TargetList.cpp.

References m_target_list, and m_target_list_mutex.

Referenced by SendAsyncInterrupt(), and SignalIfRunning().

◆ GetBroadcasterClass()

ConstString & lldb_private::TargetList::GetBroadcasterClass ( ) const
inlineoverridevirtual

This needs to be filled in if you are going to register the broadcaster with the broadcaster manager and do broadcaster class matching.

FIXME: Probably should make a ManagedBroadcaster subclass with all the bits needed to work with the BroadcasterManager, so that it is clearer how to add one.

Reimplemented from lldb_private::Broadcaster.

Definition at line 42 of file TargetList.h.

References GetStaticBroadcasterClass().

◆ GetIndexOfTarget()

uint32_t TargetList::GetIndexOfTarget ( lldb::TargetSP  target_sp) const

◆ GetNumTargets()

size_t TargetList::GetNumTargets ( ) const

◆ GetSelectedTarget()

lldb::TargetSP TargetList::GetSelectedTarget ( )

◆ GetStaticBroadcasterClass()

ConstString & TargetList::GetStaticBroadcasterClass ( )
static

Definition at line 32 of file TargetList.cpp.

Referenced by GetBroadcasterClass().

◆ GetTargetAtIndex()

lldb::TargetSP TargetList::GetTargetAtIndex ( uint32_t  index) const

◆ GetTargetSP()

TargetSP TargetList::GetTargetSP ( Target target) const

Definition at line 432 of file TargetList.cpp.

References m_target_list, and m_target_list_mutex.

◆ IsTargetInProcess()

bool TargetList::IsTargetInProcess ( lldb::TargetSP  target_sp)
private

Definition at line 579 of file TargetList.cpp.

References m_in_process_target_list, and m_target_list_mutex.

◆ operator=()

const TargetList & lldb_private::TargetList::operator= ( const TargetList )
privatedelete

◆ RegisterInProcessTarget()

void TargetList::RegisterInProcessTarget ( lldb::TargetSP  target_sp)
private

Definition at line 564 of file TargetList.cpp.

References m_in_process_target_list, and m_target_list_mutex.

Referenced by CreateTargetInternal().

◆ SendAsyncInterrupt()

uint32_t TargetList::SendAsyncInterrupt ( lldb::pid_t  pid = LLDB_INVALID_PROCESS_ID)

Send an async interrupt to one or all processes.

Find the target that contains the process with process ID pid and send a LLDB_EVENT_ASYNC_INTERRUPT event to the process's event queue.

Parameters
[in]pidThe process ID to search our target list for, if pid is LLDB_INVALID_PROCESS_ID, then the interrupt will be sent to all processes.
Returns
The number of async interrupts sent.

Definition at line 446 of file TargetList.cpp.

References lldb_private::Broadcaster::BroadcastEvent(), lldb_private::Process::eBroadcastBitInterrupt, FindTargetWithProcessID(), LLDB_INVALID_PROCESS_ID, and lldb_private::Process::SendAsyncInterrupt().

◆ SetSelectedTarget() [1/2]

void TargetList::SetSelectedTarget ( const lldb::TargetSP target)

Definition at line 534 of file TargetList.cpp.

References m_target_list, m_target_list_mutex, and SetSelectedTargetInternal().

◆ SetSelectedTarget() [2/2]

void TargetList::SetSelectedTarget ( uint32_t  index)

◆ SetSelectedTargetInternal()

void TargetList::SetSelectedTargetInternal ( uint32_t  index)
private

Definition at line 524 of file TargetList.cpp.

References lldbassert, m_selected_target_idx, and m_target_list.

Referenced by AddTargetInternal(), and SetSelectedTarget().

◆ SignalIfRunning()

uint32_t TargetList::SignalIfRunning ( lldb::pid_t  pid,
int  signo 
)

◆ Targets()

TargetIterable lldb_private::TargetList::Targets ( )
inline

◆ UnregisterInProcessTarget()

void TargetList::UnregisterInProcessTarget ( lldb::TargetSP  target_sp)
private

Definition at line 572 of file TargetList.cpp.

References m_in_process_target_list, and m_target_list_mutex.

Referenced by AddTargetInternal().

Friends And Related Function Documentation

◆ Debugger

friend class Debugger
friend

Definition at line 23 of file TargetList.h.

Member Data Documentation

◆ m_in_process_target_list

std::unordered_set<lldb::TargetSP> lldb_private::TargetList::m_in_process_target_list
private

◆ m_selected_target_idx

uint32_t lldb_private::TargetList::m_selected_target_idx
private

Definition at line 202 of file TargetList.h.

Referenced by GetSelectedTarget(), and SetSelectedTargetInternal().

◆ m_target_list

collection lldb_private::TargetList::m_target_list
private

◆ m_target_list_mutex

std::recursive_mutex lldb_private::TargetList::m_target_list_mutex
mutableprivate

The documentation for this class was generated from the following files: