Skip to content

Commit

Permalink
configs: add enable_stdout_stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Jul 14, 2024
1 parent 17cf2a2 commit 2fc0dc2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hilda/hilda_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
<b>Hilda has been successfully loaded! 😎
Usage:
<span style="color: magenta">p</span> Global to access all features.
<span style="color: magenta">F1</span> UI Show.
<span style="color: magenta">F1</span> Show UI.
<span style="color: magenta">F2</span> Toggle enabling of stdout & stderr.
<span style="color: magenta">F7</span> Step Into.
<span style="color: magenta">F8</span> Step Over.
<span style="color: magenta">F9</span> Continue.
Expand Down Expand Up @@ -92,6 +93,8 @@ class Configs:
'doc': 'Whether to exclude NSObject during evaluation - reduce ipython autocomplete results.'})
objc_verbose_monitor: bool = field(default=False, metadata={
'doc': 'When set to True, using monitor() will automatically print objc methods arguments.'})
enable_stdout_stderr: bool = field(default=True, metadata={
'doc': 'When set to True, will enable process stdout and stderr.'})

def __repr__(self):
return self.__str__()
Expand Down Expand Up @@ -1089,6 +1092,10 @@ def interact(self, additional_namespace: Optional[typing.Mapping] = None,
sys.argv = ['a']
IPython.start_ipython(config=ipython_config, user_ns=namespace)

def toggle_enable_stdout_stderr(self, *args) -> None:
self.configs.enable_stdout_stderr = not self.configs.enable_stdout_stderr
self.logger.info(f'Changed stdout and stderr status to: {self.configs.enable_stdout_stderr}')

def __enter__(self) -> 'HildaClient':
return self

Expand Down
1 change: 1 addition & 0 deletions hilda/ipython_extensions/keybindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def load_ipython_extension(ipython):
def register_keybindings():
hilda = ipython.user_ns['p']
keys_mapping = {Keys.F1: hilda.ui_manager.show,
Keys.F2: hilda.toggle_enable_stdout_stderr,
Keys.F7: hilda.step_into,
Keys.F8: hilda.step_over,
Keys.F9: lambda _: (hilda.log_info('Sending continue'), hilda.cont()),
Expand Down
22 changes: 22 additions & 0 deletions hilda/launch_lldb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import sys
from abc import ABC, abstractmethod
from threading import Thread
from typing import List, Optional
Expand Down Expand Up @@ -46,6 +47,20 @@ def _check_success(self) -> None:
return
raise LLDBError(self.error.description)

def _process_stdout(self) -> None:
stdout = self.process.GetSTDOUT(1024)
while stdout:
if lldb.hilda_client is not None and lldb.hilda_client.configs.enable_stdout_stderr:
sys.stdout.write(stdout)
stdout = self.process.GetSTDOUT(1024)

def _process_stderr(self) -> None:
stderr = self.process.GetSTDERR(1024)
while stderr:
if lldb.hilda_client is not None and lldb.hilda_client.configs.enable_stdout_stderr:
sys.stderr.write(stderr)
stderr = self.process.GetSTDERR(1024)

def run(self):
event = lldb.SBEvent()
last_state = lldb.eStateStopped
Expand All @@ -54,6 +69,13 @@ def run(self):
continue
if not lldb.SBProcess.EventIsProcessEvent(event):
continue

event_type = event.GetType()
if event_type & lldb.SBProcess.eBroadcastBitSTDOUT:
self._process_stdout()
if event_type & lldb.SBProcess.eBroadcastBitSTDERR:
self._process_stderr()

state = self.process.GetStateFromEvent(event)
if state == lldb.eStateDetached:
logger.debug('Process Detached')
Expand Down

0 comments on commit 2fc0dc2

Please sign in to comment.