diff --git a/clang.md b/clang.md index c09f909678c41200391810c67d0b47fa99330e1a..deb12cd58ad9a9137beed28400424507b5277722 100644 --- a/clang.md +++ b/clang.md @@ -813,7 +813,40 @@ We won't cover those details in this document, but here are some useful material ## Debugging, Testing and Analysis -TBD +Writing program is only the first step of the whole software development circle. If you want to write and maintain high-quality software, then you should also know how to debug, test and analyse you program efficiently. + +### Debugging + +You've written a program that complied and ran correctly on the first try. For all other times, there is debugging. + +Novice programmers have a strong tendency to debug everything by inserting print statements throughout the code, but using a debugger is often much more productive. + +[GDB](https://www.sourceware.org/gdb/), also known as GNU Debugger, is a debugger for several languages such as C and C++. It allows you to inspect what the program is doing at a certain point during execution. + +We won't cover the basic usage of GDB here, but you can find a series of tutorials here: + +- [Part 1: Getting started with the debugger](https://developers.redhat.com/blog/2021/04/30/the-gdb-developers-gnu-debugger-tutorial-part-1-getting-started-with-the-debugger#) +- [Part 2: All about debuginfo](https://developers.redhat.com/articles/2022/01/10/gdb-developers-gnu-debugger-tutorial-part-2-all-about-debuginfo#) +- [Part3: Learn how to use breakpoints](https://developers.redhat.com/articles/2022/11/08/introduction-debug-events-learn-how-use-breakpoints#what_is_a_breakpoint_) + +Along with the [GDB-reference-card](https://users.ece.utexas.edu/~adnan/gdb-refcard.pdf). + +### Unit Testing + +There are several unit-testing frameworks you can use: + +- [Google Test](https://github.com/google/googletest) (you might need to write some C++) +- [Unity](https://github.com/ThrowTheSwitch/Unity) +- [CUnit](https://cunit.sourceforge.net/) + +### Dynamic Analysis + +Dynamic analysis is the process of evaluating the program during its execution. It's useful to find runtime bugs such as memory leaks, stack buffer overflow, heap buffer overflow etc. + +You can use these tools to help you diagnose your program: + +- [Sanitizers](https://github.com/google/sanitizers) +- [Valgrind](https://valgrind.org/) ## References