diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4690e8a --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +d_demangle: + dmd -c demangle.d + dmd -oflibd_demangle.so demangle.o -shared -defaultlib=libphobos2.so diff --git a/README.md b/README.md new file mode 100644 index 0000000..accdb66 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# d_demangler + +A small utility to demange D symbols diff --git a/demangle.d b/demangle.d new file mode 100644 index 0000000..2db425e --- /dev/null +++ b/demangle.d @@ -0,0 +1,19 @@ +import std.demangle : demangle; +import std.conv : to; +import std.string : toStringz; +import core.stdc.string : strncpy; + +extern (C) int demangle_symbol(const(char)* c_name, char* buffer, int size) +{ + const auto name = to!string(c_name); + auto demangled = demangle(name); + + if (name == demangled) { + return 0; + } + + const auto c_demangled = toStringz(demangled); + strncpy(buffer, c_demangled, size - 1); + + return 1; +}