Lines Matching defs:P
85 Pread_live(struct ps_prochandle *P, void *buf, size_t n, uintptr_t addr,
88 return (pread(P->asfd, buf, n, (off_t)addr));
93 Pwrite_live(struct ps_prochandle *P, const void *buf, size_t n, uintptr_t addr,
96 return (pwrite(P->asfd, buf, n, (off_t)addr));
101 Pread_maps_live(struct ps_prochandle *P, prmap_t **Pmapp, ssize_t *nmapp,
111 procfs_path, (int)P->pid);
122 Preset_maps(P); /* utter failure; destroy tables */
135 Pread_aux_live(struct ps_prochandle *P, auxv_t **auxvp, int *nauxp, void *data)
144 procfs_path, (int)P->pid);
173 Pcred_live(struct ps_prochandle *P, prcred_t *pcrp, int ngroups, void *data)
175 return (proc_get_cred(P->pid, pcrp, ngroups));
180 Ppriv_live(struct ps_prochandle *P, prpriv_t **pprv, void *data)
184 pp = proc_get_priv(P->pid);
195 Ppsinfo_live(struct ps_prochandle *P, psinfo_t *psinfo, void *data)
197 if (proc_get_psinfo(P->pid, psinfo) == -1)
205 Plstatus_live(struct ps_prochandle *P, void *data)
207 return (read_lfile(P, "lstatus"));
212 Plpsinfo_live(struct ps_prochandle *P, void *data)
214 return (read_lfile(P, "lpsinfo"));
219 Pplatform_live(struct ps_prochandle *P, char *s, size_t n, void *data)
228 Puname_live(struct ps_prochandle *P, struct utsname *u, void *data)
235 Pzonename_live(struct ps_prochandle *P, char *s, size_t n, void *data)
237 if (getzonenamebyid(P->status.pr_zoneid, s, n) < 0)
260 Pexecname_live(struct ps_prochandle *P, char *buf, size_t buflen, void *data)
272 "%s/%d/path/a.out", procfs_path, (int)P->pid);
275 (void) Pfindobj(P, buf, buf, buflen);
284 "%s/%d/object/a.out", procfs_path, (int)P->pid);
295 "%s/%d/path/cwd", procfs_path, (int)P->pid);
300 (void) Pfindexec(P, ret > 0 ? cwd : NULL, stat_exec, &st);
308 Pldt_live(struct ps_prochandle *P, struct ssd *pldt, int nldt, void *data)
310 return (proc_get_ldt(P->pid, pldt, nldt));
428 struct ps_prochandle *P;
440 if ((P = malloc(sizeof (struct ps_prochandle))) == NULL) {
446 free(P);
463 Pcreate_callback(P); /* execute callback (see below) */
481 (void) memset(P, 0, sizeof (*P));
482 (void) mutex_init(&P->proc_lock, USYNC_THREAD, NULL);
483 P->flags |= CREATED;
484 P->state = PS_RUN;
485 P->pid = pid;
486 P->asfd = -1;
487 P->ctlfd = -1;
488 P->statfd = -1;
489 P->agentctlfd = -1;
490 P->agentstatfd = -1;
491 Pinit_ops(&P->ops, &P_live_ops);
492 Pinitsym(P);
514 P->asfd = fd;
524 P->statfd = fd;
534 P->ctlfd = fd;
536 (void) Pstop(P, 0); /* stop the controlled process */
546 (void) Psysentry(P, SYS_pause, 1);
547 (void) Psysexit(P, SYS_pause, 1);
549 if (P->state == PS_STOP &&
550 P->status.pr_lwp.pr_syscall == SYS_pause &&
551 (P->status.pr_lwp.pr_why == PR_REQUESTED ||
552 P->status.pr_lwp.pr_why == PR_SYSENTRY ||
553 P->status.pr_lwp.pr_why == PR_SYSEXIT))
556 if (P->state != PS_STOP || /* interrupt or process died */
557 Psetrun(P, 0, 0) != 0) { /* can't restart */
568 (void) Pwait(P, 0);
570 (void) Psysentry(P, SYS_pause, 0);
571 (void) Psysexit(P, SYS_pause, 0);
577 (void) Psysentry(P, SYS_exit, 1);
578 (void) Psysentry(P, SYS_execve, 1);
579 if (Psetrun(P, 0, PRSABORT) == -1) {
584 (void) Pwait(P, 0);
585 if (P->state != PS_STOP) {
595 (void) Psysexit(P, SYS_execve, TRUE);
597 while (P->state == PS_STOP &&
598 P->status.pr_lwp.pr_why == PR_SYSENTRY &&
599 P->status.pr_lwp.pr_what == SYS_execve) {
605 (void) Pread_string(P, execpath, sizeof (execpath),
606 (off_t)P->status.pr_lwp.pr_sysarg[0]);
613 (void) Psetrun(P, 0, 0);
614 (void) Pwait(P, 0);
616 if (P->state == PS_LOST && /* we lost control */
617 Preopen(P) != 0) { /* and we can't get it back */
626 if (P->state == PS_STOP &&
627 P->status.pr_lwp.pr_why == PR_SYSEXIT &&
628 P->status.pr_lwp.pr_what == SYS_execve &&
629 (lasterrno = P->status.pr_lwp.pr_errno) != 0) {
634 (void) Psetrun(P, 0, 0);
635 (void) Pwait(P, 0);
642 if (P->state == PS_STOP &&
643 P->status.pr_lwp.pr_why == PR_SYSEXIT &&
644 P->status.pr_lwp.pr_what == SYS_execve &&
645 P->status.pr_lwp.pr_errno == 0) {
650 restore_tracing_flags(P);
653 if (P->status.pr_dmodel == PR_MODEL_LP64) {
662 (void) Psetflags(P, PR_RLC);
664 return (P);
673 Pfree(P);
737 Pcreate_callback(struct ps_prochandle *P)
758 struct ps_prochandle *P;
771 if ((P = malloc(sizeof (struct ps_prochandle))) == NULL) {
776 P->asfd = -1;
777 P->ctlfd = -1;
778 P->statfd = -1;
781 if (P->ctlfd >= 0)
782 (void) close(P->ctlfd);
783 if (P->asfd >= 0)
784 (void) close(P->asfd);
785 if (P->statfd >= 0)
786 (void) close(P->statfd);
787 (void) memset(P, 0, sizeof (*P));
788 (void) mutex_init(&P->proc_lock, USYNC_THREAD, NULL);
789 P->ctlfd = -1;
790 P->asfd = -1;
791 P->statfd = -1;
792 P->agentctlfd = -1;
793 P->agentstatfd = -1;
794 Pinit_ops(&P->ops, &P_live_ops);
795 Pinitsym(P);
842 P->asfd = fd;
862 P->statfd = fd;
883 P->ctlfd = fd;
886 P->state = PS_RUN;
887 P->pid = pid;
899 if (Pstopstatus(P, PCNULL, 0) != 0) {
906 if (P->state == PS_LOST) { /* WoV */
907 (void) mutex_destroy(&P->proc_lock);
911 if (P->state == PS_UNDEAD)
922 if (P->status.pr_flags & PR_ISSYS) {
930 if (P->status.pr_dmodel == PR_MODEL_LP64) {
939 P->orig_status = P->status; /* structure copy */
956 if (Pread(P, &magic2, sizeof (magic2), (uintptr_t)&magic1)
960 Pread(P, &magic2, sizeof (magic2), (uintptr_t)&magic1)
973 if (!(P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) &&
979 if (Psetflags(P, PR_RLC) != 0) {
981 (void) mutex_destroy(&P->proc_lock);
1006 while ((P->status.pr_lwp.pr_flags & (PR_STOPPED|PR_DSTOP)) ==
1008 Pstopstatus(P, PCTWSTOP, 20) != 0) {
1015 P->status.pr_lwp.pr_flags &= ~PR_DSTOP;
1023 if (!(P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) &&
1028 if (((P->status.pr_lwp.pr_flags & PR_STOPPED) &&
1029 Pstopstatus(P, PCDSTOP, 0) != 0) ||
1030 Pstopstatus(P, PCSTOP, 2000) != 0) {
1037 if (P->state == PS_LOST) { /* WoV */
1038 (void) mutex_destroy(&P->proc_lock);
1042 (P->state != PS_STOP &&
1043 !(P->status.pr_flags & PR_DSTOP))) {
1044 if (P->state != PS_RUN && errno != ENOENT) {
1058 if (!(P->status.pr_flags & (PR_ISTOP|PR_DSTOP))) {
1068 if (P->status.pr_dmodel == PR_MODEL_LP64) {
1079 (void) Psysentry(P, 0, FALSE);
1080 (void) Psysexit(P, 0, FALSE);
1081 (void) Psignal(P, 0, FALSE);
1082 (void) Pfault(P, 0, FALSE);
1083 Psync(P);
1087 return (P);
1090 Pfree(P);
1171 Pfree(struct ps_prochandle *P)
1175 if (P->ucaddrs != NULL) {
1176 free(P->ucaddrs);
1177 P->ucaddrs = NULL;
1178 P->ucnelems = 0;
1181 (void) mutex_lock(&P->proc_lock);
1182 if (P->hashtab != NULL) {
1185 while ((L = P->hashtab[i]) != NULL)
1186 Lfree_internal(P, L);
1188 free(P->hashtab);
1191 while (P->num_fd > 0) {
1192 fd_info_t *fip = list_next(&P->fd_head);
1195 P->num_fd--;
1197 (void) mutex_unlock(&P->proc_lock);
1198 (void) mutex_destroy(&P->proc_lock);
1200 if (P->agentctlfd >= 0)
1201 (void) close(P->agentctlfd);
1202 if (P->agentstatfd >= 0)
1203 (void) close(P->agentstatfd);
1204 if (P->ctlfd >= 0)
1205 (void) close(P->ctlfd);
1206 if (P->asfd >= 0)
1207 (void) close(P->asfd);
1208 if (P->statfd >= 0)
1209 (void) close(P->statfd);
1210 Preset_maps(P);
1211 P->ops.pop_fini(P, P->data);
1214 (void) memset(P, 0, sizeof (*P));
1215 P->ctlfd = -1;
1216 P->asfd = -1;
1217 P->statfd = -1;
1218 P->agentctlfd = -1;
1219 P->agentstatfd = -1;
1221 free(P);
1228 Pstate(struct ps_prochandle *P)
1230 return (P->state);
1239 Pasfd(struct ps_prochandle *P)
1241 return (P->asfd);
1250 Pctlfd(struct ps_prochandle *P)
1252 return (P->ctlfd);
1261 Ppsinfo(struct ps_prochandle *P)
1263 return (P->ops.pop_psinfo(P, &P->psinfo, P->data));
1272 Pstatus(struct ps_prochandle *P)
1274 return (&P->status);
1278 Pread_status(struct ps_prochandle *P)
1280 P->ops.pop_status(P, &P->status, P->data);
1290 Pcred(struct ps_prochandle *P, prcred_t *pcrp, int ngroups)
1292 return (P->ops.pop_cred(P, pcrp, ngroups, P->data));
1296 Plstatus(struct ps_prochandle *P)
1298 return (P->ops.pop_lstatus(P, P->data));
1302 Plpsinfo(struct ps_prochandle *P)
1304 return (P->ops.pop_lpsinfo(P, P->data));
1316 Pldt(struct ps_prochandle *P, struct ssd *pldt, int nldt)
1318 return (P->ops.pop_ldt(P, pldt, nldt, P->data));
1327 Ppriv(struct ps_prochandle *P, prpriv_t **pprv)
1329 return (P->ops.pop_priv(P, pprv, P->data));
1333 Psetpriv(struct ps_prochandle *P, prpriv_t *pprv)
1339 if (P->state == PS_DEAD) {
1356 if (write(P->ctlfd, ctl, sz) != sz)
1367 Pprivinfo(struct ps_prochandle *P)
1369 core_info_t *core = P->data;
1372 if (P->state != PS_DEAD)
1384 Psync(struct ps_prochandle *P)
1386 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd;
1391 if (P->flags & SETHOLD) {
1395 iov[n].iov_base = (caddr_t)&P->status.pr_lwp.pr_lwphold;
1396 iov[n++].iov_len = sizeof (P->status.pr_lwp.pr_lwphold);
1398 if (P->flags & SETREGS) {
1402 if (ctlfd == P->agentctlfd)
1403 P->status.pr_lwp.pr_reg[GS] = 0;
1409 iov[n].iov_base = (caddr_t)&P->status.pr_lwp.pr_reg[0];
1410 iov[n++].iov_len = sizeof (P->status.pr_lwp.pr_reg);
1412 if (P->flags & SETSIG) {
1416 iov[n].iov_base = (caddr_t)&P->status.pr_sigtrace;
1417 iov[n++].iov_len = sizeof (P->status.pr_sigtrace);
1419 if (P->flags & SETFAULT) {
1423 iov[n].iov_base = (caddr_t)&P->status.pr_flttrace;
1424 iov[n++].iov_len = sizeof (P->status.pr_flttrace);
1426 if (P->flags & SETENTRY) {
1430 iov[n].iov_base = (caddr_t)&P->status.pr_sysentry;
1431 iov[n++].iov_len = sizeof (P->status.pr_sysentry);
1433 if (P->flags & SETEXIT) {
1437 iov[n].iov_base = (caddr_t)&P->status.pr_sysexit;
1438 iov[n++].iov_len = sizeof (P->status.pr_sysexit);
1444 P->flags &= ~(SETSIG|SETFAULT|SETENTRY|SETEXIT|SETHOLD|SETREGS);
1451 Preopen(struct ps_prochandle *P)
1457 if (P->state == PS_DEAD || P->state == PS_IDLE)
1460 if (P->agentcnt > 0) {
1461 P->agentcnt = 1;
1462 Pdestroy_agent(P);
1466 procfs_path, (int)P->pid);
1471 close(P->asfd) < 0 ||
1472 (fd = dupfd(fd, P->asfd)) != P->asfd) {
1479 P->asfd = fd;
1483 close(P->statfd) < 0 ||
1484 (fd = dupfd(fd, P->statfd)) != P->statfd) {
1491 P->statfd = fd;
1495 close(P->ctlfd) < 0 ||
1496 (fd = dupfd(fd, P->ctlfd)) != P->ctlfd) {
1503 P->ctlfd = fd;
1507 * we re-read the status from the new P->statfd. If this fails, Pwait
1509 * returning, we also forge a bit of P->status to allow the debugger to
1512 P->state = PS_RUN;
1513 if (Pwait(P, 0) == -1) {
1516 P->status.pr_dmodel = PR_MODEL_LP64;
1518 P->status.pr_lwp.pr_why = PR_SYSEXIT;
1519 P->status.pr_lwp.pr_what = SYS_execve;
1520 P->status.pr_lwp.pr_errno = 0;
1528 if (P->state == PS_STOP &&
1529 (P->status.pr_lwp.pr_why == PR_REQUESTED ||
1530 (P->status.pr_lwp.pr_why == PR_SYSEXIT &&
1531 P->status.pr_lwp.pr_what == SYS_execve))) {
1533 if (P->status.pr_lwp.pr_why == PR_REQUESTED) {
1534 P->status.pr_lwp.pr_why = PR_SYSEXIT;
1535 P->status.pr_lwp.pr_what = SYS_execve;
1536 P->status.pr_lwp.pr_errno = 0;
1557 restore_tracing_flags(struct ps_prochandle *P)
1563 if (P->flags & CREATED) {
1565 premptyset(&P->status.pr_sigtrace);
1566 premptyset(&P->status.pr_flttrace);
1567 premptyset(&P->status.pr_sysentry);
1568 premptyset(&P->status.pr_sysexit);
1569 if ((P->status.pr_flags & ALL_SETTABLE_FLAGS) != 0)
1570 (void) Punsetflags(P, ALL_SETTABLE_FLAGS);
1573 P->status.pr_sigtrace = P->orig_status.pr_sigtrace;
1574 P->status.pr_flttrace = P->orig_status.pr_flttrace;
1575 P->status.pr_sysentry = P->orig_status.pr_sysentry;
1576 P->status.pr_sysexit = P->orig_status.pr_sysexit;
1577 if ((P->status.pr_flags & ALL_SETTABLE_FLAGS) !=
1578 (flags = (P->orig_status.pr_flags & ALL_SETTABLE_FLAGS))) {
1579 (void) Punsetflags(P, ALL_SETTABLE_FLAGS);
1581 (void) Psetflags(P, flags);
1588 iov[1].iov_base = (caddr_t)&P->status.pr_sigtrace;
1589 iov[1].iov_len = sizeof (P->status.pr_sigtrace);
1594 iov[3].iov_base = (caddr_t)&P->status.pr_flttrace;
1595 iov[3].iov_len = sizeof (P->status.pr_flttrace);
1600 iov[5].iov_base = (caddr_t)&P->status.pr_sysentry;
1601 iov[5].iov_len = sizeof (P->status.pr_sysentry);
1606 iov[7].iov_base = (caddr_t)&P->status.pr_sysexit;
1607 iov[7].iov_len = sizeof (P->status.pr_sysexit);
1609 (void) writev(P->ctlfd, iov, 8);
1611 P->flags &= ~(SETSIG|SETFAULT|SETENTRY|SETEXIT);
1623 Prelease(struct ps_prochandle *P, int flags)
1625 if (P->state == PS_DEAD) {
1627 (void *)P, (int)P->pid);
1628 Pfree(P);
1632 if (P->state == PS_IDLE) {
1633 file_info_t *fptr = list_next(&P->file_head);
1635 (void *)P, fptr->file_pname);
1636 Pfree(P);
1641 (void *)P, (int)P->pid);
1643 if (P->ctlfd == -1) {
1644 Pfree(P);
1648 if (P->agentcnt > 0) {
1649 P->agentcnt = 1;
1650 Pdestroy_agent(P);
1656 P->state = PS_RUN;
1657 (void) Pstop(P, 1000);
1660 if (P->state == PS_STOP)
1661 (void) Psetrun(P, SIGKILL, 0);
1662 (void) kill(P->pid, SIGKILL);
1663 Pfree(P);
1671 if (P->state != PS_STOP &&
1672 (P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) == 0) {
1673 Pfree(P);
1680 Psync(P);
1683 P->flags |= CREATED;
1686 restore_tracing_flags(P);
1690 (void) Punsetflags(P, PR_RLC|PR_KLC);
1691 Pfree(P);
1700 if ((P->flags & CREATED) ||
1701 (P->orig_status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP)) == 0) {
1702 (void) Psetflags(P, PR_RLC);
1709 if (Psetrun(P, 0, 0) == -1 && errno == EBUSY)
1711 } while (Pstopstatus(P, PCNULL, 0) == 0 &&
1712 P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP));
1714 if (P->status.pr_lwp.pr_flags & (PR_ISTOP|PR_DSTOP))
1718 Pfree(P);
1770 prdump(struct ps_prochandle *P)
1774 prldump("Pstopstatus", &P->status.pr_lwp);
1776 bits = *((uint32_t *)&P->status.pr_sigpend);
1789 Pstopstatus(struct ps_prochandle *P,
1793 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd;
1797 int old_state = P->state;
1799 switch (P->state) {
1821 dprintf("Pstopstatus: corrupted state: %d\n", P->state);
1841 if (P->state == PS_DEAD || P->state == PS_IDLE)
1849 Psync(P);
1851 if (P->agentstatfd < 0) {
1852 if (pread(P->statfd, &P->status,
1853 sizeof (P->status), (off_t)0) < 0)
1856 if (pread(P->agentstatfd, &P->status.pr_lwp,
1857 sizeof (P->status.pr_lwp), (off_t)0) < 0)
1859 P->status.pr_flags = P->status.pr_lwp.pr_flags;
1871 P->state = PS_LOST;
1891 deadcheck(P);
1900 if (!(P->status.pr_flags & PR_STOPPED)) {
1901 P->state = PS_RUN;
1909 P->state = PS_STOP;
1912 prdump(P);
1916 * then don't use its PC to set P->sysaddr since it may have been
1922 switch (P->status.pr_lwp.pr_why) {
1925 if (Pissyscall_prev(P, P->status.pr_lwp.pr_reg[R_PC],
1926 &P->sysaddr) == 0)
1927 P->sysaddr = P->status.pr_lwp.pr_reg[R_PC];
1947 Pwait(struct ps_prochandle *P, uint_t msec)
1949 return (Pstopstatus(P, PCWSTOP, msec));
1956 Pstop(struct ps_prochandle *P, uint_t msec)
1958 return (Pstopstatus(P, PCSTOP, msec));
1965 Pdstop(struct ps_prochandle *P)
1967 return (Pstopstatus(P, PCDSTOP, 0));
1971 deadcheck(struct ps_prochandle *P)
1977 if (P->statfd < 0)
1978 P->state = PS_UNDEAD;
1980 if (P->agentstatfd < 0) {
1981 fd = P->statfd;
1982 buf = &P->status;
1983 size = sizeof (P->status);
1985 fd = P->agentstatfd;
1986 buf = &P->status.pr_lwp;
1987 size = sizeof (P->status.pr_lwp);
1992 P->state = PS_UNDEAD;
1998 P->state = PS_LOST;
2003 P->status.pr_flags = P->status.pr_lwp.pr_flags;
2011 Pgetareg(struct ps_prochandle *P, int regno, prgreg_t *preg)
2018 if (P->state == PS_IDLE) {
2023 if (P->state != PS_STOP && P->state != PS_DEAD) {
2028 *preg = P->status.pr_lwp.pr_reg[regno];
2036 Pputareg(struct ps_prochandle *P, int regno, prgreg_t reg)
2043 if (P->state != PS_STOP) {
2048 P->status.pr_lwp.pr_reg[regno] = reg;
2049 P->flags |= SETREGS; /* set registers before continuing */
2054 Psetrun(struct ps_prochandle *P,
2058 int ctlfd = (P->agentctlfd >= 0) ? P->agentctlfd : P->ctlfd;
2068 if (P->state != PS_STOP && (P->status.pr_lwp.pr_flags & sbits) == 0) {
2073 Psync(P); /* flush tracing flags and registers */
2083 } else if (sig && sig != P->status.pr_lwp.pr_cursig) {
2098 P->info_valid = 0; /* will need to update map and file info */
2104 if (P->ucaddrs != NULL) {
2105 free(P->ucaddrs);
2106 P->ucaddrs = NULL;
2107 P->ucnelems = 0;
2113 (void) Pstopstatus(P, PCNULL, 0);
2118 P->status.pr_lwp.pr_why != PR_JOBCONTROL) {
2125 P->state = PS_RUN;
2130 Pread(struct ps_prochandle *P,
2135 return (P->ops.pop_pread(P, buf, nbyte, address, P->data));
2139 Pread_string(struct ps_prochandle *P,
2160 if ((nbyte = P->ops.pop_pread(P, string, STRSZ, addr,
2161 P->data)) <= 0) {
2177 Pwrite(struct ps_prochandle *P,
2182 return (P->ops.pop_pwrite(P, buf, nbyte, address, P->data));
2186 Pclearsig(struct ps_prochandle *P)
2188 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd;
2193 P->status.pr_lwp.pr_cursig = 0;
2198 Pclearfault(struct ps_prochandle *P)
2200 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd;
2212 Psetbkpt(struct ps_prochandle *P, uintptr_t address, ulong_t *saved)
2222 if (P->state == PS_DEAD || P->state == PS_UNDEAD ||
2223 P->state == PS_IDLE) {
2245 if (write(P->ctlfd, ctl, size) != size)
2265 Pdelbkpt(struct ps_prochandle *P, uintptr_t address, ulong_t saved)
2270 if (P->state == PS_DEAD || P->state == PS_UNDEAD ||
2271 P->state == PS_IDLE) {
2283 if (Pread(P, &cur, sizeof (cur), address) == sizeof (cur) &&
2287 if (Pwrite(P, &old, sizeof (old), address) != sizeof (old))
2397 Pxecbkpt(struct ps_prochandle *P, ulong_t saved)
2399 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd;
2402 if (P->state != PS_STOP) {
2407 Psync(P);
2410 &P->status.pr_flttrace, &P->status.pr_lwp.pr_lwphold,
2411 P->status.pr_lwp.pr_reg[R_PC], saved);
2412 rv = Pstopstatus(P, PCNULL, 0);
2415 if (P->status.pr_lwp.pr_why == PR_JOBCONTROL &&
2417 P->state = PS_RUN;
2433 Psetwapt(struct ps_prochandle *P, const prwatch_t *wp)
2438 if (P->state == PS_DEAD || P->state == PS_UNDEAD ||
2439 P->state == PS_IDLE) {
2449 if (write(P->ctlfd, ctl, sizeof (ctl)) != sizeof (ctl))
2459 Pdelwapt(struct ps_prochandle *P, const prwatch_t *wp)
2464 if (P->state == PS_DEAD || P->state == PS_UNDEAD ||
2465 P->state == PS_IDLE) {
2475 if (write(P->ctlfd, ctl, sizeof (ctl)) != sizeof (ctl))
2592 Pxecwapt(struct ps_prochandle *P, const prwatch_t *wp)
2594 int ctlfd = (P->agentctlfd >= 0)? P->agentctlfd : P->ctlfd;
2597 if (P->state != PS_STOP) {
2602 Psync(P);
2604 &P->status.pr_flttrace, &P->status.pr_lwp.pr_lwphold, wp);
2605 rv = Pstopstatus(P, PCNULL, 0);
2608 if (P->status.pr_lwp.pr_why == PR_JOBCONTROL &&
2610 P->state = PS_RUN;
2623 Psetflags(struct ps_prochandle *P, long flags)
2631 if (write(P->ctlfd, ctl, 2*sizeof (long)) != 2*sizeof (long)) {
2634 P->status.pr_flags |= flags;
2635 P->status.pr_lwp.pr_flags |= flags;
2643 Punsetflags(struct ps_prochandle *P, long flags)
2651 if (write(P->ctlfd, ctl, 2*sizeof (long)) != 2*sizeof (long)) {
2654 P->status.pr_flags &= ~flags;
2655 P->status.pr_lwp.pr_flags &= ~flags;
2673 Psetaction(struct ps_prochandle *P, void *sp, size_t size,
2683 if (P->state == PS_DEAD || P->state == PS_UNDEAD ||
2684 P->state == PS_IDLE) {
2694 P->flags |= flag;
2697 P->flags |= flag;
2702 P->flags |= flag;
2705 P->flags |= flag;
2709 if (P->state == PS_RUN)
2710 Psync(P);
2719 Psignal(struct ps_prochandle *P, int which, int stop)
2728 oldval = Psetaction(P, &P->status.pr_sigtrace, sizeof (sigset_t),
2732 prdelset(&P->status.pr_sigtrace, SIGKILL);
2741 Psetsignal(struct ps_prochandle *P, const sigset_t *set)
2743 if (P->state == PS_DEAD || P->state == PS_UNDEAD ||
2744 P->state == PS_IDLE)
2747 P->status.pr_sigtrace = *set;
2748 P->flags |= SETSIG;
2750 if (P->state == PS_RUN)
2751 Psync(P);
2758 Pfault(struct ps_prochandle *P, int which, int stop)
2760 return (Psetaction(P, &P->status.pr_flttrace, sizeof (fltset_t),
2768 Psetfault(struct ps_prochandle *P, const fltset_t *set)
2770 if (P->state == PS_DEAD || P->state == PS_UNDEAD ||
2771 P->state == PS_IDLE)
2774 P->status.pr_flttrace = *set;
2775 P->flags |= SETFAULT;
2777 if (P->state == PS_RUN)
2778 Psync(P);
2785 Psysentry(struct ps_prochandle *P, int which, int stop)
2787 return (Psetaction(P, &P->status.pr_sysentry, sizeof (sysset_t),
2795 Psetsysentry(struct ps_prochandle *P, const sysset_t *set)
2797 if (P->state == PS_DEAD || P->state == PS_UNDEAD ||
2798 P->state == PS_IDLE)
2801 P->status.pr_sysentry = *set;
2802 P->flags |= SETENTRY;
2804 if (P->state == PS_RUN)
2805 Psync(P);
2812 Psysexit(struct ps_prochandle *P, int which, int stop)
2814 return (Psetaction(P, &P->status.pr_sysexit, sizeof (sysset_t),
2822 Psetsysexit(struct ps_prochandle *P, const sysset_t *set)
2824 if (P->state == PS_DEAD || P->state == PS_UNDEAD ||
2825 P->state == PS_IDLE)
2828 P->status.pr_sysexit = *set;
2829 P->flags |= SETEXIT;
2831 if (P->state == PS_RUN)
2832 Psync(P);
2841 read_lfile(struct ps_prochandle *P, const char *lname)
2851 (int)P->status.pr_pid, lname);
2890 Plwp_iter(struct ps_prochandle *P, proc_lwp_f *func, void *cd)
2897 switch (P->state) {
2899 (void) Pstopstatus(P, PCNULL, 0);
2903 Psync(P);
2915 if (P->status.pr_nlwp <= 1)
2916 return (func(cd, &P->status.pr_lwp));
2922 if (P->state == PS_DEAD) {
2923 core_info_t *core = P->data;
2940 if ((Lhp = Plstatus(P)) == NULL)
2959 Plwp_iter_all(struct ps_prochandle *P, proc_lwp_all_f *func, void *cd)
2975 if (P->state == PS_RUN)
2976 (void) Pstopstatus(P, PCNULL, 0);
2977 (void) Ppsinfo(P);
2979 if (P->state == PS_STOP)
2980 Psync(P);
2987 if (P->status.pr_nlwp + P->status.pr_nzomb <= 1)
2988 return (func(cd, &P->status.pr_lwp, &P->psinfo.pr_lwp));
2994 if (P->state == PS_DEAD) {
2995 core_info_t *core = P->data;
3013 if ((Lhp = Plstatus(P)) == NULL)
3015 if ((Lphp = Plpsinfo(P)) == NULL) {
3025 if (Lhp->pr_nent != P->status.pr_nlwp ||
3026 Lphp->pr_nent != P->status.pr_nlwp + P->status.pr_nzomb)
3077 Pcontent(struct ps_prochandle *P)
3079 core_info_t *core = P->data;
3081 if (P->state == PS_DEAD)
3083 if (P->state == PS_IDLE)
3102 Lfind(struct ps_prochandle *P, lwpid_t lwpid)
3107 for (Lp = &P->hashtab[lwpid % (HASHSIZE - 1)];
3120 Lgrab(struct ps_prochandle *P, lwpid_t lwpid, int *perr)
3129 (void) mutex_lock(&P->proc_lock);
3131 if (P->state == PS_UNDEAD || P->state == PS_IDLE)
3133 else if (P->hashtab == NULL &&
3134 (P->hashtab = calloc(HASHSIZE, sizeof (struct ps_lwphandle *)))
3137 else if (*(Lp = Lfind(P, lwpid)) != NULL)
3143 (void) mutex_unlock(&P->proc_lock);
3150 L->lwp_proc = P;
3154 if (P->state == PS_DEAD) { /* core file */
3155 if (getlwpstatus(P, lwpid, &L->lwp_status) == -1) {
3161 (void) mutex_unlock(&P->proc_lock);
3169 procfs_path, (int)P->pid, (int)lwpid);
3227 (void) mutex_unlock(&P->proc_lock);
3231 Lfree_internal(P, L);
3233 (void) mutex_unlock(&P->proc_lock);
3269 struct ps_prochandle *P = L->lwp_proc;
3271 (void) mutex_lock(&P->proc_lock);
3272 Lfree_internal(P, L);
3273 (void) mutex_unlock(&P->proc_lock);
3277 Lfree_internal(struct ps_prochandle *P, struct ps_lwphandle *L)
3279 *Lfind(P, L->lwp_id) = L->lwp_hash; /* delete from hash table */
3675 struct ps_prochandle *P = L->lwp_proc;
3685 &P->status.pr_flttrace, &L->lwp_status.pr_lwphold,
3711 struct ps_prochandle *P = L->lwp_proc;
3721 &P->status.pr_flttrace, &L->lwp_status.pr_lwphold, wp);
3742 struct ps_prochandle *P = L->lwp_proc;
3745 if (P->status.pr_dmodel == PR_MODEL_NATIVE) {
3746 if (Pread(P, stkp, sizeof (*stkp), addr) != sizeof (*stkp))
3752 if (Pread(P, &stk32, sizeof (stk32), addr) != sizeof (stk32))
3765 struct ps_prochandle *P = L->lwp_proc;
3778 if (P->status.pr_dmodel == PR_MODEL_NATIVE) {
3781 if (Pread(P, stkp, sizeof (*stkp),
3789 if (Pread(P, &stk32, sizeof (stk32),
3823 Padd_mapping(struct ps_prochandle *P, off64_t off, file_info_t *fp,
3828 if (P->map_count == P->map_alloc) {
3829 size_t next = P->map_alloc ? P->map_alloc * 2 : 16;
3831 if ((P->mappings = realloc(P->mappings,
3835 P->map_alloc = next;
3838 mp = &P->mappings[P->map_count++];
3872 Psort_mappings(struct ps_prochandle *P)
3877 qsort(P->mappings, P->map_count, sizeof (map_info_t), map_sort);
3882 for (i = 0; i < P->map_count; i++) {
3883 mp = &P->mappings[i];
3893 struct ps_prochandle *P;
3895 if ((P = calloc(1, sizeof (*P))) == NULL) {
3899 Pinit_ops(&P->ops, ops);
3900 (void) mutex_init(&P->proc_lock, USYNC_THREAD, NULL);
3901 P->pid = pid;
3902 P->state = PS_STOP;
3903 P->asfd = -1;
3904 P->ctlfd = -1;
3905 P->statfd = -1;
3906 P->agentctlfd = -1;
3907 P->agentstatfd = -1;
3908 Pinitsym(P);
3909 P->data = data;
3910 Pread_status(P);
3913 P->flags |= INCORE;
3916 return (P);