From e88abac3cef98005ce1dca0d476d039857e63f92 Mon Sep 17 00:00:00 2001 From: Lieven Hey Date: Tue, 14 Sep 2021 15:07:34 +0200 Subject: [PATCH] Initial commit --- Makefile | 3 +++ README.md | 3 +++ demangle.d | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 demangle.d 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; +}