[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- ModuleList.cpp ----------------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Core/ModuleList.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Core/FileSpecList.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Core/ModuleSpec.h"
|
2016-11-02 00:11:14 +08:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2018-03-03 06:42:44 +08:00
|
|
|
#include "lldb/Interpreter/OptionValueFileSpec.h"
|
2019-12-20 23:34:55 +08:00
|
|
|
#include "lldb/Interpreter/OptionValueFileSpecList.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Interpreter/OptionValueProperties.h"
|
2018-03-03 06:42:44 +08:00
|
|
|
#include "lldb/Interpreter/Property.h"
|
Move Host/Symbols.cpp to Symbols/LocateSymbolFile.cpp
Given that we have a target named Symbols, one wonders why a
file named Symbols.cpp is not in this target. To be clear,
the functions exposed from this file are really focused on
*locating* a symbol file on a given host, which is where the
ambiguity comes in. However, it makes more sense conceptually
to be in the Symbols target. While some of the specific places
to search for symbol files might change depending on the Host,
this is not inherently true in the same way that, for example,
"accessing the file system" or "starting threads" is
fundamentally dependent on the Host.
PDBs, for example, recently became a reality on non-Windows platforms,
and it's theoretically possible that DSYMs could become a thing on non
MacOSX platforms (maybe in a remote debugging scenario). Other types of
symbol files, such as DWO, DWP, etc have never been tied to any Host
platform anyway.
After this patch, there is only one remaining dependency from
Host to Target.
Differential Revision: https://reviews.llvm.org/D58730
llvm-svn: 355032
2019-02-28 05:42:10 +08:00
|
|
|
#include "lldb/Symbol/LocateSymbolFile.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
2019-10-01 23:40:41 +08:00
|
|
|
#include "lldb/Symbol/TypeList.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/VariableList.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Utility/ArchSpec.h"
|
|
|
|
#include "lldb/Utility/ConstString.h"
|
2022-02-03 20:26:10 +08:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Utility/UUID.h"
|
|
|
|
#include "lldb/lldb-defines.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2018-04-10 21:33:45 +08:00
|
|
|
#if defined(_WIN32)
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Host/windows/PosixApi.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
#endif
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "clang/Driver/Driver.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-03-09 01:56:08 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2017-02-07 01:55:02 +08:00
|
|
|
#include "llvm/Support/Threading.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <chrono>
|
|
|
|
#include <memory>
|
2017-04-07 05:28:29 +08:00
|
|
|
#include <mutex>
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2017-04-07 05:28:29 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
class Function;
|
|
|
|
}
|
|
|
|
namespace lldb_private {
|
|
|
|
class RegularExpression;
|
|
|
|
}
|
|
|
|
namespace lldb_private {
|
|
|
|
class Stream;
|
|
|
|
}
|
|
|
|
namespace lldb_private {
|
|
|
|
class SymbolFile;
|
|
|
|
}
|
|
|
|
namespace lldb_private {
|
|
|
|
class Target;
|
|
|
|
}
|
2017-02-07 01:55:02 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2018-03-03 06:42:44 +08:00
|
|
|
namespace {
|
|
|
|
|
2019-07-26 05:36:37 +08:00
|
|
|
#define LLDB_PROPERTIES_modulelist
|
2019-07-30 01:22:10 +08:00
|
|
|
#include "CoreProperties.inc"
|
2018-03-03 06:42:44 +08:00
|
|
|
|
2019-07-26 05:36:37 +08:00
|
|
|
enum {
|
|
|
|
#define LLDB_PROPERTIES_modulelist
|
2019-07-30 01:22:10 +08:00
|
|
|
#include "CorePropertiesEnum.inc"
|
2019-07-26 05:36:37 +08:00
|
|
|
};
|
2018-03-03 06:42:44 +08:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
ModuleListProperties::ModuleListProperties() {
|
2019-02-12 07:13:08 +08:00
|
|
|
m_collection_sp =
|
|
|
|
std::make_shared<OptionValueProperties>(ConstString("symbols"));
|
2019-07-30 00:41:30 +08:00
|
|
|
m_collection_sp->Initialize(g_modulelist_properties);
|
2019-12-20 23:34:55 +08:00
|
|
|
m_collection_sp->SetValueChangedCallback(ePropertySymLinkPaths,
|
|
|
|
[this] { UpdateSymlinkMappings(); });
|
2018-03-03 06:42:44 +08:00
|
|
|
|
|
|
|
llvm::SmallString<128> path;
|
2020-12-10 19:31:29 +08:00
|
|
|
if (clang::driver::Driver::getDefaultModuleCachePath(path)) {
|
|
|
|
lldbassert(SetClangModulesCachePath(FileSpec(path)));
|
|
|
|
}
|
Added the ability to cache the finalized symbol tables subsequent debug sessions to start faster.
This is an updated version of the https://reviews.llvm.org/D113789 patch with the following changes:
- We no longer modify modification times of the cache files
- Use LLVM caching and cache pruning instead of making a new cache mechanism (See DataFileCache.h/.cpp)
- Add signature to start of each file since we are not using modification times so we can tell when caches are stale and remove and re-create the cache file as files are changed
- Add settings to control the cache size, disk percentage and expiration in days to keep cache size under control
This patch enables symbol tables to be cached in the LLDB index cache directory. All cache files are in a single directory and the files use unique names to ensure that files from the same path will re-use the same file as files get modified. This means as files change, their cache files will be deleted and updated. The modification time of each of the cache files is not modified so that access based pruning of the cache can be implemented.
The symbol table cache files start with a signature that uniquely identifies a file on disk and contains one or more of the following items:
- object file UUID if available
- object file mod time if available
- object name for BSD archive .o files that are in .a files if available
If none of these signature items are available, then the file will not be cached. This keeps temporary object files from expressions from being cached.
When the cache files are loaded on subsequent debug sessions, the signature is compare and if the file has been modified (uuid changes, mod time changes, or object file mod time changes) then the cache file is deleted and re-created.
Module caching must be enabled by the user before this can be used:
symbols.enable-lldb-index-cache (boolean) = false
(lldb) settings set symbols.enable-lldb-index-cache true
There is also a setting that allows the user to specify a module cache directory that defaults to a directory that defaults to being next to the symbols.clang-modules-cache-path directory in a temp directory:
(lldb) settings show symbols.lldb-index-cache-path
/var/folders/9p/472sr0c55l9b20x2zg36b91h0000gn/C/lldb/IndexCache
If this setting is enabled, the finalized symbol tables will be serialized and saved to disc so they can be quickly loaded next time you debug.
Each module can cache one or more files in the index cache directory. The cache file names must be unique to a file on disk and its architecture and object name for .o files in BSD archives. This allows universal mach-o files to support caching multuple architectures in the same module cache directory. Making the file based on the this info allows this cache file to be deleted and replaced when the file gets updated on disk. This keeps the cache from growing over time during the compile/edit/debug cycle and prevents out of space issues.
If the cache is enabled, the symbol table will be loaded from the cache the next time you debug if the module has not changed.
The cache also has settings to control the size of the cache on disk. Each time LLDB starts up with the index cache enable, the cache will be pruned to ensure it stays within the user defined settings:
(lldb) settings set symbols.lldb-index-cache-expiration-days <days>
A value of zero will disable cache files from expiring when the cache is pruned. The default value is 7 currently.
(lldb) settings set symbols.lldb-index-cache-max-byte-size <size>
A value of zero will disable pruning based on a total byte size. The default value is zero currently.
(lldb) settings set symbols.lldb-index-cache-max-percent <percentage-of-disk-space>
A value of 100 will allow the disc to be filled to the max, a value of zero will disable percentage pruning. The default value is zero.
Reviewed By: labath, wallace
Differential Revision: https://reviews.llvm.org/D115324
2021-12-17 01:59:25 +08:00
|
|
|
|
|
|
|
path.clear();
|
|
|
|
if (llvm::sys::path::cache_directory(path)) {
|
|
|
|
llvm::sys::path::append(path, "lldb");
|
|
|
|
llvm::sys::path::append(path, "IndexCache");
|
|
|
|
lldbassert(SetLLDBIndexCachePath(FileSpec(path)));
|
|
|
|
}
|
|
|
|
|
2018-03-03 06:42:44 +08:00
|
|
|
}
|
|
|
|
|
2018-03-13 04:52:36 +08:00
|
|
|
bool ModuleListProperties::GetEnableExternalLookup() const {
|
|
|
|
const uint32_t idx = ePropertyEnableExternalLookup;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_modulelist_properties[idx].default_uint_value != 0);
|
2018-03-13 04:52:36 +08:00
|
|
|
}
|
|
|
|
|
2019-06-17 22:46:17 +08:00
|
|
|
bool ModuleListProperties::SetEnableExternalLookup(bool new_value) {
|
|
|
|
return m_collection_sp->SetPropertyAtIndexAsBoolean(
|
|
|
|
nullptr, ePropertyEnableExternalLookup, new_value);
|
|
|
|
}
|
|
|
|
|
2018-03-03 06:42:44 +08:00
|
|
|
FileSpec ModuleListProperties::GetClangModulesCachePath() const {
|
|
|
|
return m_collection_sp
|
|
|
|
->GetPropertyAtIndexAsOptionValueFileSpec(nullptr, false,
|
|
|
|
ePropertyClangModulesCachePath)
|
|
|
|
->GetCurrentValue();
|
|
|
|
}
|
|
|
|
|
2020-12-10 19:31:29 +08:00
|
|
|
bool ModuleListProperties::SetClangModulesCachePath(const FileSpec &path) {
|
|
|
|
return m_collection_sp->SetPropertyAtIndexAsFileSpec(
|
2018-03-03 06:42:44 +08:00
|
|
|
nullptr, ePropertyClangModulesCachePath, path);
|
|
|
|
}
|
|
|
|
|
Added the ability to cache the finalized symbol tables subsequent debug sessions to start faster.
This is an updated version of the https://reviews.llvm.org/D113789 patch with the following changes:
- We no longer modify modification times of the cache files
- Use LLVM caching and cache pruning instead of making a new cache mechanism (See DataFileCache.h/.cpp)
- Add signature to start of each file since we are not using modification times so we can tell when caches are stale and remove and re-create the cache file as files are changed
- Add settings to control the cache size, disk percentage and expiration in days to keep cache size under control
This patch enables symbol tables to be cached in the LLDB index cache directory. All cache files are in a single directory and the files use unique names to ensure that files from the same path will re-use the same file as files get modified. This means as files change, their cache files will be deleted and updated. The modification time of each of the cache files is not modified so that access based pruning of the cache can be implemented.
The symbol table cache files start with a signature that uniquely identifies a file on disk and contains one or more of the following items:
- object file UUID if available
- object file mod time if available
- object name for BSD archive .o files that are in .a files if available
If none of these signature items are available, then the file will not be cached. This keeps temporary object files from expressions from being cached.
When the cache files are loaded on subsequent debug sessions, the signature is compare and if the file has been modified (uuid changes, mod time changes, or object file mod time changes) then the cache file is deleted and re-created.
Module caching must be enabled by the user before this can be used:
symbols.enable-lldb-index-cache (boolean) = false
(lldb) settings set symbols.enable-lldb-index-cache true
There is also a setting that allows the user to specify a module cache directory that defaults to a directory that defaults to being next to the symbols.clang-modules-cache-path directory in a temp directory:
(lldb) settings show symbols.lldb-index-cache-path
/var/folders/9p/472sr0c55l9b20x2zg36b91h0000gn/C/lldb/IndexCache
If this setting is enabled, the finalized symbol tables will be serialized and saved to disc so they can be quickly loaded next time you debug.
Each module can cache one or more files in the index cache directory. The cache file names must be unique to a file on disk and its architecture and object name for .o files in BSD archives. This allows universal mach-o files to support caching multuple architectures in the same module cache directory. Making the file based on the this info allows this cache file to be deleted and replaced when the file gets updated on disk. This keeps the cache from growing over time during the compile/edit/debug cycle and prevents out of space issues.
If the cache is enabled, the symbol table will be loaded from the cache the next time you debug if the module has not changed.
The cache also has settings to control the size of the cache on disk. Each time LLDB starts up with the index cache enable, the cache will be pruned to ensure it stays within the user defined settings:
(lldb) settings set symbols.lldb-index-cache-expiration-days <days>
A value of zero will disable cache files from expiring when the cache is pruned. The default value is 7 currently.
(lldb) settings set symbols.lldb-index-cache-max-byte-size <size>
A value of zero will disable pruning based on a total byte size. The default value is zero currently.
(lldb) settings set symbols.lldb-index-cache-max-percent <percentage-of-disk-space>
A value of 100 will allow the disc to be filled to the max, a value of zero will disable percentage pruning. The default value is zero.
Reviewed By: labath, wallace
Differential Revision: https://reviews.llvm.org/D115324
2021-12-17 01:59:25 +08:00
|
|
|
FileSpec ModuleListProperties::GetLLDBIndexCachePath() const {
|
|
|
|
return m_collection_sp
|
|
|
|
->GetPropertyAtIndexAsOptionValueFileSpec(nullptr, false,
|
|
|
|
ePropertyLLDBIndexCachePath)
|
|
|
|
->GetCurrentValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModuleListProperties::SetLLDBIndexCachePath(const FileSpec &path) {
|
|
|
|
return m_collection_sp->SetPropertyAtIndexAsFileSpec(
|
|
|
|
nullptr, ePropertyLLDBIndexCachePath, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModuleListProperties::GetEnableLLDBIndexCache() const {
|
|
|
|
const uint32_t idx = ePropertyEnableLLDBIndexCache;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
|
|
|
nullptr, idx, g_modulelist_properties[idx].default_uint_value != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModuleListProperties::SetEnableLLDBIndexCache(bool new_value) {
|
|
|
|
return m_collection_sp->SetPropertyAtIndexAsBoolean(
|
|
|
|
nullptr, ePropertyEnableLLDBIndexCache, new_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t ModuleListProperties::GetLLDBIndexCacheMaxByteSize() {
|
|
|
|
const uint32_t idx = ePropertyLLDBIndexCacheMaxByteSize;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsUInt64(
|
|
|
|
nullptr, idx, g_modulelist_properties[idx].default_uint_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t ModuleListProperties::GetLLDBIndexCacheMaxPercent() {
|
|
|
|
const uint32_t idx = ePropertyLLDBIndexCacheMaxPercent;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsUInt64(
|
|
|
|
nullptr, idx, g_modulelist_properties[idx].default_uint_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t ModuleListProperties::GetLLDBIndexCacheExpirationDays() {
|
|
|
|
const uint32_t idx = ePropertyLLDBIndexCacheExpirationDays;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsUInt64(
|
|
|
|
nullptr, idx, g_modulelist_properties[idx].default_uint_value);
|
|
|
|
}
|
|
|
|
|
2019-12-20 23:34:55 +08:00
|
|
|
void ModuleListProperties::UpdateSymlinkMappings() {
|
|
|
|
FileSpecList list = m_collection_sp
|
|
|
|
->GetPropertyAtIndexAsOptionValueFileSpecList(
|
|
|
|
nullptr, false, ePropertySymLinkPaths)
|
|
|
|
->GetCurrentValue();
|
|
|
|
llvm::sys::ScopedWriter lock(m_symlink_paths_mutex);
|
|
|
|
const bool notify = false;
|
|
|
|
m_symlink_paths.Clear(notify);
|
|
|
|
for (FileSpec symlink : list) {
|
|
|
|
FileSpec resolved;
|
|
|
|
Status status = FileSystem::Instance().Readlink(symlink, resolved);
|
|
|
|
if (status.Success())
|
2021-11-02 13:14:48 +08:00
|
|
|
m_symlink_paths.Append(symlink.GetPath(), resolved.GetPath(), notify);
|
2019-12-20 23:34:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PathMappingList ModuleListProperties::GetSymlinkMappings() const {
|
|
|
|
llvm::sys::ScopedReader lock(m_symlink_paths_mutex);
|
|
|
|
return m_symlink_paths;
|
|
|
|
}
|
|
|
|
|
2022-04-20 22:30:53 +08:00
|
|
|
bool ModuleListProperties::GetLoadSymbolOnDemand() {
|
|
|
|
const uint32_t idx = ePropertyLoadSymbolOnDemand;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
|
|
|
nullptr, idx, g_modulelist_properties[idx].default_uint_value != 0);
|
|
|
|
}
|
|
|
|
|
2016-05-19 13:13:57 +08:00
|
|
|
ModuleList::ModuleList() : m_modules(), m_modules_mutex() {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-03-15 04:32:03 +08:00
|
|
|
ModuleList::ModuleList(const ModuleList &rhs) : m_modules(), m_modules_mutex() {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex);
|
|
|
|
std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex);
|
2012-06-28 03:59:26 +08:00
|
|
|
m_modules = rhs.m_modules;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 13:13:57 +08:00
|
|
|
ModuleList::ModuleList(ModuleList::Notifier *notifier)
|
|
|
|
: m_modules(), m_modules_mutex(), m_notifier(notifier) {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-26 13:51:37 +08:00
|
|
|
const ModuleList &ModuleList::operator=(const ModuleList &rhs) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (this != &rhs) {
|
2019-03-30 01:07:30 +08:00
|
|
|
std::lock(m_modules_mutex, rhs.m_modules_mutex);
|
2019-07-27 04:55:07 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex,
|
2019-03-30 01:07:30 +08:00
|
|
|
std::adopt_lock);
|
2019-07-27 04:55:07 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex,
|
2019-03-30 01:07:30 +08:00
|
|
|
std::adopt_lock);
|
|
|
|
m_modules = rhs.m_modules;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-05-19 13:13:57 +08:00
|
|
|
ModuleList::~ModuleList() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
void ModuleList::AppendImpl(const ModuleSP &module_sp, bool use_notifier) {
|
2015-07-22 08:16:02 +08:00
|
|
|
if (module_sp) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2014-03-25 00:50:33 +08:00
|
|
|
m_modules.push_back(module_sp);
|
2016-05-19 13:13:57 +08:00
|
|
|
if (use_notifier && m_notifier)
|
2019-04-09 07:03:02 +08:00
|
|
|
m_notifier->NotifyModuleAdded(*this, module_sp);
|
2014-03-25 00:50:33 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-07-27 04:55:07 +08:00
|
|
|
void ModuleList::Append(const ModuleSP &module_sp, bool notify) {
|
|
|
|
AppendImpl(module_sp, notify);
|
2019-04-09 07:03:02 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2020-10-31 03:13:26 +08:00
|
|
|
void ModuleList::ReplaceEquivalent(
|
|
|
|
const ModuleSP &module_sp,
|
|
|
|
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules) {
|
2011-04-12 13:54:46 +08:00
|
|
|
if (module_sp) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-11-08 10:22:02 +08:00
|
|
|
// First remove any equivalent modules. Equivalent modules are modules
|
|
|
|
// whose path, platform path and architecture match.
|
2012-07-13 04:32:19 +08:00
|
|
|
ModuleSpec equivalent_module_spec(module_sp->GetFileSpec(),
|
|
|
|
module_sp->GetArchitecture());
|
2012-11-08 10:22:02 +08:00
|
|
|
equivalent_module_spec.GetPlatformFileSpec() =
|
|
|
|
module_sp->GetPlatformFileSpec();
|
|
|
|
|
2016-05-19 13:13:57 +08:00
|
|
|
size_t idx = 0;
|
2012-07-13 04:32:19 +08:00
|
|
|
while (idx < m_modules.size()) {
|
2020-10-31 03:13:26 +08:00
|
|
|
ModuleSP test_module_sp(m_modules[idx]);
|
|
|
|
if (test_module_sp->MatchesModuleSpec(equivalent_module_spec)) {
|
|
|
|
if (old_modules)
|
|
|
|
old_modules->push_back(test_module_sp);
|
2012-11-08 10:22:02 +08:00
|
|
|
RemoveImpl(m_modules.begin() + idx);
|
2020-10-31 03:13:26 +08:00
|
|
|
} else {
|
2012-07-13 04:32:19 +08:00
|
|
|
++idx;
|
2020-10-31 03:13:26 +08:00
|
|
|
}
|
2012-07-13 04:32:19 +08:00
|
|
|
}
|
|
|
|
// Now add the new module to the list
|
2012-11-08 10:22:02 +08:00
|
|
|
Append(module_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-07-13 04:32:19 +08:00
|
|
|
}
|
|
|
|
|
2021-10-30 19:29:36 +08:00
|
|
|
bool ModuleList::AppendIfNeeded(const ModuleSP &new_module, bool notify) {
|
|
|
|
if (new_module) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules) {
|
|
|
|
if (module_sp.get() == new_module.get())
|
2011-04-12 13:54:46 +08:00
|
|
|
return false; // Already in the list
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-04-12 13:54:46 +08:00
|
|
|
// Only push module_sp on the list if it wasn't already in there.
|
2021-10-30 19:29:36 +08:00
|
|
|
Append(new_module, notify);
|
2011-04-12 13:54:46 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-04-12 13:54:46 +08:00
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-11-08 10:22:02 +08:00
|
|
|
void ModuleList::Append(const ModuleList &module_list) {
|
|
|
|
for (auto pos : module_list.m_modules)
|
|
|
|
Append(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModuleList::AppendIfNeeded(const ModuleList &module_list) {
|
|
|
|
bool any_in = false;
|
|
|
|
for (auto pos : module_list.m_modules) {
|
2013-08-13 09:42:25 +08:00
|
|
|
if (AppendIfNeeded(pos))
|
|
|
|
any_in = true;
|
|
|
|
}
|
2012-11-08 10:22:02 +08:00
|
|
|
return any_in;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModuleList::RemoveImpl(const ModuleSP &module_sp, bool use_notifier) {
|
2011-04-12 13:54:46 +08:00
|
|
|
if (module_sp) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2011-04-12 13:54:46 +08:00
|
|
|
collection::iterator pos, end = m_modules.end();
|
|
|
|
for (pos = m_modules.begin(); pos != end; ++pos) {
|
|
|
|
if (pos->get() == module_sp.get()) {
|
|
|
|
m_modules.erase(pos);
|
2012-11-08 10:22:02 +08:00
|
|
|
if (use_notifier && m_notifier)
|
2019-04-09 07:03:02 +08:00
|
|
|
m_notifier->NotifyModuleRemoved(*this, module_sp);
|
2011-04-12 13:54:46 +08:00
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-08 10:22:02 +08:00
|
|
|
ModuleList::collection::iterator
|
|
|
|
ModuleList::RemoveImpl(ModuleList::collection::iterator pos,
|
|
|
|
bool use_notifier) {
|
|
|
|
ModuleSP module_sp(*pos);
|
|
|
|
collection::iterator retval = m_modules.erase(pos);
|
|
|
|
if (use_notifier && m_notifier)
|
2019-04-09 07:03:02 +08:00
|
|
|
m_notifier->NotifyModuleRemoved(*this, module_sp);
|
2012-11-08 10:22:02 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2019-04-09 07:03:02 +08:00
|
|
|
bool ModuleList::Remove(const ModuleSP &module_sp, bool notify) {
|
|
|
|
return RemoveImpl(module_sp, notify);
|
2012-11-08 10:22:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ModuleList::ReplaceModule(const lldb::ModuleSP &old_module_sp,
|
2012-11-09 03:16:03 +08:00
|
|
|
const lldb::ModuleSP &new_module_sp) {
|
2012-05-18 02:38:42 +08:00
|
|
|
if (!RemoveImpl(old_module_sp, false))
|
|
|
|
return false;
|
2012-11-08 10:22:02 +08:00
|
|
|
AppendImpl(new_module_sp, false);
|
|
|
|
if (m_notifier)
|
2019-04-09 07:03:02 +08:00
|
|
|
m_notifier->NotifyModuleUpdated(*this, old_module_sp, new_module_sp);
|
2012-11-08 10:22:02 +08:00
|
|
|
return true;
|
2012-05-18 02:38:42 +08:00
|
|
|
}
|
2011-08-11 10:48:45 +08:00
|
|
|
|
2012-04-10 04:22:01 +08:00
|
|
|
bool ModuleList::RemoveIfOrphaned(const Module *module_ptr) {
|
2010-12-07 07:51:26 +08:00
|
|
|
if (module_ptr) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2010-12-07 07:51:26 +08:00
|
|
|
collection::iterator pos, end = m_modules.end();
|
|
|
|
for (pos = m_modules.begin(); pos != end; ++pos) {
|
|
|
|
if (pos->get() == module_ptr) {
|
|
|
|
if (pos->unique()) {
|
|
|
|
pos = RemoveImpl(pos);
|
2012-11-08 10:22:02 +08:00
|
|
|
return true;
|
2010-12-07 07:51:26 +08:00
|
|
|
} else
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-12-07 07:51:26 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-12-07 07:51:26 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-10 04:22:01 +08:00
|
|
|
size_t ModuleList::RemoveOrphans(bool mandatory) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::unique_lock<std::recursive_mutex> lock(m_modules_mutex, std::defer_lock);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-04-10 04:22:01 +08:00
|
|
|
if (mandatory) {
|
2016-05-19 13:13:57 +08:00
|
|
|
lock.lock();
|
2010-06-09 00:52:24 +08:00
|
|
|
} else {
|
2012-04-10 04:22:01 +08:00
|
|
|
// Not mandatory, remove orphans if we can get the mutex
|
2016-05-19 13:13:57 +08:00
|
|
|
if (!lock.try_lock())
|
2012-04-10 04:22:01 +08:00
|
|
|
return 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-08-11 10:48:45 +08:00
|
|
|
size_t remove_count = 0;
|
2020-07-20 16:47:21 +08:00
|
|
|
// Modules might hold shared pointers to other modules, so removing one
|
|
|
|
// module might make other other modules orphans. Keep removing modules until
|
|
|
|
// there are no further modules that can be removed.
|
|
|
|
bool made_progress = true;
|
|
|
|
while (made_progress) {
|
|
|
|
// Keep track if we make progress this iteration.
|
|
|
|
made_progress = false;
|
|
|
|
collection::iterator pos = m_modules.begin();
|
|
|
|
while (pos != m_modules.end()) {
|
|
|
|
if (pos->unique()) {
|
|
|
|
pos = RemoveImpl(pos);
|
|
|
|
++remove_count;
|
|
|
|
// We did make progress.
|
|
|
|
made_progress = true;
|
|
|
|
} else {
|
|
|
|
++pos;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2011-08-11 10:48:45 +08:00
|
|
|
return remove_count;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-01-28 02:45:39 +08:00
|
|
|
size_t ModuleList::Remove(ModuleList &module_list) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2010-12-07 07:51:26 +08:00
|
|
|
size_t num_removed = 0;
|
2012-11-08 10:22:02 +08:00
|
|
|
collection::iterator pos, end = module_list.m_modules.end();
|
2012-05-18 02:38:42 +08:00
|
|
|
for (pos = module_list.m_modules.begin(); pos != end; ++pos) {
|
2019-04-09 07:03:02 +08:00
|
|
|
if (Remove(*pos, false /* notify */))
|
2010-12-07 07:51:26 +08:00
|
|
|
++num_removed;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2019-04-09 07:03:02 +08:00
|
|
|
if (m_notifier)
|
|
|
|
m_notifier->NotifyModulesRemoved(module_list);
|
2012-04-10 04:22:01 +08:00
|
|
|
return num_removed;
|
2012-11-08 10:22:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModuleList::Clear() { ClearImpl(); }
|
2012-01-28 02:45:39 +08:00
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
void ModuleList::Destroy() { ClearImpl(); }
|
2012-05-30 10:19:25 +08:00
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
void ModuleList::ClearImpl(bool use_notifier) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (use_notifier && m_notifier)
|
2019-04-09 07:03:02 +08:00
|
|
|
m_notifier->NotifyWillClearList(*this);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_modules.clear();
|
|
|
|
}
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
Module *ModuleList::GetModulePointerAtIndex(size_t idx) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (idx < m_modules.size())
|
|
|
|
return m_modules[idx].get();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2011-01-27 14:44:37 +08:00
|
|
|
ModuleSP ModuleList::GetModuleAtIndex(size_t idx) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
|
|
|
return GetModuleAtIndexUnlocked(idx);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-07-12 00:40:56 +08:00
|
|
|
ModuleSP ModuleList::GetModuleAtIndexUnlocked(size_t idx) const {
|
|
|
|
ModuleSP module_sp;
|
|
|
|
if (idx < m_modules.size())
|
|
|
|
module_sp = m_modules[idx];
|
|
|
|
return module_sp;
|
|
|
|
}
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-14 01:12:24 +08:00
|
|
|
|
2019-10-18 03:56:40 +08:00
|
|
|
void ModuleList::FindFunctions(ConstString name,
|
|
|
|
FunctionNameType name_type_mask,
|
2021-08-06 00:27:19 +08:00
|
|
|
const ModuleFunctionSearchOptions &options,
|
2019-10-18 03:56:40 +08:00
|
|
|
SymbolContextList &sc_list) const {
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-14 01:12:24 +08:00
|
|
|
const size_t old_size = sc_list.GetSize();
|
|
|
|
|
2013-07-12 00:40:56 +08:00
|
|
|
if (name_type_mask & eFunctionNameTypeAuto) {
|
2014-09-20 03:38:19 +08:00
|
|
|
Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
|
|
|
|
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules) {
|
|
|
|
module_sp->FindFunctions(lookup_info.GetLookupName(),
|
|
|
|
CompilerDeclContext(),
|
|
|
|
lookup_info.GetNameTypeMask(), options, sc_list);
|
2014-09-20 03:38:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const size_t new_size = sc_list.GetSize();
|
2016-05-19 13:13:57 +08:00
|
|
|
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-14 01:12:24 +08:00
|
|
|
if (old_size < new_size)
|
|
|
|
lookup_info.Prune(sc_list, old_size);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules) {
|
|
|
|
module_sp->FindFunctions(name, CompilerDeclContext(), name_type_mask,
|
|
|
|
options, sc_list);
|
2011-07-07 09:59:51 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-07 09:59:51 +08:00
|
|
|
}
|
|
|
|
|
2019-10-18 03:56:40 +08:00
|
|
|
void ModuleList::FindFunctionSymbols(ConstString name,
|
|
|
|
lldb::FunctionNameType name_type_mask,
|
|
|
|
SymbolContextList &sc_list) {
|
2010-06-09 00:52:24 +08:00
|
|
|
const size_t old_size = sc_list.GetSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-11-08 10:22:02 +08:00
|
|
|
if (name_type_mask & eFunctionNameTypeAuto) {
|
2016-03-12 04:20:38 +08:00
|
|
|
Module::LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules) {
|
|
|
|
module_sp->FindFunctionSymbols(lookup_info.GetLookupName(),
|
|
|
|
lookup_info.GetNameTypeMask(), sc_list);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-11-19 08:19:25 +08:00
|
|
|
const size_t new_size = sc_list.GetSize();
|
|
|
|
|
|
|
|
if (old_size < new_size)
|
|
|
|
lookup_info.Prune(sc_list, old_size);
|
|
|
|
} else {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules) {
|
|
|
|
module_sp->FindFunctionSymbols(name, name_type_mask, sc_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 03:56:40 +08:00
|
|
|
void ModuleList::FindFunctions(const RegularExpression &name,
|
2021-08-06 00:27:19 +08:00
|
|
|
const ModuleFunctionSearchOptions &options,
|
2019-10-18 03:56:40 +08:00
|
|
|
SymbolContextList &sc_list) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules)
|
|
|
|
module_sp->FindFunctions(name, options, sc_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-10-18 03:56:40 +08:00
|
|
|
void ModuleList::FindCompileUnits(const FileSpec &path,
|
|
|
|
SymbolContextList &sc_list) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules)
|
|
|
|
module_sp->FindCompileUnits(path, sc_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-10-18 03:56:40 +08:00
|
|
|
void ModuleList::FindGlobalVariables(ConstString name, size_t max_matches,
|
|
|
|
VariableList &variable_list) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules) {
|
|
|
|
module_sp->FindGlobalVariables(name, CompilerDeclContext(), max_matches,
|
|
|
|
variable_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 03:56:40 +08:00
|
|
|
void ModuleList::FindGlobalVariables(const RegularExpression ®ex,
|
|
|
|
size_t max_matches,
|
|
|
|
VariableList &variable_list) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules)
|
|
|
|
module_sp->FindGlobalVariables(regex, max_matches, variable_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-10-18 03:56:40 +08:00
|
|
|
void ModuleList::FindSymbolsWithNameAndType(ConstString name,
|
|
|
|
SymbolType symbol_type,
|
|
|
|
SymbolContextList &sc_list) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules)
|
|
|
|
module_sp->FindSymbolsWithNameAndType(name, symbol_type, sc_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-10-18 03:56:40 +08:00
|
|
|
void ModuleList::FindSymbolsMatchingRegExAndType(
|
2016-02-11 05:28:13 +08:00
|
|
|
const RegularExpression ®ex, lldb::SymbolType symbol_type,
|
2019-10-18 03:56:40 +08:00
|
|
|
SymbolContextList &sc_list) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules)
|
|
|
|
module_sp->FindSymbolsMatchingRegExAndType(regex, symbol_type, sc_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-10-18 03:56:40 +08:00
|
|
|
void ModuleList::FindModules(const ModuleSpec &module_spec,
|
|
|
|
ModuleList &matching_module_list) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules) {
|
2012-02-26 13:51:37 +08:00
|
|
|
if (module_sp->MatchesModuleSpec(module_spec))
|
|
|
|
matching_module_list.Append(module_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-02-26 13:51:37 +08:00
|
|
|
ModuleSP ModuleList::FindModule(const Module *module_ptr) const {
|
|
|
|
ModuleSP module_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Scope for "locker"
|
2016-09-07 04:57:50 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2012-02-26 13:51:37 +08:00
|
|
|
collection::const_iterator pos, end = m_modules.end();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
for (pos = m_modules.begin(); pos != end; ++pos) {
|
|
|
|
if ((*pos).get() == module_ptr) {
|
|
|
|
module_sp = (*pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return module_sp;
|
|
|
|
}
|
|
|
|
|
2012-11-08 10:22:02 +08:00
|
|
|
ModuleSP ModuleList::FindModule(const UUID &uuid) const {
|
Many improvements to the Platform base class and subclasses. The base Platform
class now implements the Host functionality for a lot of things that make
sense by default so that subclasses can check:
int
PlatformSubclass::Foo ()
{
if (IsHost())
return Platform::Foo (); // Let the platform base class do the host specific stuff
// Platform subclass specific code...
int result = ...
return result;
}
Added new functions to the platform:
virtual const char *Platform::GetUserName (uint32_t uid);
virtual const char *Platform::GetGroupName (uint32_t gid);
The user and group names are cached locally so that remote platforms can avoid
sending packets multiple times to resolve this information.
Added the parent process ID to the ProcessInfo class.
Added a new ProcessInfoMatch class which helps us to match processes up
and changed the Host layer over to using this new class. The new class allows
us to search for processs:
1 - by name (equal to, starts with, ends with, contains, and regex)
2 - by pid
3 - And further check for parent pid == value, uid == value, gid == value,
euid == value, egid == value, arch == value, parent == value.
This is all hookup up to the "platform process list" command which required
adding dumping routines to dump process information. If the Host class
implements the process lookup routines, you can now lists processes on
your local machine:
machine1.foo.com % lldb
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
94727 244 username usergroup username usergroup x86_64-apple-darwin Xcode
92742 92710 username usergroup username usergroup i386-apple-darwin debugserver
This of course also works remotely with the lldb-platform:
machine1.foo.com % lldb-platform --listen 1234
machine2.foo.com % lldb
(lldb) platform create remote-macosx
Platform: remote-macosx
Connected: no
(lldb) platform connect connect://localhost:1444
Platform: remote-macosx
Triple: x86_64-apple-darwin
OS Version: 10.6.7 (10J869)
Kernel: Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386
Hostname: machine1.foo.com
Connected: yes
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99556 244 username usergroup username usergroup x86_64-apple-darwin trustevaluation
99548 65539 username usergroup username usergroup x86_64-apple-darwin lldb
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
The lldb-platform implements everything with the Host:: layer, so this should
"just work" for linux. I will probably be adding more stuff to the Host layer
for launching processes and attaching to processes so that this support should
eventually just work as well.
Modified the target to be able to be created with an architecture that differs
from the main executable. This is needed for iOS debugging since we can have
an "armv6" binary which can run on an "armv7" machine, so we want to be able
to do:
% lldb
(lldb) platform create remote-ios
(lldb) file --arch armv7 a.out
Where "a.out" is an armv6 executable. The platform then can correctly decide
to open all "armv7" images for all dependent shared libraries.
Modified the disassembly to show the current PC value. Example output:
(lldb) disassemble --frame
a.out`main:
0x1eb7: pushl %ebp
0x1eb8: movl %esp, %ebp
0x1eba: pushl %ebx
0x1ebb: subl $20, %esp
0x1ebe: calll 0x1ec3 ; main + 12 at test.c:18
0x1ec3: popl %ebx
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
0x1edb: leal 213(%ebx), %eax
0x1ee1: movl %eax, (%esp)
0x1ee4: calll 0x1f1e ; puts
0x1ee9: calll 0x1f0c ; getchar
0x1eee: movl $20, (%esp)
0x1ef5: calll 0x1e6a ; sleep_loop at test.c:6
0x1efa: movl $12, %eax
0x1eff: addl $20, %esp
0x1f02: popl %ebx
0x1f03: leave
0x1f04: ret
This can be handy when dealing with the new --line options that was recently
added:
(lldb) disassemble --line
a.out`main + 13 at test.c:19
18 {
-> 19 printf("Process: %i\n\n", getpid());
20 puts("Press any key to continue..."); getchar();
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
Modified the ModuleList to have a lookup based solely on a UUID. Since the
UUID is typically the MD5 checksum of a binary image, there is no need
to give the path and architecture when searching for a pre-existing
image in an image list.
Now that we support remote debugging a bit better, our lldb_private::Module
needs to be able to track what the original path for file was as the platform
knows it, as well as where the file is locally. The module has the two
following functions to retrieve both paths:
const FileSpec &Module::GetFileSpec () const;
const FileSpec &Module::GetPlatformFileSpec () const;
llvm-svn: 128563
2011-03-31 02:16:51 +08:00
|
|
|
ModuleSP module_sp;
|
|
|
|
|
2016-02-11 05:28:13 +08:00
|
|
|
if (uuid.IsValid()) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2010-08-03 09:26:16 +08:00
|
|
|
collection::const_iterator pos, end = m_modules.end();
|
|
|
|
|
2012-03-16 05:01:31 +08:00
|
|
|
for (pos = m_modules.begin(); pos != end; ++pos) {
|
|
|
|
if ((*pos)->GetUUID() == uuid) {
|
|
|
|
module_sp = (*pos);
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-03-16 05:01:31 +08:00
|
|
|
}
|
|
|
|
}
|
2012-02-26 13:51:37 +08:00
|
|
|
return module_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-10-01 23:40:41 +08:00
|
|
|
void ModuleList::FindTypes(Module *search_first, ConstString name,
|
|
|
|
bool name_is_fully_qualified, size_t max_matches,
|
|
|
|
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
|
|
|
|
TypeList &types) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-11-08 10:22:02 +08:00
|
|
|
collection::const_iterator pos, end = m_modules.end();
|
2019-01-15 06:41:21 +08:00
|
|
|
if (search_first) {
|
2010-06-09 00:52:24 +08:00
|
|
|
for (pos = m_modules.begin(); pos != end; ++pos) {
|
2019-01-15 06:41:21 +08:00
|
|
|
if (search_first == pos->get()) {
|
2019-10-01 23:40:41 +08:00
|
|
|
search_first->FindTypes(name, name_is_fully_qualified, max_matches,
|
|
|
|
searched_symbol_files, types);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-10-01 23:40:41 +08:00
|
|
|
if (types.GetSize() >= max_matches)
|
|
|
|
return;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:40:41 +08:00
|
|
|
for (pos = m_modules.begin(); pos != end; ++pos) {
|
|
|
|
// Search the module if the module is not equal to the one in the symbol
|
|
|
|
// context "sc". If "sc" contains a empty module shared pointer, then the
|
|
|
|
// comparison will always be true (valid_module_ptr != nullptr).
|
|
|
|
if (search_first != pos->get())
|
|
|
|
(*pos)->FindTypes(name, name_is_fully_qualified, max_matches,
|
|
|
|
searched_symbol_files, types);
|
|
|
|
|
|
|
|
if (types.GetSize() >= max_matches)
|
|
|
|
return;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-16 05:01:31 +08:00
|
|
|
bool ModuleList::FindSourceFile(const FileSpec &orig_spec,
|
|
|
|
FileSpec &new_spec) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules) {
|
|
|
|
if (module_sp->FindSourceFile(orig_spec, new_spec))
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-03-16 05:01:31 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-09-12 10:20:34 +08:00
|
|
|
void ModuleList::FindAddressesForLine(const lldb::TargetSP target_sp,
|
|
|
|
const FileSpec &file, uint32_t line,
|
|
|
|
Function *function,
|
|
|
|
std::vector<Address> &output_local,
|
|
|
|
std::vector<Address> &output_extern) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules) {
|
|
|
|
module_sp->FindAddressesForLine(target_sp, file, line, function,
|
|
|
|
output_local, output_extern);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 10:22:02 +08:00
|
|
|
ModuleSP ModuleList::FindFirstModule(const ModuleSpec &module_spec) const {
|
2010-06-09 00:52:24 +08:00
|
|
|
ModuleSP module_sp;
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2012-02-26 13:51:37 +08:00
|
|
|
collection::const_iterator pos, end = m_modules.end();
|
|
|
|
for (pos = m_modules.begin(); pos != end; ++pos) {
|
2010-06-09 00:52:24 +08:00
|
|
|
ModuleSP module_sp(*pos);
|
2012-02-26 13:51:37 +08:00
|
|
|
if (module_sp->MatchesModuleSpec(module_spec))
|
Many improvements to the Platform base class and subclasses. The base Platform
class now implements the Host functionality for a lot of things that make
sense by default so that subclasses can check:
int
PlatformSubclass::Foo ()
{
if (IsHost())
return Platform::Foo (); // Let the platform base class do the host specific stuff
// Platform subclass specific code...
int result = ...
return result;
}
Added new functions to the platform:
virtual const char *Platform::GetUserName (uint32_t uid);
virtual const char *Platform::GetGroupName (uint32_t gid);
The user and group names are cached locally so that remote platforms can avoid
sending packets multiple times to resolve this information.
Added the parent process ID to the ProcessInfo class.
Added a new ProcessInfoMatch class which helps us to match processes up
and changed the Host layer over to using this new class. The new class allows
us to search for processs:
1 - by name (equal to, starts with, ends with, contains, and regex)
2 - by pid
3 - And further check for parent pid == value, uid == value, gid == value,
euid == value, egid == value, arch == value, parent == value.
This is all hookup up to the "platform process list" command which required
adding dumping routines to dump process information. If the Host class
implements the process lookup routines, you can now lists processes on
your local machine:
machine1.foo.com % lldb
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
94727 244 username usergroup username usergroup x86_64-apple-darwin Xcode
92742 92710 username usergroup username usergroup i386-apple-darwin debugserver
This of course also works remotely with the lldb-platform:
machine1.foo.com % lldb-platform --listen 1234
machine2.foo.com % lldb
(lldb) platform create remote-macosx
Platform: remote-macosx
Connected: no
(lldb) platform connect connect://localhost:1444
Platform: remote-macosx
Triple: x86_64-apple-darwin
OS Version: 10.6.7 (10J869)
Kernel: Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386
Hostname: machine1.foo.com
Connected: yes
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99556 244 username usergroup username usergroup x86_64-apple-darwin trustevaluation
99548 65539 username usergroup username usergroup x86_64-apple-darwin lldb
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
The lldb-platform implements everything with the Host:: layer, so this should
"just work" for linux. I will probably be adding more stuff to the Host layer
for launching processes and attaching to processes so that this support should
eventually just work as well.
Modified the target to be able to be created with an architecture that differs
from the main executable. This is needed for iOS debugging since we can have
an "armv6" binary which can run on an "armv7" machine, so we want to be able
to do:
% lldb
(lldb) platform create remote-ios
(lldb) file --arch armv7 a.out
Where "a.out" is an armv6 executable. The platform then can correctly decide
to open all "armv7" images for all dependent shared libraries.
Modified the disassembly to show the current PC value. Example output:
(lldb) disassemble --frame
a.out`main:
0x1eb7: pushl %ebp
0x1eb8: movl %esp, %ebp
0x1eba: pushl %ebx
0x1ebb: subl $20, %esp
0x1ebe: calll 0x1ec3 ; main + 12 at test.c:18
0x1ec3: popl %ebx
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
0x1edb: leal 213(%ebx), %eax
0x1ee1: movl %eax, (%esp)
0x1ee4: calll 0x1f1e ; puts
0x1ee9: calll 0x1f0c ; getchar
0x1eee: movl $20, (%esp)
0x1ef5: calll 0x1e6a ; sleep_loop at test.c:6
0x1efa: movl $12, %eax
0x1eff: addl $20, %esp
0x1f02: popl %ebx
0x1f03: leave
0x1f04: ret
This can be handy when dealing with the new --line options that was recently
added:
(lldb) disassemble --line
a.out`main + 13 at test.c:19
18 {
-> 19 printf("Process: %i\n\n", getpid());
20 puts("Press any key to continue..."); getchar();
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
Modified the ModuleList to have a lookup based solely on a UUID. Since the
UUID is typically the MD5 checksum of a binary image, there is no need
to give the path and architecture when searching for a pre-existing
image in an image list.
Now that we support remote debugging a bit better, our lldb_private::Module
needs to be able to track what the original path for file was as the platform
knows it, as well as where the file is locally. The module has the two
following functions to retrieve both paths:
const FileSpec &Module::GetFileSpec () const;
const FileSpec &Module::GetPlatformFileSpec () const;
llvm-svn: 128563
2011-03-31 02:16:51 +08:00
|
|
|
return module_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
Many improvements to the Platform base class and subclasses. The base Platform
class now implements the Host functionality for a lot of things that make
sense by default so that subclasses can check:
int
PlatformSubclass::Foo ()
{
if (IsHost())
return Platform::Foo (); // Let the platform base class do the host specific stuff
// Platform subclass specific code...
int result = ...
return result;
}
Added new functions to the platform:
virtual const char *Platform::GetUserName (uint32_t uid);
virtual const char *Platform::GetGroupName (uint32_t gid);
The user and group names are cached locally so that remote platforms can avoid
sending packets multiple times to resolve this information.
Added the parent process ID to the ProcessInfo class.
Added a new ProcessInfoMatch class which helps us to match processes up
and changed the Host layer over to using this new class. The new class allows
us to search for processs:
1 - by name (equal to, starts with, ends with, contains, and regex)
2 - by pid
3 - And further check for parent pid == value, uid == value, gid == value,
euid == value, egid == value, arch == value, parent == value.
This is all hookup up to the "platform process list" command which required
adding dumping routines to dump process information. If the Host class
implements the process lookup routines, you can now lists processes on
your local machine:
machine1.foo.com % lldb
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
94727 244 username usergroup username usergroup x86_64-apple-darwin Xcode
92742 92710 username usergroup username usergroup i386-apple-darwin debugserver
This of course also works remotely with the lldb-platform:
machine1.foo.com % lldb-platform --listen 1234
machine2.foo.com % lldb
(lldb) platform create remote-macosx
Platform: remote-macosx
Connected: no
(lldb) platform connect connect://localhost:1444
Platform: remote-macosx
Triple: x86_64-apple-darwin
OS Version: 10.6.7 (10J869)
Kernel: Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386
Hostname: machine1.foo.com
Connected: yes
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99556 244 username usergroup username usergroup x86_64-apple-darwin trustevaluation
99548 65539 username usergroup username usergroup x86_64-apple-darwin lldb
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
The lldb-platform implements everything with the Host:: layer, so this should
"just work" for linux. I will probably be adding more stuff to the Host layer
for launching processes and attaching to processes so that this support should
eventually just work as well.
Modified the target to be able to be created with an architecture that differs
from the main executable. This is needed for iOS debugging since we can have
an "armv6" binary which can run on an "armv7" machine, so we want to be able
to do:
% lldb
(lldb) platform create remote-ios
(lldb) file --arch armv7 a.out
Where "a.out" is an armv6 executable. The platform then can correctly decide
to open all "armv7" images for all dependent shared libraries.
Modified the disassembly to show the current PC value. Example output:
(lldb) disassemble --frame
a.out`main:
0x1eb7: pushl %ebp
0x1eb8: movl %esp, %ebp
0x1eba: pushl %ebx
0x1ebb: subl $20, %esp
0x1ebe: calll 0x1ec3 ; main + 12 at test.c:18
0x1ec3: popl %ebx
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
0x1edb: leal 213(%ebx), %eax
0x1ee1: movl %eax, (%esp)
0x1ee4: calll 0x1f1e ; puts
0x1ee9: calll 0x1f0c ; getchar
0x1eee: movl $20, (%esp)
0x1ef5: calll 0x1e6a ; sleep_loop at test.c:6
0x1efa: movl $12, %eax
0x1eff: addl $20, %esp
0x1f02: popl %ebx
0x1f03: leave
0x1f04: ret
This can be handy when dealing with the new --line options that was recently
added:
(lldb) disassemble --line
a.out`main + 13 at test.c:19
18 {
-> 19 printf("Process: %i\n\n", getpid());
20 puts("Press any key to continue..."); getchar();
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
Modified the ModuleList to have a lookup based solely on a UUID. Since the
UUID is typically the MD5 checksum of a binary image, there is no need
to give the path and architecture when searching for a pre-existing
image in an image list.
Now that we support remote debugging a bit better, our lldb_private::Module
needs to be able to track what the original path for file was as the platform
knows it, as well as where the file is locally. The module has the two
following functions to retrieve both paths:
const FileSpec &Module::GetFileSpec () const;
const FileSpec &Module::GetPlatformFileSpec () const;
llvm-svn: 128563
2011-03-31 02:16:51 +08:00
|
|
|
return module_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t ModuleList::GetSize() const {
|
2016-05-19 13:13:57 +08:00
|
|
|
size_t size = 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
size = m_modules.size();
|
|
|
|
}
|
2011-11-19 08:19:25 +08:00
|
|
|
return size;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
void ModuleList::Dump(Stream *s) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules)
|
|
|
|
module_sp->Dump(s);
|
2010-12-14 10:59:59 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-11-08 10:22:02 +08:00
|
|
|
void ModuleList::LogUUIDAndPaths(Log *log, const char *prefix_cstr) {
|
|
|
|
if (log != nullptr) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
collection::const_iterator pos, begin = m_modules.begin(),
|
Many improvements to the Platform base class and subclasses. The base Platform
class now implements the Host functionality for a lot of things that make
sense by default so that subclasses can check:
int
PlatformSubclass::Foo ()
{
if (IsHost())
return Platform::Foo (); // Let the platform base class do the host specific stuff
// Platform subclass specific code...
int result = ...
return result;
}
Added new functions to the platform:
virtual const char *Platform::GetUserName (uint32_t uid);
virtual const char *Platform::GetGroupName (uint32_t gid);
The user and group names are cached locally so that remote platforms can avoid
sending packets multiple times to resolve this information.
Added the parent process ID to the ProcessInfo class.
Added a new ProcessInfoMatch class which helps us to match processes up
and changed the Host layer over to using this new class. The new class allows
us to search for processs:
1 - by name (equal to, starts with, ends with, contains, and regex)
2 - by pid
3 - And further check for parent pid == value, uid == value, gid == value,
euid == value, egid == value, arch == value, parent == value.
This is all hookup up to the "platform process list" command which required
adding dumping routines to dump process information. If the Host class
implements the process lookup routines, you can now lists processes on
your local machine:
machine1.foo.com % lldb
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
94727 244 username usergroup username usergroup x86_64-apple-darwin Xcode
92742 92710 username usergroup username usergroup i386-apple-darwin debugserver
This of course also works remotely with the lldb-platform:
machine1.foo.com % lldb-platform --listen 1234
machine2.foo.com % lldb
(lldb) platform create remote-macosx
Platform: remote-macosx
Connected: no
(lldb) platform connect connect://localhost:1444
Platform: remote-macosx
Triple: x86_64-apple-darwin
OS Version: 10.6.7 (10J869)
Kernel: Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386
Hostname: machine1.foo.com
Connected: yes
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99556 244 username usergroup username usergroup x86_64-apple-darwin trustevaluation
99548 65539 username usergroup username usergroup x86_64-apple-darwin lldb
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
The lldb-platform implements everything with the Host:: layer, so this should
"just work" for linux. I will probably be adding more stuff to the Host layer
for launching processes and attaching to processes so that this support should
eventually just work as well.
Modified the target to be able to be created with an architecture that differs
from the main executable. This is needed for iOS debugging since we can have
an "armv6" binary which can run on an "armv7" machine, so we want to be able
to do:
% lldb
(lldb) platform create remote-ios
(lldb) file --arch armv7 a.out
Where "a.out" is an armv6 executable. The platform then can correctly decide
to open all "armv7" images for all dependent shared libraries.
Modified the disassembly to show the current PC value. Example output:
(lldb) disassemble --frame
a.out`main:
0x1eb7: pushl %ebp
0x1eb8: movl %esp, %ebp
0x1eba: pushl %ebx
0x1ebb: subl $20, %esp
0x1ebe: calll 0x1ec3 ; main + 12 at test.c:18
0x1ec3: popl %ebx
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
0x1edb: leal 213(%ebx), %eax
0x1ee1: movl %eax, (%esp)
0x1ee4: calll 0x1f1e ; puts
0x1ee9: calll 0x1f0c ; getchar
0x1eee: movl $20, (%esp)
0x1ef5: calll 0x1e6a ; sleep_loop at test.c:6
0x1efa: movl $12, %eax
0x1eff: addl $20, %esp
0x1f02: popl %ebx
0x1f03: leave
0x1f04: ret
This can be handy when dealing with the new --line options that was recently
added:
(lldb) disassemble --line
a.out`main + 13 at test.c:19
18 {
-> 19 printf("Process: %i\n\n", getpid());
20 puts("Press any key to continue..."); getchar();
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
Modified the ModuleList to have a lookup based solely on a UUID. Since the
UUID is typically the MD5 checksum of a binary image, there is no need
to give the path and architecture when searching for a pre-existing
image in an image list.
Now that we support remote debugging a bit better, our lldb_private::Module
needs to be able to track what the original path for file was as the platform
knows it, as well as where the file is locally. The module has the two
following functions to retrieve both paths:
const FileSpec &Module::GetFileSpec () const;
const FileSpec &Module::GetPlatformFileSpec () const;
llvm-svn: 128563
2011-03-31 02:16:51 +08:00
|
|
|
end = m_modules.end();
|
2012-11-08 10:22:02 +08:00
|
|
|
for (pos = begin; pos != end; ++pos) {
|
2010-12-14 10:59:59 +08:00
|
|
|
Module *module = pos->get();
|
|
|
|
const FileSpec &module_file_spec = module->GetFileSpec();
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "%s[%u] %s (%s) \"%s\"", prefix_cstr ? prefix_cstr : "",
|
|
|
|
(uint32_t)std::distance(begin, pos),
|
|
|
|
module->GetUUID().GetAsString().c_str(),
|
|
|
|
module->GetArchitecture().GetArchitectureName(),
|
|
|
|
module_file_spec.GetPath().c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 10:22:02 +08:00
|
|
|
bool ModuleList::ResolveFileAddress(lldb::addr_t vm_addr,
|
|
|
|
Address &so_addr) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules) {
|
|
|
|
if (module_sp->ResolveFileAddress(vm_addr, so_addr))
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-03-16 05:01:31 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2018-10-26 04:45:19 +08:00
|
|
|
uint32_t
|
|
|
|
ModuleList::ResolveSymbolContextForAddress(const Address &so_addr,
|
|
|
|
SymbolContextItem resolve_scope,
|
|
|
|
SymbolContext &sc) const {
|
2010-06-09 00:52:24 +08:00
|
|
|
// The address is already section offset so it has a module
|
|
|
|
uint32_t resolved_flags = 0;
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp(so_addr.GetModule());
|
|
|
|
if (module_sp) {
|
2010-06-09 00:52:24 +08:00
|
|
|
resolved_flags =
|
2012-11-08 10:22:02 +08:00
|
|
|
module_sp->ResolveSymbolContextForAddress(so_addr, resolve_scope, sc);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
collection::const_iterator pos, end = m_modules.end();
|
|
|
|
for (pos = m_modules.begin(); pos != end; ++pos) {
|
|
|
|
resolved_flags =
|
2012-11-08 10:22:02 +08:00
|
|
|
(*pos)->ResolveSymbolContextForAddress(so_addr, resolve_scope, sc);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (resolved_flags != 0)
|
|
|
|
break;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return resolved_flags;
|
|
|
|
}
|
|
|
|
|
2016-03-12 04:20:38 +08:00
|
|
|
uint32_t ModuleList::ResolveSymbolContextForFilePath(
|
|
|
|
const char *file_path, uint32_t line, bool check_inlines,
|
2018-10-26 04:45:19 +08:00
|
|
|
SymbolContextItem resolve_scope, SymbolContextList &sc_list) const {
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec file_spec(file_path);
|
2010-06-09 00:52:24 +08:00
|
|
|
return ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
|
|
|
|
resolve_scope, sc_list);
|
|
|
|
}
|
|
|
|
|
2012-11-08 10:22:02 +08:00
|
|
|
uint32_t ModuleList::ResolveSymbolContextsForFileSpec(
|
|
|
|
const FileSpec &file_spec, uint32_t line, bool check_inlines,
|
2018-10-26 04:45:19 +08:00
|
|
|
SymbolContextItem resolve_scope, SymbolContextList &sc_list) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2021-10-30 19:29:36 +08:00
|
|
|
for (const ModuleSP &module_sp : m_modules) {
|
|
|
|
module_sp->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
|
|
|
|
resolve_scope, sc_list);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return sc_list.GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t ModuleList::GetIndexForModule(const Module *module) const {
|
|
|
|
if (module) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
collection::const_iterator pos;
|
|
|
|
collection::const_iterator begin = m_modules.begin();
|
|
|
|
collection::const_iterator end = m_modules.end();
|
|
|
|
for (pos = begin; pos != end; ++pos) {
|
|
|
|
if ((*pos).get() == module)
|
2013-03-28 07:08:40 +08:00
|
|
|
return std::distance(begin, pos);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return LLDB_INVALID_INDEX32;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2018-03-03 06:42:44 +08:00
|
|
|
namespace {
|
|
|
|
struct SharedModuleListInfo {
|
|
|
|
ModuleList module_list;
|
|
|
|
ModuleListProperties module_list_properties;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
static SharedModuleListInfo &GetSharedModuleListInfo()
|
|
|
|
{
|
|
|
|
static SharedModuleListInfo *g_shared_module_list_info = nullptr;
|
2017-02-07 01:55:02 +08:00
|
|
|
static llvm::once_flag g_once_flag;
|
|
|
|
llvm::call_once(g_once_flag, []() {
|
2010-06-09 00:52:24 +08:00
|
|
|
// NOTE: Intentionally leak the module list so a program doesn't have to
|
|
|
|
// cleanup all modules and object files as it exits. This just wastes time
|
2014-03-25 00:50:33 +08:00
|
|
|
// doing a bunch of cleanup that isn't required.
|
2018-03-03 06:42:44 +08:00
|
|
|
if (g_shared_module_list_info == nullptr)
|
|
|
|
g_shared_module_list_info = new SharedModuleListInfo();
|
2016-09-07 04:57:50 +08:00
|
|
|
});
|
2018-03-03 06:42:44 +08:00
|
|
|
return *g_shared_module_list_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ModuleList &GetSharedModuleList() {
|
|
|
|
return GetSharedModuleListInfo().module_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
ModuleListProperties &ModuleList::GetGlobalModuleListProperties() {
|
|
|
|
return GetSharedModuleListInfo().module_list_properties;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-01-28 02:45:39 +08:00
|
|
|
bool ModuleList::ModuleIsInCache(const Module *module_ptr) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (module_ptr) {
|
|
|
|
ModuleList &shared_module_list = GetSharedModuleList();
|
2016-03-12 04:20:38 +08:00
|
|
|
return shared_module_list.FindModule(module_ptr).get() != nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-03-16 05:01:31 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-10-18 03:56:40 +08:00
|
|
|
void ModuleList::FindSharedModules(const ModuleSpec &module_spec,
|
|
|
|
ModuleList &matching_module_list) {
|
|
|
|
GetSharedModuleList().FindModules(module_spec, matching_module_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t ModuleList::RemoveOrphanSharedModules(bool mandatory) {
|
2012-04-10 04:22:01 +08:00
|
|
|
return GetSharedModuleList().RemoveOrphans(mandatory);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
[lldb] GetSharedModule: Collect old modules in SmallVector
The various GetSharedModule methods have an optional out parameter for
the old module when a file has changed or been replaced, which the
Target uses to keep its module list current/correct. We've been using
a single ModuleSP to track "the" old module, and this change switches
to using a SmallVector of ModuleSP, which has a couple benefits:
- There are multiple codepaths which may discover an old module, and
this centralizes the code for how to handle multiples in one place,
in the Target code. With the single ModuleSP, each place that may
discover an old module is responsible for how it handles multiples,
and the current code is inconsistent (some code paths drop the first
old module, others drop the second).
- The API will be more natural for identifying old modules in routines
that work on sets, like ModuleList::ReplaceEquivalent (which I plan
on updating to report old module(s) in a subsequent change to fix a
bug).
I'm not convinced we can ever actually run into the case that multiple
old modules are found in the same GetOrCreateModule call, but I think
this change makes sense regardless, in light of the above.
When an old module is reported, Target::GetOrCreateModule calls
m_images.ReplaceModule, which doesn't allow multiple "old" modules; the
new code calls ReplaceModule for the first "old" module, and for any
subsequent old modules it logs the event and calls m_images.Remove.
Reviewed By: jingham
Differential Revision: https://reviews.llvm.org/D89156
2020-10-31 03:12:10 +08:00
|
|
|
Status
|
|
|
|
ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
|
|
|
|
const FileSpecList *module_search_paths_ptr,
|
|
|
|
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
|
|
|
|
bool *did_create_ptr, bool always_create) {
|
2010-06-09 00:52:24 +08:00
|
|
|
ModuleList &shared_module_list = GetSharedModuleList();
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
shared_module_list.m_modules_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
char path[PATH_MAX];
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
module_sp.reset();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (did_create_ptr)
|
|
|
|
*did_create_ptr = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-26 13:51:37 +08:00
|
|
|
const UUID *uuid_ptr = module_spec.GetUUIDPtr();
|
|
|
|
const FileSpec &module_file_spec = module_spec.GetFileSpec();
|
|
|
|
const ArchSpec &arch = module_spec.GetArchitecture();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-26 13:51:37 +08:00
|
|
|
// Make sure no one else can try and get or create a module while this
|
2018-05-01 00:49:04 +08:00
|
|
|
// function is actively working on it by doing an extra lock on the global
|
|
|
|
// mutex list.
|
2016-03-12 04:20:38 +08:00
|
|
|
if (!always_create) {
|
2012-02-26 13:51:37 +08:00
|
|
|
ModuleList matching_module_list;
|
2019-10-18 03:56:40 +08:00
|
|
|
shared_module_list.FindModules(module_spec, matching_module_list);
|
|
|
|
const size_t num_matching_modules = matching_module_list.GetSize();
|
|
|
|
|
2012-02-26 13:51:37 +08:00
|
|
|
if (num_matching_modules > 0) {
|
2013-01-26 02:06:21 +08:00
|
|
|
for (size_t module_idx = 0; module_idx < num_matching_modules;
|
|
|
|
++module_idx) {
|
2012-02-26 13:51:37 +08:00
|
|
|
module_sp = matching_module_list.GetModuleAtIndex(module_idx);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Make sure the file for the module hasn't been modified
|
2012-07-13 06:51:12 +08:00
|
|
|
if (module_sp->FileHasChanged()) {
|
[lldb] GetSharedModule: Collect old modules in SmallVector
The various GetSharedModule methods have an optional out parameter for
the old module when a file has changed or been replaced, which the
Target uses to keep its module list current/correct. We've been using
a single ModuleSP to track "the" old module, and this change switches
to using a SmallVector of ModuleSP, which has a couple benefits:
- There are multiple codepaths which may discover an old module, and
this centralizes the code for how to handle multiples in one place,
in the Target code. With the single ModuleSP, each place that may
discover an old module is responsible for how it handles multiples,
and the current code is inconsistent (some code paths drop the first
old module, others drop the second).
- The API will be more natural for identifying old modules in routines
that work on sets, like ModuleList::ReplaceEquivalent (which I plan
on updating to report old module(s) in a subsequent change to fix a
bug).
I'm not convinced we can ever actually run into the case that multiple
old modules are found in the same GetOrCreateModule call, but I think
this change makes sense regardless, in light of the above.
When an old module is reported, Target::GetOrCreateModule calls
m_images.ReplaceModule, which doesn't allow multiple "old" modules; the
new code calls ReplaceModule for the first "old" module, and for any
subsequent old modules it logs the event and calls m_images.Remove.
Reviewed By: jingham
Differential Revision: https://reviews.llvm.org/D89156
2020-10-31 03:12:10 +08:00
|
|
|
if (old_modules)
|
|
|
|
old_modules->push_back(module_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::Modules);
|
2016-03-12 04:20:38 +08:00
|
|
|
if (log != nullptr)
|
2019-11-16 08:25:46 +08:00
|
|
|
LLDB_LOGF(
|
|
|
|
log, "%p '%s' module changed: removing from global module list",
|
|
|
|
static_cast<void *>(module_sp.get()),
|
|
|
|
module_sp->GetFileSpec().GetFilename().GetCString());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-07-13 06:51:12 +08:00
|
|
|
shared_module_list.Remove(module_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
module_sp.reset();
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// The module matches and the module was not modified from when it
|
|
|
|
// was last loaded.
|
2012-07-13 06:51:12 +08:00
|
|
|
return error;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (module_sp)
|
|
|
|
return error;
|
|
|
|
|
2019-02-12 07:13:08 +08:00
|
|
|
module_sp = std::make_shared<Module>(module_spec);
|
2018-05-01 00:49:04 +08:00
|
|
|
// Make sure there are a module and an object file since we can specify a
|
|
|
|
// valid file path with an architecture that might not be in that file. By
|
|
|
|
// getting the object file we can guarantee that the architecture matches
|
2012-07-13 06:51:12 +08:00
|
|
|
if (module_sp->GetObjectFile()) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// If we get in here we got the correct arch, now we just need to verify
|
|
|
|
// the UUID if one was given
|
2016-03-12 04:20:38 +08:00
|
|
|
if (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) {
|
2014-04-04 12:06:10 +08:00
|
|
|
module_sp.reset();
|
2012-07-13 06:51:12 +08:00
|
|
|
} else {
|
|
|
|
if (module_sp->GetObjectFile() &&
|
|
|
|
module_sp->GetObjectFile()->GetType() ==
|
|
|
|
ObjectFile::eTypeStubLibrary) {
|
|
|
|
module_sp.reset();
|
|
|
|
} else {
|
|
|
|
if (did_create_ptr) {
|
|
|
|
*did_create_ptr = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2020-10-31 03:13:26 +08:00
|
|
|
shared_module_list.ReplaceEquivalent(module_sp, old_modules);
|
2012-02-26 13:51:37 +08:00
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2015-03-17 07:44:30 +08:00
|
|
|
} else {
|
2010-06-09 00:52:24 +08:00
|
|
|
module_sp.reset();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-03-17 07:44:30 +08:00
|
|
|
if (module_search_paths_ptr) {
|
|
|
|
const auto num_directories = module_search_paths_ptr->GetSize();
|
|
|
|
for (size_t idx = 0; idx < num_directories; ++idx) {
|
|
|
|
auto search_path_spec = module_search_paths_ptr->GetFileSpecAtIndex(idx);
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSystem::Instance().Resolve(search_path_spec);
|
2017-03-09 01:56:08 +08:00
|
|
|
namespace fs = llvm::sys::fs;
|
2018-11-08 08:14:50 +08:00
|
|
|
if (!FileSystem::Instance().IsDirectory(search_path_spec))
|
2015-03-17 07:44:30 +08:00
|
|
|
continue;
|
|
|
|
search_path_spec.AppendPathComponent(
|
2020-02-11 16:05:37 +08:00
|
|
|
module_spec.GetFileSpec().GetFilename().GetStringRef());
|
2018-11-02 01:09:25 +08:00
|
|
|
if (!FileSystem::Instance().Exists(search_path_spec))
|
2015-03-17 07:44:30 +08:00
|
|
|
continue;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-03-17 07:44:30 +08:00
|
|
|
auto resolved_module_spec(module_spec);
|
|
|
|
resolved_module_spec.GetFileSpec() = search_path_spec;
|
2019-02-12 07:13:08 +08:00
|
|
|
module_sp = std::make_shared<Module>(resolved_module_spec);
|
2015-03-17 07:44:30 +08:00
|
|
|
if (module_sp->GetObjectFile()) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// If we get in here we got the correct arch, now we just need to
|
|
|
|
// verify the UUID if one was given
|
2015-03-17 07:44:30 +08:00
|
|
|
if (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) {
|
2010-06-09 00:52:24 +08:00
|
|
|
module_sp.reset();
|
2015-10-22 11:50:28 +08:00
|
|
|
} else {
|
|
|
|
if (module_sp->GetObjectFile()->GetType() ==
|
|
|
|
ObjectFile::eTypeStubLibrary) {
|
2015-03-17 07:44:30 +08:00
|
|
|
module_sp.reset();
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (did_create_ptr)
|
2015-10-22 11:50:28 +08:00
|
|
|
*did_create_ptr = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-10-31 03:13:26 +08:00
|
|
|
shared_module_list.ReplaceEquivalent(module_sp, old_modules);
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-10-22 11:50:28 +08:00
|
|
|
}
|
|
|
|
} else {
|
2015-03-17 07:44:30 +08:00
|
|
|
module_sp.reset();
|
2015-10-22 11:50:28 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 07:44:30 +08:00
|
|
|
// Either the file didn't exist where at the path, or no path was given, so
|
|
|
|
// we now have to use more extreme measures to try and find the appropriate
|
|
|
|
// module.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Fixup the incoming path in case the path points to a valid file, yet the
|
|
|
|
// arch or UUID (if one was passed in) don't match.
|
2015-03-17 07:44:30 +08:00
|
|
|
ModuleSpec located_binary_modulespec =
|
|
|
|
Symbols::LocateExecutableObjectFile(module_spec);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-03-17 07:44:30 +08:00
|
|
|
// Don't look for the file if it appears to be the same one we already
|
|
|
|
// checked for above...
|
|
|
|
if (located_binary_modulespec.GetFileSpec() != module_file_spec) {
|
2018-11-02 01:09:25 +08:00
|
|
|
if (!FileSystem::Instance().Exists(
|
|
|
|
located_binary_modulespec.GetFileSpec())) {
|
2015-03-17 07:44:30 +08:00
|
|
|
located_binary_modulespec.GetFileSpec().GetPath(path, sizeof(path));
|
|
|
|
if (path[0] == '\0')
|
|
|
|
module_file_spec.GetPath(path, sizeof(path));
|
2012-02-26 13:51:37 +08:00
|
|
|
// How can this check ever be true? This branch it is false, and we
|
|
|
|
// haven't modified file_spec.
|
2018-11-02 01:09:25 +08:00
|
|
|
if (FileSystem::Instance().Exists(
|
|
|
|
located_binary_modulespec.GetFileSpec())) {
|
2012-02-26 13:51:37 +08:00
|
|
|
std::string uuid_str;
|
|
|
|
if (uuid_ptr && uuid_ptr->IsValid())
|
2015-10-22 11:50:28 +08:00
|
|
|
uuid_str = uuid_ptr->GetAsString();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-22 11:50:28 +08:00
|
|
|
if (arch.IsValid()) {
|
2013-05-04 07:56:12 +08:00
|
|
|
if (!uuid_str.empty())
|
2015-10-22 11:50:28 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"'%s' does not contain the %s architecture and UUID %s", path,
|
|
|
|
arch.GetArchitectureName(), uuid_str.c_str());
|
2012-02-26 13:51:37 +08:00
|
|
|
else
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"'%s' does not contain the %s architecture.", path,
|
|
|
|
arch.GetArchitectureName());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2011-10-26 08:56:27 +08:00
|
|
|
error.SetErrorStringWithFormat("'%s' does not exist", path);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-02-05 10:38:54 +08:00
|
|
|
if (error.Fail())
|
2010-06-09 00:52:24 +08:00
|
|
|
module_sp.reset();
|
2012-02-26 13:51:37 +08:00
|
|
|
return error;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure no one else can try and get or create a module while this
|
2018-05-01 00:49:04 +08:00
|
|
|
// function is actively working on it by doing an extra lock on the global
|
|
|
|
// mutex list.
|
2015-10-09 05:48:35 +08:00
|
|
|
ModuleSpec platform_module_spec(module_spec);
|
|
|
|
platform_module_spec.GetFileSpec() =
|
|
|
|
located_binary_modulespec.GetFileSpec();
|
|
|
|
platform_module_spec.GetPlatformFileSpec() =
|
|
|
|
located_binary_modulespec.GetFileSpec();
|
|
|
|
platform_module_spec.GetSymbolFileSpec() =
|
2012-02-26 13:51:37 +08:00
|
|
|
located_binary_modulespec.GetSymbolFileSpec();
|
|
|
|
ModuleList matching_module_list;
|
2019-10-18 03:56:40 +08:00
|
|
|
shared_module_list.FindModules(platform_module_spec, matching_module_list);
|
|
|
|
if (!matching_module_list.IsEmpty()) {
|
2012-02-26 13:51:37 +08:00
|
|
|
module_sp = matching_module_list.GetModuleAtIndex(0);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-01 05:05:18 +08:00
|
|
|
// If we didn't have a UUID in mind when looking for the object file,
|
|
|
|
// then we should make sure the modification time hasn't changed!
|
|
|
|
if (platform_module_spec.GetUUIDPtr() == nullptr) {
|
2018-11-01 05:49:27 +08:00
|
|
|
auto file_spec_mod_time = FileSystem::Instance().GetModificationTime(
|
2016-11-09 22:04:08 +08:00
|
|
|
located_binary_modulespec.GetFileSpec());
|
|
|
|
if (file_spec_mod_time != llvm::sys::TimePoint<>()) {
|
2013-05-04 07:56:12 +08:00
|
|
|
if (file_spec_mod_time != module_sp->GetModificationTime()) {
|
[lldb] GetSharedModule: Collect old modules in SmallVector
The various GetSharedModule methods have an optional out parameter for
the old module when a file has changed or been replaced, which the
Target uses to keep its module list current/correct. We've been using
a single ModuleSP to track "the" old module, and this change switches
to using a SmallVector of ModuleSP, which has a couple benefits:
- There are multiple codepaths which may discover an old module, and
this centralizes the code for how to handle multiples in one place,
in the Target code. With the single ModuleSP, each place that may
discover an old module is responsible for how it handles multiples,
and the current code is inconsistent (some code paths drop the first
old module, others drop the second).
- The API will be more natural for identifying old modules in routines
that work on sets, like ModuleList::ReplaceEquivalent (which I plan
on updating to report old module(s) in a subsequent change to fix a
bug).
I'm not convinced we can ever actually run into the case that multiple
old modules are found in the same GetOrCreateModule call, but I think
this change makes sense regardless, in light of the above.
When an old module is reported, Target::GetOrCreateModule calls
m_images.ReplaceModule, which doesn't allow multiple "old" modules; the
new code calls ReplaceModule for the first "old" module, and for any
subsequent old modules it logs the event and calls m_images.Remove.
Reviewed By: jingham
Differential Revision: https://reviews.llvm.org/D89156
2020-10-31 03:12:10 +08:00
|
|
|
if (old_modules)
|
|
|
|
old_modules->push_back(module_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
shared_module_list.Remove(module_sp);
|
2012-02-05 10:38:54 +08:00
|
|
|
module_sp.reset();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-12 04:20:38 +08:00
|
|
|
if (!module_sp) {
|
2019-02-12 07:13:08 +08:00
|
|
|
module_sp = std::make_shared<Module>(platform_module_spec);
|
2018-05-01 00:49:04 +08:00
|
|
|
// Make sure there are a module and an object file since we can specify a
|
|
|
|
// valid file path with an architecture that might not be in that file.
|
2010-06-09 00:52:24 +08:00
|
|
|
// By getting the object file we can guarantee that the architecture
|
|
|
|
// matches
|
|
|
|
if (module_sp && module_sp->GetObjectFile()) {
|
|
|
|
if (module_sp->GetObjectFile()->GetType() ==
|
|
|
|
ObjectFile::eTypeStubLibrary) {
|
|
|
|
module_sp.reset();
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (did_create_ptr)
|
|
|
|
*did_create_ptr = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-10-31 03:13:26 +08:00
|
|
|
shared_module_list.ReplaceEquivalent(module_sp, old_modules);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
} else {
|
2012-03-21 12:25:00 +08:00
|
|
|
located_binary_modulespec.GetFileSpec().GetPath(path, sizeof(path));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-22 11:50:28 +08:00
|
|
|
if (located_binary_modulespec.GetFileSpec()) {
|
|
|
|
if (arch.IsValid())
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"unable to open %s architecture in '%s'",
|
2015-10-09 05:48:35 +08:00
|
|
|
arch.GetArchitectureName(), path);
|
2011-10-26 08:56:27 +08:00
|
|
|
else
|
|
|
|
error.SetErrorStringWithFormat("unable to open '%s'", path);
|
2010-06-09 00:52:24 +08:00
|
|
|
} else {
|
2013-05-04 07:56:12 +08:00
|
|
|
std::string uuid_str;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (uuid_ptr && uuid_ptr->IsValid())
|
2013-05-04 07:56:12 +08:00
|
|
|
uuid_str = uuid_ptr->GetAsString();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-04 07:56:12 +08:00
|
|
|
if (!uuid_str.empty())
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"cannot locate a module for UUID '%s'", uuid_str.c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2020-07-21 13:57:06 +08:00
|
|
|
error.SetErrorString("cannot locate a module");
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-03-15 11:56:33 +08:00
|
|
|
bool ModuleList::RemoveSharedModule(lldb::ModuleSP &module_sp) {
|
|
|
|
return GetSharedModuleList().Remove(module_sp);
|
|
|
|
}
|
|
|
|
|
2012-05-18 02:38:42 +08:00
|
|
|
bool ModuleList::RemoveSharedModuleIfOrphaned(const Module *module_ptr) {
|
|
|
|
return GetSharedModuleList().RemoveIfOrphaned(module_ptr);
|
|
|
|
}
|
|
|
|
|
2013-05-21 06:29:23 +08:00
|
|
|
bool ModuleList::LoadScriptingResourcesInTarget(Target *target,
|
2017-05-12 12:51:55 +08:00
|
|
|
std::list<Status> &errors,
|
2013-05-21 08:00:30 +08:00
|
|
|
Stream *feedback_stream,
|
2013-05-21 06:29:23 +08:00
|
|
|
bool continue_on_error) {
|
|
|
|
if (!target)
|
|
|
|
return false;
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2013-05-21 06:29:23 +08:00
|
|
|
for (auto module : m_modules) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2013-05-21 06:29:23 +08:00
|
|
|
if (module) {
|
2013-05-21 08:00:30 +08:00
|
|
|
if (!module->LoadScriptingResourceInTarget(target, error,
|
|
|
|
feedback_stream)) {
|
|
|
|
if (error.Fail() && error.AsCString()) {
|
|
|
|
error.SetErrorStringWithFormat("unable to load scripting data for "
|
|
|
|
"module %s - error reported was %s",
|
|
|
|
module->GetFileSpec()
|
|
|
|
.GetFileNameStrippingExtension()
|
|
|
|
.GetCString(),
|
|
|
|
error.AsCString());
|
|
|
|
errors.push_back(error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-08-19 05:08:44 +08:00
|
|
|
if (!continue_on_error)
|
|
|
|
return false;
|
2013-05-21 06:29:23 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-05-21 06:29:23 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-03-12 04:20:38 +08:00
|
|
|
return errors.empty();
|
2013-05-21 06:29:23 +08:00
|
|
|
}
|
2015-02-13 09:19:24 +08:00
|
|
|
|
|
|
|
void ModuleList::ForEach(
|
|
|
|
std::function<bool(const ModuleSP &module_sp)> const &callback) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
|
2015-02-13 09:19:24 +08:00
|
|
|
for (const auto &module : m_modules) {
|
|
|
|
// If the callback returns false, then stop iterating and break out
|
|
|
|
if (!callback(module))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|