Skip to content

Commit 8dfe289

Browse files
committed
Fixup init and xcode-kotlin semver support.
1 parent aedab14 commit 8dfe289

22 files changed

+460
-273
lines changed

LLDBPlugin/lldb/__init__.pyi

+32-32
Original file line numberDiff line numberDiff line change
@@ -5767,19 +5767,19 @@ class SBLineEntry:
57675767
r"""__ne__(SBLineEntry self, SBLineEntry rhs) -> bool"""
57685768
...
57695769

5770-
def GetDescription(self, description):
5770+
def GetDescription(self, description: SBStream) -> bool:
57715771
r"""GetDescription(SBLineEntry self, SBStream description) -> bool"""
57725772
...
57735773

5774-
def __repr__(self):
5774+
def __repr__(self) -> str:
57755775
r"""__repr__(SBLineEntry self) -> std::string"""
57765776
...
57775777

5778-
file = ...
5779-
line = ...
5780-
column = ...
5781-
addr = ...
5782-
end_addr = ...
5778+
file: SBFileSpec = ...
5779+
line: int = ...
5780+
column: int = ...
5781+
addr: SBAddress = ...
5782+
end_addr: SBAddress = ...
57835783
def __eq__(self, rhs) -> bool:
57845784
...
57855785

@@ -6259,31 +6259,31 @@ class SBModule:
62596259
"""
62606260
...
62616261

6262-
def GetNumSymbols(self):
6262+
def GetNumSymbols(self) -> int:
62636263
r"""GetNumSymbols(SBModule self) -> size_t"""
62646264
...
62656265

6266-
def GetSymbolAtIndex(self, idx):
6266+
def GetSymbolAtIndex(self, idx) -> SBSymbol:
62676267
r"""GetSymbolAtIndex(SBModule self, size_t idx) -> SBSymbol"""
62686268
...
62696269

6270-
def FindSymbol(self, *args):
6270+
def FindSymbol(self, *args) -> SBSymbol:
62716271
r"""FindSymbol(SBModule self, char const * name, lldb::SymbolType type=eSymbolTypeAny) -> SBSymbol"""
62726272
...
62736273

6274-
def FindSymbols(self, *args):
6274+
def FindSymbols(self, *args) -> SBSymbolContextList:
62756275
r"""FindSymbols(SBModule self, char const * name, lldb::SymbolType type=eSymbolTypeAny) -> SBSymbolContextList"""
62766276
...
62776277

6278-
def GetNumSections(self):
6278+
def GetNumSections(self) -> int:
62796279
r"""GetNumSections(SBModule self) -> size_t"""
62806280
...
62816281

6282-
def GetSectionAtIndex(self, idx):
6282+
def GetSectionAtIndex(self, idx) -> SBSection:
62836283
r"""GetSectionAtIndex(SBModule self, size_t idx) -> SBSection"""
62846284
...
62856285

6286-
def FindFunctions(self, *args):
6286+
def FindFunctions(self, *args) -> SBSymbolContextList:
62876287
r"""
62886288
FindFunctions(SBModule self, char const * name, uint32_t name_type_mask=eFunctionNameTypeAny) -> SBSymbolContextList
62896289
@@ -6344,23 +6344,23 @@ class SBModule:
63446344
"""
63456345
...
63466346

6347-
def FindFirstType(self, name):
6347+
def FindFirstType(self, name) -> SBType:
63486348
r"""FindFirstType(SBModule self, char const * name) -> SBType"""
63496349
...
63506350

6351-
def FindTypes(self, type):
6351+
def FindTypes(self, type) -> SBTypeList:
63526352
r"""FindTypes(SBModule self, char const * type) -> SBTypeList"""
63536353
...
63546354

6355-
def GetTypeByID(self, uid):
6355+
def GetTypeByID(self, uid) -> SBType:
63566356
r"""GetTypeByID(SBModule self, lldb::user_id_t uid) -> SBType"""
63576357
...
63586358

6359-
def GetBasicType(self, type):
6359+
def GetBasicType(self, type) -> SBType:
63606360
r"""GetBasicType(SBModule self, lldb::BasicType type) -> SBType"""
63616361
...
63626362

6363-
def GetTypes(self, *args):
6363+
def GetTypes(self, *args) -> SBTypeList:
63646364
r"""
63656365
GetTypes(SBModule self, uint32_t type_mask=eTypeClassAny) -> SBTypeList
63666366
@@ -8607,19 +8607,19 @@ class SBSymbolContextList:
86078607
...
86088608

86098609
__bool__ = ...
8610-
def IsValid(self):
8610+
def IsValid(self) -> bool:
86118611
r"""IsValid(SBSymbolContextList self) -> bool"""
86128612
...
86138613

8614-
def GetSize(self):
8614+
def GetSize(self) -> int:
86158615
r"""GetSize(SBSymbolContextList self) -> uint32_t"""
86168616
...
86178617

8618-
def GetContextAtIndex(self, idx):
8618+
def GetContextAtIndex(self, idx) -> SBSymbolContext:
86198619
r"""GetContextAtIndex(SBSymbolContextList self, uint32_t idx) -> SBSymbolContext"""
86208620
...
86218621

8622-
def GetDescription(self, description):
8622+
def GetDescription(self, description: SBStream) -> bool:
86238623
r"""GetDescription(SBSymbolContextList self, SBStream description) -> bool"""
86248624
...
86258625

@@ -8634,7 +8634,7 @@ class SBSymbolContextList:
86348634
r"""Clear(SBSymbolContextList self)"""
86358635
...
86368636

8637-
def __repr__(self):
8637+
def __repr__(self) -> str:
86388638
r"""__repr__(SBSymbolContextList self) -> std::string"""
86398639
...
86408640

@@ -8643,10 +8643,10 @@ class SBSymbolContextList:
86438643
object.'''
86448644
...
86458645

8646-
def __len__(self): # -> int:
8646+
def __len__(self) -> int:
86478647
...
86488648

8649-
def __getitem__(self, key):
8649+
def __getitem__(self, key) -> SBSymbolContext:
86508650
...
86518651

86528652
def get_module_array(self): # -> list[Any]:
@@ -11652,27 +11652,27 @@ class SBTypeList:
1165211652
...
1165311653

1165411654
__bool__ = ...
11655-
def IsValid(self):
11655+
def IsValid(self) -> bool:
1165611656
r"""IsValid(SBTypeList self) -> bool"""
1165711657
...
1165811658

11659-
def Append(self, type):
11659+
def Append(self, type: SBType):
1166011660
r"""Append(SBTypeList self, SBType type)"""
1166111661
...
1166211662

11663-
def GetTypeAtIndex(self, index):
11663+
def GetTypeAtIndex(self, index) -> SBType:
1166411664
r"""GetTypeAtIndex(SBTypeList self, uint32_t index) -> SBType"""
1166511665
...
1166611666

11667-
def GetSize(self):
11667+
def GetSize(self) -> int:
1166811668
r"""GetSize(SBTypeList self) -> uint32_t"""
1166911669
...
1167011670

11671-
def __iter__(self): # -> Generator[Any, Any, None]:
11671+
def __iter__(self) -> Iterator[SBType]:
1167211672
'''Iterate over all types in a lldb.SBTypeList object.'''
1167311673
...
1167411674

11675-
def __len__(self):
11675+
def __len__(self) -> int:
1167611676
'''Return the number of types in a lldb.SBTypeList object.'''
1167711677
...
1167811678

LLDBPlugin/run.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
exit(gradle_exit_code)
1313

1414
exe = 'test_project/build/swift/app'
15+
framework_path = 'test_project/build/bin/macosArm64/debugFramework'
1516

1617
# Initialize the debugger before making any API calls.
1718
lldb.SBDebugger.Initialize()
@@ -35,14 +36,14 @@
3536

3637
if target:
3738
# target.BreakpointCreateByLocation("main.swift", 14)
38-
target.BreakpointCreateByLocation('main.kt', 47)
39+
target.BreakpointCreateByLocation('main.kt', 30)
3940

40-
process: lldb.SBProcess = target.LaunchSimple(None, None, os.getcwd())
41+
process: lldb.SBProcess = target.LaunchSimple(None, ["DYLD_FRAMEWORK_PATH={}".format(framework_path)], os.getcwd())
4142

4243
if process:
4344
import time
4445
start = time.perf_counter()
45-
debugger.HandleCommand('fr v --ptr-depth 16')
46+
debugger.HandleCommand('fr v --ptr-depth 16 -- string')
4647
print('HandleCommand took {:.6}s'.format(time.perf_counter() - start))
4748
process.Continue()
4849
# debugger.HandleCommand('fr v --ptr-depth 16 -- data')

LLDBPlugin/test_project/main.swift

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ let dataObject = DataObject.shared
1515
let basicList = [basic]
1616
let dataList = [data]
1717
let dataMap = ["hello": data]
18+
let test = Test()
19+
let testList = [test]
1820

1921
let nsBasic = basic as NSObject
2022

23+
24+
struct Test {
25+
let x = Foo()
26+
}

LLDBPlugin/touchlab_kotlin_lldb/__init__.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
from .util.log import log
99
from .commands import FieldTypeCommand, SymbolByNameCommand, TypeByAddressCommand
1010

11-
from .types import kotlin_object_type_summary, kotlin_objc_class_summary
12-
from .types.KonanProxyTypeProvider import KonanProxyTypeProvider
13-
from .types.KonanObjcProxyTypeProvider import KonanObjcProxyTypeProvider
11+
from .types.summary import kotlin_object_type_summary, kotlin_objc_class_summary
12+
from .types.proxy import KonanProxyTypeProvider, KonanObjcProxyTypeProvider
1413

1514
from .cache import LLDBCache
1615

1716
os.environ['CLIENT_TYPE'] = 'Xcode'
1817

1918
KONAN_INIT_PREFIX = '_Konan_init_'
19+
KONAN_INIT_MODULE_NAME = '[0-9a-zA-Z_]+'
2020
KONAN_INIT_SUFFIX = '_kexe'
2121

2222

@@ -41,7 +41,9 @@ def reset_cache():
4141

4242
def configure_objc_types(debugger: lldb.SBDebugger):
4343
target = debugger.GetDummyTarget()
44-
breakpoint = target.BreakpointCreateByRegex("^{}(.*){}$".format(KONAN_INIT_PREFIX, KONAN_INIT_SUFFIX))
44+
breakpoint = target.BreakpointCreateByRegex(
45+
"^{}({})({})?$".format(KONAN_INIT_PREFIX, KONAN_INIT_MODULE_NAME, KONAN_INIT_SUFFIX)
46+
)
4547
breakpoint.SetOneShot(True)
4648
breakpoint.SetAutoContinue(True)
4749
breakpoint.SetScriptCallbackFunction('{}.{}'.format(__name__, configure_objc_types_breakpoint.__name__))
@@ -68,6 +70,8 @@ def configure_objc_types_breakpoint(frame: lldb.SBFrame, bp_loc: lldb.SBBreakpoi
6870
break
6971

7072
module_name = frame.symbol.name.removeprefix(KONAN_INIT_PREFIX).removesuffix(KONAN_INIT_SUFFIX)
73+
if module_name == "stdlib":
74+
return False
7175

7276
specifiers_to_register = [
7377
lldb.SBTypeNameSpecifier(

LLDBPlugin/touchlab_kotlin_lldb/commands/FieldTypeCommand.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from lldb import SBDebugger, SBExecutionContext, SBCommandReturnObject
22

3-
from ..types.KonanProxyTypeProvider import KonanProxyTypeProvider
3+
from ..types.proxy import KonanProxyTypeProvider
44
from ..types.base import get_runtime_type
55

66

LLDBPlugin/touchlab_kotlin_lldb/commands/KonanGlobalsCommand.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from lldb import SBDebugger, SBExecutionContext, SBCommandReturnObject
44

5-
from ..types import kotlin_object_type_summary
5+
from ..types.summary import kotlin_object_type_summary
66
from ..util.expression import evaluate
77

88

LLDBPlugin/touchlab_kotlin_lldb/types/KonanArraySyntheticProvider.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77

88
class KonanArraySyntheticProvider(KonanBaseSyntheticProvider):
99
def __init__(self, valobj: lldb.SBValue, type_info: lldb.value):
10-
super().__init__(valobj.Cast(array_header_type()), type_info)
11-
1210
self._children_count = 0
1311

14-
def update(self):
12+
super().__init__(valobj.Cast(array_header_type()), type_info)
13+
14+
def update(self) -> bool:
15+
super().update()
1516
self._children_count = int(self._val.count_)
16-
return True
17+
return False
1718

1819
def num_children(self):
1920
return self._children_count
@@ -29,7 +30,7 @@ def get_child_index(self, name):
2930
def get_child_at_index(self, index):
3031

3132
value_type = -int(self._type_info.extendedInfo_.fieldsCount_)
32-
address = self._valobj.unsigned + _align_up(
33+
address = self._valobj.unsigned + self._align_up(
3334
self._valobj.type.GetPointeeType().GetByteSize(),
3435
int(runtime_type_alignment()[value_type])
3536
) + index * int(runtime_type_size()[value_type])
@@ -41,6 +42,6 @@ def to_string(self):
4142
else:
4243
return '{} values'.format(self._children_count)
4344

44-
45-
def _align_up(size, alignment):
46-
return (size + alignment - 1) & ~(alignment - 1)
45+
@staticmethod
46+
def _align_up(size, alignment):
47+
return (size + alignment - 1) & ~(alignment - 1)

LLDBPlugin/touchlab_kotlin_lldb/types/KonanBaseSyntheticProvider.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
from typing import Optional
2-
31
import lldb
42

5-
from ..util import log, DebuggerException, kotlin_object_to_string, evaluate
3+
from ..util import DebuggerException, kotlin_object_to_string
64

75

86
class KonanBaseSyntheticProvider(object):
97
def __init__(self, valobj: lldb.SBValue, type_info: lldb.value):
10-
super().__init__()
11-
128
self._valobj: lldb.SBValue = valobj
139
self._val: lldb.value = lldb.value(valobj.GetNonSyntheticValue())
1410
self._type_info: lldb.value = type_info
1511
self._process: lldb.SBProcess = lldb.debugger.GetSelectedTarget().process
1612

17-
def update(self) -> Optional[bool]:
18-
pass
13+
super().__init__()
14+
15+
# We need to call it ourselves, because Xcode doesn't seem to call it in some cases
16+
self.update()
17+
18+
def update(self) -> bool:
19+
return False
1920

2021
def read_cstring(self, address: int) -> str:
2122
error = lldb.SBError()

0 commit comments

Comments
 (0)