Skip to content

🍒/5.7/59679eeef2d471dc0c2bccb966aac5eae9195802+833882b32701ce3713c9dd9afdedf1126db691f0 #4202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/refactor/Rename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ llvm::Optional<std::vector<Range>> getMappedRanges(ArrayRef<Range> Indexed,

std::vector<size_t> Best;
size_t BestCost = std::numeric_limits<size_t>::max();
bool HasMultiple = 0;
bool HasMultiple = false;
std::vector<size_t> ResultStorage;
int Fuel = 10000;
findNearMiss(ResultStorage, Indexed, Lexed, 0, Fuel,
Expand Down
2 changes: 1 addition & 1 deletion lld/COFF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ void Writer::mergeSections() {
if (p.first == toName)
continue;
StringSet<> names;
while (1) {
while (true) {
if (!names.insert(toName).second)
fatal("/merge: cycle found for section '" + p.first + "'");
auto i = config->merge.find(toName);
Expand Down
4 changes: 2 additions & 2 deletions lld/ELF/Arch/X86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ bool X86_64::deleteFallThruJmpInsn(InputSection &is, InputFile *file,
const unsigned sizeOfJmpCCInsn = 6;
// To flip, there must be atleast one JmpCC and one direct jmp.
if (is.getSize() < sizeOfDirectJmpInsn + sizeOfJmpCCInsn)
return 0;
return false;

unsigned rbIndex =
getRelocationWithOffset(is, (is.getSize() - sizeOfDirectJmpInsn - 4));
if (rbIndex == is.relocations.size())
return 0;
return false;

Relocation &rB = is.relocations[rbIndex];

Expand Down
2 changes: 1 addition & 1 deletion lld/MachO/Arch/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void ARM::relocateOne(uint8_t *loc, const Reloc &r, uint64_t value,
return;
} else if (isBlx && !defined->thumb) {
Bitfield::set<Cond>(base, 0xe); // unconditional BL
Bitfield::set<BitfieldFlag<24>>(base, 1);
Bitfield::set<BitfieldFlag<24>>(base, true);
isBlx = false;
}
} else {
Expand Down
4 changes: 3 additions & 1 deletion lld/MachO/InputSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ class WordLiteralInputSection final : public InputSection {
bool isLive(uint64_t off) const override {
return live[off >> power2LiteralSize];
}
void markLive(uint64_t off) override { live[off >> power2LiteralSize] = 1; }
void markLive(uint64_t off) override {
live[off >> power2LiteralSize] = true;
}

static bool classof(const InputSection *isec) {
return isec->kind() == WordLiteralKind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ AppleObjCRuntimeV2::DynamicClassInfoExtractor::GetClassInfoUtilityFunctionImpl(
if (!utility_fn_or_error) {
LLDB_LOG_ERROR(
log, utility_fn_or_error.takeError(),
"Failed to get utility function for implementation lookup: {0}");
"Failed to get utility function for dynamic info extractor: {0}");
return {};
}

Expand Down Expand Up @@ -1697,7 +1697,7 @@ AppleObjCRuntimeV2::SharedCacheClassInfoExtractor::
if (!utility_fn_or_error) {
LLDB_LOG_ERROR(
log, utility_fn_or_error.takeError(),
"Failed to get utility function for implementation lookup: {0}");
"Failed to get utility function for shared class info extractor: {0}");
return nullptr;
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class AppleObjCTrampolineHandler {
public:
enum FixUpState { eFixUpNone, eFixUpFixed, eFixUpToFix };

const char *name;
bool stret_return;
bool is_super;
bool is_super2;
FixUpState fixedup;
const char *name = nullptr;
bool stret_return = false;
bool is_super = false;
bool is_super2 = false;
FixUpState fixedup = eFixUpNone;
};

lldb::addr_t SetupDispatchFunction(Thread &thread,
Expand All @@ -52,9 +52,19 @@ class AppleObjCTrampolineHandler {
const DispatchFunction &)>);

private:
/// These hold the code for the function that finds the implementation of
/// an ObjC message send given the class & selector and the kind of dispatch.
/// There are two variants depending on whether the platform uses a separate
/// _stret passing convention (e.g. Intel) or not (e.g. ARM). The difference
/// is only at the very end of the function, so the code is broken into the
/// common prefix and the suffix, which get composed appropriately before
/// the function gets compiled.
/// \{
static const char *g_lookup_implementation_function_name;
static const char *g_lookup_implementation_function_common_code;
static const char *g_lookup_implementation_with_stret_function_code;
static const char *g_lookup_implementation_no_stret_function_code;
/// \}

class AppleObjCVTables {
public:
Expand Down Expand Up @@ -144,7 +154,7 @@ class AppleObjCTrampolineHandler {
MsgsendMap m_opt_dispatch_map;
lldb::ProcessWP m_process_wp;
lldb::ModuleSP m_objc_module_sp;
const char *m_lookup_implementation_function_code;
std::string m_lookup_implementation_function_code;
std::unique_ptr<UtilityFunction> m_impl_code;
std::mutex m_impl_function_mutex;
lldb::addr_t m_impl_fn_addr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ using namespace lldb_private;
AppleThreadPlanStepThroughObjCTrampoline::
AppleThreadPlanStepThroughObjCTrampoline(
Thread &thread, AppleObjCTrampolineHandler &trampoline_handler,
ValueList &input_values, lldb::addr_t isa_addr, lldb::addr_t sel_addr)
ValueList &input_values, lldb::addr_t isa_addr, lldb::addr_t sel_addr,
lldb::addr_t sel_str_addr, llvm::StringRef sel_str)
: ThreadPlan(ThreadPlan::eKindGeneric,
"MacOSX Step through ObjC Trampoline", thread, eVoteNoOpinion,
eVoteNoOpinion),
m_trampoline_handler(trampoline_handler),
m_args_addr(LLDB_INVALID_ADDRESS), m_input_values(input_values),
m_isa_addr(isa_addr), m_sel_addr(sel_addr), m_impl_function(nullptr) {}
m_isa_addr(isa_addr), m_sel_addr(sel_addr), m_impl_function(nullptr),
m_sel_str_addr(sel_str_addr), m_sel_str(sel_str) {}

// Destructor
AppleThreadPlanStepThroughObjCTrampoline::
Expand Down Expand Up @@ -126,8 +128,10 @@ bool AppleThreadPlanStepThroughObjCTrampoline::ShouldStop(Event *event_ptr) {
}
}

// Second stage, if all went well with the function calling, then fetch the
// target address, and queue up a "run to that address" plan.
// Second stage, if all went well with the function calling, get the
// implementation function address, and queue up a "run to that address" plan.
Log *log = GetLog(LLDBLog::Step);

if (!m_run_to_sp) {
Value target_addr_value;
ExecutionContext exc_ctx;
Expand All @@ -142,7 +146,6 @@ bool AppleThreadPlanStepThroughObjCTrampoline::ShouldStop(Event *event_ptr) {
}
Address target_so_addr;
target_so_addr.SetOpcodeLoadAddress(target_addr, exc_ctx.GetTargetPtr());
Log *log = GetLog(LLDBLog::Step);
if (target_addr == 0) {
LLDB_LOGF(log, "Got target implementation of 0x0, stopping.");
SetPlanComplete();
Expand Down Expand Up @@ -174,13 +177,25 @@ bool AppleThreadPlanStepThroughObjCTrampoline::ShouldStop(Event *event_ptr) {
ObjCLanguageRuntime *objc_runtime =
ObjCLanguageRuntime::Get(*GetThread().GetProcess());
assert(objc_runtime != nullptr);
objc_runtime->AddToMethodCache(m_isa_addr, m_sel_addr, target_addr);
LLDB_LOGF(log,
"Adding {isa-addr=0x%" PRIx64 ", sel-addr=0x%" PRIx64
"} = addr=0x%" PRIx64 " to cache.",
m_isa_addr, m_sel_addr, target_addr);

// Extract the target address from the value:
if (m_sel_str_addr != LLDB_INVALID_ADDRESS) {
// Cache the string -> implementation and free the string in the target.
Status dealloc_error =
GetThread().GetProcess()->DeallocateMemory(m_sel_str_addr);
// For now just log this:
if (dealloc_error.Fail())
LLDB_LOG(log, "Failed to deallocate the sel str at {0} - error: {1}",
m_sel_str_addr, dealloc_error);
objc_runtime->AddToMethodCache(m_isa_addr, m_sel_str, target_addr);
LLDB_LOG(log,
"Adding \\{isa-addr={0}, sel-addr={1}\\} = addr={2} to cache.",
m_isa_addr, m_sel_str, target_addr);
} else {
objc_runtime->AddToMethodCache(m_isa_addr, m_sel_addr, target_addr);
LLDB_LOGF(log,
"Adding {isa-addr=0x%" PRIx64 ", sel-addr=0x%" PRIx64
"} = addr=0x%" PRIx64 " to cache.",
m_isa_addr, m_sel_addr, target_addr);
}

m_run_to_sp = std::make_shared<ThreadPlanRunToAddress>(
GetThread(), target_so_addr, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class AppleThreadPlanStepThroughObjCTrampoline : public ThreadPlan {
public:
AppleThreadPlanStepThroughObjCTrampoline(
Thread &thread, AppleObjCTrampolineHandler &trampoline_handler,
ValueList &values, lldb::addr_t isa_addr, lldb::addr_t sel_addr);
ValueList &values, lldb::addr_t isa_addr, lldb::addr_t sel_addr,
lldb::addr_t sel_str_addr, llvm::StringRef sel_str);

~AppleThreadPlanStepThroughObjCTrampoline() override;

Expand Down Expand Up @@ -70,6 +71,13 @@ class AppleThreadPlanStepThroughObjCTrampoline : public ThreadPlan {
FunctionCaller *m_impl_function; /// This is a pointer to a impl function that
/// is owned by the client that pushes this
/// plan.
lldb::addr_t m_sel_str_addr; /// If this is not LLDB_INVALID_ADDRESS then it
/// is the address we wrote the selector string
/// to. We need to deallocate it when the
/// function call is done.
std::string m_sel_str; /// This is the string we wrote to memory - we
/// use it for caching, but only if
/// m_sel_str_addr is non-null.
};

class AppleThreadPlanStepThroughDirectDispatch: public ThreadPlanStepOut {
Expand Down
23 changes: 22 additions & 1 deletion lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ char ObjCLanguageRuntime::ID = 0;
ObjCLanguageRuntime::~ObjCLanguageRuntime() = default;

ObjCLanguageRuntime::ObjCLanguageRuntime(Process *process)
: LanguageRuntime(process), m_impl_cache(),
: LanguageRuntime(process), m_impl_cache(), m_impl_str_cache(),
m_has_new_literals_and_indexing(eLazyBoolCalculate),
m_isa_to_descriptor(), m_hash_to_isa_map(), m_type_size_cache(),
m_isa_to_descriptor_stop_id(UINT32_MAX), m_complete_class_cache(),
Expand Down Expand Up @@ -75,6 +75,18 @@ void ObjCLanguageRuntime::AddToMethodCache(lldb::addr_t class_addr,
ClassAndSel(class_addr, selector), impl_addr));
}

void ObjCLanguageRuntime::AddToMethodCache(lldb::addr_t class_addr,
llvm::StringRef sel_str,
lldb::addr_t impl_addr) {
Log *log = GetLog(LLDBLog::Step);

LLDB_LOG(log, "Caching: class {0} selector {1} implementation {2}.",
class_addr, sel_str, impl_addr);

m_impl_str_cache.insert(std::pair<ClassAndSelStr, lldb::addr_t>(
ClassAndSelStr(class_addr, sel_str), impl_addr));
}

lldb::addr_t ObjCLanguageRuntime::LookupInMethodCache(lldb::addr_t class_addr,
lldb::addr_t selector) {
MsgImplMap::iterator pos, end = m_impl_cache.end();
Expand All @@ -84,6 +96,15 @@ lldb::addr_t ObjCLanguageRuntime::LookupInMethodCache(lldb::addr_t class_addr,
return LLDB_INVALID_ADDRESS;
}

lldb::addr_t ObjCLanguageRuntime::LookupInMethodCache(lldb::addr_t class_addr,
llvm::StringRef sel_str) {
MsgImplStrMap::iterator pos, end = m_impl_str_cache.end();
pos = m_impl_str_cache.find(ClassAndSelStr(class_addr, sel_str));
if (pos != end)
return (*pos).second;
return LLDB_INVALID_ADDRESS;
}

lldb::TypeSP
ObjCLanguageRuntime::LookupInCompleteClassCache(ConstString &name) {
CompleteClassMap::iterator complete_class_iter =
Expand Down
54 changes: 45 additions & 9 deletions lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/Type.h"
#include "lldb/Target/LanguageRuntime.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/lldb-private.h"

class CommandObjectObjC_ClassTable_Dump;
Expand Down Expand Up @@ -242,11 +243,19 @@ class ObjCLanguageRuntime : public LanguageRuntime {

virtual bool HasReadObjCLibrary() = 0;

// These two methods actually use different caches. The only time we'll
// cache a sel_str is if we found a "selector specific stub" for the selector
// and conversely we only add to the SEL cache if we saw a regular dispatch.
lldb::addr_t LookupInMethodCache(lldb::addr_t class_addr, lldb::addr_t sel);
lldb::addr_t LookupInMethodCache(lldb::addr_t class_addr,
llvm::StringRef sel_str);

void AddToMethodCache(lldb::addr_t class_addr, lldb::addr_t sel,
lldb::addr_t impl_addr);

void AddToMethodCache(lldb::addr_t class_addr, llvm::StringRef sel_str,
lldb::addr_t impl_addr);

TypeAndOrName LookupInClassNameCache(lldb::addr_t class_addr);

void AddToClassNameCache(lldb::addr_t class_addr, const char *name,
Expand Down Expand Up @@ -343,20 +352,22 @@ class ObjCLanguageRuntime : public LanguageRuntime {
}

private:
// We keep a map of <Class,Selector>->Implementation so we don't have to call
// the resolver function over and over.
// We keep two maps of <Class,Selector>->Implementation so we don't have
// to call the resolver function over and over.
// The first comes from regular obj_msgSend type dispatch, and maps the
// class + uniqued SEL value to an implementation.
// The second comes from the "selector-specific stubs", which are always
// of the form _objc_msgSend$SelectorName, so we don't know the uniqued
// selector, only the string name.

// FIXME: We need to watch for the loading of Protocols, and flush the cache
// for any
// class that we see so changed.

struct ClassAndSel {
ClassAndSel() {
sel_addr = LLDB_INVALID_ADDRESS;
class_addr = LLDB_INVALID_ADDRESS;
}
ClassAndSel() = default;

ClassAndSel(lldb::addr_t in_sel_addr, lldb::addr_t in_class_addr)
ClassAndSel(lldb::addr_t in_class_addr, lldb::addr_t in_sel_addr)
: class_addr(in_class_addr), sel_addr(in_sel_addr) {}

bool operator==(const ClassAndSel &rhs) {
Expand All @@ -379,18 +390,43 @@ class ObjCLanguageRuntime : public LanguageRuntime {
}
}

lldb::addr_t class_addr;
lldb::addr_t sel_addr;
lldb::addr_t class_addr = LLDB_INVALID_ADDRESS;
lldb::addr_t sel_addr = LLDB_INVALID_ADDRESS;
};

struct ClassAndSelStr {
ClassAndSelStr() = default;

ClassAndSelStr(lldb::addr_t in_class_addr, llvm::StringRef in_sel_name)
: class_addr(in_class_addr), sel_name(in_sel_name) {}

bool operator==(const ClassAndSelStr &rhs) {
return class_addr == rhs.class_addr && sel_name == rhs.sel_name;
}

bool operator<(const ClassAndSelStr &rhs) const {
if (class_addr < rhs.class_addr)
return true;
else if (class_addr > rhs.class_addr)
return false;
else
return ConstString::Compare(sel_name, rhs.sel_name);
}

lldb::addr_t class_addr = LLDB_INVALID_ADDRESS;
ConstString sel_name;
};

typedef std::map<ClassAndSel, lldb::addr_t> MsgImplMap;
typedef std::map<ClassAndSelStr, lldb::addr_t> MsgImplStrMap;
typedef std::map<ObjCISA, ClassDescriptorSP> ISAToDescriptorMap;
typedef std::multimap<uint32_t, ObjCISA> HashToISAMap;
typedef ISAToDescriptorMap::iterator ISAToDescriptorIterator;
typedef HashToISAMap::iterator HashToISAIterator;
typedef ThreadSafeDenseMap<void *, uint64_t> TypeSizeCache;

MsgImplMap m_impl_cache;
MsgImplStrMap m_impl_str_cache;
LazyBool m_has_new_literals_and_indexing;
ISAToDescriptorMap m_isa_to_descriptor;
HashToISAMap m_hash_to_isa_map;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5209,7 +5209,7 @@ void ObjectFileMachO::GetAllArchSpecs(const llvm::MachO::mach_header &header,
triple.setEnvironmentName(os_env.environment);
add_triple(triple);
}
} while (0);
} while (false);
offset = cmd_offset + load_cmd.cmdsize;
}

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Symbol/TypeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using namespace lldb;
static const size_t g_num_small_bitvector_bits = 64 - 8;
static_assert(eNumLanguageTypes < g_num_small_bitvector_bits,
"Languages bit vector is no longer small on 64 bit systems");
LanguageSet::LanguageSet() : bitvector(eNumLanguageTypes, 0) {}
LanguageSet::LanguageSet() : bitvector(eNumLanguageTypes, false) {}

llvm::Optional<LanguageType> LanguageSet::GetSingularLanguage() {
if (bitvector.count() == 1)
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Target/TraceInstructionDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ static void DumpInstructionDisassembly(Stream &s, InstructionSymbolInfo &insn) {
return;
s.Printf(" ");
insn.instruction->Dump(&s, /*show_address=*/false, /*show_bytes=*/false,
/*max_opcode_byte_size=*/0, &insn.exe_ctx, &insn.sc,
/*max_opcode_byte_size=*/false, &insn.exe_ctx,
&insn.sc,
/*prev_sym_ctx=*/nullptr,
/*disassembly_addr_format=*/nullptr,
/*max_address_text_size=*/0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def cleanup():
' 21 key/value pairs'
])

lldbutil.run_break_set_by_regexp(self, 'setAtoms')
lldbutil.run_break_set_by_symbol(self, '-[Molecule setAtoms:]')

self.runCmd("continue")
self.expect("frame variable _cmd", substrs=['setAtoms:'])
Loading