SlideShare a Scribd company logo
1 of 7
Compiling & Debugging

        Quick tutorial
What is gcc?
   Gcc is the GNU Project C compiler
   A command-line program
   Gcc takes C source files as input
   Outputs an executable: a.out
   You can specify a different output filename
   Available for you to use on
    spinlock/coredump
Gcc example:
   “hello.c” is the name of the file with the following
    contents:
    #include <stdio.h>
    int main(void) {
          printf(“Hellon“);
    }
   To compile simply type: gcc               –o hello hello.c –g -Wall
      ‘-o’ option tells the compiler to name the executable ‘HelloProg’
      ‘-g’ option adds symbolic information to Hello for debugging
      ‘–Wall’ tells it to print out all warnings (very useful!!!)
      Can also give ‘-O6’ to turn on full optimization
   To execute the program simply type: ./hello
           It should output “Hello” on the console
What is Gdb?
   GDB is the GNU Project debugger
   Gdb provides some helpful functionality
       Allows you to stop your program at any given point.
       You can examine the state of your program when it’s
        stopped.
       Change things in your program, so you can experiment with
        correcting the effects of a bug.
   Also a command-line program
   Is also available on spinlock/coredump
Using Gdb:
   To start gdb with your hello program type:
    gdb HelloProg
   When gdb starts, your program is not actually
    running.
   You have to use the run command to start execution.
   Before you do that, you should place some break
    points.
   Once you hit a break point, you can examine any
    variable.
Useful gdb commands
   run command-line-arguments
       Begin execution of your program with arguments
   break place
       place can be the name of a function or a line number
       For example: break main will stop execution at the first
        instruction of your program
   delete N
       Removes breakpoints, where N is the number of the
        breakpoint
   step
       Executes current instruction and stops on the next one
Gdb commands cont.
   next
       Same as step except this doesn’t step into functions
   print E
       Prints the value of any variable in your program when you
        are at a breakpoint, where E is the name of the variable you
        want to print
   help command
       Gives you more information about any command or all if you
        leave out command
   quit
       Exit gdb

More Related Content

What's hot

Debugging With GNU Debugger GDB
Debugging With GNU Debugger GDBDebugging With GNU Debugger GDB
Debugging With GNU Debugger GDB
kyaw thiha
 
Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handout
Suraj Kumar
 
Syncevolution: Open Source and Funambol
Syncevolution: Open Source and FunambolSyncevolution: Open Source and Funambol
Syncevolution: Open Source and Funambol
Funambol
 
淺入淺出 GDB
淺入淺出 GDB淺入淺出 GDB
淺入淺出 GDB
Jim Chang
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
Alpana Gupta
 
Claire protorpc
Claire protorpcClaire protorpc
Claire protorpc
Fan Robbin
 

What's hot (20)

C compilation process
C compilation processC compilation process
C compilation process
 
C++ compilation process
C++ compilation processC++ compilation process
C++ compilation process
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerDebugging Applications with GNU Debugger
Debugging Applications with GNU Debugger
 
Advanced Debugging with GDB
Advanced Debugging with GDBAdvanced Debugging with GDB
Advanced Debugging with GDB
 
Debugging With GNU Debugger GDB
Debugging With GNU Debugger GDBDebugging With GNU Debugger GDB
Debugging With GNU Debugger GDB
 
Gdb tutorial-handout
Gdb tutorial-handoutGdb tutorial-handout
Gdb tutorial-handout
 
Usage of GDB
Usage of GDBUsage of GDB
Usage of GDB
 
GDB Rocks!
GDB Rocks!GDB Rocks!
GDB Rocks!
 
Golang execution modes
Golang execution modesGolang execution modes
Golang execution modes
 
Syncevolution: Open Source and Funambol
Syncevolution: Open Source and FunambolSyncevolution: Open Source and Funambol
Syncevolution: Open Source and Funambol
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdb
 
淺入淺出 GDB
淺入淺出 GDB淺入淺出 GDB
淺入淺出 GDB
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about go
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
 
Review: Apitrace and Vogl
Review: Apitrace and VoglReview: Apitrace and Vogl
Review: Apitrace and Vogl
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Claire protorpc
Claire protorpcClaire protorpc
Claire protorpc
 
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
 
Gnu debugger
Gnu debuggerGnu debugger
Gnu debugger
 
Rcpp
RcppRcpp
Rcpp
 

Viewers also liked

Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler design
Janani Parthiban
 
GEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkGEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions Framework
Alexey Smirnov
 

Viewers also liked (10)

NetBeans para Java, C, C++
NetBeans para Java, C, C++NetBeans para Java, C, C++
NetBeans para Java, C, C++
 
Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler design
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Gcc opt
Gcc optGcc opt
Gcc opt
 
HRM - PM in GCC
HRM - PM in GCCHRM - PM in GCC
HRM - PM in GCC
 
GEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions FrameworkGEM - GNU C Compiler Extensions Framework
GEM - GNU C Compiler Extensions Framework
 
How it's made: C++ compilers (GCC)
How it's made: C++ compilers (GCC)How it's made: C++ compilers (GCC)
How it's made: C++ compilers (GCC)
 
MinGw Compiler
MinGw CompilerMinGw Compiler
MinGw Compiler
 
Deep C
Deep CDeep C
Deep C
 
GCC
GCCGCC
GCC
 

Similar to Gccgdb

gdb-tutorial.pdf
gdb-tutorial.pdfgdb-tutorial.pdf
gdb-tutorial.pdf
ligi14
 

Similar to Gccgdb (20)

gdb-tutorial.pdf
gdb-tutorial.pdfgdb-tutorial.pdf
gdb-tutorial.pdf
 
GNU Debugger
GNU DebuggerGNU Debugger
GNU Debugger
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
 
lab1-ppt.pdf
lab1-ppt.pdflab1-ppt.pdf
lab1-ppt.pdf
 
Rasperry pi Part 8
Rasperry pi Part 8Rasperry pi Part 8
Rasperry pi Part 8
 
Writing mruby Debugger
Writing mruby DebuggerWriting mruby Debugger
Writing mruby Debugger
 
Basics
BasicsBasics
Basics
 
MSL2009. Gdb
MSL2009. GdbMSL2009. Gdb
MSL2009. Gdb
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applications
 
Q2.12: Debugging with GDB
Q2.12: Debugging with GDBQ2.12: Debugging with GDB
Q2.12: Debugging with GDB
 
Wavedigitech gdb
Wavedigitech gdbWavedigitech gdb
Wavedigitech gdb
 
Process (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSProcess (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oS
 
gdb.ppt
gdb.pptgdb.ppt
gdb.ppt
 
C tutorial
C tutorialC tutorial
C tutorial
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
 
Introduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debuggerIntroduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debugger
 
A tutorial on C++ Programming
A tutorial on C++ ProgrammingA tutorial on C++ Programming
A tutorial on C++ Programming
 
Ch2 C Fundamentals
Ch2 C FundamentalsCh2 C Fundamentals
Ch2 C Fundamentals
 
The basics of c programming
The basics of c programmingThe basics of c programming
The basics of c programming
 
C tutorial
C tutorialC tutorial
C tutorial
 

Recently uploaded

+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
+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...
 
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
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 

Gccgdb

  • 1. Compiling & Debugging Quick tutorial
  • 2. What is gcc?  Gcc is the GNU Project C compiler  A command-line program  Gcc takes C source files as input  Outputs an executable: a.out  You can specify a different output filename  Available for you to use on spinlock/coredump
  • 3. Gcc example:  “hello.c” is the name of the file with the following contents: #include <stdio.h> int main(void) { printf(“Hellon“); }  To compile simply type: gcc –o hello hello.c –g -Wall  ‘-o’ option tells the compiler to name the executable ‘HelloProg’  ‘-g’ option adds symbolic information to Hello for debugging  ‘–Wall’ tells it to print out all warnings (very useful!!!)  Can also give ‘-O6’ to turn on full optimization  To execute the program simply type: ./hello  It should output “Hello” on the console
  • 4. What is Gdb?  GDB is the GNU Project debugger  Gdb provides some helpful functionality  Allows you to stop your program at any given point.  You can examine the state of your program when it’s stopped.  Change things in your program, so you can experiment with correcting the effects of a bug.  Also a command-line program  Is also available on spinlock/coredump
  • 5. Using Gdb:  To start gdb with your hello program type: gdb HelloProg  When gdb starts, your program is not actually running.  You have to use the run command to start execution.  Before you do that, you should place some break points.  Once you hit a break point, you can examine any variable.
  • 6. Useful gdb commands  run command-line-arguments  Begin execution of your program with arguments  break place  place can be the name of a function or a line number  For example: break main will stop execution at the first instruction of your program  delete N  Removes breakpoints, where N is the number of the breakpoint  step  Executes current instruction and stops on the next one
  • 7. Gdb commands cont.  next  Same as step except this doesn’t step into functions  print E  Prints the value of any variable in your program when you are at a breakpoint, where E is the name of the variable you want to print  help command  Gives you more information about any command or all if you leave out command  quit  Exit gdb