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

What's hot

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
 
Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Phpをいじり倒す10の方法
Phpをいじり倒す10の方法
Moriyoshi Koizumi
 
Usp
UspUsp
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
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
 

What's hot (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
 

Similar to 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 c
Benux Wei
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
Yuren Ju
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
Atul Setu
 
C
CC
C
CC
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
Khan Rahimeen
 
C tutorial
C tutorialC tutorial
C tutorial
Anuja Lad
 
C tutorial
C tutorialC tutorial
C tutorial
tuncay123
 
C++ tutorial
C++ tutorialC++ tutorial
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
 

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
 
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
 

Recently uploaded

Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 

Recently uploaded (20)

Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 

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