Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and Markuze committed Jan 12, 2023
1 parent 09f8a1c commit 8bee041
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/python/bcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from .version import __version__
from .disassembler import disassemble_prog, decode_map
from .usdt import USDT, USDTException
from .rust_demangler import rust_demangle
from .rust_demangler import rust_demangle, dehash

try:
basestring
Expand Down Expand Up @@ -94,10 +94,11 @@ def resolve(self, addr, demangle, rust):
return (None, addr, None)
if demangle:
name_res = sym.demangle_name
if b'$' in name_res and demangle:
if b'$' in name_res or b'.llvm.' in name_res:
name_res = rust_demangle(sym.name.decode('utf-8')).encode()
if not name_res:
name_res = sym.demangle_name
name_res = dehash(name_res.decode('utf-8')).encode()

lib.bcc_symbol_free_demangle_name(ct.byref(sym))
else:
Expand Down
15 changes: 9 additions & 6 deletions src/python/bcc/rust_demangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,28 @@ def rust_demangle(inpstr: str) -> str:
s = "\$" + k + "\$"
inpstr = re.sub(s, unescaped[k], inpstr)
inpstr = re.sub("\.\.", "::", inpstr)
inpstr = re.sub("::h[a-f0-9]{16}\s*$", "", inpstr);
inpstr = re.sub("\d{2}h[a-f0-9]{16}E\s*$", "", inpstr);
inpstr = re.sub("\d{2}h[a-f0-9]{16}E\s*$", "", inpstr)

## Replace digit sequences with ::
if re.search("\D\d{2,3}\D", inpstr):
if re.search("\D\d{1,3}\D", inpstr):
tmp = inpstr;
verbose = False
for mo in re.finditer("(\D)(\d{1,3})(\D)", tmp):
if not (re.match("u\d{2}\W", mo.group(0)) or mo.group(3) == '>' or mo.group(2) == '512'):
#print(f"{mo.group(0)}")
if not (re.match("u\d{2}\W", mo.group(0)) or mo.group(3) in ">)" or mo.group(2) == '512'):
#print(f"^^{mo.group(0)} {mo.group(1)} {mo.group(2)} {mo.group(3)}")
if mo.group(3) == ":":
s = mo.group(1) + "::"
else:
s = mo.group(1) + "::" + mo.group(3)
#print(f"^^{tmp} ==>> {inpstr}")
inpstr = re.sub(mo.group(0), s, inpstr)
verbose = True
#if verbose:
# print(f"{tmp} ==>> {inpstr}")
#inpstr = re.sub(">\d+", ">::", inpstr)


#print(f"{tmp} ==>> {inpstr}")
return inpstr

def dehash(inpstr: str) -> str:
return re.sub("::h[a-f0-9]{16}\s*$", "", inpstr)

0 comments on commit 8bee041

Please sign in to comment.