lunes, abril 18, 2005

Using GDB

file : File to execute/debug

set environment = : Environment variable active during the execution/debug.

x : Gives the symbol asociated with this address.

info line *() : If possible (executable compiled with '-g') gives the file and line of the HEX_ADDRESS position.

lunes, abril 11, 2005

Pstack + lsstack

Overview

Pstack and lsstack are a port of lsstack program from Solaris systems.

They print the call stacks for all threads in a command line given process, with symbolic names for functions.

Implementation

To do his work either pstack and lsstack uses ptrace call and /proc/PID/exe link to the program executable.

First of all, pstack/lsstack reads all simbols of the executable from /proc/PID/exe link using ELF specification. Then begins reading process stack using ptrace in this way:

1. ptrace(PTRACE_ATTACH, pid, 0, 0) --> Initialices the trace.

2. ptrace(PTRACE_PEEKDATA, pid, addr, 0) --> Returns a word that is in the location of addr from pid.

3. ptrace(PTRACE_PEEKUSER, pid, reg, 0) --> Reads a word at offset addr in the children's user area (where are registers and other proces info, see and ).

4. ptrace(PTRACE_CONT, thePid, 1, 0) --> Ends the trace.

sábado, abril 02, 2005

PFC: Programas a comparar

Electric Fence + dmalloc

This two APIs try to extract debugging info redefining malloc(), free(), and similars.

ElectricFence
malloc() debugger
Electric Fence (efence) is an open-source library to detect buffer overruns and under-runs in C programs.

* extensions for finding memory-leaks
http://www.pf-lug.de/projekte/haya/efence.php

Dmalloc
A Debug Malloc Library
http://dmalloc.com/

The debug memory allocation or dmalloc library has been designed as a drop in replacement for the system's malloc, realloc, calloc, free and other memory management routines while providing powerful debugging facilities configurable at runtime. These facilities include such things as memory-leak tracking, fence-post write detection, file/line number reporting, and general logging of statistics.

memprof
MemProf - Profiling and leak detection

http://www.gnome.org/projects/memprof/

MemProf is a tool for profiling memory usage and finding memory leaks. Its two major features are:

* It can generate a profile how much memory was allocated by each function in your program.
* It can scan memory and find blocks that you've allocated but are no longer referenced anywhere.

MemProf works by pre-loading a library to override the C library's memory allocation functions and does not require you to recompile your program.

One advantage MemProf has over some other similar tools that are available is that it has a nice GUI frontend and is relatively easy to use.

lsstack + PStack

Two of them have the same objective.

Dumps a stack trace for a process, given the pid of that
process.

http://www.whatsis.com/pstack/ [Not working]

http://sourceforge.net/projects/lsstack

lsstack is a Linux implementation of the "pstack" utility from Solaris lsstack is a command line utility which (efficiently and quickly) prints the call stacks for all threads in a specified process, with symbolic names for functions, where symbols are.

PFC: IDEAS

- Crear programa que a partir de la traza de libpftrace:

- indique las paginas/secciones del programa más utilizados.
- indique las páginas mas ""proximas"" en ejecución.