[lldb] Fix else-after-return in AppleObjCRuntimeV2 (NFC)

Use early returns to associate the error message with the corresponding
condition and eliminate some else-after-returns in the process.
This commit is contained in:
Jonas Devlieghere 2021-04-06 10:03:26 -07:00
parent 4059c1c32d
commit 801cea2ce9
1 changed files with 18 additions and 15 deletions

View File

@ -454,30 +454,33 @@ ExtractRuntimeGlobalSymbol(Process *process, ConstString name,
error.SetErrorString("no process"); error.SetErrorString("no process");
return default_value; return default_value;
} }
if (!module_sp) { if (!module_sp) {
error.SetErrorString("no module"); error.SetErrorString("no module");
return default_value; return default_value;
} }
if (!byte_size) if (!byte_size)
byte_size = process->GetAddressByteSize(); byte_size = process->GetAddressByteSize();
const Symbol *symbol = const Symbol *symbol =
module_sp->FindFirstSymbolWithNameAndType(name, lldb::eSymbolTypeData); module_sp->FindFirstSymbolWithNameAndType(name, lldb::eSymbolTypeData);
if (symbol && symbol->ValueIsAddress()) {
lldb::addr_t symbol_load_addr = if (!symbol || !symbol->ValueIsAddress()) {
symbol->GetAddressRef().GetLoadAddress(&process->GetTarget());
if (symbol_load_addr != LLDB_INVALID_ADDRESS) {
if (read_value)
return process->ReadUnsignedIntegerFromMemory(
symbol_load_addr, byte_size, default_value, error);
return symbol_load_addr;
} else {
error.SetErrorString("symbol address invalid");
return default_value;
}
} else {
error.SetErrorString("no symbol"); error.SetErrorString("no symbol");
return default_value; return default_value;
} }
lldb::addr_t symbol_load_addr =
symbol->GetAddressRef().GetLoadAddress(&process->GetTarget());
if (symbol_load_addr == LLDB_INVALID_ADDRESS) {
error.SetErrorString("symbol address invalid");
return default_value;
}
if (read_value)
return process->ReadUnsignedIntegerFromMemory(symbol_load_addr, byte_size,
default_value, error);
return symbol_load_addr;
} }
static void RegisterObjCExceptionRecognizer(Process *process); static void RegisterObjCExceptionRecognizer(Process *process);
@ -571,7 +574,7 @@ LanguageRuntime *AppleObjCRuntimeV2::CreateInstance(Process *process,
ObjCRuntimeVersions::eAppleObjC_V2) ObjCRuntimeVersions::eAppleObjC_V2)
return new AppleObjCRuntimeV2(process, objc_module_sp); return new AppleObjCRuntimeV2(process, objc_module_sp);
return nullptr; return nullptr;
} else }
return nullptr; return nullptr;
} }