Repository: llvm/llvm-project
File: lldb/source/Core/Debugger.cpp (C++)

Code before:
  return g_debugger_list_ptr->size();
}

lldb::DebuggerSP Debugger::GetDebuggerAtIndex(size_t index) {
  std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex());
  if (!g_debugger_list_ptr)
    return nullptr;

  if (g_debugger_list_ptr) {
    if (index < g_debugger_list_ptr->size())
      return g_debugger_list_ptr->at(index);
  }

  return nullptr;
}

DebuggerSP Debugger::FindDebuggerWithID(lldb::user_id_t id) {
  std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex());
  if (!g_debugger_list_ptr)
    return nullptr;

  if (g_debugger_list_ptr) {
    DebuggerList::iterator pos, end = g_debugger_list_ptr->end();
    for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) {
      if ((*pos)->GetID() == id)
        return *pos;
    }
  }

  return nullptr;
}

bool Debugger::FormatDisassemblerAddress(const FormatEntity::Entry *format,
                                         const SymbolContext *sc,
                                         const SymbolContext *prev_sc,
                                         const ExecutionContext *exe_ctx,
                                         const Address *addr, Stream &s) {
  FormatEntity::Entry format_entry;

  if (format == nullptr) {
    if (exe_ctx != nullptr && exe_ctx->HasTargetScope()) {
      format_entry =
          exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
      format = &format_entry;
    }
    if (format == nullptr) {
      FormatEntity::Parse("${addr}: ", format_entry);
      format = &format_entry;
    }
  }
  bool function_changed = false;

Review comment (bug):
I think you could use 

```
return llvm::find_if(g_debugger_list_ptr, [&id](auto dbg){ return dbg->GetID() == id; });
```

Code after:
  if (!g_debugger_list_ptr)
    return nullptr;

  if (index < g_debugger_list_ptr->size())
    return g_debugger_list_ptr->at(index);

  return nullptr;
}

DebuggerSP Debugger::FindDebuggerWithID(lldb::user_id_t id) {
  std::lock_guard<std::mutex> guard(GetDebuggerListMutex());
  if (!g_debugger_list_ptr)
    return nullptr;

  for (const DebuggerSP &debugger_sp : *g_debugger_list_ptr) {
    if (debugger_sp->GetID() == id)
      return debugger_sp;
  }

  return nullptr;
}

bool Debugger::FormatDisassemblerAddress(const FormatEntity::Entry *format,
                                         const SymbolContext *sc,
                                         const SymbolContext *prev_sc,
                                         const ExecutionContext *exe_ctx,
                                         const Address *addr, Stream &s) {
  FormatEntity::Entry format_entry;

  if (format == nullptr) {
    if (exe_ctx != nullptr && exe_ctx->HasTargetScope()) {
      format_entry =
          exe_ctx->GetTargetRef().GetDebugger().GetDisassemblyFormat();
      format = &format_entry;
    }
    if (format == nullptr) {
      FormatEntity::Parse("${addr}: ", format_entry);
      format = &format_entry;
    }
  }
  bool function_changed = false;
  bool initial_function = false;
  if (prev_sc && (prev_sc->function || prev_sc->symbol)) {
    if (sc && (sc->function || sc->symbol)) {
      if (prev_sc->symbol && sc->symbol) {
        if (!sc->symbol->Compare(prev_sc->symbol->GetName(),
                                 prev_sc->symbol->GetType())) {
          function_changed = true;
        }
      } else if (prev_sc->function && sc->function) {
        if (prev_sc->function->GetMangled() != sc->function->GetMangled()) {