0% found this document useful (0 votes)
33 views18 pages

Useful Tools For Develpment

This document summarizes several important tools and utilities for C/C++ development: - It outlines debugging and profiling tools like gcc, gprof, gdb, valgrind, and tools for code navigation like ctags and cscope. - It provides brief descriptions and examples of how to use valgrind to detect memory errors like use of uninitialized memory, memory leaks, and mismatched allocation/deallocation. - It also mentions tools for cache and call profiling like cachegrind and callgrind in valgrind.

Uploaded by

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

Useful Tools For Develpment

This document summarizes several important tools and utilities for C/C++ development: - It outlines debugging and profiling tools like gcc, gprof, gdb, valgrind, and tools for code navigation like ctags and cscope. - It provides brief descriptions and examples of how to use valgrind to detect memory errors like use of uninitialized memory, memory leaks, and mismatched allocation/deallocation. - It also mentions tools for cache and call profiling like cachegrind and callgrind in valgrind.

Uploaded by

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

Some important tools and utilities

Prepared by
Shreeji Sheth

gcc

Profiling: gprof,valgrind

gdb

Code nevigation: Ctags and Cscope

Doxygen

Mallochelper

Eclipse

Cunit

gcc
-E to generate .i file which is about expansion of
library and preprocessor directives;also removal
of comments
-S to generate assembly code or .s file
-c to generate object file from assembly fileunderstandable by machine
-gcc file.o -o file

gprof
Enable profiling while compilation by -pg option
$gcc -pg -o add_main add_main.c
//This will generate add_main executable with profiling enabled
$./add_main
//This will execute the binary with generating profiling output
file gmon.out
$gprof add_main gmon.out
//gprof is run with executable and profiling output file which
combined produces analysis information

Code Navigation
To find function definitions- ctags
To find function calls of particular hierarchycscope

Dynamic memory allocation


Malloc
Calloc
Memory leak and dangling pointer
bigo notation//after data structures

Project Making
Requirement Analysis
Top Level Design
Detail Design
Coding
Creation of library and using it in your program
Deletion of a module from library
Project creation/building: using make, cmake

C and Assembly interaction


Inline assembly language
Linking of two assembly files
Memory models
C and Segments in Library
Linking assembly Procedure in C program

Valgrind
$sudo apt-get install valgrind
$valgrind tool=TOOLNAME ./EXECUTABLENAME
TOOLNAME can be memcheck, callgrind, cachegrind, helgrind,
massif, DRD etc...
For more options you can read $man valgrind

memcheck
This tool can detect the following memory related problems :
Use of uninitialized memory
Reading/writing memory after it has been freed
Reading/writing off the end of mallocd blocks
Memory leaks
Mismatched use of malloc/new/new[] vs free/delete/delete[]
Doubly freed memory

Use of uninitialized memory


#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *p;
char c = *p;
printf("\n [%c]\n",c);
return 0;
}

Reading/writing memory after it has


been freed
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *p = malloc(1);
*p = 'a';
char c = *p;
printf("\n [%c]\n",c);
free(p);
c = *p;
return 0;
}

Reading/writing off the end of


mallocd blocks
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *p = malloc(1);
*p = 'a';
char c = *(p+1);
printf("\n [%c]\n",c);
free(p);
return 0;
}

Memory leaks
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *p = malloc(1);
*p = 'a';
char c = *p;
printf("\n [%c]\n",c);
return 0;
}

#include <stdio.h>

Mismatched use of
malloc/new/new[] vs
free/delete/delete[]

#include <stdlib.h>
#include<iostream>
int main(void)
{
char *p = (char*)malloc(1);
*p = 'a';
char c = *p;
printf("\n [%c]\n",c);
delete p;
return 0;
}

Doubly freed memory


#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *p = (char*)malloc(1);
*p = 'a';
char c = *p;
printf("\n [%c]\n",c);
free(p);
free(p);
return 0;
}

Cachegrind
To make your executable faster
$valgrind tool=cachegrind ./a.out
$ cg_annotate --show=Dr,Dw
cachegrind.out.<processID of your code> | grep -v
"???"
Cachegrind shows how many times your program
accessed memory to read or write data
The portion or function having more memory access
can be optimized for the same

Callgrind
$valgrind tool=callgrind ./a.out
$callgrind_annotate callgrind.out.<ProcessID
of code>
This will tell you which functions used the most
instructions to run
the functions having maximum instruction can be
modified in such a way that takes minimum
instructions

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy