2010-06-09 00:52:24 +08:00
|
|
|
//===-- ObjectContainerBSDArchive.h -----------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-02-18 07:57:45 +08:00
|
|
|
#ifndef LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_BSD_ARCHIVE_OBJECTCONTAINERBSDARCHIVE_H
|
|
|
|
#define LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_BSD_ARCHIVE_OBJECTCONTAINERBSDARCHIVE_H
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
#include "lldb/Core/UniqueCStringMap.h"
|
|
|
|
#include "lldb/Symbol/ObjectContainer.h"
|
2017-11-14 00:16:33 +08:00
|
|
|
#include "lldb/Utility/ArchSpec.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/ConstString.h"
|
2017-03-23 02:40:07 +08:00
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-11-09 23:05:45 +08:00
|
|
|
#include "llvm/Support/Chrono.h"
|
|
|
|
|
2017-03-03 14:14:38 +08:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2016-11-09 23:05:45 +08:00
|
|
|
#include <mutex>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
class ObjectContainerBSDArchive : public lldb_private::ObjectContainer {
|
|
|
|
public:
|
2015-10-24 00:56:07 +08:00
|
|
|
ObjectContainerBSDArchive(const lldb::ModuleSP &module_sp,
|
|
|
|
lldb::DataBufferSP &data_sp,
|
|
|
|
lldb::offset_t data_offset,
|
|
|
|
const lldb_private::FileSpec *file,
|
|
|
|
lldb::offset_t offset, lldb::offset_t length);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
~ObjectContainerBSDArchive() override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Static Functions
|
2013-04-25 06:29:28 +08:00
|
|
|
static void Initialize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
static void Terminate();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-01-12 13:25:17 +08:00
|
|
|
static lldb_private::ConstString GetPluginNameStatic();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-24 00:56:07 +08:00
|
|
|
static const char *GetPluginDescriptionStatic();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2015-10-24 00:56:07 +08:00
|
|
|
static lldb_private::ObjectContainer *
|
|
|
|
CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
|
|
|
|
lldb::offset_t data_offset, const lldb_private::FileSpec *file,
|
|
|
|
lldb::offset_t offset, lldb::offset_t length);
|
|
|
|
|
|
|
|
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
|
|
|
|
lldb::DataBufferSP &data_sp,
|
2013-02-07 01:22:03 +08:00
|
|
|
lldb::offset_t data_offset,
|
2015-10-24 00:56:07 +08:00
|
|
|
lldb::offset_t file_offset,
|
2013-04-25 06:29:28 +08:00
|
|
|
lldb::offset_t length,
|
2015-10-24 00:56:07 +08:00
|
|
|
lldb_private::ModuleSpecList &specs);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2015-10-24 00:56:07 +08:00
|
|
|
static bool MagicBytesMatch(const lldb_private::DataExtractor &data);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Member Functions
|
2015-10-24 00:56:07 +08:00
|
|
|
bool ParseHeader() override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-24 00:56:07 +08:00
|
|
|
size_t GetNumObjects() const override {
|
2011-09-19 02:59:15 +08:00
|
|
|
if (m_archive_sp)
|
|
|
|
return m_archive_sp->GetNumObjects();
|
|
|
|
return 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void Dump(lldb_private::Stream *s) const override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-25 06:29:28 +08:00
|
|
|
lldb::ObjectFileSP GetObjectFile(const lldb_private::FileSpec *file) override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-24 00:56:07 +08:00
|
|
|
// PluginInterface protocol
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb_private::ConstString GetPluginName() override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-24 00:56:07 +08:00
|
|
|
uint32_t GetPluginVersion() override;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
struct Object {
|
|
|
|
Object();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void Clear();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
lldb::offset_t Extract(const lldb_private::DataExtractor &data,
|
|
|
|
lldb::offset_t offset);
|
2019-07-13 04:08:41 +08:00
|
|
|
/// Object name in the archive.
|
|
|
|
lldb_private::ConstString ar_name;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-07-13 04:08:41 +08:00
|
|
|
/// Object modification time in the archive.
|
|
|
|
uint32_t modification_time;
|
|
|
|
|
|
|
|
/// Object user id in the archive.
|
|
|
|
uint16_t uid;
|
|
|
|
|
|
|
|
/// Object group id in the archive.
|
|
|
|
uint16_t gid;
|
|
|
|
|
|
|
|
/// Object octal file permissions in the archive.
|
|
|
|
uint16_t mode;
|
|
|
|
|
|
|
|
/// Object size in bytes in the archive.
|
|
|
|
uint32_t size;
|
|
|
|
|
|
|
|
/// File offset in bytes from the beginning of the file of the object data.
|
|
|
|
lldb::offset_t file_offset;
|
|
|
|
|
|
|
|
/// Length of the object data.
|
|
|
|
lldb::offset_t file_size;
|
2010-06-09 00:52:24 +08:00
|
|
|
};
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
class Archive {
|
|
|
|
public:
|
2013-04-19 06:45:39 +08:00
|
|
|
typedef std::shared_ptr<Archive> shared_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
typedef std::multimap<lldb_private::FileSpec, shared_ptr> Map;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-24 00:56:07 +08:00
|
|
|
Archive(const lldb_private::ArchSpec &arch,
|
2016-11-09 23:05:45 +08:00
|
|
|
const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset,
|
2015-10-24 00:56:07 +08:00
|
|
|
lldb_private::DataExtractor &data);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-24 00:56:07 +08:00
|
|
|
~Archive();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
static Map &GetArchiveCache();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-05-18 09:59:10 +08:00
|
|
|
static std::recursive_mutex &GetArchiveCacheMutex();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
static Archive::shared_ptr FindCachedArchive(
|
|
|
|
const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch,
|
2016-11-09 23:05:45 +08:00
|
|
|
const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
static Archive::shared_ptr ParseAndCacheArchiveForFile(
|
|
|
|
const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch,
|
2016-11-09 23:05:45 +08:00
|
|
|
const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset,
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb_private::DataExtractor &data);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-19 02:59:15 +08:00
|
|
|
size_t GetNumObjects() const { return m_objects.size(); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-07-13 06:07:46 +08:00
|
|
|
const Object *GetObjectAtIndex(size_t idx) {
|
|
|
|
if (idx < m_objects.size())
|
|
|
|
return &m_objects[idx];
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
return nullptr;
|
2013-07-13 06:07:46 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-02-07 01:22:03 +08:00
|
|
|
size_t ParseObjects();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-03-07 05:22:25 +08:00
|
|
|
Object *FindObject(lldb_private::ConstString object_name,
|
2016-11-09 23:05:45 +08:00
|
|
|
const llvm::sys::TimePoint<> &object_mod_time);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-07-13 06:07:46 +08:00
|
|
|
lldb::offset_t GetFileOffset() const { return m_file_offset; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-07-13 04:08:41 +08:00
|
|
|
const llvm::sys::TimePoint<> &GetModificationTime() {
|
|
|
|
return m_modification_time;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const lldb_private::ArchSpec &GetArchitecture() const { return m_arch; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-07-13 06:07:46 +08:00
|
|
|
void SetArchitecture(const lldb_private::ArchSpec &arch) { m_arch = arch; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-19 02:59:15 +08:00
|
|
|
bool HasNoExternalReferences() const;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-02-07 01:22:03 +08:00
|
|
|
lldb_private::DataExtractor &GetData() { return m_data; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
protected:
|
2013-01-26 02:06:21 +08:00
|
|
|
typedef lldb_private::UniqueCStringMap<uint32_t> ObjectNameToIndexMap;
|
2010-06-09 00:52:24 +08:00
|
|
|
// Member Variables
|
|
|
|
lldb_private::ArchSpec m_arch;
|
2019-07-13 04:08:41 +08:00
|
|
|
llvm::sys::TimePoint<> m_modification_time;
|
2013-07-13 06:07:46 +08:00
|
|
|
lldb::offset_t m_file_offset;
|
2019-07-13 04:08:41 +08:00
|
|
|
std::vector<Object> m_objects;
|
2013-01-26 02:06:21 +08:00
|
|
|
ObjectNameToIndexMap m_object_name_to_index_map;
|
2013-02-07 01:22:03 +08:00
|
|
|
lldb_private::DataExtractor m_data; ///< The data for this object container
|
|
|
|
///so we don't lose data if the .a files
|
|
|
|
///gets modified
|
2010-06-09 00:52:24 +08:00
|
|
|
};
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void SetArchive(Archive::shared_ptr &archive_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Archive::shared_ptr m_archive_sp;
|
|
|
|
};
|
|
|
|
|
2020-02-18 07:57:45 +08:00
|
|
|
#endif // LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_BSD_ARCHIVE_OBJECTCONTAINERBSDARCHIVE_H
|