ºÝºÝߣ

ºÝºÝߣShare 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 ¨Cg flag in gcc
int main(void)
{
         int i = 0;                                            $> gcc ¨Cg 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

What's hot (20)

C&cpu
C&cpuC&cpu
C&cpu
feathertw
?
Threads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonThreads and Callbacks for Embedded Python
Threads and Callbacks for Embedded Python
Yi-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 8
Nikita Popov
?
±Ê³ó±è¤ò¤¤¤¸¤êµ¹¤¹10¤Î·½·¨
±Ê³ó±è¤ò¤¤¤¸¤êµ¹¤¹10¤Î·½·¨±Ê³ó±è¤ò¤¤¤¸¤êµ¹¤¹10¤Î·½·¨
±Ê³ó±è¤ò¤¤¤¸¤êµ¹¤¹10¤Î·½·¨
Moriyoshi Koizumi
?
Usp
UspUsp
Usp
preethamnaik92
?
Windbg? ????
Windbg? ????Windbg? ????
Windbg? ????
Ji Hun Kim
?
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
julien pauli
?
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
julien 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
§°§ä§Ý§Ñ§Õ§Ü§Ñ §Ó GDB
Anthony Shoumikhin
?
Unit 4
Unit 4Unit 4
Unit 4
siddr
?
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
Lin 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 1
Little 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 6
siddr
?
NIO and NIO2
NIO and NIO2NIO and NIO2
NIO and NIO2
Balamurugan Soundararajan
?
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 PHP
Guilherme Blanco
?
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
rik0
?
Threads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonThreads and Callbacks for Embedded Python
Threads and Callbacks for Embedded Python
Yi-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 8
Nikita Popov
?
±Ê³ó±è¤ò¤¤¤¸¤êµ¹¤¹10¤Î·½·¨
±Ê³ó±è¤ò¤¤¤¸¤êµ¹¤¹10¤Î·½·¨±Ê³ó±è¤ò¤¤¤¸¤êµ¹¤¹10¤Î·½·¨
±Ê³ó±è¤ò¤¤¤¸¤êµ¹¤¹10¤Î·½·¨
Moriyoshi Koizumi
?
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
julien 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
§°§ä§Ý§Ñ§Õ§Ü§Ñ §Ó GDB
Anthony Shoumikhin
?
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
Lin 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 1
Little 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
?
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 PHP
Guilherme Blanco
?
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
rik0
?

Similar to 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
Benux Wei
?
Python-GTK
Python-GTKPython-GTK
Python-GTK
Yuren Ju
?
C
CC
C
Khan Rahimeen
?
C
CC
C
Anuja Lad
?
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
Atul 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 idiomatico
PyCon Italia
?
C Tutorials
C TutorialsC Tutorials
C Tutorials
Sudharsan 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-paper
Deepak 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 C
Steffen Wenz
?
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
M-TEC Computer Education
?
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
CharuJain396881
?
C tutorial
C tutorialC tutorial
C tutorial
Anuja Lad
?
C tutorial
C tutorialC tutorial
C tutorial
Khan Rahimeen
?
C tutorial
C tutorialC tutorial
C tutorial
tuncay123
?
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
sikkim manipal university
?
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answers
sheibansari
?
7 functions
7  functions7  functions
7 functions
MomenMostafa
?
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
Yung-Yu Chen
?
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
Benux Wei
?
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 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-paper
Deepak 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 C
Steffen Wenz
?
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answers
sheibansari
?
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
Yung-Yu Chen
?

Recently uploaded (20)

Microsoft Digital Defense Report 2024 .pdf
Microsoft Digital Defense Report 2024 .pdfMicrosoft Digital Defense Report 2024 .pdf
Microsoft Digital Defense Report 2024 .pdf
Abhishek Agarwal
?
Network_Packet_Brokers_Presentation.pptx
Network_Packet_Brokers_Presentation.pptxNetwork_Packet_Brokers_Presentation.pptx
Network_Packet_Brokers_Presentation.pptx
Khushi Communications
?
Why Outsource Accounting to India A Smart Business Move!.pdf
Why Outsource Accounting to India A Smart Business Move!.pdfWhy Outsource Accounting to India A Smart Business Move!.pdf
Why Outsource Accounting to India A Smart Business Move!.pdf
anjelinajones6811
?
A General introduction to Ad ranking algorithms
A General introduction to Ad ranking algorithmsA General introduction to Ad ranking algorithms
A General introduction to Ad ranking algorithms
Buhwan Jeong
?
202408_JAWSPANKRATION_Introduction_of_Minaden.pdf
202408_JAWSPANKRATION_Introduction_of_Minaden.pdf202408_JAWSPANKRATION_Introduction_of_Minaden.pdf
202408_JAWSPANKRATION_Introduction_of_Minaden.pdf
NTTDOCOMO-ServiceInnovation
?
Benefits of Moving Ellucian Banner to Oracle Cloud
Benefits of Moving Ellucian Banner to Oracle CloudBenefits of Moving Ellucian Banner to Oracle Cloud
Benefits of Moving Ellucian Banner to Oracle Cloud
AstuteBusiness
?
Getting the Best of TrueDEM ¨C April News & Updates
Getting the Best of TrueDEM ¨C April News & UpdatesGetting the Best of TrueDEM ¨C April News & Updates
Getting the Best of TrueDEM ¨C April News & Updates
panagenda
?
Next.js Development: The Ultimate Solution for High-Performance Web Apps
Next.js Development: The Ultimate Solution for High-Performance Web AppsNext.js Development: The Ultimate Solution for High-Performance Web Apps
Next.js Development: The Ultimate Solution for High-Performance Web Apps
rwinfotech31
?
Beyond the life of a CISO - Head of Trust at GDG Kathmandu Monthly Meetup
Beyond the life of a CISO -  Head of Trust at GDG Kathmandu Monthly MeetupBeyond the life of a CISO -  Head of Trust at GDG Kathmandu Monthly Meetup
Beyond the life of a CISO - Head of Trust at GDG Kathmandu Monthly Meetup
GDG Kathmandu
?
HHUG-04-2025-Close-more-deals-from-your-existing-pipeline-FOR SLIDESHARE.pptx
HHUG-04-2025-Close-more-deals-from-your-existing-pipeline-FOR SLIDESHARE.pptxHHUG-04-2025-Close-more-deals-from-your-existing-pipeline-FOR SLIDESHARE.pptx
HHUG-04-2025-Close-more-deals-from-your-existing-pipeline-FOR SLIDESHARE.pptx
HampshireHUG
?
How Telemedicine App Development is Revolutionizing Virtual Care.pptx
How Telemedicine App Development is Revolutionizing Virtual Care.pptxHow Telemedicine App Development is Revolutionizing Virtual Care.pptx
How Telemedicine App Development is Revolutionizing Virtual Care.pptx
Dash Technologies Inc
?
Recruiting Tech: A Look at Why AI is Actually OG
Recruiting Tech: A Look at Why AI is Actually OGRecruiting Tech: A Look at Why AI is Actually OG
Recruiting Tech: A Look at Why AI is Actually OG
Matt Charney
?
Leadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly Meetup
Leadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly MeetupLeadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly Meetup
Leadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly Meetup
GDG Kathmandu
?
Research Data Management (RDM): the management of dat in the research process
Research Data Management (RDM): the management of dat in the research processResearch Data Management (RDM): the management of dat in the research process
Research Data Management (RDM): the management of dat in the research process
HeilaPienaar
?
Transactional Outbox & Inbox Patterns.pptx
Transactional Outbox & Inbox Patterns.pptxTransactional Outbox & Inbox Patterns.pptx
Transactional Outbox & Inbox Patterns.pptx
Maysam Mousa
?
CIOs Speak Out - A Research Series by Jasper Colin
CIOs Speak Out - A Research Series by Jasper ColinCIOs Speak Out - A Research Series by Jasper Colin
CIOs Speak Out - A Research Series by Jasper Colin
Jasper Colin
?
Columbia Weather Systems - Product Overview
Columbia Weather Systems - Product OverviewColumbia Weather Systems - Product Overview
Columbia Weather Systems - Product Overview
Columbia Weather Systems
?
Top Tips to Get Your Data AI-Ready? ? ?? ?
Top Tips to Get Your Data AI-Ready? ? ?? ?Top Tips to Get Your Data AI-Ready? ? ?? ?
Top Tips to Get Your Data AI-Ready? ? ?? ?
Precisely
?
Least Privilege AWS IAM Role Permissions
Least Privilege AWS IAM Role PermissionsLeast Privilege AWS IAM Role Permissions
Least Privilege AWS IAM Role Permissions
Chris Wahl
?
The metaverse : A Digital Transformation
The metaverse : A Digital TransformationThe metaverse : A Digital Transformation
The metaverse : A Digital Transformation
matlotloatang03
?
Microsoft Digital Defense Report 2024 .pdf
Microsoft Digital Defense Report 2024 .pdfMicrosoft Digital Defense Report 2024 .pdf
Microsoft Digital Defense Report 2024 .pdf
Abhishek Agarwal
?
Why Outsource Accounting to India A Smart Business Move!.pdf
Why Outsource Accounting to India A Smart Business Move!.pdfWhy Outsource Accounting to India A Smart Business Move!.pdf
Why Outsource Accounting to India A Smart Business Move!.pdf
anjelinajones6811
?
A General introduction to Ad ranking algorithms
A General introduction to Ad ranking algorithmsA General introduction to Ad ranking algorithms
A General introduction to Ad ranking algorithms
Buhwan Jeong
?
Benefits of Moving Ellucian Banner to Oracle Cloud
Benefits of Moving Ellucian Banner to Oracle CloudBenefits of Moving Ellucian Banner to Oracle Cloud
Benefits of Moving Ellucian Banner to Oracle Cloud
AstuteBusiness
?
Getting the Best of TrueDEM ¨C April News & Updates
Getting the Best of TrueDEM ¨C April News & UpdatesGetting the Best of TrueDEM ¨C April News & Updates
Getting the Best of TrueDEM ¨C April News & Updates
panagenda
?
Next.js Development: The Ultimate Solution for High-Performance Web Apps
Next.js Development: The Ultimate Solution for High-Performance Web AppsNext.js Development: The Ultimate Solution for High-Performance Web Apps
Next.js Development: The Ultimate Solution for High-Performance Web Apps
rwinfotech31
?
Beyond the life of a CISO - Head of Trust at GDG Kathmandu Monthly Meetup
Beyond the life of a CISO -  Head of Trust at GDG Kathmandu Monthly MeetupBeyond the life of a CISO -  Head of Trust at GDG Kathmandu Monthly Meetup
Beyond the life of a CISO - Head of Trust at GDG Kathmandu Monthly Meetup
GDG Kathmandu
?
HHUG-04-2025-Close-more-deals-from-your-existing-pipeline-FOR SLIDESHARE.pptx
HHUG-04-2025-Close-more-deals-from-your-existing-pipeline-FOR SLIDESHARE.pptxHHUG-04-2025-Close-more-deals-from-your-existing-pipeline-FOR SLIDESHARE.pptx
HHUG-04-2025-Close-more-deals-from-your-existing-pipeline-FOR SLIDESHARE.pptx
HampshireHUG
?
How Telemedicine App Development is Revolutionizing Virtual Care.pptx
How Telemedicine App Development is Revolutionizing Virtual Care.pptxHow Telemedicine App Development is Revolutionizing Virtual Care.pptx
How Telemedicine App Development is Revolutionizing Virtual Care.pptx
Dash Technologies Inc
?
Recruiting Tech: A Look at Why AI is Actually OG
Recruiting Tech: A Look at Why AI is Actually OGRecruiting Tech: A Look at Why AI is Actually OG
Recruiting Tech: A Look at Why AI is Actually OG
Matt Charney
?
Leadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly Meetup
Leadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly MeetupLeadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly Meetup
Leadership Spectrum by Sonam Sherpa at GDG Kathmandu March Monthly Meetup
GDG Kathmandu
?
Research Data Management (RDM): the management of dat in the research process
Research Data Management (RDM): the management of dat in the research processResearch Data Management (RDM): the management of dat in the research process
Research Data Management (RDM): the management of dat in the research process
HeilaPienaar
?
Transactional Outbox & Inbox Patterns.pptx
Transactional Outbox & Inbox Patterns.pptxTransactional Outbox & Inbox Patterns.pptx
Transactional Outbox & Inbox Patterns.pptx
Maysam Mousa
?
CIOs Speak Out - A Research Series by Jasper Colin
CIOs Speak Out - A Research Series by Jasper ColinCIOs Speak Out - A Research Series by Jasper Colin
CIOs Speak Out - A Research Series by Jasper Colin
Jasper Colin
?
Top Tips to Get Your Data AI-Ready? ? ?? ?
Top Tips to Get Your Data AI-Ready? ? ?? ?Top Tips to Get Your Data AI-Ready? ? ?? ?
Top Tips to Get Your Data AI-Ready? ? ?? ?
Precisely
?
Least Privilege AWS IAM Role Permissions
Least Privilege AWS IAM Role PermissionsLeast Privilege AWS IAM Role Permissions
Least Privilege AWS IAM Role Permissions
Chris Wahl
?
The metaverse : A Digital Transformation
The metaverse : A Digital TransformationThe metaverse : A Digital Transformation
The metaverse : A Digital Transformation
matlotloatang03
?

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 ¨Cg flag in gcc int main(void) { int i = 0; $> gcc ¨Cg 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