Debugging

Logs / Print Statements

A typical debugging technique is to make use of prints and/or logging entries. This is no more than adding debug lines in the preferred programming language:

C++ Print / Logging
printf("A log message: %d - %s\n", num, msg);
std::cout << "A log message: " << num << " - " << msg << std::endl;
ACS_SHORT_LOG((LM_INFO, "A log message %d - %s", num, msg));
Java Print / Logging
System.out.println("A log message: " + num +" - " + msg);
m_logger.info("A log message: " + num +" - " + msg);
C++ Print / Logging
print("A log message: %d - %s\n" % (num, msg))
print("A log message: " + str(num) + " - " + msg)
print("A log message: ", num, msg)
logger.logInfo("A log message: %d - %s" % (num, msg)
logger.logInfo("A log message: " + str(num) + " - " + msg)

C++

GDB

A more advanced debugging technique is the use of gdb. The use is the same as with a normal process; it could be used with a core dump, attaching to a running (client/container) process or start your client/container with appropriate parameters.

Opening a core dump with GDB
> gdb maciContainer core.gas03.maciContainer.31215
#Or
> gdb -c core.gas03.maciContainer.31215 maciContainer
Attaching to a running process
> ps aux |grep maciContainer
almamgr   106852  1.8  0.2 1159516 43512 pts/2   Sl+  01:09   0:00 maciContainer bilboContainer -ORBEndpoint iiop://127.0.1.1:4002 -m corbaloc::127.0.1.1:3000/Manager
> gdb -p 106852
#Or
> gdb -p $(ps aux |grep maciContainer | grep bilboContainer | awk '{print $2}')
Start a container in GDB
#It is usually better to inspect the parameters used by the container started by ACS / ACS Daemons
> ps aux |grep maciContainer |grep bilboContainer
almamgr   106852  1.8  0.2 1159516 43512 pts/2   Sl+  01:09   0:00 maciContainer bilboContainer -ORBEndpoint iiop://127.0.1.1:4002 -m corbaloc::127.0.1.1:3000/Manager

# We then simply copy the part starting from maciContainer:
> gdb --args maciContainer bilboContainer -ORBEndpoint iiop://127.0.1.1:4002 -m corbaloc::127.0.1.1:3000/Manager
(gdb) r

Valgrind

Valgrind is used in a very similar fashion to the GDB command to start a container:

Simple Valgrind command
#It is usually better to inspect the parameters used by the container started by ACS / ACS Daemons
> ps aux |grep maciContainer |grep bilboContainer
almamgr   106852  1.8  0.2 1159516 43512 pts/2   Sl+  01:09   0:00 maciContainer bilboContainer -ORBEndpoint iiop://127.0.1.1:4002 -m corbaloc::127.0.1.1:3000/Manager

# We then simply copy the part starting from maciContainer:
valgrind maciContainer bilboContainer -ORBEndpoint iiop://127.0.1.1:4002 -m corbaloc::127.0.1.1:3000/Manager

Of course it would make more sense to define what we actually expect from Valgrind like finding memory leaks:

Detailed Valgrind command
valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --show-mismatched-frees=yes maciContainer bilboContainer -ORBEndpoint iiop://127.0.1.1:4002 -m corbaloc::127.0.1.1:3000/Manager

Components load and unload their definitions, leading to unknown pieces of code being analyzed sometimes:

==115999==    by 0x171DB80D: ???
==115999==    by 0x171EA621: ???
==115999==    by 0x1C1469AD: ???

This can easily be fixed if you know the libraries that you're interested in using LD_PRELOAD:

LD_PRELOAD="$ACSROOT/lib/libacstimer.so $ACSROOT/lib/libacsclock.so" valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --show-mismatched-frees=yes maciContainer bilboContainer -ORBEndpoint iiop://127.0.1.1:4002 -m corbaloc::127.0.1.1:3000/Manager

Or configure them in autoload:

CDB/MACI/Containers/bilboContainer/bilboContainer.xml
...
  <Autoload>
    <cdb:e string="baci" />
    <cdb:e string="acstimer" />
    <cdb:e string="acsclock" />
  </Autoload>
...

Another alternative if you happen to have a new-enough version of Valgrind (after 2018), is to use the '--keep-debuginfo=yes' flag:

valgrind --tool=memcheck --keep-debuginfo=yes --leak-check=full --show-leak-kinds=all --show-mismatched-frees=yes maciContainer bilboContainer -ORBEndpoint iiop://127.0.1.1:4002 -m corbaloc::127.0.1.1:3000/Manager

In the 3 scenarios you will get this instead:

==116118==    by 0xBD6980D: baci::CharacteristicModelImpl::CharacteristicModelImpl(ACE_String_Base<char> const&, maci::ContainerServices*) (baciCharacteristicModelImpl.cpp:55)
==116118==    by 0xBD78621: baci::CharacteristicComponentImpl::CharacteristicComponentImpl(ACE_String_Base<char> const&, maci::ContainerServices*, bool) (baciCharacteristicComponentImpl.cpp:54)
==116118==    by 0x50859AD: ClockImpl::ClockImpl(ACE_String_Base<char> const&, maci::ContainerServices*) (acstimeClockImpl.cpp:34)



  • No labels