Skip to content

Commit

Permalink
hilda_client: remove unstable is_objc_type()
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Oct 16, 2023
1 parent 4880fb4 commit 5a1693b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 73 deletions.
16 changes: 4 additions & 12 deletions hilda/hilda_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,10 @@ def unwind(self) -> bool:
""" Unwind the stack (useful when get_evaluation_unwind() == False) """
return self.thread.UnwindInnermostExpression().Success()

@cached_property
def pid(self) -> int:
return self.process.GetProcessID()

@property
def thread(self):
""" Current active thread. """
Expand Down Expand Up @@ -982,18 +986,6 @@ def interact(self, additional_namespace: typing.Mapping = None) -> None:

IPython.start_ipython(config=config, user_ns=namespace)

def is_objc_type(self, symbol: Symbol) -> bool:
"""
Test if a given symbol represents an objc object
:param symbol:
:return:
"""
try:
self.symbols.CFGetTypeID(symbol)
return True
except EvaluatingExpressionError:
return False

@staticmethod
def _add_global(name: str, value: Any, reserved_names=None):
if reserved_names is None or name not in reserved_names:
Expand Down
3 changes: 1 addition & 2 deletions hilda/objective_c_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ def hook(hilda, frame, bp_loc, options):
if 'group_uuid' in bp.options and bp.options.get('group_uuid', '') == options['group_uuid']:
hilda.remove_hilda_breakpoint(bp_id)
captured = hilda.evaluate_expression('$arg1')
if hilda.is_objc_type(captured):
captured = captured.objc_symbol
captured = captured.objc_symbol
hilda.captured_objects[options['name'].split(' ')[0].split('[')[1]] = captured
hilda.cont()

Expand Down
12 changes: 0 additions & 12 deletions hilda/objective_c_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ def show(self, recursive: bool = False):
"""
print(highlight(self._to_str(recursive), ObjectiveCLexer(), TerminalTrueColorFormatter(style='native')))

def objc_call(self, selector: str, *params):
"""
Make objc_call() from self return ObjectiveCSymbol when it's an objc symbol.
:param selector: Selector to execute.
:param params: Additional parameters.
:return: ObjectiveCSymbol when return type is an objc symbol.
"""
symbol = super(ObjectiveCSymbol, self).objc_call(selector, *params)
return symbol.objc_symbol if self._client.is_objc_type(symbol) else symbol

def _reload_ivars(self, ivars_data):
raw_ivars = sorted(ivars_data, key=lambda ivar: ivar['offset'])
for i, ivar in enumerate(raw_ivars):
Expand Down Expand Up @@ -201,8 +191,6 @@ def __getitem__(self, item):
# Ivars
for ivar in self.ivars:
if ivar.name == item:
if self._client.is_objc_type(ivar.value):
return ivar.value.objc_symbol
return ivar.value

# Properties
Expand Down
34 changes: 3 additions & 31 deletions tests/test_hilda_client/test_hilda_client.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import pytest

from hilda.exceptions import GettingObjectiveCClassError
from hilda.objective_c_symbol import ObjectiveCSymbol
from hilda.symbol import Symbol


def test_detecting_objective_c_members(hilda_client):
"""
:param hilda.hilda_client.HildaClient hilda_client: Hilda client.
"""
dictionary = hilda_client.evaluate_expression('@{@"one": @1, @"two": @2}').objc_symbol
assert isinstance(dictionary._used, Symbol) and not isinstance(dictionary._used, ObjectiveCSymbol)
assert isinstance(dictionary.description, ObjectiveCSymbol)


def test_get_objc_class_error(hilda_client):
Expand All @@ -36,9 +25,9 @@ def test_lsof(hilda_client):
"""
:param hilda.hilda_client.HildaClient hilda_client: Hilda client.
"""
temp_dir_url = hilda_client.objc_get_class('NSFileManager').defaultManager().objc_symbol.temporaryDirectory
temp_url = temp_dir_url.URLByAppendingPathComponent_(hilda_client.ns('temp.txt')).objc_symbol
c_file_path = temp_url.path.cString()
temp_dir_url = hilda_client.objc_get_class('NSFileManager').defaultManager().objc_call('temporaryDirectory')
temp_url = temp_dir_url.objc_call('URLByAppendingPathComponent:', hilda_client.ns('temp.txt')).objc_symbol
c_file_path = temp_url.path.objc_call('cString')
file_path = c_file_path.peek_str()
file_handle = hilda_client.symbols.mkstemp(c_file_path)
max_path_len = hilda_client.evaluate_expression('PATH_MAX')
Expand All @@ -49,20 +38,3 @@ def test_lsof(hilda_client):
finally:
hilda_client.symbols.close(file_handle)
hilda_client.symbols.unlink(file_path)


def test_is_objc_type(hilda_client):
"""
:param hilda.hilda_client.HildaClient hilda_client: Hilda client.
"""
file_manager = hilda_client.objc_get_class('NSFileManager').defaultManager()
assert hilda_client.is_objc_type(file_manager)
temp_dir_url = file_manager.objc_symbol.temporaryDirectory.path.cString()
assert not hilda_client.is_objc_type(temp_dir_url)


def test_is_objc_type_invalid_address(hilda_client):
"""
:param hilda.hilda_client.HildaClient hilda_client: Hilda client.
"""
assert not hilda_client.is_objc_type(hilda_client.symbol(0))
16 changes: 0 additions & 16 deletions tests/test_symbols/test_objective_c_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,6 @@ def test_call_objective_c_method_by_objc_call(hilda_client):
assert not dictionary1.objc_call('isEqualToDictionary:', dictionary2)


def test_call_objective_c_property_returns_objc_object(hilda_client):
"""
:param hilda.hilda_client.HildaClient hilda_client: Hilda client.
"""
dictionary1 = hilda_client.evaluate_expression('@{@"one": @1}').objc_symbol
assert isinstance(dictionary1.description, ObjectiveCSymbol)


def test_call_objective_c_method_returns_objc_object(hilda_client):
"""
:param hilda.hilda_client.HildaClient hilda_client: Hilda client.
"""
dictionary1 = hilda_client.evaluate_expression('@{@"one": @1}').objc_symbol
assert isinstance(dictionary1.objectForKey_(hilda_client.ns('one')), ObjectiveCSymbol)


def test_call_objective_c_method_returns_native_symbol(hilda_client):
"""
:param hilda.hilda_client.HildaClient hilda_client: Hilda client.
Expand Down

0 comments on commit 5a1693b

Please sign in to comment.