diff options
author | Daniel Jacobowitz <drow@false.org> | 2002-04-09 21:17:45 +0000 |
---|---|---|
committer | Daniel Jacobowitz <drow@false.org> | 2002-04-09 21:17:45 +0000 |
commit | ce3a066d936533891c43cf478996268b40cb2cac (patch) | |
tree | 34943e6a1ad694b9b5d817d32c2035191994600e /gdb/gdbserver/linux-low.c | |
parent | 0729219dab3a669a294ea00f471fe18c4ba65d79 (diff) | |
download | gdb-ce3a066d936533891c43cf478996268b40cb2cac.zip gdb-ce3a066d936533891c43cf478996268b40cb2cac.tar.gz gdb-ce3a066d936533891c43cf478996268b40cb2cac.tar.bz2 |
2002-04-09 Daniel Jacobowitz <drow@mvista.com>
* gdbserver/inferiors.c: New file.
* gdbserver/target.c: New file.
* gdbserver/target.h: New file.
* gdbserver/Makefile.in: Add target.o and inferiors.o. Update
dependencies.
* gdbserver/linux-low.c (inferior_pid): New static variable,
moved from server.c.
(linux_create_inferior): Renamed from create_inferior.
Call add_inferior. Return 0 on success instead of a PID.
(linux_attach): Renamed from myattach.
(linux_kill): Renamed from kill_inferior. Call clear_inferiors ().
(linux_thread_alive): Renamed from mythread_alive.
(linux_wait): Renamed from mywait. Call clear_inferiors () if the
child dies.
(linux_resume): Renamed from myresume. Add missing ``return 0''.
(regsets_store_inferior_registers): Correct error message.
Add missing ``return 0''.
(linux_fetch_registers): Renamed from fetch_inferior_registers.
(linux_store_registers): Renamed from store_inferior_registers.
(linux_read_memory): Renamed from read_inferior_memory.
(linux_write_memory): Renamed from write_inferior_memory.
(linux_target_ops): New structure.
(initialize_low): Call set_target_ops ().
* gdbserver/remote-utils.c (unhexify): New function.
(hexify): New function.
(input_interrupt): Send signals to ``signal_pid''.
* gdbserver/server.c (inferior_pid): Remove.
(start_inferior): Update create_inferior call.
(attach_inferior): Call add_inferior.
(handle_query): New function.
(main): Call handle_query for `q' packets.
* gdbserver/server.h: Include "target.h". Remove obsolete prototypes.
Add prototypes for "inferiors.c", "target.c", hexify, and unhexify.
Diffstat (limited to 'gdb/gdbserver/linux-low.c')
-rw-r--r-- | gdb/gdbserver/linux-low.c | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 4e40d07..7964f82 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -49,11 +49,13 @@ extern int num_regs; extern int regmap[]; #endif +static int inferior_pid; + /* Start an inferior process and returns its pid. ALLARGS is a vector of program-name and args. */ -int -create_inferior (char *program, char **allargs) +static int +linux_create_inferior (char *program, char **allargs) { int pid; @@ -73,13 +75,16 @@ create_inferior (char *program, char **allargs) _exit (0177); } - return pid; + add_inferior (pid); + /* FIXME remove */ + inferior_pid = pid; + return 0; } /* Attach to an inferior process. */ -int -myattach (int pid) +static int +linux_attach (int pid) { if (ptrace (PTRACE_ATTACH, pid, 0, 0) != 0) { @@ -95,26 +100,27 @@ myattach (int pid) /* Kill the inferior process. Make us have no inferior. */ -void -kill_inferior (void) +static void +linux_kill (void) { if (inferior_pid == 0) return; ptrace (PTRACE_KILL, inferior_pid, 0, 0); wait (0); + clear_inferiors (); } /* Return nonzero if the given thread is still alive. */ -int -mythread_alive (int pid) +static int +linux_thread_alive (int pid) { return 1; } /* Wait for process, returns status */ -unsigned char -mywait (char *status) +static unsigned char +linux_wait (char *status) { int pid; int w; @@ -129,11 +135,13 @@ mywait (char *status) { fprintf (stderr, "\nChild exited with retcode = %x \n", WEXITSTATUS (w)); *status = 'W'; + clear_inferiors (); return ((unsigned char) WEXITSTATUS (w)); } else if (!WIFSTOPPED (w)) { fprintf (stderr, "\nChild terminated with signal = %x \n", WTERMSIG (w)); + clear_inferiors (); *status = 'X'; return ((unsigned char) WTERMSIG (w)); } @@ -148,8 +156,8 @@ mywait (char *status) If STEP is nonzero, single-step it. If SIGNAL is nonzero, give it that signal. */ -void -myresume (int step, int signal) +static void +linux_resume (int step, int signal) { errno = 0; ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, inferior_pid, 1, signal); @@ -318,6 +326,7 @@ regsets_fetch_inferior_registers (void) regset->store_function (buf); regset ++; } + return 0; } static int @@ -360,18 +369,19 @@ regsets_store_inferior_registers (void) } else { - perror ("Warning: ptrace(regsets_fetch_inferior_registers)"); + perror ("Warning: ptrace(regsets_store_inferior_registers)"); } } regset ++; } + return 0; } #endif /* HAVE_LINUX_REGSETS */ void -fetch_inferior_registers (int regno) +linux_fetch_registers (int regno) { #ifdef HAVE_LINUX_REGSETS if (use_regsets_p) @@ -386,7 +396,7 @@ fetch_inferior_registers (int regno) } void -store_inferior_registers (int regno) +linux_store_registers (int regno) { #ifdef HAVE_LINUX_REGSETS if (use_regsets_p) @@ -404,8 +414,8 @@ store_inferior_registers (int regno) /* Copy LEN bytes from inferior's memory starting at MEMADDR to debugger memory starting at MYADDR. */ -void -read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len) +static void +linux_read_memory (CORE_ADDR memaddr, char *myaddr, int len) { register int i; /* Round starting address down to longword boundary. */ @@ -433,8 +443,8 @@ read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len) On failure (cannot write the inferior) returns the value of errno. */ -int -write_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len) +static int +linux_write_memory (CORE_ADDR memaddr, char *myaddr, int len) { register int i; /* Round starting address down to longword boundary. */ @@ -477,8 +487,22 @@ write_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len) return 0; } +static struct target_ops linux_target_ops = { + linux_create_inferior, + linux_attach, + linux_kill, + linux_thread_alive, + linux_resume, + linux_wait, + linux_fetch_registers, + linux_store_registers, + linux_read_memory, + linux_write_memory, +}; + void initialize_low (void) { + set_target_ops (&linux_target_ops); init_registers (); } |