Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Nov 1995 09:42:17 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        gavin@linux1.dlsu.edu.ph, hackers@FreeBSD.ORG
Subject:   Re: ptrace()
Message-ID:  <199511172242.JAA26667@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>How do you use the ptrace() call?  We cannot find any documentation for it.
>We are trying to use ptrace() to get the process's data and text 
>segments, also the proc structure and the user structure.  How do we do 
>this using ptrace()?

>We'd appreciate if you could include sample code to use ptrace.

This program prints the user area.  It should check for errors better.
Much more complicated examples can be found in gdb.

Bruce

---
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

int main(void)
{
    int i;
    pid_t p;
    int stat;

    switch(p = fork())
    {
    case -1:
	exit(1);
    case 0:
	ptrace(PT_TRACE_ME, 0, 0, 0);
	kill(getpid(), SIGINT);
	exit(0);
    default:
	wait(&stat);
	for (i = 0; i < 2049; ++i)
	{
	    printf("%08x ",
		    ptrace(PT_READ_U, p, (caddr_t) (4 * i), 0));
	    if ((i & 7) == 7)
		printf("\n");
	}
	printf("\n");
	exit(0);
    }
}
---



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199511172242.JAA26667>