[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
|
|
|
//===-- DynamicLoaderMacOS.cpp --------------------------------------------===//
|
2016-07-21 16:30:55 +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
|
2016-07-21 16:30:55 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Breakpoint/StoppointCallbackContext.h"
|
|
|
|
#include "lldb/Core/Debugger.h"
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/PluginManager.h"
|
|
|
|
#include "lldb/Core/Section.h"
|
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
|
|
|
#include "lldb/Symbol/SymbolVendor.h"
|
|
|
|
#include "lldb/Target/ABI.h"
|
|
|
|
#include "lldb/Target/StackFrame.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
#include "lldb/Target/Thread.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2018-08-07 19:07:21 +08:00
|
|
|
#include "lldb/Utility/State.h"
|
2016-07-21 16:30:55 +08:00
|
|
|
|
|
|
|
#include "DynamicLoaderDarwin.h"
|
|
|
|
#include "DynamicLoaderMacOS.h"
|
|
|
|
|
[lldb] Move clang-based files out of Symbol
Summary:
This change represents the move of ClangASTImporter, ClangASTMetadata,
ClangExternalASTSourceCallbacks, ClangUtil, CxxModuleHandler, and
TypeSystemClang from lldbSource to lldbPluginExpressionParserClang.h
This explicitly removes knowledge of clang internals from lldbSymbol,
moving towards a more generic core implementation of lldb.
Reviewers: JDevlieghere, davide, aprantl, teemperor, clayborg, labath, jingham, shafik
Subscribers: emaste, mgorny, arphaman, jfb, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73661
2020-01-30 03:59:28 +08:00
|
|
|
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
|
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2020-02-08 06:58:18 +08:00
|
|
|
LLDB_PLUGIN(DynamicLoaderMacOS);
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Create an instance of this class. This function is filled into the plugin
|
|
|
|
// info class that gets handed out by the plugin factory and allows the lldb to
|
|
|
|
// instantiate an instance of this class.
|
2016-07-21 16:30:55 +08:00
|
|
|
DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process *process,
|
|
|
|
bool force) {
|
|
|
|
bool create = force;
|
|
|
|
if (!create) {
|
|
|
|
create = true;
|
|
|
|
Module *exe_module = process->GetTarget().GetExecutableModulePointer();
|
|
|
|
if (exe_module) {
|
|
|
|
ObjectFile *object_file = exe_module->GetObjectFile();
|
|
|
|
if (object_file) {
|
|
|
|
create = (object_file->GetStrata() == ObjectFile::eStrataUser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-23 06:26:26 +08:00
|
|
|
if (create) {
|
|
|
|
const llvm::Triple &triple_ref =
|
|
|
|
process->GetTarget().GetArchitecture().GetTriple();
|
|
|
|
switch (triple_ref.getOS()) {
|
|
|
|
case llvm::Triple::Darwin:
|
|
|
|
case llvm::Triple::MacOSX:
|
2016-07-21 16:30:55 +08:00
|
|
|
case llvm::Triple::IOS:
|
|
|
|
case llvm::Triple::TvOS:
|
|
|
|
case llvm::Triple::WatchOS:
|
2018-10-11 08:28:35 +08:00
|
|
|
// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
|
2016-07-23 06:26:26 +08:00
|
|
|
create = triple_ref.getVendor() == llvm::Triple::Apple;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2016-07-23 06:26:26 +08:00
|
|
|
default:
|
|
|
|
create = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-07-23 06:26:26 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2018-12-15 08:15:33 +08:00
|
|
|
if (!UseDYLDSPI(process)) {
|
2016-07-21 16:30:55 +08:00
|
|
|
create = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
if (create)
|
|
|
|
return new DynamicLoaderMacOS(process);
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
return nullptr;
|
2016-07-21 16:30:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
DynamicLoaderMacOS::DynamicLoaderMacOS(Process *process)
|
|
|
|
: DynamicLoaderDarwin(process), m_image_infos_stop_id(UINT32_MAX),
|
2018-12-07 09:18:40 +08:00
|
|
|
m_break_id(LLDB_INVALID_BREAK_ID), m_mutex(),
|
|
|
|
m_maybe_image_infos_address(LLDB_INVALID_ADDRESS) {}
|
2016-07-21 16:30:55 +08:00
|
|
|
|
|
|
|
// Destructor
|
|
|
|
DynamicLoaderMacOS::~DynamicLoaderMacOS() {
|
|
|
|
if (LLDB_BREAK_ID_IS_VALID(m_break_id))
|
|
|
|
m_process->GetTarget().RemoveBreakpointByID(m_break_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DynamicLoaderMacOS::ProcessDidExec() {
|
|
|
|
std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
|
|
|
|
bool did_exec = false;
|
|
|
|
if (m_process) {
|
|
|
|
// If we are stopped after an exec, we will have only one thread...
|
|
|
|
if (m_process->GetThreadList().GetSize() == 1) {
|
2018-12-07 09:18:40 +08:00
|
|
|
// Maybe we still have an image infos address around? If so see
|
|
|
|
// if that has changed, and if so we have exec'ed.
|
|
|
|
if (m_maybe_image_infos_address != LLDB_INVALID_ADDRESS) {
|
|
|
|
lldb::addr_t image_infos_address = m_process->GetImageInfoAddress();
|
|
|
|
if (image_infos_address != m_maybe_image_infos_address) {
|
|
|
|
// We don't really have to reset this here, since we are going to
|
|
|
|
// call DoInitialImageFetch right away to handle the exec. But in
|
|
|
|
// case anybody looks at it in the meantime, it can't hurt.
|
|
|
|
m_maybe_image_infos_address = image_infos_address;
|
|
|
|
did_exec = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!did_exec) {
|
|
|
|
// See if we are stopped at '_dyld_start'
|
|
|
|
ThreadSP thread_sp(m_process->GetThreadList().GetThreadAtIndex(0));
|
|
|
|
if (thread_sp) {
|
|
|
|
lldb::StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0));
|
|
|
|
if (frame_sp) {
|
|
|
|
const Symbol *symbol =
|
|
|
|
frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol;
|
|
|
|
if (symbol) {
|
Allow direct comparison of ConstString against StringRef
Summary:
When we want to compare a ConstString against a string literal (or any other non-ConstString),
we currently have to explicitly turn the other string into a ConstString. This makes sense as
comparing ConstStrings against each other is only a fast pointer comparison.
However, currently we (rather incorrectly) use in several places in LLDB temporary ConstStrings when
we just want to compare a given ConstString against a hardcoded value, for example like this:
```
if (extension != ConstString(".oat") && extension != ConstString(".odex"))
```
Obviously this kind of defeats the point of ConstStrings. In the comparison above we would
construct two temporary ConstStrings every time we hit the given code. Constructing a
ConstString is relatively expensive: we need to go to the StringPool, take a read and possibly
an exclusive write-lock and then look up our temporary string in the string map of the pool.
So we do a lot of heavy work for essentially just comparing a <6 characters in two strings.
I initially wanted to just fix these issues by turning the temporary ConstString in static variables/
members, but that made the code much less readable. Instead I propose to add a new overload
for the ConstString comparison operator that takes a StringRef. This comparison operator directly
compares the ConstString content against the given StringRef without turning the StringRef into
a ConstString.
This means that the example above can look like this now:
```
if (extension != ".oat" && extension != ".odex")
```
It also no longer has to unlock/lock two locks and call multiple functions in other TUs for constructing
the temporary ConstString instances. Instead this should end up just being a direct string comparison
of the two given strings on most compilers.
This patch also directly updates all uses of temporary and short ConstStrings in LLDB to use this new
comparison operator. It also adds a some unit tests for the new and old comparison operator.
Reviewers: #lldb, JDevlieghere, espindola, amccarth
Reviewed By: JDevlieghere, amccarth
Subscribers: amccarth, clayborg, JDevlieghere, emaste, arichardson, MaskRay, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D60667
llvm-svn: 359281
2019-04-26 15:21:36 +08:00
|
|
|
if (symbol->GetName() == "_dyld_start")
|
2018-12-07 09:18:40 +08:00
|
|
|
did_exec = true;
|
|
|
|
}
|
2016-07-21 16:30:55 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-07-21 16:30:55 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-07-21 16:30:55 +08:00
|
|
|
|
|
|
|
if (did_exec) {
|
|
|
|
m_libpthread_module_wp.reset();
|
|
|
|
m_pthread_getspecific_addr.Clear();
|
|
|
|
}
|
|
|
|
return did_exec;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear out the state of this class.
|
|
|
|
void DynamicLoaderMacOS::DoClear() {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
|
|
|
|
|
|
|
if (LLDB_BREAK_ID_IS_VALID(m_break_id))
|
|
|
|
m_process->GetTarget().RemoveBreakpointByID(m_break_id);
|
|
|
|
|
|
|
|
m_break_id = LLDB_INVALID_BREAK_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we have found DYLD yet
|
|
|
|
bool DynamicLoaderMacOS::DidSetNotificationBreakpoint() {
|
|
|
|
return LLDB_BREAK_ID_IS_VALID(m_break_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DynamicLoaderMacOS::ClearNotificationBreakpoint() {
|
|
|
|
if (LLDB_BREAK_ID_IS_VALID(m_break_id)) {
|
|
|
|
m_process->GetTarget().RemoveBreakpointByID(m_break_id);
|
2017-01-21 09:17:36 +08:00
|
|
|
m_break_id = LLDB_INVALID_BREAK_ID;
|
2016-07-21 16:30:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Try and figure out where dyld is by first asking the Process if it knows
|
|
|
|
// (which currently calls down in the lldb::Process to get the DYLD info
|
|
|
|
// (available on SnowLeopard only). If that fails, then check in the default
|
|
|
|
// addresses.
|
2016-07-21 16:30:55 +08:00
|
|
|
void DynamicLoaderMacOS::DoInitialImageFetch() {
|
|
|
|
Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Remove any binaries we pre-loaded in the Target before
|
|
|
|
// launching/attaching. If the same binaries are present in the process,
|
|
|
|
// we'll get them from the shared module cache, we won't need to re-load them
|
|
|
|
// from disk.
|
2017-01-19 08:20:29 +08:00
|
|
|
UnloadAllImages();
|
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
StructuredData::ObjectSP all_image_info_json_sp(
|
|
|
|
m_process->GetLoadedDynamicLibrariesInfos());
|
|
|
|
ImageInfo::collection image_infos;
|
|
|
|
if (all_image_info_json_sp.get() &&
|
|
|
|
all_image_info_json_sp->GetAsDictionary() &&
|
|
|
|
all_image_info_json_sp->GetAsDictionary()->HasKey("images") &&
|
|
|
|
all_image_info_json_sp->GetAsDictionary()
|
|
|
|
->GetValueForKey("images")
|
|
|
|
->GetAsArray()) {
|
|
|
|
if (JSONImageInformationIntoImageInfo(all_image_info_json_sp,
|
|
|
|
image_infos)) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Initial module fetch: Adding %" PRId64 " modules.\n",
|
|
|
|
(uint64_t)image_infos.size());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
UpdateSpecialBinariesFromNewImageInfos(image_infos);
|
|
|
|
AddModulesUsingImageInfos(image_infos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dyld_image_infos_stop_id = m_process->GetStopID();
|
2018-12-07 09:18:40 +08:00
|
|
|
m_maybe_image_infos_address = m_process->GetImageInfoAddress();
|
2016-07-21 16:30:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DynamicLoaderMacOS::NeedToDoInitialImageFetch() { return true; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
// Static callback function that gets called when our DYLD notification
|
2018-05-01 00:49:04 +08:00
|
|
|
// breakpoint gets hit. We update all of our image infos and then let our super
|
|
|
|
// class DynamicLoader class decide if we should stop or not (based on global
|
|
|
|
// preference).
|
2016-07-21 16:30:55 +08:00
|
|
|
bool DynamicLoaderMacOS::NotifyBreakpointHit(void *baton,
|
|
|
|
StoppointCallbackContext *context,
|
|
|
|
lldb::user_id_t break_id,
|
|
|
|
lldb::user_id_t break_loc_id) {
|
|
|
|
// Let the event know that the images have changed
|
|
|
|
// DYLD passes three arguments to the notification breakpoint.
|
2018-05-01 00:49:04 +08:00
|
|
|
// Arg1: enum dyld_notify_mode mode - 0 = adding, 1 = removing, 2 = remove
|
|
|
|
// all Arg2: unsigned long icount - Number of shared libraries
|
|
|
|
// added/removed Arg3: uint64_t mach_headers[] - Array of load addresses
|
|
|
|
// of binaries added/removed
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
DynamicLoaderMacOS *dyld_instance = (DynamicLoaderMacOS *)baton;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
ExecutionContext exe_ctx(context->exe_ctx_ref);
|
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
// This is a sanity check just in case this dyld_instance is an old dyld
|
|
|
|
// plugin's breakpoint still lying around.
|
|
|
|
if (process != dyld_instance->m_process)
|
2016-07-23 06:26:26 +08:00
|
|
|
return false;
|
2016-07-21 16:30:55 +08:00
|
|
|
|
2016-07-23 06:26:26 +08:00
|
|
|
if (dyld_instance->m_image_infos_stop_id != UINT32_MAX &&
|
2016-07-21 16:30:55 +08:00
|
|
|
process->GetStopID() < dyld_instance->m_image_infos_stop_id) {
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
const lldb::ABISP &abi = process->GetABI();
|
|
|
|
if (abi) {
|
|
|
|
// Build up the value array to store the three arguments given above, then
|
|
|
|
// get the values from the ABI:
|
2016-09-07 04:57:50 +08:00
|
|
|
|
[lldb][NFC] Rename ClangASTContext to TypeSystemClang
Summary:
This commit renames ClangASTContext to TypeSystemClang to better reflect what this class is actually supposed to do
(implement the TypeSystem interface for Clang). It also gets rid of the very confusing situation that we have both a
`clang::ASTContext` and a `ClangASTContext` in clang (which sometimes causes Clang people to think I'm fiddling
with Clang's ASTContext when I'm actually just doing LLDB work).
I also have plans to potentially have multiple clang::ASTContext instances associated with one ClangASTContext so
the ASTContext naming will then become even more confusing to people.
Reviewers: #lldb, aprantl, shafik, clayborg, labath, JDevlieghere, davide, espindola, jdoerfert, xiaobai
Reviewed By: clayborg, labath, xiaobai
Subscribers: wuzish, emaste, nemanjai, mgorny, kbarton, MaskRay, arphaman, jfb, usaxena95, jingham, xiaobai, abidh, JDevlieghere, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D72684
2020-01-23 17:04:13 +08:00
|
|
|
TypeSystemClang *clang_ast_context =
|
|
|
|
TypeSystemClang::GetScratch(process->GetTarget());
|
2019-11-15 05:41:52 +08:00
|
|
|
if (!clang_ast_context)
|
|
|
|
return false;
|
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
ValueList argument_values;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
Value mode_value; // enum dyld_notify_mode { dyld_notify_adding=0,
|
|
|
|
// dyld_notify_removing=1, dyld_notify_remove_all=2 };
|
|
|
|
Value count_value; // unsigned long count
|
2016-07-23 06:26:26 +08:00
|
|
|
Value headers_value; // uint64_t machHeaders[] (aka void*)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
CompilerType clang_void_ptr_type =
|
|
|
|
clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
|
|
|
|
CompilerType clang_uint32_type =
|
|
|
|
clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(
|
|
|
|
lldb::eEncodingUint, 32);
|
|
|
|
CompilerType clang_uint64_type =
|
|
|
|
clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(
|
|
|
|
lldb::eEncodingUint, 32);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
mode_value.SetValueType(Value::eValueTypeScalar);
|
|
|
|
mode_value.SetCompilerType(clang_uint32_type);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-23 06:26:26 +08:00
|
|
|
if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 4) {
|
2016-07-21 16:30:55 +08:00
|
|
|
count_value.SetValueType(Value::eValueTypeScalar);
|
|
|
|
count_value.SetCompilerType(clang_uint32_type);
|
|
|
|
} else {
|
|
|
|
count_value.SetValueType(Value::eValueTypeScalar);
|
|
|
|
count_value.SetCompilerType(clang_uint64_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
headers_value.SetValueType(Value::eValueTypeScalar);
|
|
|
|
headers_value.SetCompilerType(clang_void_ptr_type);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
argument_values.PushValue(mode_value);
|
|
|
|
argument_values.PushValue(count_value);
|
|
|
|
argument_values.PushValue(headers_value);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
if (abi->GetArgumentValues(exe_ctx.GetThreadRef(), argument_values)) {
|
|
|
|
uint32_t dyld_mode =
|
|
|
|
argument_values.GetValueAtIndex(0)->GetScalar().UInt(-1);
|
|
|
|
if (dyld_mode != static_cast<uint32_t>(-1)) {
|
|
|
|
// Okay the mode was right, now get the number of elements, and the
|
|
|
|
// array of new elements...
|
|
|
|
uint32_t image_infos_count =
|
|
|
|
argument_values.GetValueAtIndex(1)->GetScalar().UInt(-1);
|
|
|
|
if (image_infos_count != static_cast<uint32_t>(-1)) {
|
|
|
|
addr_t header_array =
|
|
|
|
argument_values.GetValueAtIndex(2)->GetScalar().ULongLong(-1);
|
|
|
|
if (header_array != static_cast<uint64_t>(-1)) {
|
|
|
|
std::vector<addr_t> image_load_addresses;
|
|
|
|
for (uint64_t i = 0; i < image_infos_count; i++) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-07-21 16:30:55 +08:00
|
|
|
addr_t addr = process->ReadUnsignedIntegerFromMemory(
|
|
|
|
header_array + (8 * i), 8, LLDB_INVALID_ADDRESS, error);
|
|
|
|
if (addr != LLDB_INVALID_ADDRESS) {
|
|
|
|
image_load_addresses.push_back(addr);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-07-21 16:30:55 +08:00
|
|
|
if (dyld_mode == 0) {
|
|
|
|
// dyld_notify_adding
|
|
|
|
dyld_instance->AddBinaries(image_load_addresses);
|
|
|
|
} else if (dyld_mode == 1) {
|
|
|
|
// dyld_notify_removing
|
|
|
|
dyld_instance->UnloadImages(image_load_addresses);
|
|
|
|
} else if (dyld_mode == 2) {
|
|
|
|
// dyld_notify_remove_all
|
|
|
|
dyld_instance->UnloadAllImages();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-07-21 16:30:55 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-07-21 16:30:55 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
process->GetTarget().GetDebugger().GetAsyncErrorStream()->Printf(
|
|
|
|
"No ABI plugin located for triple %s -- shared libraries will not be "
|
|
|
|
"registered!\n",
|
|
|
|
process->GetTarget().GetArchitecture().GetTriple().getTriple().c_str());
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
// Return true to stop the target, false to just let the target run
|
|
|
|
return dyld_instance->GetStopWhenImagesChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DynamicLoaderMacOS::AddBinaries(
|
|
|
|
const std::vector<lldb::addr_t> &load_addresses) {
|
|
|
|
Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
|
|
|
|
ImageInfo::collection image_infos;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Adding %" PRId64 " modules.",
|
|
|
|
(uint64_t)load_addresses.size());
|
2016-07-21 16:30:55 +08:00
|
|
|
StructuredData::ObjectSP binaries_info_sp =
|
|
|
|
m_process->GetLoadedDynamicLibrariesInfos(load_addresses);
|
|
|
|
if (binaries_info_sp.get() && binaries_info_sp->GetAsDictionary() &&
|
|
|
|
binaries_info_sp->GetAsDictionary()->HasKey("images") &&
|
|
|
|
binaries_info_sp->GetAsDictionary()
|
|
|
|
->GetValueForKey("images")
|
|
|
|
->GetAsArray() &&
|
|
|
|
binaries_info_sp->GetAsDictionary()
|
|
|
|
->GetValueForKey("images")
|
|
|
|
->GetAsArray()
|
|
|
|
->GetSize() == load_addresses.size()) {
|
|
|
|
if (JSONImageInformationIntoImageInfo(binaries_info_sp, image_infos)) {
|
|
|
|
UpdateSpecialBinariesFromNewImageInfos(image_infos);
|
|
|
|
AddModulesUsingImageInfos(image_infos);
|
|
|
|
}
|
|
|
|
m_dyld_image_infos_stop_id = m_process->GetStopID();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-07-21 16:30:55 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Dump the _dyld_all_image_infos members and all current image infos that we
|
|
|
|
// have parsed to the file handle provided.
|
2016-07-21 16:30:55 +08:00
|
|
|
void DynamicLoaderMacOS::PutToLog(Log *log) const {
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
if (log == nullptr)
|
2016-07-21 16:30:55 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DynamicLoaderMacOS::SetNotificationBreakpoint() {
|
|
|
|
if (m_break_id == LLDB_INVALID_BREAK_ID) {
|
|
|
|
ConstString g_symbol_name("_dyld_debugger_notification");
|
|
|
|
const Symbol *symbol = nullptr;
|
|
|
|
ModuleSP dyld_sp(GetDYLDModule());
|
|
|
|
if (dyld_sp) {
|
|
|
|
symbol = dyld_sp->FindFirstSymbolWithNameAndType(g_symbol_name,
|
|
|
|
eSymbolTypeCode);
|
|
|
|
}
|
|
|
|
if (symbol &&
|
|
|
|
(symbol->ValueIsAddress() || symbol->GetAddressRef().IsValid())) {
|
|
|
|
addr_t symbol_address =
|
|
|
|
symbol->GetAddressRef().GetOpcodeLoadAddress(&m_process->GetTarget());
|
|
|
|
if (symbol_address != LLDB_INVALID_ADDRESS) {
|
|
|
|
bool internal = true;
|
|
|
|
bool hardware = false;
|
|
|
|
Breakpoint *breakpoint =
|
|
|
|
m_process->GetTarget()
|
|
|
|
.CreateBreakpoint(symbol_address, internal, hardware)
|
2016-09-07 04:57:50 +08:00
|
|
|
.get();
|
2016-07-21 16:30:55 +08:00
|
|
|
breakpoint->SetCallback(DynamicLoaderMacOS::NotifyBreakpointHit, this,
|
2016-09-07 04:57:50 +08:00
|
|
|
true);
|
2016-07-21 16:30:55 +08:00
|
|
|
breakpoint->SetBreakpointKind("shared-library-event");
|
|
|
|
m_break_id = breakpoint->GetID();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-21 16:30:55 +08:00
|
|
|
return m_break_id != LLDB_INVALID_BREAK_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr_t
|
|
|
|
DynamicLoaderMacOS::GetDyldLockVariableAddressFromModule(Module *module) {
|
|
|
|
SymbolContext sc;
|
|
|
|
Target &target = m_process->GetTarget();
|
2019-08-05 17:21:47 +08:00
|
|
|
if (Symtab *symtab = module->GetSymtab()) {
|
|
|
|
std::vector<uint32_t> match_indexes;
|
|
|
|
ConstString g_symbol_name("_dyld_global_lock_held");
|
|
|
|
uint32_t num_matches = 0;
|
|
|
|
num_matches =
|
|
|
|
symtab->AppendSymbolIndexesWithName(g_symbol_name, match_indexes);
|
|
|
|
if (num_matches == 1) {
|
|
|
|
Symbol *symbol = symtab->SymbolAtIndex(match_indexes[0]);
|
|
|
|
if (symbol &&
|
|
|
|
(symbol->ValueIsAddress() || symbol->GetAddressRef().IsValid())) {
|
|
|
|
return symbol->GetAddressRef().GetOpcodeLoadAddress(&target);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-07-21 16:30:55 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-07-21 16:30:55 +08:00
|
|
|
return LLDB_INVALID_ADDRESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for this symbol:
|
|
|
|
//
|
2016-07-23 06:26:26 +08:00
|
|
|
// int __attribute__((visibility("hidden"))) _dyld_global_lock_held =
|
|
|
|
// 0;
|
2016-07-21 16:30:55 +08:00
|
|
|
//
|
|
|
|
// in libdyld.dylib.
|
2017-05-12 12:51:55 +08:00
|
|
|
Status DynamicLoaderMacOS::CanLoadImage() {
|
|
|
|
Status error;
|
2016-07-21 16:30:55 +08:00
|
|
|
addr_t symbol_address = LLDB_INVALID_ADDRESS;
|
|
|
|
Target &target = m_process->GetTarget();
|
|
|
|
const ModuleList &target_modules = target.GetImages();
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
|
|
|
|
const size_t num_modules = target_modules.GetSize();
|
|
|
|
ConstString g_libdyld_name("libdyld.dylib");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
// Find any modules named "libdyld.dylib" and look for the symbol there first
|
|
|
|
for (size_t i = 0; i < num_modules; i++) {
|
|
|
|
Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i);
|
|
|
|
if (module_pointer) {
|
|
|
|
if (module_pointer->GetFileSpec().GetFilename() == g_libdyld_name) {
|
|
|
|
symbol_address = GetDyldLockVariableAddressFromModule(module_pointer);
|
|
|
|
if (symbol_address != LLDB_INVALID_ADDRESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
// Search through all modules looking for the symbol in them
|
|
|
|
if (symbol_address == LLDB_INVALID_ADDRESS) {
|
|
|
|
for (size_t i = 0; i < num_modules; i++) {
|
|
|
|
Module *module_pointer =
|
|
|
|
target_modules.GetModulePointerAtIndexUnlocked(i);
|
|
|
|
if (module_pointer) {
|
|
|
|
addr_t symbol_address =
|
|
|
|
GetDyldLockVariableAddressFromModule(module_pointer);
|
|
|
|
if (symbol_address != LLDB_INVALID_ADDRESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-07-21 16:30:55 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Default assumption is that it is OK to load images. Only say that we
|
|
|
|
// cannot load images if we find the symbol in libdyld and it indicates that
|
|
|
|
// we cannot.
|
2016-07-21 16:30:55 +08:00
|
|
|
|
|
|
|
if (symbol_address != LLDB_INVALID_ADDRESS) {
|
2016-07-22 08:17:55 +08:00
|
|
|
{
|
|
|
|
int lock_held =
|
|
|
|
m_process->ReadUnsignedIntegerFromMemory(symbol_address, 4, 0, error);
|
|
|
|
if (lock_held != 0) {
|
2017-05-06 09:15:47 +08:00
|
|
|
error.SetErrorString("dyld lock held - unsafe to load images.");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-07-22 08:17:55 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// If we were unable to find _dyld_global_lock_held in any modules, or it
|
|
|
|
// is not loaded into memory yet, we may be at process startup (sitting at
|
|
|
|
// _dyld_start) - so we should not allow dlopen calls. But if we found more
|
|
|
|
// than one module then we are clearly past _dyld_start so in that case
|
|
|
|
// we'll default to "it's safe".
|
2017-05-06 09:15:47 +08:00
|
|
|
if (num_modules <= 1)
|
|
|
|
error.SetErrorString("could not find the dyld library or "
|
|
|
|
"the dyld lock symbol");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-07-21 16:30:55 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2016-07-29 08:18:39 +08:00
|
|
|
bool DynamicLoaderMacOS::GetSharedCacheInformation(
|
|
|
|
lldb::addr_t &base_address, UUID &uuid, LazyBool &using_shared_cache,
|
|
|
|
LazyBool &private_shared_cache) {
|
|
|
|
base_address = LLDB_INVALID_ADDRESS;
|
|
|
|
uuid.Clear();
|
|
|
|
using_shared_cache = eLazyBoolCalculate;
|
|
|
|
private_shared_cache = eLazyBoolCalculate;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-29 08:18:39 +08:00
|
|
|
if (m_process) {
|
|
|
|
StructuredData::ObjectSP info = m_process->GetSharedCacheInfo();
|
|
|
|
StructuredData::Dictionary *info_dict = nullptr;
|
|
|
|
if (info.get() && info->GetAsDictionary()) {
|
|
|
|
info_dict = info->GetAsDictionary();
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// {"shared_cache_base_address":140735683125248,"shared_cache_uuid
|
|
|
|
// ":"DDB8D70C-
|
|
|
|
// C9A2-3561-B2C8-BE48A4F33F96","no_shared_cache":false,"shared_cache_private_cache":false}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-29 08:18:39 +08:00
|
|
|
if (info_dict && info_dict->HasKey("shared_cache_uuid") &&
|
|
|
|
info_dict->HasKey("no_shared_cache") &&
|
|
|
|
info_dict->HasKey("shared_cache_base_address")) {
|
|
|
|
base_address = info_dict->GetValueForKey("shared_cache_base_address")
|
|
|
|
->GetIntegerValue(LLDB_INVALID_ADDRESS);
|
2020-01-29 03:23:46 +08:00
|
|
|
std::string uuid_str = std::string(
|
|
|
|
info_dict->GetValueForKey("shared_cache_uuid")->GetStringValue());
|
2016-07-29 08:18:39 +08:00
|
|
|
if (!uuid_str.empty())
|
2018-06-21 23:24:39 +08:00
|
|
|
uuid.SetFromStringRef(uuid_str);
|
2018-12-15 08:15:33 +08:00
|
|
|
if (!info_dict->GetValueForKey("no_shared_cache")->GetBooleanValue())
|
2016-07-29 08:18:39 +08:00
|
|
|
using_shared_cache = eLazyBoolYes;
|
|
|
|
else
|
|
|
|
using_shared_cache = eLazyBoolNo;
|
|
|
|
if (info_dict->GetValueForKey("shared_cache_private_cache")
|
|
|
|
->GetBooleanValue())
|
|
|
|
private_shared_cache = eLazyBoolYes;
|
|
|
|
else
|
|
|
|
private_shared_cache = eLazyBoolNo;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-29 08:18:39 +08:00
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-07-29 08:18:39 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:30:55 +08:00
|
|
|
void DynamicLoaderMacOS::Initialize() {
|
|
|
|
PluginManager::RegisterPlugin(GetPluginNameStatic(),
|
|
|
|
GetPluginDescriptionStatic(), CreateInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DynamicLoaderMacOS::Terminate() {
|
|
|
|
PluginManager::UnregisterPlugin(CreateInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb_private::ConstString DynamicLoaderMacOS::GetPluginNameStatic() {
|
|
|
|
static ConstString g_name("macos-dyld");
|
|
|
|
return g_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *DynamicLoaderMacOS::GetPluginDescriptionStatic() {
|
|
|
|
return "Dynamic loader plug-in that watches for shared library loads/unloads "
|
|
|
|
"in MacOSX user processes.";
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginInterface protocol
|
|
|
|
lldb_private::ConstString DynamicLoaderMacOS::GetPluginName() {
|
|
|
|
return GetPluginNameStatic();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t DynamicLoaderMacOS::GetPluginVersion() { return 1; }
|