diff options
Diffstat (limited to 'source/Plugins/DynamicLoader')
6 files changed, 316 insertions, 275 deletions
| diff --git a/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp b/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp index 23c8416f4986..5b19647a27ba 100644 --- a/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp +++ b/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp @@ -277,8 +277,7 @@ bool DynamicLoaderHexagonDYLD::SetRendezvousBreakpoint() {    // Do not try to set the breakpoint if we don't know where to put it    if (break_addr == LLDB_INVALID_ADDRESS) { -    if (log) -      log->Printf("Unable to locate _rtld_debug_state breakpoint address"); +    LLDB_LOGF(log, "Unable to locate _rtld_debug_state breakpoint address");      return false;    } @@ -301,7 +300,7 @@ bool DynamicLoaderHexagonDYLD::SetRendezvousBreakpoint() {                 .GetID() == m_dyld_bid);      if (log && dyld_break == nullptr) -      log->Printf("Failed to create _rtld_debug_state breakpoint"); +      LLDB_LOGF(log, "Failed to create _rtld_debug_state breakpoint");      // check we have successfully set bp      return (dyld_break != nullptr); @@ -316,8 +315,7 @@ bool DynamicLoaderHexagonDYLD::RendezvousBreakpointHit(      user_id_t break_loc_id) {    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); -  if (log) -    log->Printf("Rendezvous breakpoint hit!"); +  LLDB_LOGF(log, "Rendezvous breakpoint hit!");    DynamicLoaderHexagonDYLD *dyld_instance = nullptr;    dyld_instance = static_cast<DynamicLoaderHexagonDYLD *>(baton); @@ -333,11 +331,9 @@ bool DynamicLoaderHexagonDYLD::RendezvousBreakpointHit(      if (structAddr != LLDB_INVALID_ADDRESS) {        dyld_instance->m_rendezvous.SetRendezvousAddress(structAddr); -      if (log) -        log->Printf("Found _rtld_debug structure @ 0x%08" PRIx64, structAddr); +      LLDB_LOGF(log, "Found _rtld_debug structure @ 0x%08" PRIx64, structAddr);      } else { -      if (log) -        log->Printf("Unable to resolve the _rtld_debug structure"); +      LLDB_LOGF(log, "Unable to resolve the _rtld_debug structure");      }    } @@ -375,11 +371,11 @@ void DynamicLoaderHexagonDYLD::RefreshModules() {        }        if (log) { -        log->Printf("Target is loading '%s'", I->path.c_str()); +        LLDB_LOGF(log, "Target is loading '%s'", I->path.c_str());          if (!module_sp.get()) -          log->Printf("LLDB failed to load '%s'", I->path.c_str()); +          LLDB_LOGF(log, "LLDB failed to load '%s'", I->path.c_str());          else -          log->Printf("LLDB successfully loaded '%s'", I->path.c_str()); +          LLDB_LOGF(log, "LLDB successfully loaded '%s'", I->path.c_str());        }      }      m_process->GetTarget().ModulesDidLoad(new_modules); @@ -400,8 +396,7 @@ void DynamicLoaderHexagonDYLD::RefreshModules() {          UnloadSections(module_sp);        } -      if (log) -        log->Printf("Target is unloading '%s'", I->path.c_str()); +      LLDB_LOGF(log, "Target is unloading '%s'", I->path.c_str());      }      loaded_modules.Remove(old_modules);      m_process->GetTarget().ModulesDidUnload(old_modules, false); @@ -472,10 +467,10 @@ void DynamicLoaderHexagonDYLD::LoadAllCurrentModules() {    if (!m_rendezvous.Resolve()) {      Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); -    if (log) -      log->Printf( -          "DynamicLoaderHexagonDYLD::%s unable to resolve rendezvous address", -          __FUNCTION__); +    LLDB_LOGF( +        log, +        "DynamicLoaderHexagonDYLD::%s unable to resolve rendezvous address", +        __FUNCTION__);      return;    } @@ -493,10 +488,10 @@ void DynamicLoaderHexagonDYLD::LoadAllCurrentModules() {        module_list.Append(module_sp);      } else {        Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); -      if (log) -        log->Printf("DynamicLoaderHexagonDYLD::%s failed loading module %s at " -                    "0x%" PRIx64, -                    __FUNCTION__, module_path, I->base_addr); +      LLDB_LOGF(log, +                "DynamicLoaderHexagonDYLD::%s failed loading module %s at " +                "0x%" PRIx64, +                __FUNCTION__, module_path, I->base_addr);      }    } @@ -604,12 +599,11 @@ DynamicLoaderHexagonDYLD::GetThreadLocalData(const lldb::ModuleSP module,    Module *mod = module.get();    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); -  if (log) -    log->Printf("DynamicLoaderHexagonDYLD::Performed TLS lookup: " -                "module=%s, link_map=0x%" PRIx64 ", tp=0x%" PRIx64 -                ", modid=%i, tls_block=0x%" PRIx64, -                mod->GetObjectName().AsCString(""), link_map, tp, modid, -                tls_block); +  LLDB_LOGF(log, +            "DynamicLoaderHexagonDYLD::Performed TLS lookup: " +            "module=%s, link_map=0x%" PRIx64 ", tp=0x%" PRIx64 +            ", modid=%i, tls_block=0x%" PRIx64, +            mod->GetObjectName().AsCString(""), link_map, tp, modid, tls_block);    if (tls_block == LLDB_INVALID_ADDRESS)      return LLDB_INVALID_ADDRESS; diff --git a/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp b/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp index 844a06c2b37d..f4788816d4ea 100644 --- a/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp +++ b/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp @@ -290,8 +290,9 @@ bool HexagonDYLDRendezvous::FindMetadata(const char *name, PThreadField field,    Target &target = m_process->GetTarget();    SymbolContextList list; -  if (!target.GetImages().FindSymbolsWithNameAndType(ConstString(name), -                                                     eSymbolTypeAny, list)) +  target.GetImages().FindSymbolsWithNameAndType(ConstString(name), +                                                eSymbolTypeAny, list); +  if (list.IsEmpty())      return false;    Address address = list[0].symbol->GetAddress(); @@ -339,16 +340,16 @@ void HexagonDYLDRendezvous::DumpToLog(Log *log) const {      return;    log->PutCString("HexagonDYLDRendezvous:"); -  log->Printf("   Address: %" PRIx64, GetRendezvousAddress()); -  log->Printf("   Version: %" PRIu64, GetVersion()); -  log->Printf("   Link   : %" PRIx64, GetLinkMapAddress()); -  log->Printf("   Break  : %" PRIx64, GetBreakAddress()); -  log->Printf("   LDBase : %" PRIx64, GetLDBase()); -  log->Printf("   State  : %s", -              (state == eConsistent) -                  ? "consistent" -                  : (state == eAdd) ? "add" : (state == eDelete) ? "delete" -                                                                 : "unknown"); +  LLDB_LOGF(log, "   Address: %" PRIx64, GetRendezvousAddress()); +  LLDB_LOGF(log, "   Version: %" PRIu64, GetVersion()); +  LLDB_LOGF(log, "   Link   : %" PRIx64, GetLinkMapAddress()); +  LLDB_LOGF(log, "   Break  : %" PRIx64, GetBreakAddress()); +  LLDB_LOGF(log, "   LDBase : %" PRIx64, GetLDBase()); +  LLDB_LOGF(log, "   State  : %s", +            (state == eConsistent) +                ? "consistent" +                : (state == eAdd) ? "add" +                                  : (state == eDelete) ? "delete" : "unknown");    iterator I = begin();    iterator E = end(); @@ -357,11 +358,11 @@ void HexagonDYLDRendezvous::DumpToLog(Log *log) const {      log->PutCString("HexagonDYLDRendezvous SOEntries:");    for (int i = 1; I != E; ++I, ++i) { -    log->Printf("\n   SOEntry [%d] %s", i, I->path.c_str()); -    log->Printf("      Base : %" PRIx64, I->base_addr); -    log->Printf("      Path : %" PRIx64, I->path_addr); -    log->Printf("      Dyn  : %" PRIx64, I->dyn_addr); -    log->Printf("      Next : %" PRIx64, I->next); -    log->Printf("      Prev : %" PRIx64, I->prev); +    LLDB_LOGF(log, "\n   SOEntry [%d] %s", i, I->path.c_str()); +    LLDB_LOGF(log, "      Base : %" PRIx64, I->base_addr); +    LLDB_LOGF(log, "      Path : %" PRIx64, I->path_addr); +    LLDB_LOGF(log, "      Dyn  : %" PRIx64, I->dyn_addr); +    LLDB_LOGF(log, "      Next : %" PRIx64, I->next); +    LLDB_LOGF(log, "      Prev : %" PRIx64, I->prev);    }  } diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp b/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp index 0d736738ebb5..737599303a60 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp @@ -33,16 +33,14 @@ static addr_t ResolveRendezvousAddress(Process *process) {    Status error;    if (!process) { -    if (log) -      log->Printf("%s null process provided", __FUNCTION__); +    LLDB_LOGF(log, "%s null process provided", __FUNCTION__);      return LLDB_INVALID_ADDRESS;    }    // Try to get it from our process.  This might be a remote process and might    // grab it via some remote-specific mechanism.    info_location = process->GetImageInfoAddress(); -  if (log) -    log->Printf("%s info_location = 0x%" PRIx64, __FUNCTION__, info_location); +  LLDB_LOGF(log, "%s info_location = 0x%" PRIx64, __FUNCTION__, info_location);    // If the process fails to return an address, fall back to seeing if the    // local object file can help us find it. @@ -54,42 +52,38 @@ static addr_t ResolveRendezvousAddress(Process *process) {        if (addr.IsValid()) {          info_location = addr.GetLoadAddress(target); -        if (log) -          log->Printf( -              "%s resolved via direct object file approach to 0x%" PRIx64, -              __FUNCTION__, info_location); +        LLDB_LOGF(log, +                  "%s resolved via direct object file approach to 0x%" PRIx64, +                  __FUNCTION__, info_location);        } else { -        if (log) -          log->Printf("%s FAILED - direct object file approach did not yield a " -                      "valid address", -                      __FUNCTION__); +        LLDB_LOGF(log, +                  "%s FAILED - direct object file approach did not yield a " +                  "valid address", +                  __FUNCTION__);        }      }    }    if (info_location == LLDB_INVALID_ADDRESS) { -    if (log) -      log->Printf("%s FAILED - invalid info address", __FUNCTION__); +    LLDB_LOGF(log, "%s FAILED - invalid info address", __FUNCTION__);      return LLDB_INVALID_ADDRESS;    } -  if (log) -    log->Printf("%s reading pointer (%" PRIu32 " bytes) from 0x%" PRIx64, -                __FUNCTION__, process->GetAddressByteSize(), info_location); +  LLDB_LOGF(log, "%s reading pointer (%" PRIu32 " bytes) from 0x%" PRIx64, +            __FUNCTION__, process->GetAddressByteSize(), info_location);    info_addr = process->ReadPointerFromMemory(info_location, error);    if (error.Fail()) { -    if (log) -      log->Printf("%s FAILED - could not read from the info location: %s", -                  __FUNCTION__, error.AsCString()); +    LLDB_LOGF(log, "%s FAILED - could not read from the info location: %s", +              __FUNCTION__, error.AsCString());      return LLDB_INVALID_ADDRESS;    }    if (info_addr == 0) { -    if (log) -      log->Printf("%s FAILED - the rendezvous address contained at 0x%" PRIx64 -                  " returned a null value", -                  __FUNCTION__, info_location); +    LLDB_LOGF(log, +              "%s FAILED - the rendezvous address contained at 0x%" PRIx64 +              " returned a null value", +              __FUNCTION__, info_location);      return LLDB_INVALID_ADDRESS;    } @@ -109,14 +103,13 @@ DYLDRendezvous::DYLDRendezvous(Process *process)      Module *exe_mod = m_process->GetTarget().GetExecutableModulePointer();      if (exe_mod) {        m_exe_file_spec = exe_mod->GetPlatformFileSpec(); -      if (log) -        log->Printf("DYLDRendezvous::%s exe module executable path set: '%s'", -                    __FUNCTION__, m_exe_file_spec.GetCString()); +      LLDB_LOGF(log, "DYLDRendezvous::%s exe module executable path set: '%s'", +                __FUNCTION__, m_exe_file_spec.GetCString());      } else { -      if (log) -        log->Printf("DYLDRendezvous::%s cannot cache exe module path: null " -                    "executable module pointer", -                    __FUNCTION__); +      LLDB_LOGF(log, +                "DYLDRendezvous::%s cannot cache exe module path: null " +                "executable module pointer", +                __FUNCTION__);      }    }  } @@ -133,17 +126,16 @@ bool DYLDRendezvous::Resolve() {    address_size = m_process->GetAddressByteSize();    padding = address_size - word_size; -  if (log) -    log->Printf("DYLDRendezvous::%s address size: %" PRIu64 -                ", padding %" PRIu64, -                __FUNCTION__, uint64_t(address_size), uint64_t(padding)); +  LLDB_LOGF(log, +            "DYLDRendezvous::%s address size: %" PRIu64 ", padding %" PRIu64, +            __FUNCTION__, uint64_t(address_size), uint64_t(padding));    if (m_rendezvous_addr == LLDB_INVALID_ADDRESS)      cursor = info_addr = ResolveRendezvousAddress(m_process);    else      cursor = info_addr = m_rendezvous_addr; -  if (log) -    log->Printf("DYLDRendezvous::%s cursor = 0x%" PRIx64, __FUNCTION__, cursor); +  LLDB_LOGF(log, "DYLDRendezvous::%s cursor = 0x%" PRIx64, __FUNCTION__, +            cursor);    if (cursor == LLDB_INVALID_ADDRESS)      return false; @@ -168,7 +160,10 @@ bool DYLDRendezvous::Resolve() {    m_previous = m_current;    m_current = info; -  if (UpdateSOEntries(true)) +  if (m_current.map_addr == 0) +    return false; + +  if (UpdateSOEntriesFromRemote())      return true;    return UpdateSOEntries(); @@ -178,53 +173,91 @@ bool DYLDRendezvous::IsValid() {    return m_rendezvous_addr != LLDB_INVALID_ADDRESS;  } -bool DYLDRendezvous::UpdateSOEntries(bool fromRemote) { -  SOEntry entry; -  LoadedModuleInfoList module_list; +DYLDRendezvous::RendezvousAction DYLDRendezvous::GetAction() const { +  switch (m_current.state) { + +  case eConsistent: +    switch (m_previous.state) { +    // When the previous and current states are consistent this is the first +    // time we have been asked to update.  Just take a snapshot of the +    // currently loaded modules. +    case eConsistent: +      return eTakeSnapshot; +    // If we are about to add or remove a shared object clear out the current +    // state and take a snapshot of the currently loaded images. +    case eAdd: +      return eAddModules; +    case eDelete: +      return eRemoveModules; +    } +    break; -  // If we can't get the SO info from the remote, return failure. -  if (fromRemote && m_process->LoadModules(module_list) == 0) -    return false; +  case eAdd: +  case eDelete: +    // Some versions of the android dynamic linker might send two +    // notifications with state == eAdd back to back. Ignore them until we +    // get an eConsistent notification. +    if (!(m_previous.state == eConsistent || +          (m_previous.state == eAdd && m_current.state == eDelete))) +      return eNoAction; + +    return eTakeSnapshot; +  } + +  return eNoAction; +} + +bool DYLDRendezvous::UpdateSOEntriesFromRemote() { +  auto action = GetAction(); -  if (!fromRemote && m_current.map_addr == 0) +  if (action == eNoAction)      return false; -  // When the previous and current states are consistent this is the first time -  // we have been asked to update.  Just take a snapshot of the currently -  // loaded modules. -  if (m_previous.state == eConsistent && m_current.state == eConsistent) -    return fromRemote ? SaveSOEntriesFromRemote(module_list) -                      : TakeSnapshot(m_soentries); - -  // If we are about to add or remove a shared object clear out the current -  // state and take a snapshot of the currently loaded images. -  if (m_current.state == eAdd || m_current.state == eDelete) { -    // Some versions of the android dynamic linker might send two notifications -    // with state == eAdd back to back. Ignore them until we get an eConsistent -    // notification. -    if (!(m_previous.state == eConsistent || -          (m_previous.state == eAdd && m_current.state == eDelete))) -      return false; +  if (action == eTakeSnapshot) { +    m_added_soentries.clear(); +    m_removed_soentries.clear(); +    // We already have the loaded list from the previous update so no need to +    // find all the modules again. +    if (!m_loaded_modules.m_list.empty()) +      return true; +  } + +  llvm::Expected<LoadedModuleInfoList> module_list = +      m_process->GetLoadedModuleList(); +  if (!module_list) { +    llvm::consumeError(module_list.takeError()); +    return false; +  } +  switch (action) { +  case eTakeSnapshot:      m_soentries.clear(); -    if (fromRemote) -      return SaveSOEntriesFromRemote(module_list); +    return SaveSOEntriesFromRemote(*module_list); +  case eAddModules: +    return AddSOEntriesFromRemote(*module_list); +  case eRemoveModules: +    return RemoveSOEntriesFromRemote(*module_list); +  case eNoAction: +    return false; +  } +  llvm_unreachable("Fully covered switch above!"); +} +bool DYLDRendezvous::UpdateSOEntries() { +  switch (GetAction()) { +  case eTakeSnapshot: +    m_soentries.clear();      m_added_soentries.clear();      m_removed_soentries.clear();      return TakeSnapshot(m_soentries); +  case eAddModules: +    return AddSOEntries(); +  case eRemoveModules: +    return RemoveSOEntries(); +  case eNoAction: +    return false;    } -  assert(m_current.state == eConsistent); - -  // Otherwise check the previous state to determine what to expect and update -  // accordingly. -  if (m_previous.state == eAdd) -    return fromRemote ? AddSOEntriesFromRemote(module_list) : AddSOEntries(); -  else if (m_previous.state == eDelete) -    return fromRemote ? RemoveSOEntriesFromRemote(module_list) -                      : RemoveSOEntries(); - -  return false; +  llvm_unreachable("Fully covered switch above!");  }  bool DYLDRendezvous::FillSOEntryFromModuleInfo( @@ -255,7 +288,7 @@ bool DYLDRendezvous::FillSOEntryFromModuleInfo(  }  bool DYLDRendezvous::SaveSOEntriesFromRemote( -    LoadedModuleInfoList &module_list) { +    const LoadedModuleInfoList &module_list) {    for (auto const &modInfo : module_list.m_list) {      SOEntry entry;      if (!FillSOEntryFromModuleInfo(modInfo, entry)) @@ -270,7 +303,8 @@ bool DYLDRendezvous::SaveSOEntriesFromRemote(    return true;  } -bool DYLDRendezvous::AddSOEntriesFromRemote(LoadedModuleInfoList &module_list) { +bool DYLDRendezvous::AddSOEntriesFromRemote( +    const LoadedModuleInfoList &module_list) {    for (auto const &modInfo : module_list.m_list) {      bool found = false;      for (auto const &existing : m_loaded_modules.m_list) { @@ -288,8 +322,10 @@ bool DYLDRendezvous::AddSOEntriesFromRemote(LoadedModuleInfoList &module_list) {        return false;      // Only add shared libraries and not the executable. -    if (!SOEntryIsMainExecutable(entry)) +    if (!SOEntryIsMainExecutable(entry)) {        m_soentries.push_back(entry); +      m_added_soentries.push_back(entry); +    }    }    m_loaded_modules = module_list; @@ -297,7 +333,7 @@ bool DYLDRendezvous::AddSOEntriesFromRemote(LoadedModuleInfoList &module_list) {  }  bool DYLDRendezvous::RemoveSOEntriesFromRemote( -    LoadedModuleInfoList &module_list) { +    const LoadedModuleInfoList &module_list) {    for (auto const &existing : m_loaded_modules.m_list) {      bool found = false;      for (auto const &modInfo : module_list.m_list) { @@ -321,6 +357,7 @@ bool DYLDRendezvous::RemoveSOEntriesFromRemote(          return false;        m_soentries.erase(pos); +      m_removed_soentries.push_back(entry);      }    } @@ -521,9 +558,10 @@ bool DYLDRendezvous::FindMetadata(const char *name, PThreadField field,    Target &target = m_process->GetTarget();    SymbolContextList list; -  if (!target.GetImages().FindSymbolsWithNameAndType(ConstString(name), -                                                     eSymbolTypeAny, list)) -    return false; +  target.GetImages().FindSymbolsWithNameAndType(ConstString(name), +                                                eSymbolTypeAny, list); +  if (list.IsEmpty()) +  return false;    Address address = list[0].symbol->GetAddress();    addr_t addr = address.GetLoadAddress(&target); @@ -569,16 +607,16 @@ void DYLDRendezvous::DumpToLog(Log *log) const {      return;    log->PutCString("DYLDRendezvous:"); -  log->Printf("   Address: %" PRIx64, GetRendezvousAddress()); -  log->Printf("   Version: %" PRIu64, GetVersion()); -  log->Printf("   Link   : %" PRIx64, GetLinkMapAddress()); -  log->Printf("   Break  : %" PRIx64, GetBreakAddress()); -  log->Printf("   LDBase : %" PRIx64, GetLDBase()); -  log->Printf("   State  : %s", -              (state == eConsistent) -                  ? "consistent" -                  : (state == eAdd) ? "add" : (state == eDelete) ? "delete" -                                                                 : "unknown"); +  LLDB_LOGF(log, "   Address: %" PRIx64, GetRendezvousAddress()); +  LLDB_LOGF(log, "   Version: %" PRIu64, GetVersion()); +  LLDB_LOGF(log, "   Link   : %" PRIx64, GetLinkMapAddress()); +  LLDB_LOGF(log, "   Break  : %" PRIx64, GetBreakAddress()); +  LLDB_LOGF(log, "   LDBase : %" PRIx64, GetLDBase()); +  LLDB_LOGF(log, "   State  : %s", +            (state == eConsistent) +                ? "consistent" +                : (state == eAdd) ? "add" +                                  : (state == eDelete) ? "delete" : "unknown");    iterator I = begin();    iterator E = end(); @@ -587,11 +625,11 @@ void DYLDRendezvous::DumpToLog(Log *log) const {      log->PutCString("DYLDRendezvous SOEntries:");    for (int i = 1; I != E; ++I, ++i) { -    log->Printf("\n   SOEntry [%d] %s", i, I->file_spec.GetCString()); -    log->Printf("      Base : %" PRIx64, I->base_addr); -    log->Printf("      Path : %" PRIx64, I->path_addr); -    log->Printf("      Dyn  : %" PRIx64, I->dyn_addr); -    log->Printf("      Next : %" PRIx64, I->next); -    log->Printf("      Prev : %" PRIx64, I->prev); +    LLDB_LOGF(log, "\n   SOEntry [%d] %s", i, I->file_spec.GetCString()); +    LLDB_LOGF(log, "      Base : %" PRIx64, I->base_addr); +    LLDB_LOGF(log, "      Path : %" PRIx64, I->path_addr); +    LLDB_LOGF(log, "      Dyn  : %" PRIx64, I->dyn_addr); +    LLDB_LOGF(log, "      Next : %" PRIx64, I->next); +    LLDB_LOGF(log, "      Prev : %" PRIx64, I->prev);    }  } diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h b/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h index 993e62f5e9f9..536eeeaaf334 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.h @@ -222,16 +222,20 @@ protected:    /// Updates the current set of SOEntries, the set of added entries, and the    /// set of removed entries. -  bool UpdateSOEntries(bool fromRemote = false); +  bool UpdateSOEntries(); + +  /// Same as UpdateSOEntries but it gets the list of loaded modules from the +  /// remote debug server (faster when supported). +  bool UpdateSOEntriesFromRemote();    bool FillSOEntryFromModuleInfo(        LoadedModuleInfoList::LoadedModuleInfo const &modInfo, SOEntry &entry); -  bool SaveSOEntriesFromRemote(LoadedModuleInfoList &module_list); +  bool SaveSOEntriesFromRemote(const LoadedModuleInfoList &module_list); -  bool AddSOEntriesFromRemote(LoadedModuleInfoList &module_list); +  bool AddSOEntriesFromRemote(const LoadedModuleInfoList &module_list); -  bool RemoveSOEntriesFromRemote(LoadedModuleInfoList &module_list); +  bool RemoveSOEntriesFromRemote(const LoadedModuleInfoList &module_list);    bool AddSOEntries(); @@ -248,6 +252,17 @@ protected:    enum PThreadField { eSize, eNElem, eOffset };    bool FindMetadata(const char *name, PThreadField field, uint32_t &value); + +  enum RendezvousAction { +    eNoAction, +    eTakeSnapshot, +    eAddModules, +    eRemoveModules +  }; + +  /// Returns the current action to be taken given the current and previous +  /// state +  RendezvousAction GetAction() const;  };  #endif diff --git a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp index b55660899d0d..9d61c8feb923 100644 --- a/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp +++ b/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp @@ -85,32 +85,31 @@ DynamicLoaderPOSIXDYLD::~DynamicLoaderPOSIXDYLD() {  void DynamicLoaderPOSIXDYLD::DidAttach() {    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); -  if (log) -    log->Printf("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64, __FUNCTION__, -                m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID); -  m_auxv = llvm::make_unique<AuxVector>(m_process->GetAuxvData()); +  LLDB_LOGF(log, "DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64, __FUNCTION__, +            m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID); +  m_auxv = std::make_unique<AuxVector>(m_process->GetAuxvData()); -  if (log) -    log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data", -                __FUNCTION__, -                m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID); +  LLDB_LOGF( +      log, "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data", +      __FUNCTION__, m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);    // ask the process if it can load any of its own modules -  m_process->LoadModules(); +  auto error = m_process->LoadModules(); +  LLDB_LOG_ERROR(log, std::move(error), "Couldn't load modules: {0}");    ModuleSP executable_sp = GetTargetExecutable();    ResolveExecutableModule(executable_sp);    // find the main process load offset    addr_t load_offset = ComputeLoadOffset(); -  if (log) -    log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 -                " executable '%s', load_offset 0x%" PRIx64, -                __FUNCTION__, -                m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID, -                executable_sp ? executable_sp->GetFileSpec().GetPath().c_str() -                              : "<null executable>", -                load_offset); +  LLDB_LOGF(log, +            "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 +            " executable '%s', load_offset 0x%" PRIx64, +            __FUNCTION__, +            m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID, +            executable_sp ? executable_sp->GetFileSpec().GetPath().c_str() +                          : "<null executable>", +            load_offset);    EvalSpecialModulesStatus(); @@ -137,12 +136,12 @@ void DynamicLoaderPOSIXDYLD::DidAttach() {      ModuleList module_list;      module_list.Append(executable_sp); -    if (log) -      log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 -                  " added executable '%s' to module load list", -                  __FUNCTION__, -                  m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID, -                  executable_sp->GetFileSpec().GetPath().c_str()); +    LLDB_LOGF(log, +              "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 +              " added executable '%s' to module load list", +              __FUNCTION__, +              m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID, +              executable_sp->GetFileSpec().GetPath().c_str());      UpdateLoadedSections(executable_sp, LLDB_INVALID_ADDRESS, load_offset,                           true); @@ -151,14 +150,15 @@ void DynamicLoaderPOSIXDYLD::DidAttach() {      m_process->GetTarget().ModulesDidLoad(module_list);      if (log) { -      log->Printf("DynamicLoaderPOSIXDYLD::%s told the target about the " -                  "modules that loaded:", -                  __FUNCTION__); +      LLDB_LOGF(log, +                "DynamicLoaderPOSIXDYLD::%s told the target about the " +                "modules that loaded:", +                __FUNCTION__);        for (auto module_sp : module_list.Modules()) { -        log->Printf("-- [module] %s (pid %" PRIu64 ")", -                    module_sp ? module_sp->GetFileSpec().GetPath().c_str() -                              : "<null>", -                    m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID); +        LLDB_LOGF(log, "-- [module] %s (pid %" PRIu64 ")", +                  module_sp ? module_sp->GetFileSpec().GetPath().c_str() +                            : "<null>", +                  m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);        }      }    } @@ -174,13 +174,12 @@ void DynamicLoaderPOSIXDYLD::DidAttach() {  void DynamicLoaderPOSIXDYLD::DidLaunch() {    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); -  if (log) -    log->Printf("DynamicLoaderPOSIXDYLD::%s()", __FUNCTION__); +  LLDB_LOGF(log, "DynamicLoaderPOSIXDYLD::%s()", __FUNCTION__);    ModuleSP executable;    addr_t load_offset; -  m_auxv = llvm::make_unique<AuxVector>(m_process->GetAuxvData()); +  m_auxv = std::make_unique<AuxVector>(m_process->GetAuxvData());    executable = GetTargetExecutable();    load_offset = ComputeLoadOffset(); @@ -191,9 +190,8 @@ void DynamicLoaderPOSIXDYLD::DidLaunch() {      module_list.Append(executable);      UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_offset, true); -    if (log) -      log->Printf("DynamicLoaderPOSIXDYLD::%s about to call ProbeEntry()", -                  __FUNCTION__); +    LLDB_LOGF(log, "DynamicLoaderPOSIXDYLD::%s about to call ProbeEntry()", +              __FUNCTION__);      if (!SetRendezvousBreakpoint()) {        // If we cannot establish rendezvous breakpoint right now we'll try again @@ -227,22 +225,20 @@ void DynamicLoaderPOSIXDYLD::ProbeEntry() {    const addr_t entry = GetEntryPoint();    if (entry == LLDB_INVALID_ADDRESS) { -    if (log) -      log->Printf( -          "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 -          " GetEntryPoint() returned no address, not setting entry breakpoint", -          __FUNCTION__, -          m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID); +    LLDB_LOGF( +        log, +        "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 +        " GetEntryPoint() returned no address, not setting entry breakpoint", +        __FUNCTION__, m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);      return;    } -  if (log) -    log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 -                " GetEntryPoint() returned address 0x%" PRIx64 -                ", setting entry breakpoint", -                __FUNCTION__, -                m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID, -                entry); +  LLDB_LOGF(log, +            "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 +            " GetEntryPoint() returned address 0x%" PRIx64 +            ", setting entry breakpoint", +            __FUNCTION__, +            m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID, entry);    if (m_process) {      Breakpoint *const entry_break = @@ -271,11 +267,10 @@ bool DynamicLoaderPOSIXDYLD::EntryBreakpointHit(    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));    DynamicLoaderPOSIXDYLD *const dyld_instance =        static_cast<DynamicLoaderPOSIXDYLD *>(baton); -  if (log) -    log->Printf("DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64, -                __FUNCTION__, -                dyld_instance->m_process ? dyld_instance->m_process->GetID() -                                         : LLDB_INVALID_PROCESS_ID); +  LLDB_LOGF(log, "DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64, +            __FUNCTION__, +            dyld_instance->m_process ? dyld_instance->m_process->GetID() +                                     : LLDB_INVALID_PROCESS_ID);    // Disable the breakpoint --- if a stop happens right after this, which we've    // seen on occasion, we don't want the breakpoint stepping thread-plan logic @@ -287,22 +282,22 @@ bool DynamicLoaderPOSIXDYLD::EntryBreakpointHit(      BreakpointSP breakpoint_sp =          dyld_instance->m_process->GetTarget().GetBreakpointByID(break_id);      if (breakpoint_sp) { -      if (log) -        log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 -                    " disabling breakpoint id %" PRIu64, -                    __FUNCTION__, dyld_instance->m_process->GetID(), break_id); +      LLDB_LOGF(log, +                "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 +                " disabling breakpoint id %" PRIu64, +                __FUNCTION__, dyld_instance->m_process->GetID(), break_id);        breakpoint_sp->SetEnabled(false);      } else { -      if (log) -        log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 -                    " failed to find breakpoint for breakpoint id %" PRIu64, -                    __FUNCTION__, dyld_instance->m_process->GetID(), break_id); +      LLDB_LOGF(log, +                "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 +                " failed to find breakpoint for breakpoint id %" PRIu64, +                __FUNCTION__, dyld_instance->m_process->GetID(), break_id);      }    } else { -    if (log) -      log->Printf("DynamicLoaderPOSIXDYLD::%s breakpoint id %" PRIu64 -                  " no Process instance!  Cannot disable breakpoint", -                  __FUNCTION__, break_id); +    LLDB_LOGF(log, +              "DynamicLoaderPOSIXDYLD::%s breakpoint id %" PRIu64 +              " no Process instance!  Cannot disable breakpoint", +              __FUNCTION__, break_id);    }    dyld_instance->LoadAllCurrentModules(); @@ -393,23 +388,22 @@ bool DynamicLoaderPOSIXDYLD::RendezvousBreakpointHit(    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));    DynamicLoaderPOSIXDYLD *const dyld_instance =        static_cast<DynamicLoaderPOSIXDYLD *>(baton); -  if (log) -    log->Printf("DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64, -                __FUNCTION__, -                dyld_instance->m_process ? dyld_instance->m_process->GetID() -                                         : LLDB_INVALID_PROCESS_ID); +  LLDB_LOGF(log, "DynamicLoaderPOSIXDYLD::%s called for pid %" PRIu64, +            __FUNCTION__, +            dyld_instance->m_process ? dyld_instance->m_process->GetID() +                                     : LLDB_INVALID_PROCESS_ID);    dyld_instance->RefreshModules();    // Return true to stop the target, false to just let the target run.    const bool stop_when_images_change = dyld_instance->GetStopWhenImagesChange(); -  if (log) -    log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 -                " stop_when_images_change=%s", -                __FUNCTION__, -                dyld_instance->m_process ? dyld_instance->m_process->GetID() -                                         : LLDB_INVALID_PROCESS_ID, -                stop_when_images_change ? "true" : "false"); +  LLDB_LOGF(log, +            "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 +            " stop_when_images_change=%s", +            __FUNCTION__, +            dyld_instance->m_process ? dyld_instance->m_process->GetID() +                                     : LLDB_INVALID_PROCESS_ID, +            stop_when_images_change ? "true" : "false");    return stop_when_images_change;  } @@ -562,10 +556,10 @@ void DynamicLoaderPOSIXDYLD::LoadAllCurrentModules() {    LoadVDSO();    if (!m_rendezvous.Resolve()) { -    if (log) -      log->Printf("DynamicLoaderPOSIXDYLD::%s unable to resolve POSIX DYLD " -                  "rendezvous address", -                  __FUNCTION__); +    LLDB_LOGF(log, +              "DynamicLoaderPOSIXDYLD::%s unable to resolve POSIX DYLD " +              "rendezvous address", +              __FUNCTION__);      return;    } @@ -589,10 +583,10 @@ void DynamicLoaderPOSIXDYLD::LoadAllCurrentModules() {        module_list.Append(module_sp);      } else {        Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); -      if (log) -        log->Printf( -            "DynamicLoaderPOSIXDYLD::%s failed loading module %s at 0x%" PRIx64, -            __FUNCTION__, I->file_spec.GetCString(), I->base_addr); +      LLDB_LOGF( +          log, +          "DynamicLoaderPOSIXDYLD::%s failed loading module %s at 0x%" PRIx64, +          __FUNCTION__, I->file_spec.GetCString(), I->base_addr);      }    } @@ -697,12 +691,12 @@ DynamicLoaderPOSIXDYLD::GetThreadLocalData(const lldb::ModuleSP module_sp,    addr_t tls_block = ReadPointer(dtv_slot + metadata.tls_offset);    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); -  if (log) -    log->Printf("DynamicLoaderPOSIXDYLD::Performed TLS lookup: " -                "module=%s, link_map=0x%" PRIx64 ", tp=0x%" PRIx64 -                ", modid=%" PRId64 ", tls_block=0x%" PRIx64 "\n", -                module_sp->GetObjectName().AsCString(""), link_map, tp, -                (int64_t)modid, tls_block); +  LLDB_LOGF(log, +            "DynamicLoaderPOSIXDYLD::Performed TLS lookup: " +            "module=%s, link_map=0x%" PRIx64 ", tp=0x%" PRIx64 +            ", modid=%" PRId64 ", tls_block=0x%" PRIx64 "\n", +            module_sp->GetObjectName().AsCString(""), link_map, tp, +            (int64_t)modid, tls_block);    if (tls_block == LLDB_INVALID_ADDRESS)      return LLDB_INVALID_ADDRESS; @@ -722,18 +716,17 @@ void DynamicLoaderPOSIXDYLD::ResolveExecutableModule(    ProcessInstanceInfo process_info;    if (!m_process->GetProcessInfo(process_info)) { -    if (log) -      log->Printf("DynamicLoaderPOSIXDYLD::%s - failed to get process info for " -                  "pid %" PRIu64, -                  __FUNCTION__, m_process->GetID()); +    LLDB_LOGF(log, +              "DynamicLoaderPOSIXDYLD::%s - failed to get process info for " +              "pid %" PRIu64, +              __FUNCTION__, m_process->GetID());      return;    } -  if (log) -    log->Printf("DynamicLoaderPOSIXDYLD::%s - got executable by pid %" PRIu64 -                ": %s", -                __FUNCTION__, m_process->GetID(), -                process_info.GetExecutableFile().GetPath().c_str()); +  LLDB_LOGF( +      log, "DynamicLoaderPOSIXDYLD::%s - got executable by pid %" PRIu64 ": %s", +      __FUNCTION__, m_process->GetID(), +      process_info.GetExecutableFile().GetPath().c_str());    ModuleSpec module_spec(process_info.GetExecutableFile(),                           process_info.GetArchitecture()); @@ -748,10 +741,10 @@ void DynamicLoaderPOSIXDYLD::ResolveExecutableModule(      StreamString stream;      module_spec.Dump(stream); -    if (log) -      log->Printf("DynamicLoaderPOSIXDYLD::%s - failed to resolve executable " -                  "with module spec \"%s\": %s", -                  __FUNCTION__, stream.GetData(), error.AsCString()); +    LLDB_LOGF(log, +              "DynamicLoaderPOSIXDYLD::%s - failed to resolve executable " +              "with module spec \"%s\": %s", +              __FUNCTION__, stream.GetData(), error.AsCString());      return;    } diff --git a/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp b/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp index fa3fbe0d9fa6..25ab30e9db9c 100644 --- a/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp +++ b/source/Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.cpp @@ -122,38 +122,37 @@ lldb::addr_t DynamicLoaderWindowsDYLD::GetLoadAddress(ModuleSP executable) {  void DynamicLoaderWindowsDYLD::DidAttach() {      Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); -  if (log) -    log->Printf("DynamicLoaderWindowsDYLD::%s()", __FUNCTION__); +    LLDB_LOGF(log, "DynamicLoaderWindowsDYLD::%s()", __FUNCTION__); -  ModuleSP executable = GetTargetExecutable(); +    ModuleSP executable = GetTargetExecutable(); -  if (!executable.get()) -    return; +    if (!executable.get()) +      return; -  // Try to fetch the load address of the file from the process, since there -  // could be randomization of the load address. -  lldb::addr_t load_addr = GetLoadAddress(executable); -  if (load_addr == LLDB_INVALID_ADDRESS) -    return; +    // Try to fetch the load address of the file from the process, since there +    // could be randomization of the load address. +    lldb::addr_t load_addr = GetLoadAddress(executable); +    if (load_addr == LLDB_INVALID_ADDRESS) +      return; -  // Request the process base address. -  lldb::addr_t image_base = m_process->GetImageInfoAddress(); -  if (image_base == load_addr) -    return; +    // Request the process base address. +    lldb::addr_t image_base = m_process->GetImageInfoAddress(); +    if (image_base == load_addr) +      return; -  // Rebase the process's modules if there is a mismatch. -  UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_addr, false); +    // Rebase the process's modules if there is a mismatch. +    UpdateLoadedSections(executable, LLDB_INVALID_ADDRESS, load_addr, false); -  ModuleList module_list; -  module_list.Append(executable); -  m_process->GetTarget().ModulesDidLoad(module_list); -  m_process->LoadModules(); +    ModuleList module_list; +    module_list.Append(executable); +    m_process->GetTarget().ModulesDidLoad(module_list); +    auto error = m_process->LoadModules(); +    LLDB_LOG_ERROR(log, std::move(error), "failed to load modules: {0}");  }  void DynamicLoaderWindowsDYLD::DidLaunch() {    Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); -  if (log) -    log->Printf("DynamicLoaderWindowsDYLD::%s()", __FUNCTION__); +  LLDB_LOGF(log, "DynamicLoaderWindowsDYLD::%s()", __FUNCTION__);    ModuleSP executable = GetTargetExecutable();    if (!executable.get()) @@ -167,7 +166,8 @@ void DynamicLoaderWindowsDYLD::DidLaunch() {      ModuleList module_list;      module_list.Append(executable);      m_process->GetTarget().ModulesDidLoad(module_list); -    m_process->LoadModules(); +    auto error = m_process->LoadModules(); +    LLDB_LOG_ERROR(log, std::move(error), "failed to load modules: {0}");    }  } | 
