NAME
FreeBSD::i386::Ptrace - Ptrace for FreeBSD-i386
VERSION
$Id: Ptrace.pm,v 0.1 2009/03/14 12:45:27 dankogai Exp dankogai $
SYNOPSIS
# simple strace in perl
use strict;
use warnings;
use FreeBSD::i386::Ptrace;
use FreeBSD::i386::Ptrace::Syscall;
die "$0 prog args ..." unless @ARGV;
my $pid = fork();
die "fork failed:$!" if !defined($pid);
if ($pid == 0){ # son
pt_trace_me;
exec @ARGV;
}else{ mom
wait; # for exec;
my $count = 0; # odd on enter, even on leave
my ($call, $retval);
while(pt_syscall($pid) == 0){
last if wait == -1;
if (++$count & 1){
$call = pt_getcall($pid);
}else{
$retval = pt_getcall($pid);
my $name = $SYS{$call} || 'unknown';
warn "$name -> $retval";
}
}
warn $count/2," system calls issued";
}
EXPORT
ptrace
, pt_trace_me
, pt_attach
, pt_detach
, pt_syscall
pt_getcall
pt_kill
and PT_* constants.
for %SYS
, use <FreeBSD::i386::Ptrace::Syscall>.
FUNCTIONS
- ptrace($request, $pid, $addr, $data)
-
A thin wrapper to "2" in ptrace.
#include <sys/types.h> #include <sys/ptrace.h> int ptrace(int request, pid_t pid, caddr_t addr, int data);
All arguments are integer from perl.
- pt_trace_me()
-
Shortand for
ptrace(PT_TRACE_ME, 0, 0, 0)
. - pt_attach($pid)
-
Shortand for
ptrace(PT_ATTACH, pid, 0, 0)
. - pt_detach($pid)
-
Shortand for
ptrace(PT_DETACH, pid, 0, 0)
. - pt_syscall($pid)
-
Shortand for
ptrace(PT_SYSCALL, pid, 1, 0)
. Unlike Linux the 3rd argument must be 1 or it loops infinitely.Note PT_SYSCALL is invoked both on entry to and return from the system call. See "SYNOPSIS" to see how to switch between them.
- pt_getcall($pid)
-
Returns the value of EAX register which holds the system call NUMBER on entry and the return value on return.
To get the name of system call you can import
FreeBSD::i386::Ptrace::Syscall
and use%SYS
.my $call = pt_getcall(pid); my $name = %SYS{$call};
- pt_kill($pid)
-
Shortand for
ptrace(PT_KILL, $pid, 0, 0
;ptrace
,pt_trace_me
,pt_attach
,pt_detach
,pt_syscall
pt_getcall
pt_kill
and PT_* constants.
AUTHOR
Dan Kogai, <dankogai at dan.co.jp>
BUGS
Please report any bugs or feature requests to bug-freebsd-i386-ptrace at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FreeBSD-i386-Ptrace. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc FreeBSD::i386::Ptrace
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=FreeBSD-i386-Ptrace
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2009 Dan Kogai, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.