Path: blob/main/contrib/llvm-project/lldb/source/API/SBAttachInfo.cpp
39587 views
//===-- SBAttachInfo.cpp --------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/API/SBAttachInfo.h"9#include "Utils.h"10#include "lldb/API/SBFileSpec.h"11#include "lldb/API/SBListener.h"12#include "lldb/API/SBStructuredData.h"13#include "lldb/Target/Process.h"14#include "lldb/Utility/Instrumentation.h"15#include "lldb/Utility/ScriptedMetadata.h"1617using namespace lldb;18using namespace lldb_private;1920SBAttachInfo::SBAttachInfo() : m_opaque_sp(new ProcessAttachInfo()) {21LLDB_INSTRUMENT_VA(this);22}2324SBAttachInfo::SBAttachInfo(lldb::pid_t pid)25: m_opaque_sp(new ProcessAttachInfo()) {26LLDB_INSTRUMENT_VA(this, pid);2728m_opaque_sp->SetProcessID(pid);29}3031SBAttachInfo::SBAttachInfo(const char *path, bool wait_for)32: m_opaque_sp(new ProcessAttachInfo()) {33LLDB_INSTRUMENT_VA(this, path, wait_for);3435if (path && path[0])36m_opaque_sp->GetExecutableFile().SetFile(path, FileSpec::Style::native);37m_opaque_sp->SetWaitForLaunch(wait_for);38}3940SBAttachInfo::SBAttachInfo(const char *path, bool wait_for, bool async)41: m_opaque_sp(new ProcessAttachInfo()) {42LLDB_INSTRUMENT_VA(this, path, wait_for, async);4344if (path && path[0])45m_opaque_sp->GetExecutableFile().SetFile(path, FileSpec::Style::native);46m_opaque_sp->SetWaitForLaunch(wait_for);47m_opaque_sp->SetAsync(async);48}4950SBAttachInfo::SBAttachInfo(const SBAttachInfo &rhs)51: m_opaque_sp(new ProcessAttachInfo()) {52LLDB_INSTRUMENT_VA(this, rhs);5354m_opaque_sp = clone(rhs.m_opaque_sp);55}5657SBAttachInfo::~SBAttachInfo() = default;5859lldb_private::ProcessAttachInfo &SBAttachInfo::ref() { return *m_opaque_sp; }6061SBAttachInfo &SBAttachInfo::operator=(const SBAttachInfo &rhs) {62LLDB_INSTRUMENT_VA(this, rhs);6364if (this != &rhs)65m_opaque_sp = clone(rhs.m_opaque_sp);66return *this;67}6869lldb::pid_t SBAttachInfo::GetProcessID() {70LLDB_INSTRUMENT_VA(this);7172return m_opaque_sp->GetProcessID();73}7475void SBAttachInfo::SetProcessID(lldb::pid_t pid) {76LLDB_INSTRUMENT_VA(this, pid);7778m_opaque_sp->SetProcessID(pid);79}8081uint32_t SBAttachInfo::GetResumeCount() {82LLDB_INSTRUMENT_VA(this);8384return m_opaque_sp->GetResumeCount();85}8687void SBAttachInfo::SetResumeCount(uint32_t c) {88LLDB_INSTRUMENT_VA(this, c);8990m_opaque_sp->SetResumeCount(c);91}9293const char *SBAttachInfo::GetProcessPluginName() {94LLDB_INSTRUMENT_VA(this);9596return ConstString(m_opaque_sp->GetProcessPluginName()).GetCString();97}9899void SBAttachInfo::SetProcessPluginName(const char *plugin_name) {100LLDB_INSTRUMENT_VA(this, plugin_name);101102return m_opaque_sp->SetProcessPluginName(plugin_name);103}104105void SBAttachInfo::SetExecutable(const char *path) {106LLDB_INSTRUMENT_VA(this, path);107108if (path && path[0])109m_opaque_sp->GetExecutableFile().SetFile(path, FileSpec::Style::native);110else111m_opaque_sp->GetExecutableFile().Clear();112}113114void SBAttachInfo::SetExecutable(SBFileSpec exe_file) {115LLDB_INSTRUMENT_VA(this, exe_file);116117if (exe_file.IsValid())118m_opaque_sp->GetExecutableFile() = exe_file.ref();119else120m_opaque_sp->GetExecutableFile().Clear();121}122123bool SBAttachInfo::GetWaitForLaunch() {124LLDB_INSTRUMENT_VA(this);125126return m_opaque_sp->GetWaitForLaunch();127}128129void SBAttachInfo::SetWaitForLaunch(bool b) {130LLDB_INSTRUMENT_VA(this, b);131132m_opaque_sp->SetWaitForLaunch(b);133}134135void SBAttachInfo::SetWaitForLaunch(bool b, bool async) {136LLDB_INSTRUMENT_VA(this, b, async);137138m_opaque_sp->SetWaitForLaunch(b);139m_opaque_sp->SetAsync(async);140}141142bool SBAttachInfo::GetIgnoreExisting() {143LLDB_INSTRUMENT_VA(this);144145return m_opaque_sp->GetIgnoreExisting();146}147148void SBAttachInfo::SetIgnoreExisting(bool b) {149LLDB_INSTRUMENT_VA(this, b);150151m_opaque_sp->SetIgnoreExisting(b);152}153154uint32_t SBAttachInfo::GetUserID() {155LLDB_INSTRUMENT_VA(this);156157return m_opaque_sp->GetUserID();158}159160uint32_t SBAttachInfo::GetGroupID() {161LLDB_INSTRUMENT_VA(this);162163return m_opaque_sp->GetGroupID();164}165166bool SBAttachInfo::UserIDIsValid() {167LLDB_INSTRUMENT_VA(this);168169return m_opaque_sp->UserIDIsValid();170}171172bool SBAttachInfo::GroupIDIsValid() {173LLDB_INSTRUMENT_VA(this);174175return m_opaque_sp->GroupIDIsValid();176}177178void SBAttachInfo::SetUserID(uint32_t uid) {179LLDB_INSTRUMENT_VA(this, uid);180181m_opaque_sp->SetUserID(uid);182}183184void SBAttachInfo::SetGroupID(uint32_t gid) {185LLDB_INSTRUMENT_VA(this, gid);186187m_opaque_sp->SetGroupID(gid);188}189190uint32_t SBAttachInfo::GetEffectiveUserID() {191LLDB_INSTRUMENT_VA(this);192193return m_opaque_sp->GetEffectiveUserID();194}195196uint32_t SBAttachInfo::GetEffectiveGroupID() {197LLDB_INSTRUMENT_VA(this);198199return m_opaque_sp->GetEffectiveGroupID();200}201202bool SBAttachInfo::EffectiveUserIDIsValid() {203LLDB_INSTRUMENT_VA(this);204205return m_opaque_sp->EffectiveUserIDIsValid();206}207208bool SBAttachInfo::EffectiveGroupIDIsValid() {209LLDB_INSTRUMENT_VA(this);210211return m_opaque_sp->EffectiveGroupIDIsValid();212}213214void SBAttachInfo::SetEffectiveUserID(uint32_t uid) {215LLDB_INSTRUMENT_VA(this, uid);216217m_opaque_sp->SetEffectiveUserID(uid);218}219220void SBAttachInfo::SetEffectiveGroupID(uint32_t gid) {221LLDB_INSTRUMENT_VA(this, gid);222223m_opaque_sp->SetEffectiveGroupID(gid);224}225226lldb::pid_t SBAttachInfo::GetParentProcessID() {227LLDB_INSTRUMENT_VA(this);228229return m_opaque_sp->GetParentProcessID();230}231232void SBAttachInfo::SetParentProcessID(lldb::pid_t pid) {233LLDB_INSTRUMENT_VA(this, pid);234235m_opaque_sp->SetParentProcessID(pid);236}237238bool SBAttachInfo::ParentProcessIDIsValid() {239LLDB_INSTRUMENT_VA(this);240241return m_opaque_sp->ParentProcessIDIsValid();242}243244SBListener SBAttachInfo::GetListener() {245LLDB_INSTRUMENT_VA(this);246247return SBListener(m_opaque_sp->GetListener());248}249250void SBAttachInfo::SetListener(SBListener &listener) {251LLDB_INSTRUMENT_VA(this, listener);252253m_opaque_sp->SetListener(listener.GetSP());254}255256SBListener SBAttachInfo::GetShadowListener() {257LLDB_INSTRUMENT_VA(this);258259lldb::ListenerSP shadow_sp = m_opaque_sp->GetShadowListener();260if (!shadow_sp)261return SBListener();262return SBListener(shadow_sp);263}264265void SBAttachInfo::SetShadowListener(SBListener &listener) {266LLDB_INSTRUMENT_VA(this, listener);267268m_opaque_sp->SetShadowListener(listener.GetSP());269}270271const char *SBAttachInfo::GetScriptedProcessClassName() const {272LLDB_INSTRUMENT_VA(this);273274ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();275276if (!metadata_sp || !*metadata_sp)277return nullptr;278279// Constify this string so that it is saved in the string pool. Otherwise it280// would be freed when this function goes out of scope.281ConstString class_name(metadata_sp->GetClassName().data());282return class_name.AsCString();283}284285void SBAttachInfo::SetScriptedProcessClassName(const char *class_name) {286LLDB_INSTRUMENT_VA(this, class_name);287288ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();289290if (!metadata_sp)291metadata_sp = std::make_shared<ScriptedMetadata>(class_name, nullptr);292else293metadata_sp = std::make_shared<ScriptedMetadata>(class_name,294metadata_sp->GetArgsSP());295296m_opaque_sp->SetScriptedMetadata(metadata_sp);297}298299lldb::SBStructuredData SBAttachInfo::GetScriptedProcessDictionary() const {300LLDB_INSTRUMENT_VA(this);301302ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();303304SBStructuredData data;305if (!metadata_sp)306return data;307308lldb_private::StructuredData::DictionarySP dict_sp = metadata_sp->GetArgsSP();309data.m_impl_up->SetObjectSP(dict_sp);310311return data;312}313314void SBAttachInfo::SetScriptedProcessDictionary(lldb::SBStructuredData dict) {315LLDB_INSTRUMENT_VA(this, dict);316317if (!dict.IsValid() || !dict.m_impl_up)318return;319320StructuredData::ObjectSP obj_sp = dict.m_impl_up->GetObjectSP();321322if (!obj_sp)323return;324325StructuredData::DictionarySP dict_sp =326std::make_shared<StructuredData::Dictionary>(obj_sp);327if (!dict_sp || dict_sp->GetType() == lldb::eStructuredDataTypeInvalid)328return;329330ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();331332if (!metadata_sp)333metadata_sp = std::make_shared<ScriptedMetadata>("", dict_sp);334else335metadata_sp = std::make_shared<ScriptedMetadata>(336metadata_sp->GetClassName(), dict_sp);337338m_opaque_sp->SetScriptedMetadata(metadata_sp);339}340341342