From e2f901814a29cbce51862e1417422b1365a8f380 Mon Sep 17 00:00:00 2001 From: doronz88 Date: Wed, 3 Jul 2024 09:18:23 +0300 Subject: [PATCH] hilda_client: fix override of globals from interactive shell --- hilda/hilda_client.py | 9 ++++----- hilda/ipython_extensions/events.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/hilda/hilda_client.py b/hilda/hilda_client.py index f980228..d6f31c3 100644 --- a/hilda/hilda_client.py +++ b/hilda/hilda_client.py @@ -142,6 +142,7 @@ def __init__(self, debugger: lldb.SBDebugger): self.configs = Configs() self._dynamic_env_loaded = False self._symbols_loaded = False + self.globals: typing.MutableMapping[str, Any] = globals() # the frame called within the context of the hit BP self._bp_frame = None @@ -1060,8 +1061,7 @@ def interact(self, additional_namespace: Optional[typing.Mapping] = None, ipython_config.InteractiveShellApp.exec_files = startup_files self.log_debug(f'Startup files - {startup_files}') - namespace = globals() - namespace.update(locals()) + namespace = self.globals namespace['p'] = self namespace['ui'] = self.ui_manager namespace['cfg'] = self.configs @@ -1076,11 +1076,10 @@ def __enter__(self) -> 'HildaClient': def __exit__(self, exc_type, exc_val, exc_tb) -> None: self.detach() - @staticmethod - def _add_global(name: str, value: Any, reserved_names=None): + def _add_global(self, name: str, value: Any, reserved_names=None) -> None: if reserved_names is None or name not in reserved_names: # don't override existing symbols - globals()[name] = value + self.globals[name] = value @staticmethod def _get_saved_state_filename(): diff --git a/hilda/ipython_extensions/events.py b/hilda/ipython_extensions/events.py index 047640f..c4edc6f 100644 --- a/hilda/ipython_extensions/events.py +++ b/hilda/ipython_extensions/events.py @@ -26,7 +26,7 @@ def pre_run_cell(self, info): # we are only interested in names continue - if node.id in locals() or node.id in globals() or node.id in dir(builtins): + if node.id in locals() or node.id in self.hilda_client.globals or node.id in dir(builtins): # That are undefined continue