Cling: Possibility debug cling scripts using Visual studio, take 2

Hi !

I’ve briefly analyzed cling code, and apparently it’s huge, and to my best understanding cling “interprets” code using snipet by snipet approach, not possible to compile to .dll.
Clang in a turn should be mostly compatible with Visual studio, see following link:
https://clang.llvm.org/docs/MSVCCompatibility.html
But definitely .dll + .pdb files are needed for this.

It’s also possible that I need a clang, not cling if I want to debug the code. Wondering now if it’s possible to use clang as a compiler service (e.g. .dll).

Btw - in Visual studio I can see already C++ modules support on experimental level (haven’t yet tried them). Does cling / clang has support for C++ modules ?

Hi!

Yes clang has C++ Modules support. You can learn more here: https://clang.llvm.org/docs/Modules.html

Cling as a wrapper of clang, has this support but for the moment it is a little trickier to enable. There is a document describing the current state of C++ Modules in ROOT here: https://github.com/root-project/root/blob/master/README/README.CXXMODULES.md

Best, Vassil

Hi,

The only possibility I see is to build a .dll yourself. And indeed, that would be very nice to be able to debug jitted code with Visual Studio…

Cheers, Bertrand.

Actually debugging is possible with Runtime Compiled C++ sample code -

I have tried to upgrade to vs2017 and it actually work.

I plan to pick up that environment and will try to upgrade it - my idea is to have some sort of Visual studio extension for autorunning C++ scripts, and I’m analyzing bit deeper what and how needs to be done for it.

If anyone is interested in help me out in this or beta test new VS extension, send me mail to tapika-at-yahoo.com.

C++ Modules on experimental level is supported on vs2017, 15.9.3.

C++ Modules can be linked as a static libraries, but not as .dll’s. C++ modules are .ifc files, which includes binary serialized form of C++ header (*.h) files, but not implementation. Implementation is supplied in static libraries.

On forum there is mentioned ifc.exe command line tool for manipulating .ifc files, but unfortunately it does not work at all.

There is no documentation on how they plan to export classes over .dll boundary. __declspec(dllexport) can be used, but it’s ignored by compiler.

To make your own modules - you must have static library with special compiler flag “/module:export”.

For using or making your own c++ modules you must use as “C++ Language Standard” as “ISO C++ Latest Draft Standard (/std:c++latest)” and “Enable C++ Modules Support (experimental)” to “Yes (/experimental:module)”.

Intellisense gives some errors (not manifested by compiler) with your own c++ modules.

To use standard c++ modules even standard cout gives compiler error, which cannot be disabled except with

#pragma warning(disable:4996)

(This has something to do with special define handling in c++ modules).

To use your own c++ module you need to use

/module:reference “<path to .ifc file>”

from compiler flags and also link static library itself.

Go to definition and intellisense does not work for functions in system c++ modules. Go to definition works only if your solution includes project from where .ifc was compiled from - but go to definition works without header files - so jumping directly to implementation in .cpp file. (No header files in that sense).

Debugging / step in in C++ modules seems to be working ok.

.ifc file format seems to be binary serialization of c++ type information. It’s analogue of clang abstract syntax tree (AST), but on Microsoft they tried to follow ideas of Gabriel Dos Reis and Bjarne Stroustrup -

A Principled, Complete, and Efficient Representation of C++

http://www.stroustrup.com/gdr-bs-macis09.pdf

There also exists early prototype of IPR Internal Program Representation in here:

Compiler-neutral Internal Program Representation for C++

https://github.com/GabrielDosReis/ipr

But it does not gives a sample of binary serialization / deserialization.

I’ve queried about IPR / IFC parsers from multiple places but did not receive any reply yet.

Related articles:

C++ Modules in VS 2015 Update 1

https://blogs.msdn.microsoft.com/vcblog/2015/12/03/c-modules-in-vs-2015-update-1/#comment-896805

Using C++ Modules in Visual Studio 2017

https://blogs.msdn.microsoft.com/vcblog/2017/05/05/cpp-modules-in-visual-studio-2017/

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.