Samsung / netcoredbg

NetCoreDbg is a managed code debugger with GDB/MI, VSCode DAP and CLI interfaces for CoreCLR.
MIT License
836 stars 103 forks source link

Tests fail with error "Unable to load /home/jacob/dev/netcoredbg/build/src/libdbgshim.so" #136

Closed lem102 closed 1 year ago

lem102 commented 1 year ago

Hey all,

When I try to run the tests using NETCOREDBG=../build/src/netcoredbg bash run_tests.sh, all the tests fail, displaying the following for each test project:

Unable to load /home/jacob/dev/netcoredbg/build/src/libdbgshim.so
TestRunner: netcoredbg is dead with exit code 1.
MSBuild version 17.6.3+07e294721 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  NetcoreDbgTest -> /home/jacob/dev/netcoredbg/test-suite/NetcoreDbgTest/bin/Debug/netcoreapp3.1/NetcoreDbgTest.dll
  MITestBreakpoint -> /home/jacob/dev/netcoredbg/test-suite/MITestBreakpoint/bin/Debug/netcoreapp3.1/MITestBreakpoint.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:06.77

Any assistance gratefully received :)

gbalykov commented 1 year ago

Does /home/jacob/dev/netcoredbg/build/src/libdbgshim.so exist?

lem102 commented 1 year ago

yes

~/dev/netcoredbg/build/src$ ls
bin
CMakeFiles
cmake_install.cmake
errormessage.cpp
errormessage.h
generrmsg
libcorguids.a
libdbgshim.so
...
viewizard commented 1 year ago

Unable to load /home/jacob/dev/netcoredbg/build/src/libdbgshim.so mean dlopen(RTLD_GLOBAL | RTLD_NOW) failed. Make sure this libdbgshim.so built for proper arch, for example, you could test this by execute in terminal file libdbgshim.so (could be Microsoft.Diagnostics.DbgShim nuget download issue) Another idea - try with full path instead of relative in "NETCOREDBG=../build/src/netcoredbg"

lem102 commented 1 year ago

Using a full path does not help.

file libdbgshim.so gives me

~/dev/netcoredbg/build/src$ file libdbgshim.so 
libdbgshim.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0a4aa7b675186f809b6862413ff6ad78af12c611, not stripped

This laptop's architecture is x86_64 so that looks ok to me.

Is there some way I can get a more detailed error explaining the problem with dlopen(RTLD_GLOBAL | RTLD_NOW)?

viewizard commented 1 year ago

I believe the only way is change code in https://github.com/Samsung/netcoredbg/blob/bac8ea845dc5484218b88ecf015abf81e6ef95d2/src/utils/dynlibs_unix.cpp#L24-L27

dlopen don't return error code and don't change errno https://man7.org/linux/man-pages/man3/dlopen.3.html the only way is call ::dlopen(path.c_str(), RTLD_GLOBAL | RTLD_NOW) and right after this call add code with dlerror that will " ,,, returns a human-readable, null-terminated string describing the most recent error that occurred from a call to one of the functions in the dlopen API ..." https://man7.org/linux/man-pages/man3/dlerror.3.html. Something like:

DLHandle DLOpen(const std::string &path)
{
    void *tmp = ::dlopen(path.c_str(), RTLD_GLOBAL | RTLD_NOW);
    if (tmp == NULL)
    {
        char *err = dlerror();
        if (err != NULL)
            fprintf(stderr, "dlerror: %s\n", err);
        else
            fprintf(stderr, "dlopen() failed, but dlerror() return NULL\n");
    }
    return reinterpret_cast<DLHandle>(tmp);
}
lem102 commented 1 year ago

Thank you, using that code I get this:

dlerror: libstdc++.so.6: cannot open shared object file: No such file or directory

I don't know much about c/c++, does this indicate I am missing some library?

viewizard commented 1 year ago

I am sure you have libstdc++.so in your system, but some old version (with previous ABI). Looks like libdbgshim.so from Microsoft.Diagnostics.DbgShim nuget was built by MS with another libstdc++.so (probably newer version). You could upgrade your system (you probably need some new version of libstdc++) or rebuild libdbgshim.so that is part of https://github.com/dotnet/diagnostics now (https://github.com/dotnet/diagnostics/tree/main/src/dbgshim).

viewizard commented 1 year ago

And one more option, in case you have installed .NET SDK 6.0 or older, you could use libdbgshim.so from it. Just find it with find /.net_location -name libdbgshim.so and copy close to debugger. Till .NET SDK 7.0 release, libdbgshim.so was shipped with SDK itself.

lem102 commented 1 year ago

The library was on my system, I needed to update my LD_LIBRARY_PATH env variable, like so:

~/dev/netcoredbg/test-suite$ LD_LIBRARY_PATH=/nix/store/6plx60y4x4q2lfp6n7190kaihyxr7m1w-gcc-11.3.0-lib/lib/:$LD_LIBRARY_PATH NETCOREDBG=/home/jacob/dev/netcoredbg/build/src/netcoredbg ./run_tests.sh

After running this, I get:

Total tests: 62. Passed: 62. Failed: 0.

Thanks all for the help :grin: