Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I retrieve the source code of the library packaged with Conan package manager to be able to debug in it?

Typically Conan package contains only build artifacts like *.dll, *.lib, *.pdb, *.so, *.a, *.dylib files as well headers of given C or C++ library. However sometimes when you debugging your code consuming the library is very useful to be able to step into the library code to look what happens inside. For example to determine when having some problem whether this is because of incorrect use of the library or because of bug in it.

  1. Is it possible alongside package which you consume to retrieve the source code from which it is build to be able to debug in it?
  2. If this is not possible for arbitrary package whether it is possible to create such package by yourself?
like image 445
bobeff Avatar asked Aug 05 '17 18:08

bobeff


People also ask

What does conan package manager do?

Conan is a MIT-licensed, Open Source package manager for C and C++ development, allowing development teams to easily and efficiently manage their packages and dependencies across platforms and build systems.

Where does conan install libraries?

You can add the libraries' folders to the path (LD_LIBRARY_PATH environment variable in Linux, DYLD_LIBRARY_PATH in OSX, or system PATH in Windows), or copy those shared libraries to some system folder where they can be found by the OS.

How do I use conan package?

Create a build directory with mkdir build , and cd build . Run conan install , passing the directory where your conanfile. txt is, to download and install dependencies and generate the conanbuildinfo. cmake used by CMakeLists.


1 Answers

There are two strategies that might work to debug dependencies:

  • Forcing it to build from sources, with the --build=PkgName argument. When you build from sources the package, depending on the build system, it is possible that the binary artifacts reference the temporary build folder where the package was built, and then be able to find them and use the to debug. This strategy can work for third party packages, even when they do not consider debug.
  • If you are creating the packages yourself, and you want to be able to directly debug the binary artifact, without re-building it from source, then the correct way would be to package the sources too. If the debugger needs some help to locate those sources, then it should be used.

With gdb you could do something like

def build(self):
    cmake = CMake(self.settings)
    gcc_dbg_src = ""
    if self.settings.compiler == "gcc" and self.settings.build_type == "Debug":
        gcc_dbg_src =  ' -DCMAKE_CXX_FLAGS="-fdebug-prefix-map=%s/hello=src"' % os.getcwd()
    self.run('cmake hello %s %s' % (cmake.command_line, gcc_dbg_src))
    self.run("cmake --build . %s" % cmake.build_config)

def package(self):
    self.copy("*.h", dst="include", src="hello")
    if self.settings.build_type == "Debug":
        self.copy("*.cpp", dst="src", src="hello")
    self.copy("*.lib", dst="lib", keep_path=False)
    self.copy("*.a", dst="lib", keep_path=False)

To make sure that you compile with the right flags, and also that the source files are packaged too. Then, in the consumer side, you might want to imports the .cpp files, so the gdb debugger can find them besides the binary being debug, or play with your debugger path to add the package folder.

In Windows, with Visual Studio, you probably want to package the .pdb files

like image 93
drodri Avatar answered Oct 22 '22 12:10

drodri