From owner-freebsd-hackers@FreeBSD.ORG Tue Apr 4 10:05:13 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0325116A42C for ; Tue, 4 Apr 2006 10:05:13 +0000 (UTC) (envelope-from n.cormier@gmail.com) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.236]) by mx1.FreeBSD.org (Postfix) with ESMTP id 765B243D5A for ; Tue, 4 Apr 2006 10:05:11 +0000 (GMT) (envelope-from n.cormier@gmail.com) Received: by wproxy.gmail.com with SMTP id i31so1189036wra for ; Tue, 04 Apr 2006 03:05:10 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=sF9xZE1a+CtAhPzLBpMa/mi1Bx7eYHeQJ1AC/d4L+aUt7oMffdL4/GuBe0kLcPEs1+ptxoVI9QS4j3EAgHk5sgJ0SNAw2MKPWoYgBbLQRzwB97xR0qhdV3KEVBOsjO5r/65CnP0nt0hWRCSqRZZsZHWeqVdXNZ//ebbKvSMm/i0= Received: by 10.65.151.3 with SMTP id d3mr216582qbo; Tue, 04 Apr 2006 03:05:10 -0700 (PDT) Received: by 10.65.116.5 with HTTP; Tue, 4 Apr 2006 03:05:10 -0700 (PDT) Message-ID: Date: Tue, 4 Apr 2006 12:05:10 +0200 From: "Nicolas Cormier" To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Subject: Function calling X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Apr 2006 10:05:13 -0000 Hello. I'm writing a function tracer on freebsd to know which function the process passes inside. ex: ---- nico > cat toto.c int foo4() { } int foo3() { } int foo2() { foo3(); } int foo1() { foo2(); } int main() { foo1(); foo4(); } nico > will print: 0x80484a8 (foo1) 0x804849c (foo2) 0x8048494 (foo3) ret @ 0x8048498 ret @ 0x80484a5 ret @ 0x80484b1 0x804848c (foo4) ret @ 0x8048490 ---- I use PTRACE to run the process in single-stepping mode. For each step I look on the next instruction (read at %eip) and I seek the following sequence: call [backup eip in addr and wait a step] pushl=09%ebp movl=09%esp, %ebp [print addr and the sym associed] OR (plt call) call jmp =09* pushl=09$ jmp =09. [print eip and the sym associed] OR leave ret [print ret @ eip] But when the program uses the libc I have more RET than call ... What's the good way to find function calls and return ? Thanks in advance for your help and sorry for my poor english. -- Nico