libunwind-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libunwind] remote unwinding and ptrace()


From: Umut Aymakoglu
Subject: [libunwind] remote unwinding and ptrace()
Date: Thu, 11 Dec 2003 13:54:15 -0800

Hi -
I have the following problem:
The owner of the target process is root and the permissions are 6755 (-rwsr-sr-x). The program that will attach and unwind the target process does not have the root ownership and the permissions are 2755(-rwxr-sr-x). The group ids are same on both of the programs. The program does a ptrace(PTRACE_ATTACH) call to attach the target process and receives EPERM error. The 2nd program can not have the root ownership. Is there a way to make this work?

x.c:

main()
{ a();}

a()
{b();}

b()
{ while(1);}

z.c

#include <stdio.h>
#include <libunwind.h>
#include <sys/ptrace.h>
main( int argc, char **argv)
{
unw_cursor_t c;
unw_word_t ip;
unw_addr_space_t as;
struct UPT_info *ui;
char buf[512];
int ret;
pid_t pid;

pid = atol(argv[1]);
ret = ptrace(PTRACE_ATTACH,pid); printf("attach = %d\n",ret);
as = unw_create_addr_space(&_UPT_accessors,0);
ui = _UPT_create(pid);
unw_init_remote(&c,as,ui);

do {
unw_get_proc_name(&c,buf,sizeof(buf),NULL);
printf("%s\n",buf);
}
while((ret = unw_step(&c)) > 0);

_UPT_destroy(ui);
ptrace(PTRACE_DETACH,pid,0,0);
}


% gcc -o x x.c
% gcc -o z z.c /usr/local/lib/libunwind.a
% ./x &
% ./z <pid from previous>

if run as super user the output will show the stack.


thanks,
Umut


reply via email to

[Prev in Thread] Current Thread [Next in Thread]