Skip to content

Commit a62e1c8

Browse files
authored
[lldb] Fix incorrect nullptr check in DumpAddressAndContent (#117219)
When checking the section load list, the existing code assumed that a valid execution context guaranteed a valid target. This is a speculative fix for a crash report (without a reproducer). rdar://133969831
1 parent 6c52a18 commit a62e1c8

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

lldb/source/Core/FormatEntity.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -410,31 +410,31 @@ static bool DumpAddressAndContent(Stream &s, const SymbolContext *sc,
410410
const Address &addr,
411411
bool print_file_addr_or_load_addr) {
412412
Target *target = Target::GetTargetFromContexts(exe_ctx, sc);
413+
413414
addr_t vaddr = LLDB_INVALID_ADDRESS;
414-
if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
415+
if (target && !target->GetSectionLoadList().IsEmpty())
415416
vaddr = addr.GetLoadAddress(target);
416417
if (vaddr == LLDB_INVALID_ADDRESS)
417418
vaddr = addr.GetFileAddress();
419+
if (vaddr == LLDB_INVALID_ADDRESS)
420+
return false;
418421

419-
if (vaddr != LLDB_INVALID_ADDRESS) {
420-
int addr_width = 0;
421-
if (exe_ctx && target) {
422-
addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
423-
}
424-
if (addr_width == 0)
425-
addr_width = 16;
426-
if (print_file_addr_or_load_addr) {
427-
ExecutionContextScope *exe_scope = nullptr;
428-
if (exe_ctx)
429-
exe_scope = exe_ctx->GetBestExecutionContextScope();
430-
addr.Dump(&s, exe_scope, Address::DumpStyleLoadAddress,
431-
Address::DumpStyleModuleWithFileAddress, 0);
432-
} else {
433-
s.Printf("0x%*.*" PRIx64, addr_width, addr_width, vaddr);
434-
}
435-
return true;
422+
int addr_width = 0;
423+
if (target)
424+
addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
425+
if (addr_width == 0)
426+
addr_width = 16;
427+
428+
if (print_file_addr_or_load_addr) {
429+
ExecutionContextScope *exe_scope =
430+
exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr;
431+
addr.Dump(&s, exe_scope, Address::DumpStyleLoadAddress,
432+
Address::DumpStyleModuleWithFileAddress, 0);
433+
} else {
434+
s.Printf("0x%*.*" PRIx64, addr_width, addr_width, vaddr);
436435
}
437-
return false;
436+
437+
return true;
438438
}
439439

440440
static bool DumpAddressOffsetFromFunction(Stream &s, const SymbolContext *sc,

0 commit comments

Comments
 (0)