Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Ca series of presentations to help a bunch of   brilliant space scientists understand a       brilliant programming language
Debugging
DebuggingIt is the process of finding and removing “bugs”(logical errors) from a program
bluntly put … … debugging is an art
depends on …•Skill of programmer•Complexity of the program•Simplicity of the programming language•Availability of debuggin...
TechniquesPrint / Trace It involves adding a ‘printf’ statement at various locations to inspect the value stored in the va...
DebuggerDebuggers are tools that enablethe programmer to monitor thememory and/or execution of theprogram.
DemonstrationData Display Debugger (DDD)•DDD is a well known C debugger in the Linux platform.•It’s a GUI based front end ...
Demonstration//simple_loop.c                                                              1. Compile the file using#includ...
Demonstration        Data Window                      Control                       PanelSource Code
Control Panel                   Start the programStep program until it reaches       a different source lineStep program, ...
BreakpointA breakpoint informs the debuggerto freeze execution at a chosen line.A programmer can then evaluate allthe vari...
Breakpoint  1. Right click on the line you     wish to set the breakpoint  2. Select ‘Set Breakpoint’
Conditional BreakpointsA breakpoint that informs the debuggerto freeze execution at a chosen linewhen a desired condition ...
Conditional Breakpoint   1. Right click on the new      breakpoint   2. Select ‘Properties’
Conditional Breakpoint1. Set your required   condition in the   ‘Condition’ text box2. Click ‘Apply’
Conditional Breakpoints    //complex_loop.c#include <stdio.h>                                    How do I stop theint main...
Conditional Breakpoints
Conditional Breakpoints//file_read.c                                                                   input.dat#include <...
Conditional Breakpoints
Conditional Breakpoints//file_read.c                                                                   input.dat#include <...
Conditional Breakpoints
Final WordsPrevention is better than cureAlways strive for simplicity in your code. A good measure ofsimplicity lies in th...
what next?  File I/O                      Data types                Standard       & structures                C Library  ...
A man who wants to lead an orchestra   must turn his back on the crowd             - Max Lucado                           ...
Upcoming SlideShare
Loading in …5
×

C ISRO Debugging

721 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

C ISRO Debugging

  1. 1. Ca series of presentations to help a bunch of brilliant space scientists understand a brilliant programming language
  2. 2. Debugging
  3. 3. DebuggingIt is the process of finding and removing “bugs”(logical errors) from a program
  4. 4. bluntly put … … debugging is an art
  5. 5. depends on …•Skill of programmer•Complexity of the program•Simplicity of the programming language•Availability of debugging tools
  6. 6. TechniquesPrint / Trace It involves adding a ‘printf’ statement at various locations to inspect the value stored in the variablesCore dump Analysis Analyzing the memory snapshot of the program after the crash. The operating system dumps the entire contents of the memory related to the program into a core dump file. Used to detect memory related bugs in your program.Execution monitoring Step by step execution of the program to analyze the execution path and change in control or data.
  7. 7. DebuggerDebuggers are tools that enablethe programmer to monitor thememory and/or execution of theprogram.
  8. 8. DemonstrationData Display Debugger (DDD)•DDD is a well known C debugger in the Linux platform.•It’s a GUI based front end for GNU Debugger (gdb) program.
  9. 9. Demonstration//simple_loop.c 1. Compile the file using#include <stdio.h> the –g flag in gccint main(void){ int i = 0; $> gcc –g simple_loop.c printf("Entering Loopn"); for(i=0;i<10;i++) { printf("%d ",i); } 2. Load ‘a.out’ in DDD printf("Exiting Loopn"); return 0; $> ddd a.out &} -g flag stores extra information regarding the program which is required for the debugger
  10. 10. Demonstration Data Window Control PanelSource Code
  11. 11. Control Panel Start the programStep program until it reaches a different source lineStep program, proceeding through subroutine calls Execute until source line reaches greater than current … rest for homework :P
  12. 12. BreakpointA breakpoint informs the debuggerto freeze execution at a chosen line.A programmer can then evaluate allthe variables and stack of theprogram. Demonstration: setting a breakpoint in DDD
  13. 13. Breakpoint 1. Right click on the line you wish to set the breakpoint 2. Select ‘Set Breakpoint’
  14. 14. Conditional BreakpointsA breakpoint that informs the debuggerto freeze execution at a chosen linewhen a desired condition is met . Demonstration: setting a conditional breakpoint in DDD
  15. 15. Conditional Breakpoint 1. Right click on the new breakpoint 2. Select ‘Properties’
  16. 16. Conditional Breakpoint1. Set your required condition in the ‘Condition’ text box2. Click ‘Apply’
  17. 17. Conditional Breakpoints //complex_loop.c#include <stdio.h> How do I stop theint main(void) execution when{ int i = 0; int j = 0; i = 0 int k = 0; for(i = 0; i < 10; i++) j = 10 { for(j = 0; j < 10000; j++) { k = 3000 for(k = 0; k < 10000; k++) { printf("%d ",i+j+k); } } } return 0;}
  18. 18. Conditional Breakpoints
  19. 19. Conditional Breakpoints//file_read.c input.dat#include <stdio.h>#include <string.h> id animalint main(void) 1 CAT{ 2 SHEEP FILE *input_fp = NULL; char buff[255]; 3 WOLF int id = 0; 4 DOG char animal[16]; input_fp = fopen("input.dat","r"); 5 MONKEY 6 EAGLE while(fgets(buff,sizeof(buff)-1,input_fp) != NULL) { 7 MAN sscanf(buff,"%d %s %*[^n]",&id,animal); printf("Animal at pos %d is %sn",id,animal); } fclose(input_fp); return 0;} How do I stop the id = 4 execution when
  20. 20. Conditional Breakpoints
  21. 21. Conditional Breakpoints//file_read.c input.dat#include <stdio.h>#include <string.h> id animalint main(void) 1 CAT{ 2 SHEEP FILE *input_fp = NULL; char buff[255]; 3 WOLF int id = 0; 4 DOG char animal[16]; input_fp = fopen("input.dat","r"); 5 MONKEY 6 EAGLE while(fgets(buff,sizeof(buff)-1,input_fp) != NULL) { 7 MAN sscanf(buff,"%d %s %*[^n]",&id,animal); printf("Animal at pos %d is %sn",id,animal); } fclose(input_fp); return 0;} How do I stop the animal = MAN execution when
  22. 22. Conditional Breakpoints
  23. 23. Final WordsPrevention is better than cureAlways strive for simplicity in your code. A good measure ofsimplicity lies in the number of instructions used to get thejob done. Lesser the better.Less conditional statements (if, else if , else)More repeatable statements (loops, function recursion )Less nested statements (loop in a loop, nested ifs)Learn and be aware of standard library functionsDon’t re-invent the wheel, many open source library areavailable to solve various problems in the scientific domain
  24. 24. what next? File I/O Data types Standard & structures C Library Pointers & Memory Allocation Debugging Macro and VersionPre Processor Management Multi file projects
  25. 25. A man who wants to lead an orchestra must turn his back on the crowd - Max Lucado thank you

×