Skip to content

Commit

Permalink
hilda_client: add wait_for_module()
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Jul 8, 2024
1 parent e04069e commit 966d512
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ Here is a gist of methods you can access from `p`:
- sets the currently selected thread, which is used in other parts of the program, such as displaying disassembly or
checking registers.
This ensures the application focuses on the specified thread for these operations.
- `wait_for_module`
- Wait for a module to be loaded (`dlopen`) by checking if given expression is contained within its filename
All these methods are available from the global `p` within the newly created IPython shell. In addition, you may invoke any of the exported APIs described in the [Python API](#python-api)
Expand Down
18 changes: 18 additions & 0 deletions hilda/hilda_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,24 @@ def add_lldb_symbol(self, symbol: lldb.SBSymbol) -> Symbol:

return value

def wait_for_module(self, expression: str) -> None:
""" Wait for a module to be loaded using `dlopen` by matching given expression """
self.log_info(f'Waiting for module name containing "{expression}" to be loaded')

def bp(client: HildaClient, frame, bp_loc, options) -> None:
loading_module_name = client.evaluate_expression('$arg1').peek_str()
client.log_info(f'Loading module: {loading_module_name}')
if expression not in loading_module_name:
client.cont()
return
client.finish()
client.log_info(f'Desired module has been loaded: {expression}. Process remains stopped')
bp = bp_loc.GetBreakpoint()
client.remove_hilda_breakpoint(bp.id)

self.bp('dlopen', bp)
self.cont()

def interact(self, additional_namespace: Optional[typing.Mapping] = None,
startup_files: Optional[List[str]] = None) -> None:
""" Start an interactive Hilda shell """
Expand Down

0 comments on commit 966d512

Please sign in to comment.