📄 linux-xen-low.c
字号:
else {#ifdef DEBUG perror ("Warning: ptrace(regsets_store_inferior_registers)");#endif } } regset ++; free (buf); } return 0;}voidlinux_fetch_registers (int regno){ if (use_regsets_p) { if (regsets_fetch_inferior_registers () == 0) return; }}voidlinux_store_registers (int regno){ if (use_regsets_p) { if (regsets_store_inferior_registers () == 0) return; }}/* Copy LEN bytes from inferior's memory starting at MEMADDR to debugger memory starting at MYADDR. */static intlinux_read_memory (CORE_ADDR memaddr, char *myaddr, int len){ register int i; /* Round starting address down to longword boundary. */ register CORE_ADDR addr = memaddr & -(CORE_ADDR) sizeof (PTRACE_XFER_TYPE); /* Round ending address up; get number of longwords that makes. */ register int count = (((memaddr + len) - addr) + sizeof (PTRACE_XFER_TYPE) - 1) / sizeof (PTRACE_XFER_TYPE); /* Allocate buffer of that many longwords. */ register PTRACE_XFER_TYPE *buffer = (PTRACE_XFER_TYPE *) alloca (count * sizeof (PTRACE_XFER_TYPE)); TRACE_ENTER; /* Read all the longwords */ for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) { errno = 0; buffer[i] = xc_ptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid(), (PTRACE_ARG3_TYPE) addr, 0); if (errno) return errno; } /* Copy appropriate bytes out of the buffer. */ memcpy (myaddr, (char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), len); return 0;}/* Copy LEN bytes of data from debugger memory at MYADDR to inferior's memory at MEMADDR. On failure (cannot write the inferior) returns the value of errno. */static intlinux_write_memory (CORE_ADDR memaddr, const char *myaddr, int len){ register int i; /* Round starting address down to longword boundary. */ register CORE_ADDR addr = memaddr & -(CORE_ADDR) sizeof (PTRACE_XFER_TYPE); /* Round ending address up; get number of longwords that makes. */ register int count = (((memaddr + len) - addr) + sizeof (PTRACE_XFER_TYPE) - 1) / sizeof (PTRACE_XFER_TYPE); /* Allocate buffer of that many longwords. */ register PTRACE_XFER_TYPE *buffer = (PTRACE_XFER_TYPE *) alloca (count * sizeof (PTRACE_XFER_TYPE)); extern int errno; TRACE_ENTER; /* Fill start and end extra bytes of buffer with existing memory data. */ buffer[0] = xc_ptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid(), (PTRACE_ARG3_TYPE) addr, 0); if (count > 1) { buffer[count - 1] = xc_ptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid(), (PTRACE_ARG3_TYPE) (addr + (count - 1) * sizeof (PTRACE_XFER_TYPE)), 0); } /* Copy data to be written over corresponding part of buffer */ memcpy ((char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), myaddr, len); /* Write the entire buffer. */ for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) { errno = 0; xc_ptrace (xc_handle, PTRACE_POKETEXT, curvcpuid(), (PTRACE_ARG3_TYPE) addr, buffer[i]); if (errno) return errno; } return 0;}static voidlinux_look_up_symbols (void){ if (using_threads) return; using_threads = thread_db_init ();}static voidlinux_send_signal (int signum){ extern int signal_pid; TRACE_ENTER; signal_to_send = signum; psignal(signum, "need to send "); if (cont_thread > 0) { struct process_info *process; process = get_thread_process (current_inferior); kill (process->lwpid, signum); } else kill (signal_pid, signum);}/* Copy LEN bytes from inferior's auxiliary vector starting at OFFSET to debugger memory starting at MYADDR. */static intlinux_read_auxv (CORE_ADDR offset, char *myaddr, unsigned int len){ char filename[PATH_MAX]; int fd, n; TRACE_ENTER; snprintf (filename, sizeof filename, "/proc/%d/auxv", inferior_pid); fd = open (filename, O_RDONLY); if (fd < 0) return -1; if (offset != (CORE_ADDR) 0 && lseek (fd, (off_t) offset, SEEK_SET) != (off_t) offset) n = -1; else n = read (fd, myaddr, len); close (fd); return n;}static struct target_ops linux_xen_target_ops = { linux_create_inferior, linux_attach, linux_kill, linux_detach, linux_thread_alive, linux_resume, linux_wait, linux_fetch_registers, linux_store_registers, linux_read_memory, linux_write_memory, linux_look_up_symbols, linux_send_signal, linux_read_auxv,};static voidlinux_init_signals (){ /* FIXME drow/2002-06-09: As above, we should check with LinuxThreads to find what the cancel signal actually is. */ signal (__SIGRTMIN+1, SIG_IGN);}voidinitialize_low (void){ using_threads = 0; xc_handle = xc_interface_open(); set_target_ops (&linux_xen_target_ops); set_breakpoint_data (the_low_target.breakpoint, the_low_target.breakpoint_len); init_registers (); linux_init_signals (); using_threads = thread_db_init ();}static voidthread_create_callback(long vcpuid){ struct thread_info *inferior; struct process_info *process; /* If we are attaching to our first thread, things are a little * different. */ if (all_threads.head == all_threads.tail) { inferior = (struct thread_info *) all_threads.head; process = get_thread_process (inferior); if (process->thread_known == 0) { /* Switch to indexing the threads list by TID. */ change_inferior_id (&all_threads, vcpuid); goto found; } } if (debug_threads) fprintf (stderr, "looking up thread %ld\n", vcpuid); inferior = (struct thread_info *) find_inferior_id (&all_threads, vcpuid); /* if vcpu alread registered - do nothing */ if (inferior != NULL) return; if (debug_threads) fprintf (stderr, "Attaching to thread %ld\n", vcpuid); process = add_process(current_domid, vcpuid); add_thread(vcpuid, process); inferior = (struct thread_info *) find_inferior_id (&all_threads, vcpuid); if (inferior == NULL) { warning ("Could not attach to thread %ld\n", vcpuid); return; }found: if (debug_threads) fprintf (stderr, "notifying of new thread %ld\n", vcpuid); new_thread_notify (vcpuid); process->tid = vcpuid; process->lwpid = vcpuid; process->thread_known = 1;}static voidthread_death_callback(long vcpuid){ if (debug_threads) fprintf (stderr, "Buuurp...! CPU down event.\n");}intthread_db_init(void){ debug_threads = 0; xc_register_event_handler(thread_create_callback, TD_CREATE); xc_register_event_handler(thread_death_callback, TD_DEATH); return 1;}/* XXX GAG ME */static int breakpoint_found;static voidset_breakpoint_inferior (struct inferior_list_entry *entry){ struct thread_info *thread = (struct thread_info *) entry; struct thread_info *saved_inferior = current_inferior; CORE_ADDR eip; unsigned char buf[2] = {0, 0}; current_inferior = thread; if (!breakpoint_found) { eip = get_stop_pc(); linux_read_memory(eip, buf, 1); if (buf[0] == 0xcc) { breakpoint_found = 1; return; } } else if (breakpoint_found == 2) { if (get_thread_process (current_inferior)->stepping) { printf("stepping\n"); breakpoint_found = 1; return; } } current_inferior = saved_inferior;}static voidlinux_set_inferior (void){ breakpoint_found = 0; for_each_inferior (&all_threads, set_breakpoint_inferior); if (!breakpoint_found) { breakpoint_found = 2; for_each_inferior (&all_threads, set_breakpoint_inferior); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -