debugging


1. Using assert() Macro:

assert(x > 0);  // Check if x is greater than 0, else terminate with an assertion error message

2. Using std::exception:

try {
    // Code that may throw an exception
} catch (const std::exception& e) {
    std::cerr << "Exception: " << e.what() << std::endl;
}

3. Using std::cerr for Printing Error Messages:

std::cerr << "Error: " << errorMessage << std::endl;

4. Using std::cout for Printing Debug Information:

std::cout << "Debug: " << debugMessage << std::endl;

5. Using std::ofstream for Logging Debug Information:

std::ofstream logFile("debug.log");
logFile << "Debug: " << debugMessage << std::endl;

6. Using GDB (GNU Debugger):

// Set breakpoints at specific lines using `gdb --args ./a.out`
(gdb) break 15

7. Using LLDB (Low Level Debugger):

8. Using Visual Studio Debugger:

9. Using valgrind for Memory Debugging:

10. Using asan (Address Sanitizer):

11. Using msan (Memory Sanitizer):

12. Using ubsan (Undefined Behavior Sanitizer):

13. Using tsan (Thread Sanitizer):

14. Using drd (Data Race Detector):

15. Using gdb with bt Command for Backtrace:

16. Using gdb with p Command for Printing Variables:

17. Using gdb with watch Command for Watching Variables:

18. Using gdb with disassemble Command for Disassembling Instructions:

19. Using gdb with stepi Command for Stepping into Functions:

20. Using gdb with nexti Command for Stepping over Function Calls:

21. Using gdb with finish Command for Running until Function Returns:

22. Using gdb with continue Command for Continuing Execution:

23. Using gdb with list Command for Listing Source Code:

24. Using gdb with info Command for Getting Information:

25. Using gdb with r Command for Running the Program:

26. Using gdb with b Command for Setting Breakpoints:

27. Using gdb with tbreak Command for Setting Temporary Breakpoints:

28. Using gdb with n Command for Stepping to the Next Statement:

29. Using gdb with s Command for Stepping into Functions:

30. Using gdb with until Command for Stepping until a Given Line:

31. Using gdb with watch Command for Watching Variables:

32. Using gdb with print Command for Printing Values:

33. Using gdb with display Command for Displaying Values:

34. Using gdb with set Command for Setting Variables:

35. Using gdb with x Command for Examining Memory:

36. Using gdb with bt Command for Backtracing the Call Stack:

37. Using gdb with info Command for Getting Information:

38. Using gdb with source Command for Reading Source Code:

39. Using gdb with help Command for Getting Help:

40. Using gdb with quit Command for Quitting the Debugger:

41. Using printf() for Simple Debugging:

42. Using cout for Debugging in C++:

43. Using cerr for Error Handling:

44. Using assert() for Assertions:

45. Using throw for Throwing Exceptions:

46. Using try-catch for Catching Exceptions:

47. Using debugger Keyword for Entering Debugger:

48. Using _CrtSetBreakAlloc() for Detecting Memory Leaks:

49. Using _CrtDumpMemoryLeaks() for Dumping Memory Leaks:

50. Using a Custom Debugger: