Skip to content

Commit

Permalink
hilda_client: add std::string formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Jan 29, 2024
1 parent 161a49a commit 9cad361
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion hilda/hilda_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import os
import pickle
import struct
import time
import typing
from collections import namedtuple
Expand All @@ -16,8 +17,8 @@
from pathlib import Path
from typing import Any, List, Optional, Union

import hexdump
import IPython
import hexdump
import lldb
from humanfriendly import prompts
from humanfriendly.terminal.html import html_to_ansi
Expand Down Expand Up @@ -333,6 +334,7 @@ def file_symbol(self, address: int, module_name: Optional[str] = None) -> Symbol
module = self.target
else:
module = self.target.FindModule(lldb.SBFileSpec(module_name))

return self.symbol(module.ResolveFileAddress(address).GetLoadAddress(self.target))

def get_register(self, name) -> Symbol:
Expand Down Expand Up @@ -402,6 +404,8 @@ def monitor(self, address, condition: str = None, **options) -> lldb.SBBreakpoin
s: string
cf: use CFCopyDescription() to get more informative description of the object
po: use LLDB po command
std::string: for std::string
User defined function, will be called like `format_function(hilda_client, value)`.
For example:
Expand Down Expand Up @@ -1089,6 +1093,13 @@ def _ipython_run_cell_hook(self, info):
symbol if symbol.type_ != lldb.eSymbolTypeObjCMetaClass else self.objc_get_class(node.id)
)

@staticmethod
def _std_string(value):
if struct.unpack("b", (value + 23).peek(1))[0] >= 0:
return value.peek_str()
else:
return value[0].peek_str()

def _monitor_format_value(self, fmt, value):
if callable(fmt):
return fmt(self, value)
Expand All @@ -1097,6 +1108,7 @@ def _monitor_format_value(self, fmt, value):
's': lambda val: val.peek_str(),
'cf': lambda val: val.cf_description,
'po': lambda val: val.po(),
'std::string': self._std_string
}
if fmt in formatters:
return formatters[fmt](value)
Expand Down

0 comments on commit 9cad361

Please sign in to comment.