0% found this document useful (0 votes)
2 views

Development Tools

The document outlines a training agenda for the C programming language, covering tools such as GCC, Clang, Make, Gdb, Valgrind, and Doxygen. It includes a quiz section with questions related to C programming concepts and provides detailed descriptions of each tool's functionality and usage. Additionally, it assigns homework that involves writing a C program, creating a Makefile, debugging with Gdb, detecting memory leaks with Valgrind, and documenting the code with Doxygen.

Uploaded by

maariaam.gh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Development Tools

The document outlines a training agenda for the C programming language, covering tools such as GCC, Clang, Make, Gdb, Valgrind, and Doxygen. It includes a quiz section with questions related to C programming concepts and provides detailed descriptions of each tool's functionality and usage. Additionally, it assigns homework that involves writing a C program, creating a Makefile, debugging with Gdb, detecting memory leaks with Valgrind, and documenting the code with Doxygen.

Uploaded by

maariaam.gh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

The C Programming Language

Development Tools
Agenda


Quiz

GCC

Clang

Make and Makefile

Gdb

Valgrind

Doxygen

Homework
Quiz


What are the C program compilation steps ? Describe each of
them.

What are the standard library memory allocation functions ?

What is the function pointer ?

What does “typedef” keyword do ?

What kind of arithmetic operations can we do with pointers ?

What is the size of a CPU register ?
GCC

GCC, the GNU Compiler Collection

Includes front ends for C, C++, Objective-C, Fortran, Ada, Go,
D and Modula-2 as well as libraries for these languages.

gcc [options] file
– gcc -Wall source.c -o opt
– gcc -Wall -Werror source.c -o opt
– gcc -save-temps source.c -o opt
– gcc -Wall source.c -o opt -lm
– gcc -Wall -std=c11 source.c -o opt
– gcc -c source.c
– gcc -g source.c -o debub
Clang

Clang is an "LLVM native" C/C++/Objective-C compiler

Clang can be used as a drop-in substitute for GCC

clang [options] file
– clang -Wall source.c -o opt
– clang -Wall -Werror source.c -o opt
– clang -save-temps source.c -o opt
– clang -Wall source.c -o opt -lm
– clang -Wall -std=c11 source.c -o opt
– clang -c source.c
– clang -g source.c -o debub
Make and Makefile

GNU Make is a tool which controls the generation of
executables and other non-source files of a program from the
program's source files.

Make gets its knowledge of how to build your program from a
file called the Makefile, which lists each of the non-source files
and how to compute it from other files

A rule in the Makefile tells Make how to execute a series of
commands in order to build a target file from source files.

A rule also specifies a list of dependencies of the target file.
Make and Makefile
Make and Makefile
Gdb

Gdb is a debugger for C (and C++)

It allows you to do things like run the program up to a certain
point then stop and print out the values of certain variables at
that point, or step through the program one line at a time and
print out the values of each variable after executing each line.

To prepare your program for debugging with gdb, you must
compile it with the -g flag։ gcc -g example.c -o ex

It uses a command line interface.

Type gdb at the unix prompt to launch debugger

Type quit at the gdb promt to exit the program
Gdb

file exe - Use “exe” as program to be debugged.

b fl:n - Puts a breakpoint at the line n of the file "fl"

b fn - Puts a breakpoint at the beginning of function "fn"

d N - Deletes breakpoint number N

info break - list breakpoints

r - Runs the program until a breakpoint or error or successful
termination

c - Continues running the program until the next breakpoint or error

f - Runs until the current function is finished

s - Runs the next line of the program

n - Like s, but it does not step into functions

p var - Prints the current value of the variable "var"

bt - Prints a stack trace

u - Goes up a level in the stack

d - Goes down a level in the stack

help – print the help
Valgrind

The Valgrind tool suite provides a number of debugging and profiling
tools that help you make your programs faster and more correct.

Memcheck - detects many memory-related errors.

Cachegrind - performs detailed simulation of the I1, D1 and L2
caches in your CPU.

Massif - performs detailed heap profiling.

Helgrind - is a thread debugger which finds data races in
multithreaded programs.

DRD - is a tool for detecting errors in multithreaded C and C++
programs.

DHAT - is a tool for examining how programs use their heap
allocations.

Most popular tool is the Memcheck.

Compile your program with -g to include debugging information so
that Memcheck's error messages include exact line numbers.
Valgrind


example.c


Valgrind result
Doxygen

Doxygen is a tool to document the code. It is a “documentation
system.”

Doxygen reads specially formatted comment blocks and turns them
into documentation.

To use Doxygen:
– write comments in source code using the format that Doxygen
understands:
https://www.doxygen.nl/manual/docblocks.html#specialblock
– Create a configuration file:
– Run Doxygen:
Doxygen
Homework
Write a C program to sort an array of integers entered by the user.
Ask the user for the number of elements they want to sort, then read
array elements into the dynamically created array. The sorting should
be done in a separate function.
– Write a Makefile for the program.
– Compile using optimized and debug modes.
– Set breakpoint in the sorting function, and run the program step by
step using GDB.
– Intentionally make a memory leak and detect it using Valgrind.
– Document code using Doxygen format and generate
documentation for it.
Thank You !

You might also like