23 #include <sys/ptrace.h>
24 #include <sys/piddef.h>
26 #include <sys/ioctl.h>
55 va_start (args,
string);
56 fprintf (stderr,
"DEBUG(lynx): ");
57 vfprintf (stderr,
string, args);
58 fprintf (stderr,
"\n");
111 #define CASE(X) case X: return #X
114 CASE(PTRACE_TRACEME);
115 CASE(PTRACE_PEEKTEXT);
116 CASE(PTRACE_PEEKDATA);
117 CASE(PTRACE_PEEKUSER);
118 CASE(PTRACE_POKETEXT);
119 CASE(PTRACE_POKEDATA);
120 CASE(PTRACE_POKEUSER);
123 CASE(PTRACE_SINGLESTEP);
126 CASE(PTRACE_GETREGS);
127 CASE(PTRACE_SETREGS);
128 CASE(PTRACE_GETFPREGS);
129 CASE(PTRACE_SETFPREGS);
130 CASE(PTRACE_READDATA);
131 CASE(PTRACE_WRITEDATA);
132 CASE(PTRACE_READTEXT);
133 CASE(PTRACE_WRITETEXT);
134 CASE(PTRACE_GETFPAREGS);
135 CASE(PTRACE_SETFPAREGS);
136 CASE(PTRACE_GETWINDOW);
137 CASE(PTRACE_SETWINDOW);
138 CASE(PTRACE_SYSCALL);
139 CASE(PTRACE_DUMPCORE);
140 CASE(PTRACE_SETWRBKPT);
141 CASE(PTRACE_SETACBKPT);
142 CASE(PTRACE_CLRBKPT);
143 CASE(PTRACE_GET_UCODE);
162 #ifdef PTRACE_PEEKUSP
163 CASE(PTRACE_PEEKUSP);
165 #ifdef PTRACE_POKEUSP
166 CASE(PTRACE_POKEUSP);
168 CASE(PTRACE_PEEKTHREAD);
169 CASE(PTRACE_THREADUSER);
171 CASE(PTRACE_FPWRITE);
173 CASE(PTRACE_CONT_ONE);
174 CASE(PTRACE_KILL_ONE);
175 CASE(PTRACE_SINGLESTEP_ONE);
176 CASE(PTRACE_GETLOADINFO);
177 CASE(PTRACE_GETTRACESIG);
178 #ifdef PTRACE_GETTHREADLIST
179 CASE(PTRACE_GETTHREADLIST);
184 return "<unknown-request>";
198 fprintf (stderr,
"PTRACE (%s, pid=%d(pid=%d, tid=%d), addr=0x%x, "
199 "data=0x%x, addr2=0x%x)",
202 result = ptrace (request, pid, addr, data, addr2);
205 fprintf (stderr,
" -> %d (=0x%x)\n", result, result);
250 ioctl (0, TIOCSPGRP, &pgrp);
252 execv (program, allargs);
253 fprintf (stderr,
"Cannot exec %s: %s.\n", program,
strerror (
errno));
278 int thread_pid, thread_tid;
280 f = popen (
"ps atx",
"r");
284 while (fgets (buf,
sizeof (buf), f) != NULL)
285 if ((sscanf (buf,
"%d %d", &thread_pid, &thread_tid) == 2
286 && thread_pid == pid))
292 lynx_debug (
"New thread: (pid = %d, tid = %d)",
308 if (
lynx_ptrace (PTRACE_ATTACH, ptid, 0, 0, 0) != 0)
309 error (
"Cannot attach to process %lu: %s (%d)\n", pid,
325 = (resume_info[0].
kind == resume_step
326 ? (n == 1 ? PTRACE_SINGLESTEP_ONE : PTRACE_SINGLESTEP)
328 const int signal = resume_info[0].
sig;
361 resume_info.
thread = ptid;
362 resume_info.
kind = resume_continue;
378 ret = waitpid (pid, stat_loc,
WNOHANG);
434 lynx_debug (
"New thread: (pid = %d, tid = %d)",
441 status->kind = TARGET_WAITKIND_STOPPED;
443 lynx_debug (
"process stopped with signal: %d",
444 status->value.integer);
448 status->kind = TARGET_WAITKIND_EXITED;
450 lynx_debug (
"process exited with code: %d", status->value.integer);
454 status->kind = TARGET_WAITKIND_SIGNALLED;
456 lynx_debug (
"process terminated with code: %d",
457 status->value.integer);
464 status->kind = TARGET_WAITKIND_STOPPED;
472 if (status->kind == TARGET_WAITKIND_STOPPED
473 && status->value.integer == GDB_SIGNAL_TRAP)
475 const int realsig =
lynx_ptrace (PTRACE_GETTRACESIG, new_ptid, 0, 0, 0);
504 lynx_debug (
"lynx_wait (pid = %d, tid = %ld)",
507 lynx_debug (
" -> (pid=%d, tid=%ld, status->kind = %d)",
519 struct target_waitstatus status;
588 lynx_debug (
"lynx_fetch_registers (regno = %d)", regno);
590 while (regset->
size >= 0)
613 lynx_debug (
"lynx_store_registers (regno = %d)", regno);
615 while (regset->
size >= 0)
645 const int xfer_size =
sizeof (buf);
649 while (addr < memaddr + len)
656 skip = memaddr - addr;
657 if (addr + xfer_size > memaddr + len)
658 truncate = addr + xfer_size - memaddr - len;
659 buf =
lynx_ptrace (PTRACE_PEEKTEXT, inferior_ptid, addr, 0, 0);
662 memcpy (myaddr + (addr - memaddr) + skip, (
gdb_byte *) &buf + skip,
663 xfer_size - skip - truncate);
678 const int xfer_size =
sizeof (buf);
682 while (addr < memaddr + len)
688 skip = memaddr - addr;
689 if (addr + xfer_size > memaddr + len)
690 truncate = addr + xfer_size - memaddr - len;
691 if (skip > 0 || truncate > 0)
699 memcpy ((
gdb_byte *) &buf + skip, myaddr + (addr - memaddr) + skip,
700 xfer_size - skip - truncate);
702 lynx_ptrace (PTRACE_POKETEXT, inferior_ptid, addr, buf, 0);
struct thread_info * current_thread
struct process_info * add_process(int pid, int attached)
struct thread_info * find_thread_ptid(ptid_t ptid)
int ptid_equal(ptid_t ptid1, ptid_t ptid2)
void(* store_function)(struct regcache *regcache, const char *buf)
static void lynx_mourn(struct process_info *proc)
static int lynx_create_inferior(char *program, char **allargs)
static int lynx_ptrace(int request, ptid_t ptid, int addr, int data, int addr2)
void(* fill_function)(struct regcache *regcache, char *buf)
struct process_info * find_process_pid(int pid)
static int lynx_write_memory(CORE_ADDR memaddr, const unsigned char *myaddr, int len)
void(* mourn)(struct process_info *proc)
struct linux_target_ops the_low_target
struct target_ops * the_target
const struct target_desc * tdesc
void perror(const char *)
ptid_t ptid_build(int pid, long lwp, long tid)
static long lynx_ptid_get_tid(ptid_t ptid)
static char * ptrace_request_to_str(int request)
void regcache_invalidate(void)
static int lynx_ptrace_pid_from_ptid(ptid_t ptid)
const struct target_desc * lynx_tdesc
static void lynx_debug(char *string,...)
static void lynx_resume(struct thread_resume *resume_info, size_t n)
ptid_t thread_to_gdb_id(struct thread_info *thread)
enum gdb_signal gdb_signal_from_host(int)
static int lynx_waitpid(int pid, int *stat_loc)
static int lynx_detach(int pid)
void set_target_ops(struct target_ops *target)
struct process_info * current_process(void)
struct process_info_private * priv
void close_most_fds(void)
static int lynx_kill(int pid)
int ptid_get_pid(ptid_t ptid)
static ptid_t lynx_ptid_build(int pid, long tid)
struct lynx_regset_info lynx_target_regsets[]
static ptid_t lynx_wait_1(ptid_t ptid, struct target_waitstatus *status, int options)
ptid_t last_wait_event_ptid
static int lynx_thread_alive(ptid_t ptid)
void perror_with_name(const char *string)
void remove_thread(struct thread_info *thread)
static void lynx_continue(ptid_t ptid)
long ptid_get_lwp(ptid_t ptid)
static ptid_t lynx_wait(ptid_t ptid, struct target_waitstatus *status, int options)
void initialize_low(void)
static struct process_info * lynx_add_process(int pid, int attached)
static int lynx_attach(unsigned long pid)
static void lynx_join(int pid)
static int lynx_ptid_get_pid(ptid_t ptid)
static void lynx_fetch_registers(struct regcache *regcache, int regno)
struct thread_info * add_thread(ptid_t ptid, void *target_data)
static void lynx_store_registers(struct regcache *regcache, int regno)
PTR xcalloc(size_t number, size_t size)
void clear_inferiors(void)
static void lynx_add_threads_after_attach(int pid)
void error(const char *fmt,...)
static int lynx_read_memory(CORE_ADDR memaddr, unsigned char *myaddr, int len)
static void lynx_request_interrupt(void)