Skip to content

Commit ff29fdf

Browse files
committed
[lldb] Format AppleObjCRuntimeV2 (NFC)
1 parent 927050a commit ff29fdf

File tree

2 files changed

+73
-71
lines changed

2 files changed

+73
-71
lines changed

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

Lines changed: 71 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ char AppleObjCRuntimeV2::ID = 0;
7575

7676
static const char *g_get_dynamic_class_info_name =
7777
"__lldb_apple_objc_v2_get_dynamic_class_info";
78-
// Testing using the new C++11 raw string literals. If this breaks GCC then we
79-
// will need to revert to the code above...
78+
8079
static const char *g_get_dynamic_class_info_body = R"(
8180
8281
extern "C"
@@ -176,8 +175,7 @@ extern "C"
176175

177176
static const char *g_get_shared_cache_class_info_name =
178177
"__lldb_apple_objc_v2_get_shared_cache_class_info";
179-
// Testing using the new C++11 raw string literals. If this breaks GCC then we
180-
// will need to revert to the code above...
178+
181179
static const char *g_get_shared_cache_class_info_body = R"(
182180
183181
extern "C"
@@ -297,7 +295,7 @@ __lldb_apple_objc_v2_get_shared_cache_class_info (void *objc_opt_ro_ptr,
297295
DEBUG_PRINTF("clsOffset == invalidEntryOffset\n");
298296
continue; // invalid offset
299297
}
300-
298+
301299
if (class_infos && idx < max_class_infos)
302300
{
303301
class_infos[idx].isa = (Class)((uint8_t *)clsopt + clsOffset);
@@ -327,7 +325,7 @@ __lldb_apple_objc_v2_get_shared_cache_class_info (void *objc_opt_ro_ptr,
327325
}
328326
++idx;
329327
}
330-
328+
331329
const uint32_t *duplicate_count_ptr = (uint32_t *)&classOffsets[clsopt->capacity];
332330
const uint32_t duplicate_count = *duplicate_count_ptr;
333331
const objc_classheader_t *duplicateClassOffsets = (const objc_classheader_t *)(&duplicate_count_ptr[1]);
@@ -340,7 +338,7 @@ __lldb_apple_objc_v2_get_shared_cache_class_info (void *objc_opt_ro_ptr,
340338
continue; // duplicate
341339
else if (clsOffset == invalidEntryOffset)
342340
continue; // invalid offset
343-
341+
344342
if (class_infos && idx < max_class_infos)
345343
{
346344
class_infos[idx].isa = (Class)((uint8_t *)clsopt + clsOffset);
@@ -359,7 +357,7 @@ __lldb_apple_objc_v2_get_shared_cache_class_info (void *objc_opt_ro_ptr,
359357
{
360358
h = 0;
361359
break;
362-
}
360+
}
363361
h = ((h << 5) + h) + c;
364362
}
365363
class_infos[idx].hash = h;
@@ -401,8 +399,7 @@ ExtractRuntimeGlobalSymbol(Process *process, ConstString name,
401399
if (read_value)
402400
return process->ReadUnsignedIntegerFromMemory(
403401
symbol_load_addr, byte_size, default_value, error);
404-
else
405-
return symbol_load_addr;
402+
return symbol_load_addr;
406403
} else {
407404
error.SetErrorString("symbol address invalid");
408405
return default_value;
@@ -504,15 +501,21 @@ LanguageRuntime *AppleObjCRuntimeV2::CreateInstance(Process *process,
504501
if (AppleObjCRuntime::GetObjCVersion(process, objc_module_sp) ==
505502
ObjCRuntimeVersions::eAppleObjC_V2)
506503
return new AppleObjCRuntimeV2(process, objc_module_sp);
507-
else
508-
return nullptr;
504+
return nullptr;
509505
} else
510506
return nullptr;
511507
}
512508

513509
static constexpr OptionDefinition g_objc_classtable_dump_options[] = {
514-
{LLDB_OPT_SET_ALL, false, "verbose", 'v', OptionParser::eNoArgument,
515-
nullptr, {}, 0, eArgTypeNone,
510+
{LLDB_OPT_SET_ALL,
511+
false,
512+
"verbose",
513+
'v',
514+
OptionParser::eNoArgument,
515+
nullptr,
516+
{},
517+
0,
518+
eArgTypeNone,
516519
"Print ivar and method information in detail"}};
517520

518521
class CommandObjectObjC_ClassTable_Dump : public CommandObjectParsed {
@@ -554,12 +557,13 @@ class CommandObjectObjC_ClassTable_Dump : public CommandObjectParsed {
554557
};
555558

556559
CommandObjectObjC_ClassTable_Dump(CommandInterpreter &interpreter)
557-
: CommandObjectParsed(
558-
interpreter, "dump", "Dump information on Objective-C classes "
559-
"known to the current process.",
560-
"language objc class-table dump",
561-
eCommandRequiresProcess | eCommandProcessMustBeLaunched |
562-
eCommandProcessMustBePaused),
560+
: CommandObjectParsed(interpreter, "dump",
561+
"Dump information on Objective-C classes "
562+
"known to the current process.",
563+
"language objc class-table dump",
564+
eCommandRequiresProcess |
565+
eCommandProcessMustBeLaunched |
566+
eCommandProcessMustBePaused),
563567
m_options() {
564568
CommandArgumentEntry arg;
565569
CommandArgumentData index_arg;
@@ -661,11 +665,10 @@ class CommandObjectObjC_ClassTable_Dump : public CommandObjectParsed {
661665
}
662666
result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
663667
return true;
664-
} else {
665-
result.AppendError("current process has no Objective-C runtime loaded");
666-
result.SetStatus(lldb::eReturnStatusFailed);
667-
return false;
668668
}
669+
result.AppendError("current process has no Objective-C runtime loaded");
670+
result.SetStatus(lldb::eReturnStatusFailed);
671+
return false;
669672
}
670673

671674
CommandOptions m_options;
@@ -747,11 +750,10 @@ class CommandObjectMultiwordObjC_TaggedPointer_Info
747750
}
748751
result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
749752
return true;
750-
} else {
751-
result.AppendError("current process has no Objective-C runtime loaded");
752-
result.SetStatus(lldb::eReturnStatusFailed);
753-
return false;
754753
}
754+
result.AppendError("current process has no Objective-C runtime loaded");
755+
result.SetStatus(lldb::eReturnStatusFailed);
756+
return false;
755757
}
756758
};
757759

@@ -1220,11 +1222,9 @@ AppleObjCRuntimeV2::GetClassDescriptor(ValueObject &valobj) {
12201222

12211223
objc_class_sp = GetClassDescriptorFromISA(isa);
12221224
if (isa && !objc_class_sp) {
1223-
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
1224-
LIBLLDB_LOG_TYPES));
1225+
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_TYPES));
12251226
LLDB_LOGF(log,
1226-
"0x%" PRIx64
1227-
": AppleObjCRuntimeV2::GetClassDescriptor() ISA was "
1227+
"0x%" PRIx64 ": AppleObjCRuntimeV2::GetClassDescriptor() ISA was "
12281228
"not in class descriptor cache 0x%" PRIx64,
12291229
isa_pointer, isa);
12301230
}
@@ -1235,28 +1235,29 @@ lldb::addr_t AppleObjCRuntimeV2::GetTaggedPointerObfuscator() {
12351235
if (m_tagged_pointer_obfuscator != LLDB_INVALID_ADDRESS)
12361236
return m_tagged_pointer_obfuscator;
12371237

1238-
12391238
Process *process = GetProcess();
12401239
ModuleSP objc_module_sp(GetObjCModule());
12411240

12421241
if (!objc_module_sp)
12431242
return LLDB_INVALID_ADDRESS;
12441243

1245-
static ConstString g_gdb_objc_obfuscator("objc_debug_taggedpointer_obfuscator");
1244+
static ConstString g_gdb_objc_obfuscator(
1245+
"objc_debug_taggedpointer_obfuscator");
12461246

12471247
const Symbol *symbol = objc_module_sp->FindFirstSymbolWithNameAndType(
1248-
g_gdb_objc_obfuscator, lldb::eSymbolTypeAny);
1248+
g_gdb_objc_obfuscator, lldb::eSymbolTypeAny);
12491249
if (symbol) {
12501250
lldb::addr_t g_gdb_obj_obfuscator_ptr =
1251-
symbol->GetLoadAddress(&process->GetTarget());
1251+
symbol->GetLoadAddress(&process->GetTarget());
12521252

12531253
if (g_gdb_obj_obfuscator_ptr != LLDB_INVALID_ADDRESS) {
12541254
Status error;
1255-
m_tagged_pointer_obfuscator = process->ReadPointerFromMemory(
1256-
g_gdb_obj_obfuscator_ptr, error);
1255+
m_tagged_pointer_obfuscator =
1256+
process->ReadPointerFromMemory(g_gdb_obj_obfuscator_ptr, error);
12571257
}
12581258
}
1259-
// If we don't have a correct value at this point, there must be no obfuscation.
1259+
// If we don't have a correct value at this point, there must be no
1260+
// obfuscation.
12601261
if (m_tagged_pointer_obfuscator == LLDB_INVALID_ADDRESS)
12611262
m_tagged_pointer_obfuscator = 0;
12621263

@@ -1402,12 +1403,12 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic(
14021403
arguments.GetValueAtIndex(0)->GetScalar() = hash_table.GetTableLoadAddress();
14031404
arguments.GetValueAtIndex(1)->GetScalar() = class_infos_addr;
14041405
arguments.GetValueAtIndex(2)->GetScalar() = class_infos_byte_size;
1405-
1406+
14061407
// Only dump the runtime classes from the expression evaluation if the log is
14071408
// verbose:
14081409
Log *type_log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES);
14091410
bool dump_log = type_log && type_log->GetVerbose();
1410-
1411+
14111412
arguments.GetValueAtIndex(3)->GetScalar() = dump_log ? 1 : 0;
14121413

14131414
bool success = false;
@@ -1513,15 +1514,16 @@ uint32_t AppleObjCRuntimeV2::ParseClassInfoArray(const DataExtractor &data,
15131514
ClassDescriptorSP descriptor_sp(
15141515
new ClassDescriptorV2(*this, isa, nullptr));
15151516

1516-
// The code in g_get_shared_cache_class_info_body sets the value of the hash
1517-
// to 0 to signal a demangled symbol. We use class_getName() in that code to
1518-
// find the class name, but this returns a demangled name for Swift symbols.
1519-
// For those symbols, recompute the hash here by reading their name from the
1520-
// runtime.
1517+
// The code in g_get_shared_cache_class_info_body sets the value of the
1518+
// hash to 0 to signal a demangled symbol. We use class_getName() in that
1519+
// code to find the class name, but this returns a demangled name for
1520+
// Swift symbols. For those symbols, recompute the hash here by reading
1521+
// their name from the runtime.
15211522
if (name_hash)
15221523
AddClass(isa, descriptor_sp, name_hash);
15231524
else
1524-
AddClass(isa, descriptor_sp, descriptor_sp->GetClassName().AsCString(nullptr));
1525+
AddClass(isa, descriptor_sp,
1526+
descriptor_sp->GetClassName().AsCString(nullptr));
15251527
num_parsed++;
15261528
if (should_log)
15271529
LLDB_LOGF(log,
@@ -1591,17 +1593,17 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
15911593
// use that in our jitted expression. Else fall back to the old
15921594
// class_getName.
15931595
static ConstString g_class_getName_symbol_name("class_getName");
1594-
static ConstString g_class_getNameRaw_symbol_name("objc_debug_class_getNameRaw");
1596+
static ConstString g_class_getNameRaw_symbol_name(
1597+
"objc_debug_class_getNameRaw");
15951598
ConstString class_name_getter_function_name = g_class_getName_symbol_name;
15961599

15971600
ObjCLanguageRuntime *objc_runtime = ObjCLanguageRuntime::Get(*process);
15981601
if (objc_runtime) {
15991602
for (lldb::ModuleSP mod_sp : process->GetTarget().GetImages().Modules()) {
16001603
if (objc_runtime->IsModuleObjCLibrary(mod_sp)) {
1601-
const Symbol *symbol =
1602-
mod_sp->FindFirstSymbolWithNameAndType(g_class_getNameRaw_symbol_name,
1603-
lldb::eSymbolTypeCode);
1604-
if (symbol &&
1604+
const Symbol *symbol = mod_sp->FindFirstSymbolWithNameAndType(
1605+
g_class_getNameRaw_symbol_name, lldb::eSymbolTypeCode);
1606+
if (symbol &&
16051607
(symbol->ValueIsAddress() || symbol->GetAddressRef().IsValid())) {
16061608
class_name_getter_function_name = g_class_getNameRaw_symbol_name;
16071609
}
@@ -1613,10 +1615,10 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
16131615
// concatenate the two parts of our expression text. The format string
16141616
// has two %s's, so provide the name twice.
16151617
std::string shared_class_expression;
1616-
llvm::raw_string_ostream(shared_class_expression) << llvm::format(
1617-
g_shared_cache_class_name_funcptr,
1618-
class_name_getter_function_name.AsCString(),
1619-
class_name_getter_function_name.AsCString());
1618+
llvm::raw_string_ostream(shared_class_expression)
1619+
<< llvm::format(g_shared_cache_class_name_funcptr,
1620+
class_name_getter_function_name.AsCString(),
1621+
class_name_getter_function_name.AsCString());
16201622

16211623
shared_class_expression += g_get_shared_cache_class_info_body;
16221624

@@ -1684,7 +1686,7 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
16841686
// verbose:
16851687
Log *type_log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES);
16861688
bool dump_log = type_log && type_log->GetVerbose();
1687-
1689+
16881690
arguments.GetValueAtIndex(3)->GetScalar() = dump_log ? 1 : 0;
16891691

16901692
bool success = false;
@@ -1981,9 +1983,10 @@ lldb::addr_t AppleObjCRuntimeV2::LookupRuntimeSymbol(ConstString name) {
19811983
const ConstString ivar_name_cs(class_and_ivar.second);
19821984
const char *ivar_name_cstr = ivar_name_cs.AsCString();
19831985

1984-
auto ivar_func = [&ret, ivar_name_cstr](
1985-
const char *name, const char *type, lldb::addr_t offset_addr,
1986-
uint64_t size) -> lldb::addr_t {
1986+
auto ivar_func = [&ret,
1987+
ivar_name_cstr](const char *name, const char *type,
1988+
lldb::addr_t offset_addr,
1989+
uint64_t size) -> lldb::addr_t {
19871990
if (!strcmp(name, ivar_name_cstr)) {
19881991
ret = offset_addr;
19891992
return true;
@@ -2401,9 +2404,9 @@ AppleObjCRuntimeV2::TaggedPointerVendorExtended::GetClassDescriptor(
24012404
m_ext_cache[slot] = actual_class_descriptor_sp;
24022405
}
24032406

2404-
data_payload =
2405-
(((uint64_t)unobfuscated << m_objc_debug_taggedpointer_ext_payload_lshift) >>
2406-
m_objc_debug_taggedpointer_ext_payload_rshift);
2407+
data_payload = (((uint64_t)unobfuscated
2408+
<< m_objc_debug_taggedpointer_ext_payload_lshift) >>
2409+
m_objc_debug_taggedpointer_ext_payload_rshift);
24072410

24082411
return ClassDescriptorSP(
24092412
new ClassDescriptorV2Tagged(actual_class_descriptor_sp, data_payload));
@@ -2604,13 +2607,14 @@ void AppleObjCRuntimeV2::GetValuesForGlobalCFBooleans(lldb::addr_t &cf_true,
26042607
#pragma mark Frame recognizers
26052608

26062609
class ObjCExceptionRecognizedStackFrame : public RecognizedStackFrame {
2607-
public:
2610+
public:
26082611
ObjCExceptionRecognizedStackFrame(StackFrameSP frame_sp) {
26092612
ThreadSP thread_sp = frame_sp->GetThread();
26102613
ProcessSP process_sp = thread_sp->GetProcess();
26112614

26122615
const lldb::ABISP &abi = process_sp->GetABI();
2613-
if (!abi) return;
2616+
if (!abi)
2617+
return;
26142618

26152619
TypeSystemClang *clang_ast_context =
26162620
ScratchTypeSystemClang::GetForTarget(process_sp->GetTarget());
@@ -2624,7 +2628,8 @@ class ObjCExceptionRecognizedStackFrame : public RecognizedStackFrame {
26242628
input_value.SetCompilerType(voidstar);
26252629
args.PushValue(input_value);
26262630

2627-
if (!abi->GetArgumentValues(*thread_sp, args)) return;
2631+
if (!abi->GetArgumentValues(*thread_sp, args))
2632+
return;
26282633

26292634
addr_t exception_addr = args.GetValueAtIndex(0)->GetScalar().ULongLong();
26302635

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime {
2626
public:
2727
~AppleObjCRuntimeV2() override = default;
2828

29-
// Static Functions
3029
static void Initialize();
3130

3231
static void Terminate();
@@ -46,7 +45,6 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime {
4645
return runtime->isA(&ID);
4746
}
4847

49-
// These are generic runtime functions:
5048
bool GetDynamicTypeAndAddress(ValueObject &in_value,
5149
lldb::DynamicValueType use_dynamic,
5250
TypeAndOrName &class_type_or_name,
@@ -56,7 +54,6 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime {
5654
llvm::Expected<std::unique_ptr<UtilityFunction>>
5755
CreateObjectChecker(std::string name, ExecutionContext &exe_ctx) override;
5856

59-
// PluginInterface protocol
6057
ConstString GetPluginName() override;
6158

6259
uint32_t GetPluginVersion() override;
@@ -105,8 +102,8 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime {
105102

106103
protected:
107104
lldb::BreakpointResolverSP
108-
CreateExceptionResolver(const lldb::BreakpointSP &bkpt,
109-
bool catch_bp, bool throw_bp) override;
105+
CreateExceptionResolver(const lldb::BreakpointSP &bkpt, bool catch_bp,
106+
bool throw_bp) override;
110107

111108
private:
112109
class HashTableSignature {

0 commit comments

Comments
 (0)