[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2019-06-08 Thread James S Blachly, MD via Phabricator via lldb-commits
jblachly added a comment.

I sat down to write my own plugin today and found this.

@timotheecour , thanks for writing this -- can I help with anything to get this 
across the finish line?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44321/new/

https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-21 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

The Terminate function is a good place to do this kind of cleanup.




Comment at: source/Plugins/Language/D/DLanguage.cpp:34-36
+// D Plugin will define these symbols. They're declared to use with decltype.
+extern "C" {
+// called once, to initialize druntime. Return true on success

Instead of using decltype everywhere, you could just define the type of these 
functions  with typedef and use that.


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-20 Thread Johan Engelen via Phabricator via lldb-commits
johanengelen added a comment.

In https://reviews.llvm.org/D44321#1038241, @timotheecour wrote:

> > When druntime is initialized, a number of resources are allocated (e.g. 
> > memory and mutex). Yes you initialize druntime once, I can see that. You 
> > don't deinitialize druntime at all: that's the resource leak.
>
> Where would you want me to deinit? inside ` DLanguage::Terminate` ?


I don't know enough of LLDB to know where to put the deinitialization. Sorry, 
can't help you there, except for making it easy and doing the deinitialization 
using a dtor in the library...


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-14 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour updated this revision to Diff 138477.
timotheecour added a comment.

- fix assert fail when plugin.language.D.pluginfile empty


https://reviews.llvm.org/D44321

Files:
  include/lldb/Core/Mangled.h
  include/lldb/Core/PluginManager.h
  source/API/SystemInitializerFull.cpp
  source/Core/CMakeLists.txt
  source/Core/Mangled.cpp
  source/Core/PluginManager.cpp
  source/Plugins/Language/CMakeLists.txt
  source/Plugins/Language/D/CMakeLists.txt
  source/Plugins/Language/D/DLanguage.cpp
  source/Plugins/Language/D/DLanguage.h

Index: source/Plugins/Language/D/DLanguage.h
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.h
@@ -0,0 +1,81 @@
+//===-- DLanguage.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+/*
+to use, add this to .lldbinit:
+settings set plugin.language.D.pluginfile "path/to/liblldbdplugin.dylib"
+example of such plugin:
+https://github.com/timotheecour/dtools/blob/master/dtools/lldbdplugin.d
+*/
+
+#ifndef liblldb_DLanguage_h_
+#define liblldb_DLanguage_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Target/Language.h"
+#include "lldb/lldb-private.h"
+
+namespace lldb_private {
+
+class DLanguageProperties : public Properties {
+public:
+  DLanguageProperties();
+
+  ~DLanguageProperties() override;
+
+  llvm::StringRef GetPluginfileDlang();
+};
+
+class DLanguage : public Language {
+public:
+  typedef std::shared_ptr DLanguagePropertiesSP;
+
+  DLanguage() = default;
+
+  ~DLanguage() override = default;
+
+  lldb::LanguageType GetLanguageType() const override {
+return lldb::eLanguageTypeD;
+  }
+
+  //--
+  // Static Functions
+  //--
+  static void Initialize();
+
+  static void Terminate();
+
+  static lldb_private::Language *CreateInstance(lldb::LanguageType language);
+
+  static void DebuggerInitialize(lldb_private::Debugger );
+
+  static DLanguage *Instance();
+
+  static const DLanguagePropertiesSP ();
+
+  static lldb_private::ConstString GetPluginNameStatic();
+
+  static bool IsDMangledName(const char *name);
+  // Consider using non-static methods
+  static char *demangle(const ConstString );
+
+  //--
+  // PluginInterface protocol
+  //--
+  ConstString GetPluginName() override;
+
+  uint32_t GetPluginVersion() override;
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_DLanguage_h_
Index: source/Plugins/Language/D/DLanguage.cpp
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.cpp
@@ -0,0 +1,158 @@
+//===-- DLanguage.cpp ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DLanguage.h"
+
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Interpreter/OptionValueString.h"
+#include "lldb/Interpreter/Property.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/Log.h"
+#include "llvm/Support/DynamicLibrary.h"
+
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+using llvm::sys::DynamicLibrary;
+
+namespace {
+
+template 
+Fun *getTypedSymbol(DynamicLibrary , const char *symbol) {
+  return reinterpret_cast(lib.getAddressOfSymbol(symbol));
+}
+
+// D Plugin will define these symbols. They're declared to use with decltype.
+extern "C" {
+// called once, to initialize druntime. Return true on success
+bool d_initialize();
+// can be called to release resources allocated via d_initialize. Return true on
+// success.
+bool d_terminate();
+// The returned pointer should be allocated via malloc and owned by the caller.
+char *lldbd_demangle(size_t length, const char *mangled);
+}
+
+static PropertyDefinition g_properties[] = {
+{"pluginfile", OptionValue::eTypeString, true,
+ OptionValueString::eOptionEncodeCharacterEscapeSequences, "", nullptr,
+ "The plugin shared library file to use for D language."},
+};
+
+enum {
+  ePropertyPluginfileDlang,
+};
+
+} // anonymous namespace
+
+// DLanguageProperties
+DLanguageProperties::~DLanguageProperties() = default;
+
+DLanguageProperties::DLanguageProperties() : Properties() {
+  m_collection_sp.reset(

[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-14 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour added a comment.

> When druntime is initialized, a number of resources are allocated (e.g. 
> memory and mutex). Yes you initialize druntime once, I can see that. You 
> don't deinitialize druntime at all: that's the resource leak.

Where would you want me to deinit? inside ` DLanguage::Terminate` ?


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-14 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour added inline comments.



Comment at: source/Plugins/Language/D/DLanguage.cpp:108
+
+auto fun0=lib2->getFun("d_initialize");
+(*fun0)();

johanengelen wrote:
> timotheecour wrote:
> > johanengelen wrote:
> > > Would it help to initialize druntime using a static module constructor in 
> > > the lldbdplugin dll?
> > > (then you can also do de-init using a static module destructor)
> > I don't really like static module constructor because it adds cyclic 
> > dependencies, see for vibe.d moving away from it: 
> > https://forum.dlang.org/post/qtabwblpaqwpteyst...@forum.dlang.org
> > explicit calling `d_initialize` is simple enough.
> > 
> > 
> > 
> Module ctors don't add cyclic dependencies by themselves. There is also no 
> danger of that here.
> How do you de-initialize druntime? (without de-init, there is a big mem leak)
> Module ctors don't add cyclic dependencies by themselves. There is also no 
> danger of that here.

* We can have cyclic dependencies but not when Module ctors are involved; see 
previous argument I made with vibe.d, or other threads (eg 
https://forum.dlang.org/post/rrcshskphugsvksao...@forum.dlang.org).

* Also, current code allows for liblldbplugin.d to be imported from another 
module whereas it would cause complications if it contained a module ctor that 
would initialize druntime.

calling `d_initialize` as I'm doing works fine.




Comment at: source/Plugins/Language/D/DLanguage.cpp:108
+
+auto fun0=lib2->getFun("d_initialize");
+(*fun0)();

timotheecour wrote:
> johanengelen wrote:
> > timotheecour wrote:
> > > johanengelen wrote:
> > > > Would it help to initialize druntime using a static module constructor 
> > > > in the lldbdplugin dll?
> > > > (then you can also do de-init using a static module destructor)
> > > I don't really like static module constructor because it adds cyclic 
> > > dependencies, see for vibe.d moving away from it: 
> > > https://forum.dlang.org/post/qtabwblpaqwpteyst...@forum.dlang.org
> > > explicit calling `d_initialize` is simple enough.
> > > 
> > > 
> > > 
> > Module ctors don't add cyclic dependencies by themselves. There is also no 
> > danger of that here.
> > How do you de-initialize druntime? (without de-init, there is a big mem 
> > leak)
> > Module ctors don't add cyclic dependencies by themselves. There is also no 
> > danger of that here.
> 
> * We can have cyclic dependencies but not when Module ctors are involved; see 
> previous argument I made with vibe.d, or other threads (eg 
> https://forum.dlang.org/post/rrcshskphugsvksao...@forum.dlang.org).
> 
> * Also, current code allows for liblldbplugin.d to be imported from another 
> module whereas it would cause complications if it contained a module ctor 
> that would initialize druntime.
> 
> calling `d_initialize` as I'm doing works fine.
> 
> How do you de-initialize druntime? (without de-init, there is a big mem leak)

There is no memory leak because d_initialize once (using c++11 static 
initialization pattern) and is intended to last for duration of application; so 
druntime will be initialized only once, upon 1st use.

I've however added d_terminate in case a future PR wants to de-initialize 
druntime (eg in DLanguage::Terminate)


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-14 Thread Johan Engelen via Phabricator via lldb-commits
johanengelen added a comment.

In https://reviews.llvm.org/D44321#1038160, @timotheecour wrote:

> > How do you de-initialize druntime? (without de-init, there is a big mem 
> > leak)
>
> There is no memory leak because `d_initialize` once (using c++11 static 
> initialization pattern) and is intended to last for duration of application; 
> so druntime will be initialized only once, upon 1st use.


When druntime is initialized, a number of resources are allocated (e.g. memory 
and mutex). Yes you initialize druntime once, I can see that. You don't 
deinitialize druntime at all: that's the resource leak.


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-14 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour added a comment.

> How do you de-initialize druntime? (without de-init, there is a big mem leak)

There is no memory leak because `d_initialize` once (using c++11 static 
initialization pattern) and is intended to last for duration of application; so 
druntime will be initialized only once, upon 1st use.

I've however added `d_terminate` in case a future PR wants to de-initialize 
druntime (eg in DLanguage::Terminate)


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-14 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour updated this revision to Diff 138471.
timotheecour added a comment.

- added d_terminate
- format


https://reviews.llvm.org/D44321

Files:
  include/lldb/Core/Mangled.h
  include/lldb/Core/PluginManager.h
  source/API/SystemInitializerFull.cpp
  source/Core/CMakeLists.txt
  source/Core/Mangled.cpp
  source/Core/PluginManager.cpp
  source/Plugins/Language/CMakeLists.txt
  source/Plugins/Language/D/CMakeLists.txt
  source/Plugins/Language/D/DLanguage.cpp
  source/Plugins/Language/D/DLanguage.h

Index: source/Plugins/Language/D/DLanguage.h
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.h
@@ -0,0 +1,81 @@
+//===-- DLanguage.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+/*
+to use, add this to .lldbinit:
+settings set plugin.language.D.pluginfile "path/to/liblldbdplugin.dylib"
+example of such plugin:
+https://github.com/timotheecour/dtools/blob/master/dtools/lldbdplugin.d
+*/
+
+#ifndef liblldb_DLanguage_h_
+#define liblldb_DLanguage_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Target/Language.h"
+#include "lldb/lldb-private.h"
+
+namespace lldb_private {
+
+class DLanguageProperties : public Properties {
+public:
+  DLanguageProperties();
+
+  ~DLanguageProperties() override;
+
+  llvm::StringRef GetPluginfileDlang();
+};
+
+class DLanguage : public Language {
+public:
+  typedef std::shared_ptr DLanguagePropertiesSP;
+
+  DLanguage() = default;
+
+  ~DLanguage() override = default;
+
+  lldb::LanguageType GetLanguageType() const override {
+return lldb::eLanguageTypeD;
+  }
+
+  //--
+  // Static Functions
+  //--
+  static void Initialize();
+
+  static void Terminate();
+
+  static lldb_private::Language *CreateInstance(lldb::LanguageType language);
+
+  static void DebuggerInitialize(lldb_private::Debugger );
+
+  static DLanguage *Instance();
+
+  static const DLanguagePropertiesSP ();
+
+  static lldb_private::ConstString GetPluginNameStatic();
+
+  static bool IsDMangledName(const char *name);
+  // Consider using non-static methods
+  static char *demangle(const ConstString );
+
+  //--
+  // PluginInterface protocol
+  //--
+  ConstString GetPluginName() override;
+
+  uint32_t GetPluginVersion() override;
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_DLanguage_h_
Index: source/Plugins/Language/D/DLanguage.cpp
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.cpp
@@ -0,0 +1,156 @@
+//===-- DLanguage.cpp ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DLanguage.h"
+
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Interpreter/OptionValueString.h"
+#include "lldb/Interpreter/Property.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/Log.h"
+#include "llvm/Support/DynamicLibrary.h"
+
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+using llvm::sys::DynamicLibrary;
+
+namespace {
+
+template 
+Fun *getTypedSymbol(DynamicLibrary , const char *symbol) {
+  return reinterpret_cast(lib.getAddressOfSymbol(symbol));
+}
+
+// D Plugin will define these symbols. They're declared to use with decltype.
+extern "C" {
+// called once, to initialize druntime. Return true on success
+bool d_initialize();
+// can be called to release resources allocated via d_initialize. Return true on
+// success.
+bool d_terminate();
+// The returned pointer should be allocated via malloc and owned by the caller.
+char *lldbd_demangle(size_t length, const char *mangled);
+}
+
+static PropertyDefinition g_properties[] = {
+{"pluginfile", OptionValue::eTypeString, true,
+ OptionValueString::eOptionEncodeCharacterEscapeSequences, "", nullptr,
+ "The plugin shared library file to use for D language."},
+};
+
+enum {
+  ePropertyPluginfileDlang,
+};
+
+} // anonymous namespace
+
+// DLanguageProperties
+DLanguageProperties::~DLanguageProperties() = default;
+
+DLanguageProperties::DLanguageProperties() : Properties() {
+  m_collection_sp.reset(
+  new 

[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-13 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour updated this revision to Diff 138291.
timotheecour added a comment.

- document C interface


https://reviews.llvm.org/D44321

Files:
  include/lldb/Core/Mangled.h
  include/lldb/Core/PluginManager.h
  source/API/SystemInitializerFull.cpp
  source/Core/CMakeLists.txt
  source/Core/Mangled.cpp
  source/Core/PluginManager.cpp
  source/Plugins/Language/CMakeLists.txt
  source/Plugins/Language/D/CMakeLists.txt
  source/Plugins/Language/D/DLanguage.cpp
  source/Plugins/Language/D/DLanguage.h

Index: source/Plugins/Language/D/DLanguage.h
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.h
@@ -0,0 +1,81 @@
+//===-- DLanguage.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+/*
+to use, add this to .lldbinit:
+settings set plugin.language.D.pluginfile "path/to/liblldbdplugin.dylib"
+example of such plugin:
+https://github.com/timotheecour/dtools/blob/master/dtools/lldbdplugin.d
+*/
+
+#ifndef liblldb_DLanguage_h_
+#define liblldb_DLanguage_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Target/Language.h"
+#include "lldb/lldb-private.h"
+
+namespace lldb_private {
+
+class DLanguageProperties : public Properties {
+public:
+  DLanguageProperties();
+
+  ~DLanguageProperties() override;
+
+  llvm::StringRef GetPluginfileDlang();
+};
+
+class DLanguage : public Language {
+public:
+  typedef std::shared_ptr DLanguagePropertiesSP;
+
+  DLanguage() = default;
+
+  ~DLanguage() override = default;
+
+  lldb::LanguageType GetLanguageType() const override {
+return lldb::eLanguageTypeD;
+  }
+
+  //--
+  // Static Functions
+  //--
+  static void Initialize();
+
+  static void Terminate();
+
+  static lldb_private::Language *CreateInstance(lldb::LanguageType language);
+
+  static void DebuggerInitialize(lldb_private::Debugger );
+
+  static DLanguage *Instance();
+
+  static const DLanguagePropertiesSP ();
+
+  static lldb_private::ConstString GetPluginNameStatic();
+
+  static bool IsDMangledName(const char *name);
+  // Consider using non-static methods
+  static char *demangle(const ConstString );
+
+  //--
+  // PluginInterface protocol
+  //--
+  ConstString GetPluginName() override;
+
+  uint32_t GetPluginVersion() override;
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_DLanguage_h_
Index: source/Plugins/Language/D/DLanguage.cpp
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.cpp
@@ -0,0 +1,153 @@
+//===-- DLanguage.cpp ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DLanguage.h"
+
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Interpreter/OptionValueString.h"
+#include "lldb/Interpreter/Property.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/Log.h"
+#include "llvm/Support/DynamicLibrary.h"
+
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+using llvm::sys::DynamicLibrary;
+
+namespace {
+
+template 
+Fun *getTypedSymbol(DynamicLibrary , const char *symbol) {
+  return reinterpret_cast(lib.getAddressOfSymbol(symbol));
+}
+
+// D Plugin will define these symbols. They're declared to use with decltype.
+extern "C" {
+// called once, to initialize druntime.
+void d_initialize();
+// The returned pointer should be allocated via malloc and owned by the caller.
+char *lldbd_demangle(size_t length, const char *mangled);
+}
+
+static PropertyDefinition g_properties[] = {
+{"pluginfile", OptionValue::eTypeString, true,
+ OptionValueString::eOptionEncodeCharacterEscapeSequences, "", nullptr,
+ "The plugin shared library file to use for D language."},
+};
+
+enum {
+  ePropertyPluginfileDlang,
+};
+
+} // anonymous namespace
+
+// DLanguageProperties
+DLanguageProperties::~DLanguageProperties() = default;
+
+DLanguageProperties::DLanguageProperties() : Properties() {
+  m_collection_sp.reset(
+  new OptionValueProperties(DLanguage::GetPluginNameStatic()));
+  m_collection_sp->Initialize(g_properties);
+}
+
+// DLanguage
+llvm::StringRef 

[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-13 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour added a comment.

> Actually, this is not the correct interface is it? The returned pointer 
> should point to newly allocated memory using malloc, right?
>  Good to document that somewhere.

not 100% sure what you mean in that comment but I just pushed a commit that 
clarifies that point: 'The returned pointer should be allocated via malloc and 
owned by the caller' ; the reference implementation of liblldbplugin does the 
right thing.


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-11 Thread Johan Engelen via Phabricator via lldb-commits
johanengelen added a comment.

In https://reviews.llvm.org/D44321#1034168, @johanengelen wrote:

>   extern "C" char* lldbd_demangle(size_t length, const char* mangled) {
>  if (mangled == "_D3fooFZv") // pseudo code
>  return "void foo()";
>  else
>  return mangled;
>   }
>


Actually, this is not the correct interface is it? The returned pointer should 
point to newly allocated memory using `malloc`, right?
Good to document that somewhere.


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-11 Thread Johan Engelen via Phabricator via lldb-commits
johanengelen added a comment.

In https://reviews.llvm.org/D44321#1034141, @timotheecour wrote:

> > It's a little more complicated for D because it's an out-of-tree compiler 
> > so it poses interesting challenges.
>
> the demangling itself is thoroughly tested in 
> https://github.com/dlang/druntime/blob/master/src/core/demangle.d


It's not the correct demangling of strings that needs to be tested. What needs 
testing:

- recognising D language and D mangled name
- loading of dynamic lib (plus testing that when loading fails lldb doesn't 
crash/exit; note: errmsg can be improved to e.g. "Failed to load D language 
plugin...")
- test that indeed the demangling function of the dyn lib is called

To test this, I think you can make a mock dynamic lib that implements the 
required interface, but in C++. The mock demangler could be something like this 
or even simpler:

  extern "C" char* lldbd_demangle(size_t length, const char* mangled) {
 if (mangled == "_D3fooFZv") // pseudo code
 return "void foo()";
 else
 return mangled;
  }

Then build that library in the test, and test loading and use on a fabricated 
piece of code (probably easiest to use C code with this in it: `extern "C" 
_D3fooFZv() { trap(); }`.


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-11 Thread Johan Engelen via Phabricator via lldb-commits
johanengelen added inline comments.



Comment at: source/Plugins/Language/D/DLanguage.cpp:108
+
+auto fun0=lib2->getFun("d_initialize");
+(*fun0)();

timotheecour wrote:
> johanengelen wrote:
> > Would it help to initialize druntime using a static module constructor in 
> > the lldbdplugin dll?
> > (then you can also do de-init using a static module destructor)
> I don't really like static module constructor because it adds cyclic 
> dependencies, see for vibe.d moving away from it: 
> https://forum.dlang.org/post/qtabwblpaqwpteyst...@forum.dlang.org
> explicit calling `d_initialize` is simple enough.
> 
> 
> 
Module ctors don't add cyclic dependencies by themselves. There is also no 
danger of that here.
How do you de-initialize druntime? (without de-init, there is a big mem leak)


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-10 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour added a comment.

Note that the D plugin is not loaded by default (so default behavior is not 
affected) ; it's only loaded if user adds to his .lldbinit:
settings set plugin.language.D.pluginfile "path_to/liblldbdplugin.dylib"


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-10 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour added a comment.

> It's a little more complicated for D because it's an out-of-tree compiler so 
> it poses interesting challenges.

the demangling itself is thoroughly tested in 
https://github.com/dlang/druntime/blob/master/src/core/demangle.d


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-10 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour updated this revision to Diff 137942.
timotheecour added a comment.

- added doc


https://reviews.llvm.org/D44321

Files:
  include/lldb/Core/Mangled.h
  include/lldb/Core/PluginManager.h
  source/API/SystemInitializerFull.cpp
  source/Core/CMakeLists.txt
  source/Core/Mangled.cpp
  source/Core/PluginManager.cpp
  source/Plugins/Language/CMakeLists.txt
  source/Plugins/Language/D/CMakeLists.txt
  source/Plugins/Language/D/DLanguage.cpp
  source/Plugins/Language/D/DLanguage.h

Index: source/Plugins/Language/D/DLanguage.h
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.h
@@ -0,0 +1,81 @@
+//===-- DLanguage.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+/*
+to use, add this to .lldbinit:
+settings set plugin.language.D.pluginfile "path/to/liblldbdplugin.dylib"
+example of such plugin:
+https://github.com/timotheecour/dtools/blob/master/dtools/lldbdplugin.d
+*/
+
+#ifndef liblldb_DLanguage_h_
+#define liblldb_DLanguage_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Target/Language.h"
+#include "lldb/lldb-private.h"
+
+namespace lldb_private {
+
+class DLanguageProperties : public Properties {
+public:
+  DLanguageProperties();
+
+  ~DLanguageProperties() override;
+
+  llvm::StringRef GetPluginfileDlang();
+};
+
+class DLanguage : public Language {
+public:
+  typedef std::shared_ptr DLanguagePropertiesSP;
+
+  DLanguage() = default;
+
+  ~DLanguage() override = default;
+
+  lldb::LanguageType GetLanguageType() const override {
+return lldb::eLanguageTypeD;
+  }
+
+  //--
+  // Static Functions
+  //--
+  static void Initialize();
+
+  static void Terminate();
+
+  static lldb_private::Language *CreateInstance(lldb::LanguageType language);
+
+  static void DebuggerInitialize(lldb_private::Debugger );
+
+  static DLanguage *Instance();
+
+  static const DLanguagePropertiesSP ();
+
+  static lldb_private::ConstString GetPluginNameStatic();
+
+  static bool IsDMangledName(const char *name);
+  // Consider using non-static methods
+  static char *demangle(const ConstString );
+
+  //--
+  // PluginInterface protocol
+  //--
+  ConstString GetPluginName() override;
+
+  uint32_t GetPluginVersion() override;
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_DLanguage_h_
Index: source/Plugins/Language/D/DLanguage.cpp
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.cpp
@@ -0,0 +1,151 @@
+//===-- DLanguage.cpp ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DLanguage.h"
+
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Interpreter/OptionValueString.h"
+#include "lldb/Interpreter/Property.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/Log.h"
+#include "llvm/Support/DynamicLibrary.h"
+
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+using llvm::sys::DynamicLibrary;
+
+namespace {
+
+template 
+Fun *getTypedSymbol(DynamicLibrary , const char *symbol) {
+  return reinterpret_cast(lib.getAddressOfSymbol(symbol));
+}
+
+// D Plugin will define these symbols. They're declared to use with decltype.
+extern "C" {
+char *lldbd_demangle(size_t length, const char *mangled);
+void d_initialize();
+}
+
+static PropertyDefinition g_properties[] = {
+{"pluginfile", OptionValue::eTypeString, true,
+ OptionValueString::eOptionEncodeCharacterEscapeSequences, "", nullptr,
+ "The plugin shared library file to use for D language."},
+};
+
+enum {
+  ePropertyPluginfileDlang,
+};
+
+} // anonymous namespace
+
+// DLanguageProperties
+DLanguageProperties::~DLanguageProperties() = default;
+
+DLanguageProperties::DLanguageProperties() : Properties() {
+  m_collection_sp.reset(
+  new OptionValueProperties(DLanguage::GetPluginNameStatic()));
+  m_collection_sp->Initialize(g_properties);
+}
+
+// DLanguage
+llvm::StringRef DLanguageProperties::GetPluginfileDlang() {
+  const uint32_t idx = ePropertyPluginfileDlang;
+  assert(m_collection_sp);
+  return 

[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-10 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour added a comment.

update: we can now set lldbdplugin in .lldbinit via `settings set 
plugin.language.D.pluginfile` so this avoids hardcoding that file


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-10 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour updated this revision to Diff 137940.
timotheecour added a comment.

- format
- use llvm::sys::DynamicLibrary
- added DLanguageProperties


https://reviews.llvm.org/D44321

Files:
  include/lldb/Core/Mangled.h
  include/lldb/Core/PluginManager.h
  source/API/SystemInitializerFull.cpp
  source/Core/CMakeLists.txt
  source/Core/Mangled.cpp
  source/Core/PluginManager.cpp
  source/Plugins/Language/CMakeLists.txt
  source/Plugins/Language/D/CMakeLists.txt
  source/Plugins/Language/D/DLanguage.cpp
  source/Plugins/Language/D/DLanguage.h

Index: source/Plugins/Language/D/DLanguage.h
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.h
@@ -0,0 +1,74 @@
+//===-- DLanguage.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef liblldb_DLanguage_h_
+#define liblldb_DLanguage_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Target/Language.h"
+#include "lldb/lldb-private.h"
+
+namespace lldb_private {
+
+class DLanguageProperties : public Properties {
+public:
+  DLanguageProperties();
+
+  ~DLanguageProperties() override;
+
+  llvm::StringRef GetPluginfileDlang();
+};
+
+class DLanguage : public Language {
+public:
+  typedef std::shared_ptr DLanguagePropertiesSP;
+
+  DLanguage() = default;
+
+  ~DLanguage() override = default;
+
+  lldb::LanguageType GetLanguageType() const override {
+return lldb::eLanguageTypeD;
+  }
+
+  //--
+  // Static Functions
+  //--
+  static void Initialize();
+
+  static void Terminate();
+
+  static lldb_private::Language *CreateInstance(lldb::LanguageType language);
+
+  static void DebuggerInitialize(lldb_private::Debugger );
+
+  static DLanguage *Instance();
+
+  static const DLanguagePropertiesSP ();
+
+  static lldb_private::ConstString GetPluginNameStatic();
+
+  static bool IsDMangledName(const char *name);
+  // Consider using non-static methods
+  static char *demangle(const ConstString );
+
+  //--
+  // PluginInterface protocol
+  //--
+  ConstString GetPluginName() override;
+
+  uint32_t GetPluginVersion() override;
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_DLanguage_h_
Index: source/Plugins/Language/D/DLanguage.cpp
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.cpp
@@ -0,0 +1,151 @@
+//===-- DLanguage.cpp ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DLanguage.h"
+
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Interpreter/OptionValueString.h"
+#include "lldb/Interpreter/Property.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/Log.h"
+#include "llvm/Support/DynamicLibrary.h"
+
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+using llvm::sys::DynamicLibrary;
+
+namespace {
+
+template 
+Fun *getTypedSymbol(DynamicLibrary , const char *symbol) {
+  return reinterpret_cast(lib.getAddressOfSymbol(symbol));
+}
+
+// D Plugin will define these symbols. They're declared to use with decltype.
+extern "C" {
+char *lldbd_demangle(size_t length, const char *mangled);
+void d_initialize();
+}
+
+static PropertyDefinition g_properties[] = {
+{"pluginfile", OptionValue::eTypeString, true,
+ OptionValueString::eOptionEncodeCharacterEscapeSequences, "", nullptr,
+ "The plugin shared library file to use for D language."},
+};
+
+enum {
+  ePropertyPluginfileDlang,
+};
+
+} // anonymous namespace
+
+// DLanguageProperties
+DLanguageProperties::~DLanguageProperties() = default;
+
+DLanguageProperties::DLanguageProperties() : Properties() {
+  m_collection_sp.reset(
+  new OptionValueProperties(DLanguage::GetPluginNameStatic()));
+  m_collection_sp->Initialize(g_properties);
+}
+
+// DLanguage
+llvm::StringRef DLanguageProperties::GetPluginfileDlang() {
+  const uint32_t idx = ePropertyPluginfileDlang;
+  assert(m_collection_sp);
+  return m_collection_sp->GetPropertyAtIndexAsString(
+  nullptr, idx, g_properties[idx].default_cstr_value);
+}
+
+void DLanguage::Initialize() {
+  

[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-10 Thread Davide Italiano via Phabricator via lldb-commits
davide added a comment.

In https://reviews.llvm.org/D44321#1034043, @timotheecour wrote:

> In https://reviews.llvm.org/D44321#1033325, @davide wrote:
>
> > This patch has no testcase. It shouldn't be particularly hard to write one, 
> > you can take inspiration from the one in `lit/`.
> >
> > Thanks!
>
>
> 5d29d3f0aa2f540c277a67eac5873feca8c62d51 (Support for OCaml native debugging) 
> introduced a much larger change and had no test case either. If you really 
> insist on a test case please provide more concrete guidance.


That was a while ago. In fact, the OCaml support is going to be removed. New 
languages need to meet an high(er) bar to be included. One of the requirements 
is, e.g. being tested.
It's a little more complicated for D because it's an out-of-tree compiler so it 
poses interesting challenges.
Let me think about it a little more and I'll come back to you.

Thanks,

-

Davide


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-10 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour added a comment.

In https://reviews.llvm.org/D44321#1033325, @davide wrote:

> This patch has no testcase. It shouldn't be particularly hard to write one, 
> you can take inspiration from the one in `lit/`.
>
> Thanks!


5d29d3f0aa2f540c277a67eac5873feca8c62d51 (Support for OCaml native debugging) 
introduced a much larger change and had no test case either. If you really 
insist on a test case please provide more concrete guidance.


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-10 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour marked an inline comment as done.
timotheecour added inline comments.



Comment at: source/Plugins/Language/D/DLanguage.cpp:24
+// TODO:MOVE
+struct SharedLib{
+  void* handle;

johanengelen wrote:
> Did you look into using llvm/Support/DynamicLibrary.h ?
> That would make the code crossplatform (notably: Windows).
thx for tip! done, used llvm::sys::DynamicLibrary


https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-10 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour updated this revision to Diff 137930.
timotheecour added a comment.

- use llvm::sys::DynamicLibrary
- format


https://reviews.llvm.org/D44321

Files:
  include/lldb/Core/Mangled.h
  source/Core/CMakeLists.txt
  source/Core/Mangled.cpp
  source/Plugins/Language/CMakeLists.txt
  source/Plugins/Language/D/CMakeLists.txt
  source/Plugins/Language/D/DLanguage.cpp
  source/Plugins/Language/D/DLanguage.h

Index: source/Plugins/Language/D/DLanguage.h
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.h
@@ -0,0 +1,57 @@
+//===-- DLanguage.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef liblldb_DLanguage_h_
+#define liblldb_DLanguage_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Target/Language.h"
+#include "lldb/lldb-private.h"
+
+namespace lldb_private {
+
+class DLanguage : public Language {
+public:
+  DLanguage() = default;
+
+  ~DLanguage() override = default;
+
+  lldb::LanguageType GetLanguageType() const override {
+return lldb::eLanguageTypeD;
+  }
+
+  //--
+  // Static Functions
+  //--
+  static void Initialize();
+
+  static void Terminate();
+
+  static lldb_private::Language *CreateInstance(lldb::LanguageType language);
+
+  static lldb_private::ConstString GetPluginNameStatic();
+
+  static bool IsDMangledName(const char *name);
+  // Consider using non-static methods
+  static char *demangle(const ConstString );
+
+  //--
+  // PluginInterface protocol
+  //--
+  ConstString GetPluginName() override;
+
+  uint32_t GetPluginVersion() override;
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_DLanguage_h_
Index: source/Plugins/Language/D/DLanguage.cpp
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.cpp
@@ -0,0 +1,99 @@
+//===-- DLanguage.cpp ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DLanguage.h"
+
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Utility/ConstString.h"
+#include "llvm/Support/DynamicLibrary.h"
+
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+using llvm::sys::DynamicLibrary;
+
+template 
+Fun *getTypedSymbol(DynamicLibrary , const char *symbol) {
+  return reinterpret_cast(lib.getAddressOfSymbol(symbol));
+}
+
+// D Plugin will define these symbols. They're declared to use with decltype.
+extern "C" {
+char *lldbd_demangle(size_t length, const char *mangled);
+void d_initialize();
+}
+
+void DLanguage::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(), "D Language",
+CreateInstance);
+}
+
+void DLanguage::Terminate() { PluginManager::UnregisterPlugin(CreateInstance); }
+
+lldb_private::ConstString DLanguage::GetPluginNameStatic() {
+  static ConstString g_name("D");
+  return g_name;
+}
+
+//--
+// PluginInterface protocol
+//--
+lldb_private::ConstString DLanguage::GetPluginName() {
+  return GetPluginNameStatic();
+}
+
+uint32_t DLanguage::GetPluginVersion() { return 1; }
+
+//--
+// Static Functions
+//--
+Language *DLanguage::CreateInstance(lldb::LanguageType language) {
+  switch (language) {
+  case lldb::eLanguageTypeD:
+return new DLanguage();
+  default:
+return nullptr;
+  }
+}
+
+char *DLanguage::demangle(const ConstString ) {
+  auto len = mangled.GetLength();
+  auto s = mangled.GetCString();
+  static auto fun = []() -> decltype(lldbd_demangle) * {
+// TODO: so vs dylib
+auto file = "liblldbdplugin.dylib";
+std::string errMsg;
+auto lib2 = DynamicLibrary::getPermanentLibrary(file, );
+
+if (!lib2.isValid()) {
+  // Not dumping `errMsg` because would result in noise if user did not
+  // intend to call dlopen.
+  return nullptr;
+}
+
+auto fun0 = getTypedSymbol(lib2, "d_initialize");
+assert(fun0);
+  

[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-10 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour added inline comments.



Comment at: source/Plugins/Language/D/DLanguage.cpp:108
+
+auto fun0=lib2->getFun("d_initialize");
+(*fun0)();

johanengelen wrote:
> Would it help to initialize druntime using a static module constructor in the 
> lldbdplugin dll?
> (then you can also do de-init using a static module destructor)
I don't really like static module constructor because it adds cyclic 
dependencies, see for vibe.d moving away from it: 
https://forum.dlang.org/post/qtabwblpaqwpteyst...@forum.dlang.org
explicit calling `d_initialize` is simple enough.





https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-10 Thread Timothee Cour via Phabricator via lldb-commits
timotheecour updated this revision to Diff 137927.
timotheecour marked 4 inline comments as done.
timotheecour edited the summary of this revision.
timotheecour added a comment.

- format
- format
- fixup


https://reviews.llvm.org/D44321

Files:
  include/lldb/Core/Mangled.h
  source/Core/CMakeLists.txt
  source/Core/Mangled.cpp
  source/Plugins/Language/CMakeLists.txt
  source/Plugins/Language/D/CMakeLists.txt
  source/Plugins/Language/D/DLanguage.cpp
  source/Plugins/Language/D/DLanguage.h

Index: source/Plugins/Language/D/DLanguage.h
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.h
@@ -0,0 +1,57 @@
+//===-- DLanguage.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef liblldb_DLanguage_h_
+#define liblldb_DLanguage_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Target/Language.h"
+#include "lldb/lldb-private.h"
+
+namespace lldb_private {
+
+class DLanguage : public Language {
+public:
+  DLanguage() = default;
+
+  ~DLanguage() override = default;
+
+  lldb::LanguageType GetLanguageType() const override {
+return lldb::eLanguageTypeD;
+  }
+
+  //--
+  // Static Functions
+  //--
+  static void Initialize();
+
+  static void Terminate();
+
+  static lldb_private::Language *CreateInstance(lldb::LanguageType language);
+
+  static lldb_private::ConstString GetPluginNameStatic();
+
+  static bool IsDMangledName(const char *name);
+  // TODO: not static?
+  static char *demangle(const ConstString );
+
+  //--
+  // PluginInterface protocol
+  //--
+  ConstString GetPluginName() override;
+
+  uint32_t GetPluginVersion() override;
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_DLanguage_h_
Index: source/Plugins/Language/D/DLanguage.cpp
===
--- /dev/null
+++ source/Plugins/Language/D/DLanguage.cpp
@@ -0,0 +1,119 @@
+//===-- DLanguage.cpp ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DLanguage.h"
+
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Utility/ConstString.h"
+
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+// D Plugin will define these symbols. They're declared to use with decltype.
+extern "C"{
+  char *lldbd_demangle(size_t length, const char *mangled);
+  void d_initialize();
+}
+
+// TODO:MOVE
+struct SharedLib {
+  void *handle;
+  const char *libraryFile;
+  int flagDefault = RTLD_LOCAL | RTLD_LAZY;
+  SharedLib() {}
+
+  ~SharedLib() { release(); }
+
+  // Return true if `dlopen` succeeded
+  bool open(const char *libraryFile, int flag) {
+release();
+this->libraryFile = libraryFile;
+handle = dlopen(libraryFile, flag);
+if (handle)
+  return true;
+return false;
+  }
+
+  void release() {
+// if(handle) seems needed:
+// https://stackoverflow.com/questions/11412943is-it-safe-to-call-dlclosenull
+if (handle)
+  dlclose(handle);
+  }
+
+  template  Fun *getFun(const char *symbol) {
+assert(handle);
+return reinterpret_cast(dlsym(handle, symbol));
+  }
+};
+
+void DLanguage::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(), "D Language",
+CreateInstance);
+}
+
+void DLanguage::Terminate() { PluginManager::UnregisterPlugin(CreateInstance); }
+
+lldb_private::ConstString DLanguage::GetPluginNameStatic() {
+  static ConstString g_name("D");
+  return g_name;
+}
+
+//--
+// PluginInterface protocol
+//--
+lldb_private::ConstString DLanguage::GetPluginName() {
+  return GetPluginNameStatic();
+}
+
+uint32_t DLanguage::GetPluginVersion() { return 1; }
+
+//--
+// Static Functions
+//--
+Language *DLanguage::CreateInstance(lldb::LanguageType language) {
+  switch (language) {
+  case lldb::eLanguageTypeD:
+return new DLanguage();
+  default:
+return nullptr;
+  }
+}
+
+char 

[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-09 Thread Davide Italiano via Phabricator via lldb-commits
davide requested changes to this revision.
davide added a comment.
This revision now requires changes to proceed.

This patch has no testcase. It shouldn't be particularly hard to write one, you 
can take inspiration from the one in `lit/`.

Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D44321: Support demangling for D symbols via dlopen

2018-03-09 Thread Johan Engelen via Phabricator via lldb-commits
johanengelen added inline comments.



Comment at: source/Plugins/Language/D/DLanguage.cpp:1
+//===-- DLanguage.cpp
+//

fix header, and also need to clang-format the file



Comment at: source/Plugins/Language/D/DLanguage.cpp:20
+
+char* lldbd_demangle(size_t length, const char* mangled);
+void d_initialize();

add comment about the purpose of these fwd decls.



Comment at: source/Plugins/Language/D/DLanguage.cpp:24
+// TODO:MOVE
+struct SharedLib{
+  void* handle;

Did you look into using llvm/Support/DynamicLibrary.h ?
That would make the code crossplatform (notably: Windows).



Comment at: source/Plugins/Language/D/DLanguage.cpp:35
+
+  // Return true of `dlopen` succeeded
+  bool open(const char* libraryFile, int flag)

typo: "if"



Comment at: source/Plugins/Language/D/DLanguage.cpp:108
+
+auto fun0=lib2->getFun("d_initialize");
+(*fun0)();

Would it help to initialize druntime using a static module constructor in the 
lldbdplugin dll?
(then you can also do de-init using a static module destructor)



Comment at: source/Plugins/Language/D/DLanguage.h:1
+//===-- DLanguage.h --*- C++ -*-===//
+//

fix header line


Repository:
  rL LLVM

https://reviews.llvm.org/D44321



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits