X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fuw-thread.c;h=cc6ed6daf4c94a0214cb5df4d145aaa0754cb0b2;hb=54c2a1e69352852e0cd74552e8560321e29b787e;hp=e3650a93b51380f11062608405bb2b47b66de37c;hpb=6c7e601e3ebf5781d8b834a49ae8e63824a3a142;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/uw-thread.c b/gdb/uw-thread.c index e3650a93b5..cc6ed6daf4 100644 --- a/gdb/uw-thread.c +++ b/gdb/uw-thread.c @@ -1,7 +1,7 @@ /* Low level interface for debugging UnixWare user-mode threads for GDB, the GNU debugger. - Copyright 1999, 2000 Free Software Foundation, Inc. + Copyright 1999, 2000, 2001 Free Software Foundation, Inc. Written by Nick Duffek . This file is part of GDB. @@ -101,6 +101,7 @@ #include "gdbthread.h" #include "target.h" #include "inferior.h" +#include "regcache.h" #include /* includes , which requires boolean_t from @@ -112,6 +113,16 @@ #include /* for UnixWare 2.x */ +/* Prototypes for supply_gregset etc. */ +#include "gregset.h" + +/* Offset from SP to first arg on stack at first instruction of a + function. We provide a default here that's right for most, if not + all, targets that use this file. */ + +#ifndef SP_ARG0 +#define SP_ARG0 (1 * 4) +#endif /* Whether to emit debugging output. */ @@ -132,7 +143,7 @@ #endif /* Back end to CALL_BASE() and TRY_BASE(): evaluate CALL, then convert - inferior_pid to a composite thread/process id. */ + inferior_ptid to a composite thread/process id. */ #define CALL_BASE_1(call) \ do { \ @@ -141,8 +152,8 @@ do { \ do_cleanups (infpid_cleanup); \ } while (0) -/* If inferior_pid can be converted to a composite lwp/process id, do so, - evaluate base_ops function CALL, and then convert inferior_pid back to a +/* If inferior_ptid can be converted to a composite lwp/process id, do so, + evaluate base_ops function CALL, and then convert inferior_ptid back to a composite thread/process id. Otherwise, issue an error message and return nonlocally. */ @@ -155,7 +166,7 @@ do { \ } while (0) /* Like CALL_BASE(), but instead of returning nonlocally on error, set - *CALLED to whether the inferior_pid conversion was successful. */ + *CALLED to whether the inferior_ptid conversion was successful. */ #define TRY_BASE(call, called) \ do { \ @@ -217,7 +228,7 @@ static CORE_ADDR thr_map_main; libthread.so passes null map when calling stub with tc_*_complete. */ static struct thread_info *switchto_thread; -/* Cleanup chain for safely restoring inferior_pid after CALL_BASE. */ +/* Cleanup chain for safely restoring inferior_ptid after CALL_BASE. */ static struct cleanup *infpid_cleanup; @@ -258,7 +269,7 @@ dbg (char *fmt, ...) /* Return a string representing composite PID's components. */ static char * -dbgpid (int pid) +dbgpid (ptid_t ptid) { static char *buf, buf1[80], buf2[80]; if (!buf || buf == buf2) @@ -266,10 +277,10 @@ dbgpid (int pid) else buf = buf2; - if (pid <= 0) - sprintf (buf, "%d", pid); + if (PIDGET (ptid) <= 0) + sprintf (buf, "%d", PIDGET (ptid)); else - sprintf (buf, "%s %d/%d", ISTID (pid) ? "thr" : "lwp", + sprintf (buf, "%s %ld/%d", ISTID (pid) ? "thr" : "lwp", TIDGET (pid), PIDGET (pid)); return buf; @@ -321,7 +332,7 @@ static int read_thr_debug (struct thread_debug *debugp) { return base_ops.to_xfer_memory (thr_debug_addr, (char *)debugp, - sizeof (*debugp), 0, &base_ops); + sizeof (*debugp), 0, NULL, &base_ops); } /* Read into MAP the contents of the thread map at inferior process address @@ -331,7 +342,7 @@ static int read_map (CORE_ADDR mapp, struct thread_map *map) { return base_ops.to_xfer_memory ((CORE_ADDR)THR_MAP (mapp), (char *)map, - sizeof (*map), 0, &base_ops); + sizeof (*map), 0, NULL, &base_ops); } /* Read into LWP the contents of the lwp decriptor at inferior process address @@ -341,7 +352,7 @@ static int read_lwp (CORE_ADDR lwpp, __lwp_desc_t *lwp) { return base_ops.to_xfer_memory (lwpp, (char *)lwp, - sizeof (*lwp), 0, &base_ops); + sizeof (*lwp), 0, NULL, &base_ops); } /* Iterate through all user threads, applying FUNC(, , DATA) until @@ -364,7 +375,7 @@ thread_iter (int (*func)(iter_t *, void *), void *data) if (!read_thr_debug (&debug)) return 0; if (!base_ops.to_xfer_memory ((CORE_ADDR)debug.thr_map, (char *)&mapp, - sizeof (mapp), 0, &base_ops)) + sizeof (mapp), 0, NULL, &base_ops)) return 0; if (!mapp) return 0; @@ -401,20 +412,20 @@ deactivate_uw_thread (void) /* Return the composite lwp/process id corresponding to composite id PID. If PID is a thread with no lwp, return 0. */ -static int -thr_to_lwp (int pid) +static ptid_t +thr_to_lwp (ptid_t ptid) { struct thread_info *info; - int lid; + ptid_t lid; - if (!ISTID (pid)) - lid = pid; - else if (!(info = find_thread_pid (pid))) - lid = 0; + if (!ISTID (ptid)) + lid = ptid; + else if (!(info = find_thread_pid (ptid))) + lid = null_ptid; else if (!info->private->lwpid) - lid = 0; + lid = null_ptid; else - lid = MKLID (pid, info->private->lwpid); + lid = MKLID (PIDGET (ptid), info->private->lwpid); DBG2((" thr_to_lwp(%s) = %s", dbgpid (pid), dbgpid (lid))); return lid; @@ -428,7 +439,7 @@ find_thread_lwp_callback (struct thread_info *tp, void *data) { int lwpid = (int)data; - if (!ISTID (tp->pid)) + if (!ISTID (tp->ptid)) return 0; if (!tp->private->stable) return 0; @@ -451,51 +462,52 @@ find_thread_lwp (int lwpid) /* Return the composite thread/process id corresponding to composite id PID. If PID is an lwp with no thread, return PID. */ -static int -lwp_to_thr (int pid) +static ptid_t +lwp_to_thr (ptid_t ptid) { struct thread_info *info; - int tid = pid, lwpid; + int lwpid; + ptid_t tid = ptid; - if (ISTID (pid)) + if (ISTID (ptid)) goto done; - if (!(lwpid = LIDGET (pid))) + if (!(lwpid = LIDGET (ptid))) goto done; if (!(info = find_thread_lwp (lwpid))) goto done; - tid = MKTID (pid, info->private->thrid); + tid = MKTID (PIDGET (ptid), info->private->thrid); done: - DBG2((ISTID (tid) ? NULL : "lwp_to_thr: no thr for %s", dbgpid (pid))); + DBG2((ISTID (tid) ? NULL : "lwp_to_thr: no thr for %s", dbgpid (ptid))); return tid; } -/* do_cleanups() callback: convert inferior_pid to a composite +/* do_cleanups() callback: convert inferior_ptid to a composite thread/process id after having made a procfs call. */ static void thr_infpid (void *unused) { - int pid = lwp_to_thr (inferior_pid); - DBG2((" inferior_pid from procfs: %s => %s", - dbgpid (inferior_pid), dbgpid (pid))); - inferior_pid = pid; + ptid_t ptid = lwp_to_thr (inferior_ptid); + DBG2((" inferior_ptid from procfs: %s => %s", + dbgpid (inferior_ptid), dbgpid (ptid))); + inferior_ptid = ptid; } -/* If possible, convert inferior_pid to a composite lwp/process id in +/* If possible, convert inferior_ptid to a composite lwp/process id in preparation for making a procfs call. Return success. */ static int lwp_infpid (void) { - int pid = thr_to_lwp (inferior_pid); - DBG2((" inferior_pid to procfs: %s => %s", - dbgpid (inferior_pid), dbgpid (pid))); + ptid_t ptid = thr_to_lwp (inferior_ptid); + DBG2((" inferior_ptid to procfs: %s => %s", + dbgpid (inferior_ptid), dbgpid (ptid))); - if (!pid) + if (ptid_equal (ptid, null_ptid)) return 0; - inferior_pid = pid; + inferior_ptid = ptid; infpid_cleanup = make_cleanup (thr_infpid, NULL); return 1; } @@ -504,11 +516,11 @@ lwp_infpid (void) lwp id LWPID, map address MAPP, and composite thread/process PID. */ static void -add_thread_uw (int thrid, int lwpid, CORE_ADDR mapp, int pid) +add_thread_uw (int thrid, int lwpid, CORE_ADDR mapp, ptid_t ptid) { struct thread_info *newthread; - if ((newthread = add_thread (pid)) == NULL) + if ((newthread = add_thread (ptid)) == NULL) error ("failed to create new thread structure"); newthread->private = xmalloc (sizeof (struct private_thread_info)); @@ -518,7 +530,7 @@ add_thread_uw (int thrid, int lwpid, CORE_ADDR mapp, int pid) newthread->private->mapp = mapp; if (target_has_execution) - printf_unfiltered ("[New %s]\n", target_pid_to_str (pid)); + printf_unfiltered ("[New %s]\n", target_pid_to_str (ptid)); } /* notice_threads() and find_main() callback: if the thread list doesn't @@ -530,10 +542,10 @@ notice_thread (iter_t *iter, void *data) { int thrid = iter->map.thr_tid; int lwpid = !iter->map.thr_lwpp ? 0 : iter->lwp.lwp_id; - int pid = MKTID (inferior_pid, thrid); + ptid_t ptid = MKTID (PIDGET (inferior_ptid), thrid); - if (!find_thread_pid (pid) && (!data || thrid == 1)) - add_thread_uw (thrid, lwpid, iter->mapp, pid); + if (!find_thread_pid (ptid) && (!data || thrid == 1)) + add_thread_uw (thrid, lwpid, iter->mapp, ptid); return 0; } @@ -555,7 +567,7 @@ find_main (void) { struct thread_info *info; thread_iter (notice_thread, (void *)1); - if ((info = find_thread_pid (MKTID (inferior_pid, 1)))) + if ((info = find_thread_pid (MKTID (PIDGET (inferior_ptid), 1)))) thr_map_main = info->private->mapp; } return thr_map_main; @@ -587,12 +599,16 @@ uw_thread_detach (char *args, int from_tty) and all threads otherwise. */ static void -uw_thread_resume (int pid, int step, enum target_signal signo) +uw_thread_resume (ptid_t ptid, int step, enum target_signal signo) { - if (pid > 0 && !(pid = thr_to_lwp (pid))) - pid = -1; + if (PIDGET (ptid) > 0) + { + ptid = thr_to_lwp (ptid); + if (ptid_equal (ptid, null_ptid)) + ptid = pid_to_ptid (-1); + } - CALL_BASE (base_ops.to_resume (pid, step, signo)); + CALL_BASE (base_ops.to_resume (ptid, step, signo)); } /* If the trap we just received from lwp PID was due to a breakpoint @@ -600,26 +616,27 @@ uw_thread_resume (int pid, int step, enum target_signal signo) accordingly. */ static void -libthread_stub (int pid) +libthread_stub (ptid_t ptid) { CORE_ADDR sp, mapp, mapp_main; enum thread_change change; struct thread_map map; __lwp_desc_t lwp; - int tid = 0, lwpid; + int lwpid; + ptid_t tid = null_ptid; struct thread_info *info; /* Check for stub breakpoint. */ - if (read_pc_pid (pid) - DECR_PC_AFTER_BREAK != thr_brk_addr) + if (read_pc_pid (ptid) - DECR_PC_AFTER_BREAK != thr_brk_addr) return; /* Retrieve stub args. */ - sp = read_register_pid (SP_REGNUM, pid); + sp = read_register_pid (SP_REGNUM, ptid); if (!base_ops.to_xfer_memory (sp + SP_ARG0, (char *)&mapp, - sizeof (mapp), 0, &base_ops)) + sizeof (mapp), 0, NULL, &base_ops)) goto err; if (!base_ops.to_xfer_memory (sp + SP_ARG0 + sizeof (mapp), (char *)&change, - sizeof (change), 0, &base_ops)) + sizeof (change), 0, NULL, &base_ops)) goto err; /* create_inferior() may not have finished yet, so notice the main @@ -639,7 +656,7 @@ libthread_stub (int pid) break; if (!read_map (mapp, &map)) goto err; - tid = MKTID (pid, map.thr_tid); + tid = MKTID (PIDGET (ptid), map.thr_tid); switch (change) { case tc_thread_create: /* new thread */ @@ -655,8 +672,8 @@ libthread_stub (int pid) case tc_thread_exit: /* thread has exited */ printf_unfiltered ("[Exited %s]\n", target_pid_to_str (tid)); delete_thread (tid); - if (tid == inferior_pid) - inferior_pid = pid; + if (ptid_equal (tid, inferior_ptid)) + inferior_ptid = ptid; break; case tc_switch_begin: /* lwp is switching threads */ @@ -717,22 +734,25 @@ libthread_stub (int pid) /* Wait for thread/lwp/process ID if >= 0 or for any thread otherwise. */ -static int -uw_thread_wait (int pid, struct target_waitstatus *status) +static ptid_t +uw_thread_wait (ptid_t ptid, struct target_waitstatus *status) { - if (pid > 0) - pid = thr_to_lwp (pid); - CALL_BASE (pid = base_ops.to_wait (pid > 0 ? pid : -1, status)); + if (PIDGET (ptid) > 0) + ptid = thr_to_lwp (ptid); + if (PIDGET (ptid) <= 0) + ptid = pid_to_ptid (-1); + + CALL_BASE (ptid = base_ops.to_wait (ptid, status)); if (status->kind == TARGET_WAITKIND_STOPPED && status->value.sig == TARGET_SIGNAL_TRAP) - libthread_stub (pid); + libthread_stub (ptid); - return lwp_to_thr (pid); + return lwp_to_thr (ptid); } /* Tell gdb about the registers in the thread/lwp/process specified by - inferior_pid. */ + inferior_ptid. */ static void uw_thread_fetch_registers (int regno) @@ -745,7 +765,7 @@ uw_thread_fetch_registers (int regno) if (called) return; - if (!(info = find_thread_pid (inferior_pid))) + if (!(info = find_thread_pid (inferior_ptid))) return; if (!read_map (info->private->mapp, &map)) return; @@ -755,7 +775,7 @@ uw_thread_fetch_registers (int regno) } /* Store gdb's current view of the register set into the thread/lwp/process - specified by inferior_pid. */ + specified by inferior_ptid. */ static void uw_thread_store_registers (int regno) @@ -819,14 +839,14 @@ uw_thread_can_run (void) /* Return whether thread PID is still valid. */ static int -uw_thread_alive (int pid) +uw_thread_alive (ptid_t ptid) { - if (!ISTID (pid)) - return base_ops.to_thread_alive (pid); + if (!ISTID (ptid)) + return base_ops.to_thread_alive (ptid); /* If it's in the thread list, it's valid, because otherwise libthread_stub() would have deleted it. */ - return in_thread_list (pid); + return in_thread_list (ptid); } /* Add to the thread list any threads and lwps it doesn't already contain. */ @@ -843,16 +863,16 @@ uw_thread_find_new_threads (void) This may be called by either procfs.c or by generic gdb. */ static char * -uw_thread_pid_to_str (int pid) +uw_thread_pid_to_str (ptid_t ptid) { -#define FMT "Thread %d" - static char buf[sizeof (FMT) + 3 * sizeof (pid)]; +#define FMT "Thread %ld" + static char buf[sizeof (FMT) + 3 * sizeof (long)]; - if (!ISTID (pid)) + if (!ISTID (ptid)) /* core_ops says "process foo", so call procfs_ops explicitly. */ - return procfs_ops.to_pid_to_str (pid); + return procfs_ops.to_pid_to_str (ptid); - sprintf (buf, FMT, TIDGET (pid)); + sprintf (buf, FMT, TIDGET (ptid)); #undef FMT return buf; } @@ -869,7 +889,7 @@ uw_extra_thread_info (struct thread_info *info) int lwpid; char *name; - if (!ISTID (info->pid)) + if (!ISTID (info->ptid)) return NULL; if (!info->private->stable) @@ -963,7 +983,7 @@ libthread_init (void) /* Activate the stub function. */ onp = (CORE_ADDR)&((struct thread_debug *)thr_debug_addr)->thr_debug_on; if (!base_ops.to_xfer_memory ((CORE_ADDR)onp, (char *)&one, - sizeof (one), 1, &base_ops)) + sizeof (one), 1, NULL, &base_ops)) { delete_breakpoint (b); goto err;