raisimTech / raisimLib

Visit www.raisim.com
http://www.raisim.com
Other
338 stars 91 forks source link

Valgrind usage help #532

Closed hilario closed 7 months ago

hilario commented 8 months ago

Could you please indicate how to run Valgrind with a program linked to Raisim?

When I run Valgrind on the speed_test example the output is:

==24959== Memcheck, a memory error detector
==24959== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==24959== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==24959== Command: ./speed_test
==24959== 
vex amd64->IR: unhandled instruction bytes: 0xC5 0x79 0xD6 0xC5 0xC4 0xE2 0xF9 0xBD 0xF9 0xC4
vex amd64->IR:   REX=0 REX.W=0 REX.R=1 REX.X=0 REX.B=0
vex amd64->IR:   VEX=1 VEX.L=0 VEX.nVVVV=0x0 ESC=0F
vex amd64->IR:   PFX.66=1 PFX.F2=0 PFX.F3=0
==24959== valgrind: Unrecognised instruction at address 0x4894cdb.
==24959==    at 0x4894CDB: raisim::ArticulatedSystem::articulatedBodyAlgorithm(raisim::Mat<3ul, 1ul> const&, double) (in /home/hilario/raisimLib/raisim/linux/lib/libraisim.so.1.1.7)
==24959==    by 0x489E4FE: raisim::ArticulatedSystem::preContactSolverUpdate2(raisim::Mat<3ul, 1ul> const&, double, std::vector<raisim::contact::Single3DContactProblem, raisim::AlignedAllocator<raisim::contact::Single3DContactProblem, 32ul> >&) (in /home/hilario/raisimLib/raisim/linux/lib/libraisim.so.1.1.7)
==24959==    by 0x48F29A7: raisim::World::integrate2() (in /home/hilario/raisimLib/raisim/linux/lib/libraisim.so.1.1.7)
==24959==    by 0x10C6A4: main (in /home/hilario/raisimLib/build/examples/speed_test)
==24959== Your program just tried to execute an instruction that Valgrind
==24959== did not recognise.  There are two possible reasons for this.
==24959== 1. Your program has a bug and erroneously jumped to a non-code
==24959==    location.  If you are running Memcheck and you just saw a
==24959==    warning about a bad jump, it's probably your program's fault.
==24959== 2. The instruction is legitimate but Valgrind doesn't handle it,
==24959==    i.e. it's Valgrind's fault.  If you think this is the case or
==24959==    you are not sure, please let us know and we'll try to fix it.
==24959== Either way, Valgrind will now raise a SIGILL signal which will
==24959== probably kill your program.
==24959== 
==24959== Process terminating with default action of signal 4 (SIGILL)
==24959==  Illegal opcode at address 0x4894CDB
==24959==    at 0x4894CDB: raisim::ArticulatedSystem::articulatedBodyAlgorithm(raisim::Mat<3ul, 1ul> const&, double) (in /home/hilario/raisimLib/raisim/linux/lib/libraisim.so.1.1.7)
==24959==    by 0x489E4FE: raisim::ArticulatedSystem::preContactSolverUpdate2(raisim::Mat<3ul, 1ul> const&, double, std::vector<raisim::contact::Single3DContactProblem, raisim::AlignedAllocator<raisim::contact::Single3DContactProblem, 32ul> >&) (in /home/hilario/raisimLib/raisim/linux/lib/libraisim.so.1.1.7)
==24959==    by 0x48F29A7: raisim::World::integrate2() (in /home/hilario/raisimLib/raisim/linux/lib/libraisim.so.1.1.7)
==24959==    by 0x10C6A4: main (in /home/hilario/raisimLib/build/examples/speed_test)
==24959== 
==24959== HEAP SUMMARY:
==24959==     in use at exit: 244,942 bytes in 345 blocks
==24959==   total heap usage: 4,163 allocs, 3,818 frees, 962,864 bytes allocated
==24959== 
==24959== LEAK SUMMARY:
==24959==    definitely lost: 0 bytes in 0 blocks
==24959==    indirectly lost: 0 bytes in 0 blocks
==24959==      possibly lost: 0 bytes in 0 blocks
==24959==    still reachable: 244,942 bytes in 345 blocks
==24959==         suppressed: 0 bytes in 0 blocks
==24959== Rerun with --leak-check=full to see details of leaked memory
==24959== 
==24959== For lists of detected and suppressed errors, rerun with: -s
==24959== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Illegal instruction (core dumped)

The operating system is: Ubuntu 20.04.6 LTS CPU: Intel® Core™ i7-9850H CPU @ 2.60GHz × 12 Valgrind version: valgrind-3.15.0

The same thing happens downloading the latest version of Valgrind: 3.22.0

Thank you!

jhwangbo commented 8 months ago

Did you run the example as is or did you modify the executable? You don't need anything special for running valgrind for raisim. Many raisim functions are missing symbols so you won't see them but you don't need them to debug your code.

hilario commented 8 months ago

We need Valgrind to profile our code that links with raisim, we faced that error in the process and saw that it can be reproduced with the unmodified speed_test example, discarding that the problem comes from our side of the code.

jhwangbo commented 8 months ago

Can you run the examples without any issues?

hilario commented 8 months ago

I can execute the examples and our linked code with no problems.

jhwangbo commented 8 months ago

I could reproduce this on my machine. I'll try to figure out the issue and get back to you soon

jhwangbo commented 7 months ago

Hi Hilario. Sorry for getting back to you late. This issue is due to a bug in Valgrind. More specifically, valgrind doesn't have an implementation for some instructions used in the previous version.

I included the debug version in linux. This is built without uncommon instructions so valgrind can debug it. It works on my machine. Let me know if it works on yours

hilario commented 6 months ago

Hi Jemin

Thank you for the support, I have downloaded the latest version to check the fix, but now I get this compilation error:

/usr/bin/ld: /home/hilario/raisimLib/raisim/linux/lib/libraisimd.so.1.1.7: undefined reference to std::ios_base_library_init()@GLIBCXX_3.4.32' /usr/bin/ld: /home/hilario/raisimLib/raisim/linux/lib/libraisimd.so.1.1.7: undefined reference tostd::__throw_bad_array_new_length()@GLIBCXX_3.4.29'

My system is the same as described before.

jhwangbo commented 6 months ago

My bad. I accidently upgraded my libc++ version somewhere. I'll upload a fix very soon

jhwangbo commented 6 months ago

can you pull and test?

jhwangbo commented 6 months ago

Hi Hilario, I did some tests on the GLIBCXX issue and switched the GLIBCXX version back to the newer one (GLIBCXX_3.4.32). You can easily get it by

sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test sudo apt install -y g++-11

The old version somehow doesn't work with the newer ones.

hilario commented 6 months ago

I have tested the debug version with Valgrind and it works, I will try the new glibc version and let you know.

Thank you!

jhwangbo commented 6 months ago

if it works, you don't have to change the glibc version. I lowered the glibc version again in the last commit so it should work for native 20.04. The issue is whenever I install g++-11, it updates the glibc.Now I will try not to install a newer glibc on my pc...