Skip to content

Commit 30016f8

Browse files
Merge pull request #1021 from augusto2112/check_if_objc_runtime_null
Check if objc runtime pointer is null before using it
2 parents ef37f13 + a27c779 commit 30016f8

File tree

6 files changed

+63
-17
lines changed

6 files changed

+63
-17
lines changed

lldb/source/Core/ValueObject.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -363,23 +363,24 @@ CompilerType ValueObject::MaybeCalculateCompleteType() {
363363
}
364364

365365
// then try the runtime
366-
std::vector<CompilerDecl> compiler_decls;
367-
auto *objc_language_runtime = ObjCLanguageRuntime::Get(*process_sp);
368-
if (auto runtime_vendor = objc_language_runtime->GetDeclVendor()) {
369-
if (runtime_vendor->FindDecls(class_name, false, UINT32_MAX,
370-
compiler_decls) > 0 &&
371-
compiler_decls.size() > 0) {
372-
auto *ctx = llvm::dyn_cast<TypeSystemClang>(compiler_decls[0].GetTypeSystem());
373-
if (ctx) {
374-
CompilerType runtime_type =
375-
ctx->GetTypeForDecl(compiler_decls[0].GetOpaqueDecl());
376-
m_override_type =
377-
is_pointer_type ? runtime_type.GetPointerType() : runtime_type;
366+
if (auto *objc_language_runtime = ObjCLanguageRuntime::Get(*process_sp)) {
367+
if (auto *runtime_vendor = objc_language_runtime->GetDeclVendor()) {
368+
std::vector<CompilerDecl> compiler_decls;
369+
runtime_vendor->FindDecls(class_name, false, UINT32_MAX, compiler_decls);
370+
if (!compiler_decls.empty()) {
371+
auto *ctx =
372+
llvm::dyn_cast<TypeSystemClang>(compiler_decls[0].GetTypeSystem());
373+
if (ctx) {
374+
CompilerType runtime_type =
375+
ctx->GetTypeForDecl(compiler_decls[0].GetOpaqueDecl());
376+
m_override_type =
377+
is_pointer_type ? runtime_type.GetPointerType() : runtime_type;
378+
}
378379
}
379-
}
380380

381-
if (m_override_type.IsValid())
382-
return m_override_type;
381+
if (m_override_type.IsValid())
382+
return m_override_type;
383+
}
383384
}
384385
return compiler_type;
385386
}

lldb/source/Plugins/Language/Swift/FoundationValueTypes.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,11 @@ bool lldb_private::formatters::swift::Measurement_SummaryProvider(
159159
if (!process_sp)
160160
return false;
161161

162-
auto descriptor_sp(
163-
ObjCLanguageRuntime::Get(*process_sp)->GetClassDescriptor(*unit_sp));
162+
ObjCLanguageRuntime *objc_runtime = ObjCLanguageRuntime::Get(*process_sp);
163+
if (!objc_runtime)
164+
return false;
165+
166+
auto descriptor_sp(objc_runtime->GetClassDescriptor(*unit_sp));
164167
if (!descriptor_sp)
165168
return false;
166169

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
3+
include Makefile.rules
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Test that contiguous array prints correctly
3+
"""
4+
import lldb
5+
from lldbsuite.test.decorators import *
6+
import lldbsuite.test.lldbtest as lldbtest
7+
import lldbsuite.test.lldbutil as lldbutil
8+
import os
9+
import unittest2
10+
11+
12+
class TestContiguousArray(lldbtest.TestBase):
13+
14+
mydir = lldbtest.TestBase.compute_mydir(__file__)
15+
16+
@swiftTest
17+
def test_frame_contiguous_array(self):
18+
"""Test that contiguous array prints correctly"""
19+
self.build()
20+
lldbutil.run_to_source_breakpoint(
21+
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))
22+
23+
self.expect("frame variable --dynamic-type run-target",
24+
startstr="""(ContiguousArray<a.Class>) array = {
25+
_buffer = {
26+
_storage = 1 value {
27+
[0] = 0x""")
28+
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Class {}
2+
3+
func use<T>(_ t: T) {}
4+
5+
func main() {
6+
let array = ContiguousArray<Class>([Class()])
7+
use(array)// Set breakpoint here
8+
}
9+
10+
main()
11+

0 commit comments

Comments
 (0)