SlideShare ist ein Scribd-Unternehmen logo
1 von 25
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

Weitere Àhnliche Inhalte

Was ist angesagt?

Threads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonThreads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonYi-Lung Tsai
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Nikita Popov
 
Phpをいじり怒す10たæ–čæł•
Phpをいじり怒す10たæ–čæł•Phpをいじり怒す10たæ–čæł•
Phpをいじり怒す10たæ–čæł•Moriyoshi Koizumi
 
Windbg랑 ìčœí•Žì§€êž°
Windbg랑 ìčœí•Žì§€êž°Windbg랑 ìčœí•Žì§€êž°
Windbg랑 ìčœí•Žì§€êž°Ji Hun Kim
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is comingjulien pauli
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from insidejulien pauli
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)Olve Maudal
 
ОтлаЎĐșĐ° ĐČ GDB
ОтлаЎĐșĐ° ĐČ GDBОтлаЎĐșĐ° ĐČ GDB
ОтлаЎĐșĐ° ĐČ GDBAnthony Shoumikhin
 
Unit 4
Unit 4Unit 4
Unit 4siddr
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersLin Yo-An
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?Nikita Popov
 
àžŸàž±àž‡àžàčŒàžŠàž±àčˆàž™àžąàčˆàž­àžąàčàž„àž°àč‚àž›àžŁàčàžàžŁàžĄàžĄàžČàž•àžŁàžàžČàž™ àžĄ. 6 1
àžŸàž±àž‡àžàčŒàžŠàž±àčˆàž™àžąàčˆàž­àžąàčàž„àž°àč‚àž›àžŁàčàžàžŁàžĄàžĄàžČàž•àžŁàžàžČàž™ àžĄ. 6  1àžŸàž±àž‡àžàčŒàžŠàž±àčˆàž™àžąàčˆàž­àžąàčàž„àž°àč‚àž›àžŁàčàžàžŁàžĄàžĄàžČàž•àžŁàžàžČàž™ àžĄ. 6  1
àžŸàž±àž‡àžàčŒàžŠàž±àčˆàž™àžąàčˆàž­àžąàčàž„àž°àč‚àž›àžŁàčàžàžŁàžĄàžĄàžČàž•àžŁàžàžČàž™ àžĄ. 6 1Little Tukta Lita
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Nikita Popov
 
Unit 6
Unit 6Unit 6
Unit 6siddr
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPGuilherme Blanco
 
Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 

Was ist angesagt? (20)

C&cpu
C&cpuC&cpu
C&cpu
 
Threads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonThreads and Callbacks for Embedded Python
Threads and Callbacks for Embedded Python
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
Phpをいじり怒す10たæ–čæł•
Phpをいじり怒す10たæ–čæł•Phpをいじり怒す10たæ–čæł•
Phpをいじり怒す10たæ–čæł•
 
Usp
UspUsp
Usp
 
Windbg랑 ìčœí•Žì§€êž°
Windbg랑 ìčœí•Žì§€êž°Windbg랑 ìčœí•Žì§€êž°
Windbg랑 ìčœí•Žì§€êž°
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
 
ОтлаЎĐșĐ° ĐČ GDB
ОтлаЎĐșĐ° ĐČ GDBОтлаЎĐșĐ° ĐČ GDB
ОтлаЎĐșĐ° ĐČ GDB
 
Unit 4
Unit 4Unit 4
Unit 4
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
àžŸàž±àž‡àžàčŒàžŠàž±àčˆàž™àžąàčˆàž­àžąàčàž„àž°àč‚àž›àžŁàčàžàžŁàžĄàžĄàžČàž•àžŁàžàžČàž™ àžĄ. 6 1
àžŸàž±àž‡àžàčŒàžŠàž±àčˆàž™àžąàčˆàž­àžąàčàž„àž°àč‚àž›àžŁàčàžàžŁàžĄàžĄàžČàž•àžŁàžàžČàž™ àžĄ. 6  1àžŸàž±àž‡àžàčŒàžŠàž±àčˆàž™àžąàčˆàž­àžąàčàž„àž°àč‚àž›àžŁàčàžàžŁàžĄàžĄàžČàž•àžŁàžàžČàž™ àžĄ. 6  1
àžŸàž±àž‡àžàčŒàžŠàž±àčˆàž™àžąàčˆàž­àžąàčàž„àž°àč‚àž›àžŁàčàžàžŁàžĄàžĄàžČàž•àžŁàžàžČàž™ àžĄ. 6 1
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 
Unit 6
Unit 6Unit 6
Unit 6
 
NIO and NIO2
NIO and NIO2NIO and NIO2
NIO and NIO2
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 

Ähnlich wie C ISRO Debugging

Tdd with python unittest for embedded c
Tdd with python unittest for embedded cTdd with python unittest for embedded c
Tdd with python unittest for embedded cBenux Wei
 
Python-GTK
Python-GTKPython-GTK
Python-GTKYuren Ju
 
Csdfsadf
CsdfsadfCsdfsadf
CsdfsadfAtul Setu
 
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)securityxploded
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomaticoPyCon Italia
 
C Tutorials
C TutorialsC Tutorials
C TutorialsSudharsan S
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Yuren Ju
 
Computer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paperComputer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paperDeepak Singh
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CSteffen Wenz
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comM-TEC Computer Education
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.pptCharuJain396881
 
C tutorial
C tutorialC tutorial
C tutorialtuncay123
 
C tutorial
C tutorialC tutorial
C tutorialAnuja Lad
 
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answerssheibansari
 
Start Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeStart Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeYung-Yu Chen
 

Ähnlich wie C ISRO Debugging (20)

Tdd with python unittest for embedded c
Tdd with python unittest for embedded cTdd with python unittest for embedded c
Tdd with python unittest for embedded c
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
 
C
CC
C
 
C
CC
C
 
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 
Computer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paperComputer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paper
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
 
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answers
 
7 functions
7  functions7  functions
7 functions
 
Start Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeStart Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New Rope
 

KĂŒrzlich hochgeladen

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂșjo
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

KĂŒrzlich hochgeladen (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

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