Skip to content

Commit

Permalink
Merge pull request #67 from doronz88/feature/wait-for-module
Browse files Browse the repository at this point in the history
Feature/wait for module
  • Loading branch information
doronz88 authored Jul 8, 2024
2 parents e04069e + be5e72d commit 68bfb4c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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
21 changes: 20 additions & 1 deletion hilda/hilda_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ def callback(hilda, frame, bp_loc, options):
:param dict options: User defined options.
"""
bp = bp_loc.GetBreakpoint()
symbol = hilda.breakpoints[bp.id].address # type: Symbol

symbol = hilda.symbol(hilda.frame.addr.GetLoadAddress(hilda.target)) # type: Symbol

# by default, attempt to resolve the symbol name through lldb
name = str(symbol.lldb_symbol)
Expand Down Expand Up @@ -1043,6 +1044,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 68bfb4c

Please sign in to comment.