LM_DemangleSymbol
Demangles a symbol name from its mangled form to a human-readable format.Signature
Parameters
The mangled symbol name to demangle (e.g.,
"_ZN3foo3barEv").The buffer where the demangled symbol name will be stored.
If this is
NULL, the symbol will be dynamically allocated and maxsize is ignored.The maximum size of the buffer where the demangled symbol name will be stored.
This parameter is ignored if
demangled_buf is NULL.Return Value
Returns a pointer to the demangled symbol string, orNULL if it fails.
If the symbol was dynamically allocated (when demangled_buf is NULL), you need to free it with LM_FreeDemangledSymbol.
Description
This function converts mangled C++ symbol names (as generated by the compiler’s name mangling scheme) into their human-readable form. C++ compilers mangle names to encode additional information like namespaces, class names, and parameter types.Example 1: Using a User-Provided Buffer
Example 2: Using Dynamic Allocation
Example 3: Demangling Symbols from a Module
Common Mangled Name Examples
| Mangled Name | Demangled Name |
|---|---|
_ZN3foo3barEv | foo::bar() |
_ZN6Player10takeDamageEi | Player::takeDamage(int) |
_ZNSt6vectorIiE4sizeEv | std::vector<int>::size() |
_ZN9MyClass15myTemplateMethodIiEEvT_ | void MyClass::myTemplateMethod<int>(int) |
Notes
- When using dynamic allocation (
demangled_bufisNULL), always free the result withLM_FreeDemangledSymbol. - When using a fixed buffer, ensure the buffer is large enough to hold the demangled name.
- If the symbol is not a mangled C++ name, the function may fail and return
NULL. - Different compilers use different mangling schemes (Itanium ABI for GCC/Clang, MSVC for Visual Studio).
LM_FreeDemangledSymbol
Frees the memory allocated for a demangled symbol name.Signature
Parameters
The demangled symbol name to free. This should be a pointer that was returned by
LM_DemangleSymbol when using dynamic allocation (when demangled_buf was NULL).Return Value
This function does not return a value.Description
This function deallocates memory that was dynamically allocated byLM_DemangleSymbol. You should only call this function on pointers returned by LM_DemangleSymbol when you passed NULL as the demangled_buf parameter.
Example
Important Notes
- Only use this function for dynamically allocated symbols: Do not call this on symbols that were demangled into a user-provided buffer.
- Memory Management: Always pair
LM_DemangleSymbol(withNULLbuffer) withLM_FreeDemangledSymbolto avoid memory leaks. - NULL Safety: It is safe to call this function with a
NULLpointer (it will do nothing).
Correct vs Incorrect Usage
Correct Usage (Dynamic Allocation)
Incorrect Usage (User Buffer)
See Also
LM_DemangleSymbol- Demangle a symbol nameLM_EnumSymbolsDemangled- Enumerate symbols with automatic demanglingLM_FindSymbolAddressDemangled- Find a symbol by its demangled name