Tools for testing and debugging memory issues (part 2)
On this page
Clang-14 and debugging symbols
When compiling by hand, you'd include -g to have the compiler write debugging symbols. This is what
is shown in some of the videos presented in this lesson. For
the version of clang++ that we're using (v. 14.0.5), DWARFv5 debug format is used by default.
Unfortunately,some of our tools will not properly read the DWARF5 generated by
clang-14. Therefore, instead of using the -g flag, use -gdwarf-4.
UndefinedBehaviorSanitizer (UBSan)
Valgrind
valgrind the flag --leak-check=full to show
each leak in detail, and --track-origins=yes to have valgrind
track the origin of undefined values. For line-by-line details about
what went wrong, you need to tell clang++ to write the executable
with debugging symbols, which you can do by providing the compiler the
-gdwarf-4 flag. Additional tools
Questions
Answer the following questions with consideration to the material introduced in both Parts 1 and 2 of this lesson.
Q1
QTools for Testing and Debugging Pt2Q1
This question is ungraded.
Which sanitizer is defined to help detect undefined behavior?
Q2
QTools for Testing and Debugging Pt2Q2
This question is ungraded.
A memcheck tool tells you the following:
Total heap usage: 2 allocs, 1 frees, 72,744 bytes
What is this message reporting?
Q3
QTools for Testing and Debugging Pt2Q3
This question is ungraded.
Your program terminates due to a segmentation fault. You have been working with dynamically allocated objects and fear that you may have attempted member access on the nullptr. Which sanitizer should you employ to investigate your suspicion?