0

Pretty much what the question says.

Context: in cuda-gdb, if you have a templated struct and want to know what type it is, you will get something like this: @something mangled_name. I want to write a pretty-printer and I need to match the name of the type in demangled form. The issue is I don't know how to do this using the gdb module. I know how to extract the mangled name.

Details: I also tried using other libraries but when I source the pretty-printer, it says Module not found. I can only install the third party modules in a virtual environment.

1
  • Why do you need to demangle it via python? Maybe show an example of what you're really trying to accomplish. Commented Dec 19, 2024 at 15:19

1 Answer 1

0

Found this as a solution/hack. I was hoping gdb module had a demangler. I'll wait for a better answer.

import subprocess

def demangle(name):
    args = ['c++filt', name]
    pipe = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    stdout, _ = pipe.communicate()
    return stdout[:-1].decode("utf-8")
Sign up to request clarification or add additional context in comments.

1 Comment

Maybe try return gdb.execute("demangle -l c++ " + name, to_string=True).strip().

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.