1*bdd1243dSDimitry Andric //===-- ObjectContainer.cpp -----------------------------------------------===//
2*bdd1243dSDimitry Andric //
3*bdd1243dSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*bdd1243dSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*bdd1243dSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*bdd1243dSDimitry Andric //
7*bdd1243dSDimitry Andric //===----------------------------------------------------------------------===//
8*bdd1243dSDimitry Andric 
9*bdd1243dSDimitry Andric #include "lldb/Symbol/ObjectContainer.h"
10*bdd1243dSDimitry Andric #include "lldb/Core/Module.h"
11*bdd1243dSDimitry Andric #include "lldb/Core/PluginManager.h"
12*bdd1243dSDimitry Andric #include "lldb/Target/Process.h"
13*bdd1243dSDimitry Andric #include "lldb/Utility/Timer.h"
14*bdd1243dSDimitry Andric 
15*bdd1243dSDimitry Andric using namespace lldb;
16*bdd1243dSDimitry Andric using namespace lldb_private;
17*bdd1243dSDimitry Andric 
ObjectContainer(const lldb::ModuleSP & module_sp,const FileSpec * file,lldb::offset_t file_offset,lldb::offset_t length,lldb::DataBufferSP data_sp,lldb::offset_t data_offset)18*bdd1243dSDimitry Andric ObjectContainer::ObjectContainer(const lldb::ModuleSP &module_sp,
19*bdd1243dSDimitry Andric                                  const FileSpec *file,
20*bdd1243dSDimitry Andric                                  lldb::offset_t file_offset,
21*bdd1243dSDimitry Andric                                  lldb::offset_t length,
22*bdd1243dSDimitry Andric                                  lldb::DataBufferSP data_sp,
23*bdd1243dSDimitry Andric                                  lldb::offset_t data_offset)
24*bdd1243dSDimitry Andric     : ModuleChild(module_sp),
25*bdd1243dSDimitry Andric       m_file(), // This file can be different than the module's file spec
26*bdd1243dSDimitry Andric       m_offset(file_offset), m_length(length) {
27*bdd1243dSDimitry Andric   if (file)
28*bdd1243dSDimitry Andric     m_file = *file;
29*bdd1243dSDimitry Andric   if (data_sp)
30*bdd1243dSDimitry Andric     m_data.SetData(data_sp, data_offset, length);
31*bdd1243dSDimitry Andric }
32*bdd1243dSDimitry Andric 
FindPlugin(const lldb::ModuleSP & module_sp,const ProcessSP & process_sp,lldb::addr_t header_addr,WritableDataBufferSP data_sp)33*bdd1243dSDimitry Andric ObjectContainerSP ObjectContainer::FindPlugin(const lldb::ModuleSP &module_sp,
34*bdd1243dSDimitry Andric                                               const ProcessSP &process_sp,
35*bdd1243dSDimitry Andric                                               lldb::addr_t header_addr,
36*bdd1243dSDimitry Andric                                               WritableDataBufferSP data_sp) {
37*bdd1243dSDimitry Andric   if (!module_sp)
38*bdd1243dSDimitry Andric     return {};
39*bdd1243dSDimitry Andric 
40*bdd1243dSDimitry Andric   LLDB_SCOPED_TIMERF("ObjectContainer::FindPlugin (module = "
41*bdd1243dSDimitry Andric                      "%s, process = %p, header_addr = "
42*bdd1243dSDimitry Andric                      "0x%" PRIx64 ")",
43*bdd1243dSDimitry Andric                      module_sp->GetFileSpec().GetPath().c_str(),
44*bdd1243dSDimitry Andric                      static_cast<void *>(process_sp.get()), header_addr);
45*bdd1243dSDimitry Andric 
46*bdd1243dSDimitry Andric   ObjectContainerCreateMemoryInstance create_callback;
47*bdd1243dSDimitry Andric   for (size_t idx = 0;
48*bdd1243dSDimitry Andric        (create_callback =
49*bdd1243dSDimitry Andric             PluginManager::GetObjectContainerCreateMemoryCallbackAtIndex(
50*bdd1243dSDimitry Andric                 idx)) != nullptr;
51*bdd1243dSDimitry Andric        ++idx) {
52*bdd1243dSDimitry Andric     ObjectContainerSP object_container_sp(
53*bdd1243dSDimitry Andric         create_callback(module_sp, data_sp, process_sp, header_addr));
54*bdd1243dSDimitry Andric     if (object_container_sp)
55*bdd1243dSDimitry Andric       return object_container_sp;
56*bdd1243dSDimitry Andric   }
57*bdd1243dSDimitry Andric 
58*bdd1243dSDimitry Andric   return {};
59*bdd1243dSDimitry Andric }
60