ptrace: Refactor to make more portable and add PowerPC support

Slightly buggy (returns error when the program exits).