jueves, mayo 12, 2005

Linux VM Manager





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


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.


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.

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

A Debug Malloc Library

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 - Profiling and leak detection


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

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


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.


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

jueves, marzo 31, 2005

Reunion 30/3/2005

- redefinir __syscall_return(a,b) --> aixi no depenem d'errno . (podem confondre al sistema pq estem modificant errno y despres ho pot consultar el programa q executem).

__cxa_finalize --> com son weak les podem redefinir (fent-les strong).

- fer strtol c[i] -'0' ...

- pftrace_open inicialitzar el mode a un valor.

- Fer fitxer de configuració amb les libreries que no s'han de carregar a memória y amb les opcions de configuracio.

- Agafar adreces a la libc de les funcions que redefinim (sigaction, dlopen...).

- Fer unes pagines del manual --> amb comparació utilitats similar (electricfence, pstack, dmalloc, memprof).

Dos tipus:
1) provar que el programa funciona
2) provar que funcionara a un sistema --> desitjable donar pistes de pq no funcionarà:
- Mirar on es carreguen les dades inicialitzades, dades no ini, dades anonimes, codi de les llibreries. --> Fer .so's que serveixin de test. (aixi podem demostrar si podem correr a un sistema o no).


- dlsym ---> dona l'addresa de la funcio x a la llibreria y, podem fer calls a les funcions de les llibreries que volguem

- ld prepara __environ abans de carregar les funcions init de les llibreries.

Stub --> es per anomenar el que he fet amb les system calls.

martes, marzo 29, 2005

Test a fer per a libptrace

Test 1: Provar la llibreria amb un programa que no càpiga a memória. --> Veurem el comportament de la llibreria al descarregar de memoria pàgines protegides.

Test 2: Accesos a @ ilegals (posicio q no existeix al rang del programa).

Test 3: Varios threads

Test 4: dlopen(), dlclose(), sigaction()

viernes, marzo 18, 2005


Today I noticed about that strange library "linux-gate.so.1" because when I make:

ldd libpftrace.so.1.0.1

It shows:

linux-gate.so.1 => (0xffffe000)
libc.so.6 => /lib/libc.so.6 (0xb7ed8000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)

I investigate and found that is a dynamically shared object (DSO) for
system call purposes (e.g., to speed up system calls and for signal
trampoline/sigreturn purposes).

More info: