2 * Copyright (c) 2017 Dell EMC
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/ptrace.h>
34 #include <libprocstat.h>
39 procstat_ptlwpinfo(struct procstat *prstat)
41 struct ptrace_lwpinfo *pl;
42 unsigned int count, i;
44 pl = procstat_getptlwpinfo(prstat, &count);
49 xo_emit("{:/%6s %7s %5s %5s %5s %6s %5s} {[:/%d}{:/%s}{]:}"
51 "LWPID", "EVENT", "SIGNO", "CODE", "ERRNO", "PID", "UID",
52 2 * sizeof(void *) + 2, "ADDR", "TDNAME");
54 for (i = 0; i < count; i++) {
55 xo_emit("{:lpwid/%6d} ", pl[i].pl_lwpid);
56 switch (pl[i].pl_event) {
58 xo_emit("{eq:event/none}{d:event/%7s} ", "none");
61 xo_emit("{eq:event/signal}{d:event/%7s} ", "signal");
64 xo_emit("{eq:event/unknown}{d:event/%7s} ", "?");
67 if ((pl[i].pl_flags & PL_FLAG_SI) != 0) {
70 si = &pl[i].pl_siginfo;
71 xo_emit("{:signal_number/%5d} ", si->si_signo);
72 xo_emit("{:code/%5d} ", si->si_code);
73 xo_emit("{:signal_errno/%5d} ", si->si_errno);
74 xo_emit("{:process_id/%6d} ", si->si_pid);
75 xo_emit("{:user_id/%5d} ", si->si_uid);
76 xo_emit("{[:/%d}{:address/%p}{]:} ",
77 2 * sizeof(void *) + 2, si->si_addr);
79 xo_emit("{:signal_number/%5s} ", "-");
80 xo_emit("{:code/%5s} ", "-");
81 xo_emit("{:signal_errno/%5s} ", "-");
82 xo_emit("{:process_id/%6s} ", "-");
83 xo_emit("{:user_id/%5s} ", "-");
84 xo_emit("{[:/%d}{:address/%s}{]:} ",
85 2 * sizeof(void *) + 2, "-");
87 xo_emit("{:tdname/%s}\n", pl[i].pl_tdname);
90 procstat_freeptlwpinfo(prstat, pl);