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