SlideShare a Scribd company logo
C
a series of presentations to help a bunch of
   brilliant space scientists understand a
       brilliant programming language
Debugging
Debugging
It 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 debugging tools
Techniques
Print / Trace
 It involves adding a ‘printf’ statement at various locations to
 inspect the value stored in the variables


Core 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.
Debugger

Debuggers are tools that enable
the programmer to monitor the
memory and/or execution of the
program.
Demonstration
Data 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.
Demonstration
//simple_loop.c
                                                              1. Compile the file using
#include <stdio.h>                                            the –g flag in gcc
int 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
Demonstration


        Data Window


                      Control
                       Panel




Source Code
Control Panel

                   Start the program


Step program until it reaches
       a different source line



Step program, proceeding
  through subroutine calls



               Execute until source line
           reaches greater than current


                                 … rest for homework :P
Breakpoint

A breakpoint informs the debugger
to freeze execution at a chosen line.
A programmer can then evaluate all
the variables and stack of the
program.


   Demonstration: setting a breakpoint in DDD
Breakpoint




  1. Right click on the line you
     wish to set the breakpoint
  2. Select ‘Set Breakpoint’
Conditional Breakpoints


A breakpoint that informs the debugger
to freeze execution at a chosen line
when a desired condition is met .




 Demonstration: setting a conditional breakpoint in DDD
Conditional Breakpoint



   1. Right click on the new
      breakpoint
   2. Select ‘Properties’
Conditional Breakpoint

1. Set your required
   condition in the
   ‘Condition’ text box
2. Click ‘Apply’
Conditional Breakpoints
    //complex_loop.c
#include <stdio.h>                                    How do I stop the
int 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;
}
Conditional Breakpoints
Conditional Breakpoints
//file_read.c
                                                                   input.dat
#include <stdio.h>
#include <string.h>                                                id   animal
int 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
Conditional Breakpoints
Conditional Breakpoints
//file_read.c
                                                                   input.dat
#include <stdio.h>
#include <string.h>                                                id   animal
int 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
Conditional Breakpoints
Final Words
Prevention is better than cure

Always strive for simplicity in your code. A good measure of
simplicity lies in the number of instructions used to get the
job 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 functions

Don’t re-invent the wheel, many open source library are
available to solve various problems in the scientific domain
what next?
  File I/O                      Data types
                Standard       & structures
                C Library

     Pointers & Memory
          Allocation          Debugging


 Macro and                      Version
Pre Processor                 Management

                 Multi file
                 projects
A man who wants to lead an orchestra
   must turn his back on the crowd
             - Max Lucado




                            thank you

More Related Content

ODP
OpenGurukul : Language : PHP
KEY
Yapcasia2011 - Hello Embed Perl
PDF
Hachiojipm11
PDF
3 1. preprocessor, math, stdlib
PPT
Constructor,destructors cpp
PPT
Unit 5
PDF
Boost.Python - domesticating the snake
ODP
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : PHP
Yapcasia2011 - Hello Embed Perl
Hachiojipm11
3 1. preprocessor, math, stdlib
Constructor,destructors cpp
Unit 5
Boost.Python - domesticating the snake
OpenGurukul : Language : C++ Programming

What's hot (20)

PDF
C&cpu
PDF
Threads and Callbacks for Embedded Python
PDF
Just-In-Time Compiler in PHP 8
PDF
Phpをいじり倒す10の方法
PDF
Windbg랑 친해지기
PDF
PHP7 is coming
PDF
Quick tour of PHP from inside
PDF
C++ idioms by example (Nov 2008)
ODP
Отладка в GDB
PPT
Unit 4
PDF
OSDC.TW - Gutscript for PHP haters
PDF
What's new in PHP 8.0?
PPTX
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
PDF
Static Optimization of PHP bytecode (PHPSC 2017)
PPT
Unit 6
PPTX
PDF
Nikita Popov "What’s new in PHP 8.0?"
PDF
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
PDF
Pydiomatic
C&cpu
Threads and Callbacks for Embedded Python
Just-In-Time Compiler in PHP 8
Phpをいじり倒す10の方法
Windbg랑 친해지기
PHP7 is coming
Quick tour of PHP from inside
C++ idioms by example (Nov 2008)
Отладка в GDB
Unit 4
OSDC.TW - Gutscript for PHP haters
What's new in PHP 8.0?
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
Static Optimization of PHP bytecode (PHPSC 2017)
Unit 6
Nikita Popov "What’s new in PHP 8.0?"
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
Pydiomatic
Ad

Similar to C ISRO Debugging (20)

PDF
Tdd with python unittest for embedded c
PDF
Python-GTK
PPT
PPT
Csdfsadf
PPTX
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
PDF
Python idiomatico
PPT
C Tutorials
PDF
Python GTK (Hacking Camp)
PPTX
luckfuckfunctioneekefkfejewnfiwnfnenf.pptx
PDF
Computer science-2010-cbse-question-paper
PDF
Cluj.py Meetup: Extending Python in C
PDF
C Programming Tutorial - www.infomtec.com
PPT
Linux_C_LabBasics.ppt
PPT
C tutorial
PPT
C tutorial
PPT
C tutorial
PPT
PDF
C++aptitude questions and answers
PDF
7 functions
Tdd with python unittest for embedded c
Python-GTK
Csdfsadf
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
Python idiomatico
C Tutorials
Python GTK (Hacking Camp)
luckfuckfunctioneekefkfejewnfiwnfnenf.pptx
Computer science-2010-cbse-question-paper
Cluj.py Meetup: Extending Python in C
C Programming Tutorial - www.infomtec.com
Linux_C_LabBasics.ppt
C tutorial
C tutorial
C tutorial
C++aptitude questions and answers
7 functions
Ad

Recently uploaded (20)

PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Advanced IT Governance
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Machine learning based COVID-19 study performance prediction
PPT
Teaching material agriculture food technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Dropbox Q2 2025 Financial Results & Investor Presentation
Reach Out and Touch Someone: Haptics and Empathic Computing
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Understanding_Digital_Forensics_Presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Chapter 3 Spatial Domain Image Processing.pdf
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Advanced IT Governance
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
The AUB Centre for AI in Media Proposal.docx
Machine learning based COVID-19 study performance prediction
Teaching material agriculture food technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Mobile App Security Testing_ A Comprehensive Guide.pdf

C ISRO Debugging

  • 1. C a series of presentations to help a bunch of brilliant space scientists understand a brilliant programming language
  • 3. Debugging It is the process of finding and removing “bugs” (logical errors) from a program
  • 4. bluntly put … … debugging is an art
  • 5. depends on … •Skill of programmer •Complexity of the program •Simplicity of the programming language •Availability of debugging tools
  • 6. Techniques Print / Trace It involves adding a ‘printf’ statement at various locations to inspect the value stored in the variables Core 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. Debugger Debuggers are tools that enable the programmer to monitor the memory and/or execution of the program.
  • 8. Demonstration Data 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. Demonstration //simple_loop.c 1. Compile the file using #include <stdio.h> the –g flag in gcc int 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. Demonstration Data Window Control Panel Source Code
  • 11. Control Panel Start the program Step program until it reaches a different source line Step program, proceeding through subroutine calls Execute until source line reaches greater than current … rest for homework :P
  • 12. Breakpoint A breakpoint informs the debugger to freeze execution at a chosen line. A programmer can then evaluate all the variables and stack of the program. Demonstration: setting a breakpoint in DDD
  • 13. Breakpoint 1. Right click on the line you wish to set the breakpoint 2. Select ‘Set Breakpoint’
  • 14. Conditional Breakpoints A breakpoint that informs the debugger to freeze execution at a chosen line when a desired condition is met . Demonstration: setting a conditional breakpoint in DDD
  • 15. Conditional Breakpoint 1. Right click on the new breakpoint 2. Select ‘Properties’
  • 16. Conditional Breakpoint 1. Set your required condition in the ‘Condition’ text box 2. Click ‘Apply’
  • 17. Conditional Breakpoints //complex_loop.c #include <stdio.h> How do I stop the int 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; }
  • 19. Conditional Breakpoints //file_read.c input.dat #include <stdio.h> #include <string.h> id animal int 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
  • 21. Conditional Breakpoints //file_read.c input.dat #include <stdio.h> #include <string.h> id animal int 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
  • 23. Final Words Prevention is better than cure Always strive for simplicity in your code. A good measure of simplicity lies in the number of instructions used to get the job 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 functions Don’t re-invent the wheel, many open source library are available to solve various problems in the scientific domain
  • 24. what next? File I/O Data types Standard & structures C Library Pointers & Memory Allocation Debugging Macro and Version Pre Processor Management Multi file projects
  • 25. A man who wants to lead an orchestra must turn his back on the crowd - Max Lucado thank you