gdb: definitions for ptrace() and syscall part of TRACEME

This commit is contained in:
Naoki Hamada
2014-09-22 16:24:07 +09:00
committed by Tomoki Shirasawa
parent dbecaa2fc8
commit da17625be9
3 changed files with 65 additions and 15 deletions

View File

@ -62,8 +62,45 @@
#define PT_TRACED 0x1 /* The process is ptraced */
#define PT_TRACE_EXEC 0x2 /* Trace execve(2) */
#define PTRACE_TRACEME 0
#define PTRACE_PEEKTEXT 1
#define PTRACE_PEEKDATA 2
#define PTRACE_PEEKUSER 3
#define PTRACE_POKETEXT 4
#define PTRACE_POKEDATA 5
#define PTRACE_POKEUSER 6
#define PTRACE_CONT 7
#define PTRACE_KILL 8
#define PTRACE_SINGLESTEP 9
#define PTRACE_GETREGS 12
#define PTRACE_SETREGS 13
#define PTRACE_GETFPREGS 14
#define PTRACE_SETFPREGS 15
#define PTRACE_ATTACH 16
#define PTRACE_DETACH 17
#define PTRACE_GETFPXREGS 18
#define PTRACE_SETFPXREGS 19
#define PTRACE_SYSCALL 24
#define PTRACE_SETOPTIONS 0x4200
#define PTRACE_GETEVENTMSG 0x4201
#define PTRACE_GETSIGINFO 0x4202
#define PTRACE_SETSIGINFO 0x4203
#define PTRACE_O_TRACESYSGOOD 1
#define PTRACE_O_TRACEFORK 2
#define PTRACE_O_TRACEVFORK 4
#define PTRACE_O_TRACECLONE 8
#define PTRACE_O_TRACEEXEC 0x10
#define PTRACE_O_TRACEVFORKDONE 0x20
#define PTRACE_O_TRACEEXIT 0x40
#define PTRACE_O_MASK 0x7f
#define PTRACE_EVENT_FORK 1
#define PTRACE_EVENT_VFORK 2
#define PTRACE_EVENT_CLONE 3
#define PTRACE_EVENT_EXEC 4
#define PTRACE_EVENT_VFORK_DONE 5
#define PTRACE_EVENT_EXIT 6
#define SIGNAL_STOP_STOPPED 0x1 /* The process has been stopped by SIGSTOP */
#define SIGNAL_STOP_CONTINUED 0x2 /* The process has been resumed by SIGCONT */

View File

@ -84,12 +84,11 @@ void init_fork_tree_node(struct fork_tree_node *ftn,
/* These will be filled out when changing status */
ftn->pid = -1;
ftn->exit_status = -1;
ftn->group_exit_status = 0;
ftn->status = PS_RUNNING;
#if 1
ftn->ptrace = parent ? PT_TRACED : 0; /*debug*//*takagi*/
#endif
ftn->signal_flags = 0;
ftn->group_exit_status = 0;
ftn->ptrace = 0;
ftn->signal_flags = 0;
ftn->parent = NULL;
if (parent) {
@ -98,9 +97,6 @@ void init_fork_tree_node(struct fork_tree_node *ftn,
INIT_LIST_HEAD(&ftn->children);
INIT_LIST_HEAD(&ftn->siblings_list);
if (parent) {
ftn->ppid_parent = parent; /*debug*//*takagi*/
}
INIT_LIST_HEAD(&ftn->ptrace_children);
INIT_LIST_HEAD(&ftn->ptrace_siblings_list);
@ -297,12 +293,6 @@ struct process *clone_process(struct process *org, unsigned long pc,
list_add_tail(&proc->ftn->siblings_list, &org->ftn->children);
ihk_mc_spinlock_unlock_noirq(&org->ftn->lock);
/*takagi*//*debug*/
#if 1
ihk_mc_spinlock_lock_noirq(&org->ftn->lock);
list_add_tail(&proc->ftn->ptrace_siblings_list, &org->ftn->ptrace_children);
ihk_mc_spinlock_unlock_noirq(&org->ftn->lock);
#endif
/* We hold a reference to parent */
hold_fork_tree_node(proc->ftn->parent);
@ -327,6 +317,25 @@ err_free_proc:
return NULL;
}
int ptrace_traceme(void){
struct process *proc = cpu_local_var(current);
struct fork_tree_node *ftn = proc->ftn, *parent;
ftn->ptrace = PT_TRACED;
parent = ftn->parent;
if (parent != NULL) {
ftn->ppid_parent = parent;
ihk_mc_spinlock_lock_noirq(&parent->lock);
list_add_tail(&ftn->ptrace_siblings_list, &parent->ptrace_children);
ihk_mc_spinlock_unlock_noirq(&parent->lock);
}
return 0;
}
static int copy_user_ranges(struct process *proc, struct process *org)
{
struct vm_range *src_range;

View File

@ -459,7 +459,7 @@ rescan:
}
if(child_iter->status & (PS_STOPPED | PS_TRACED)) {
/* ptraced and in stopeed or trace-stopped state */
/* ptraced and in stopped or trace-stopped state */
ret = wait_stopped(proc, child_iter, status, options);
if(ret) {
goto out_found;
@ -2277,6 +2277,8 @@ SYSCALL_DECLARE(getrlimit)
return ret;
}
extern int ptrace_traceme(void);
static int ptrace_wakeup_sig(int pid, long request, long data) {
dkprintf("ptrace_wakeup_sig,pid=%d,data=%08x\n", pid, data);
int error;
@ -2353,6 +2355,8 @@ SYSCALL_DECLARE(ptrace)
int error;
switch(request) {
case PTRACE_TRACEME:
error = ptrace_traceme();
case PTRACE_KILL:
case PTRACE_CONT:
error = ptrace_wakeup_sig(pid, request, data);