summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/gcore/elfcore.c21
-rw-r--r--usr.bin/procstat/Makefile1
-rw-r--r--usr.bin/procstat/procstat.14
-rw-r--r--usr.bin/procstat/procstat.c14
-rw-r--r--usr.bin/procstat/procstat.h2
-rw-r--r--usr.bin/procstat/procstat_ptlwpinfo.c91
6 files changed, 129 insertions, 4 deletions
diff --git a/usr.bin/gcore/elfcore.c b/usr.bin/gcore/elfcore.c
index 0a09888..786116d 100644
--- a/usr.bin/gcore/elfcore.c
+++ b/usr.bin/gcore/elfcore.c
@@ -1,4 +1,5 @@
/*-
+ * Copyright (c) 2017 Dell EMC
* Copyright (c) 2007 Sandvine Incorporated
* Copyright (c) 1998 John D. Polstra
* All rights reserved.
@@ -102,6 +103,7 @@ static void *elf_note_fpregset(void *, size_t *);
static void *elf_note_prpsinfo(void *, size_t *);
static void *elf_note_prstatus(void *, size_t *);
static void *elf_note_thrmisc(void *, size_t *);
+static void *elf_note_ptlwpinfo(void *, size_t *);
#if defined(__i386__) || defined(__amd64__)
static void *elf_note_x86_xstate(void *, size_t *);
#endif
@@ -358,6 +360,7 @@ elf_putnotes(pid_t pid, struct sbuf *sb, size_t *sizep)
elf_putnote(NT_PRSTATUS, elf_note_prstatus, tids + i, sb);
elf_putnote(NT_FPREGSET, elf_note_fpregset, tids + i, sb);
elf_putnote(NT_THRMISC, elf_note_thrmisc, tids + i, sb);
+ elf_putnote(NT_PTLWPINFO, elf_note_ptlwpinfo, tids + i, sb);
#if defined(__i386__) || defined(__amd64__)
elf_putnote(NT_X86_XSTATE, elf_note_x86_xstate, tids + i, sb);
#endif
@@ -661,6 +664,24 @@ elf_note_thrmisc(void *arg, size_t *sizep)
return (thrmisc);
}
+static void *
+elf_note_ptlwpinfo(void *arg, size_t *sizep)
+{
+ lwpid_t tid;
+ void *p;
+
+ tid = *(lwpid_t *)arg;
+ p = calloc(1, sizeof(int) + sizeof(struct ptrace_lwpinfo));
+ if (p == NULL)
+ errx(1, "out of memory");
+ *(int *)p = sizeof(struct ptrace_lwpinfo);
+ ptrace(PT_LWPINFO, tid,
+ (char *)p + sizeof (int), sizeof(struct ptrace_lwpinfo));
+
+ *sizep = sizeof(int) + sizeof(struct ptrace_lwpinfo);
+ return (p);
+}
+
#if defined(__i386__) || defined(__amd64__)
static void *
elf_note_x86_xstate(void *arg, size_t *sizep)
diff --git a/usr.bin/procstat/Makefile b/usr.bin/procstat/Makefile
index 6e65d0c..10b9040 100644
--- a/usr.bin/procstat/Makefile
+++ b/usr.bin/procstat/Makefile
@@ -13,6 +13,7 @@ SRCS= procstat.c \
procstat_cs.c \
procstat_files.c \
procstat_kstack.c \
+ procstat_ptlwpinfo.c \
procstat_rlimit.c \
procstat_rusage.c \
procstat_sigs.c \
diff --git a/usr.bin/procstat/procstat.1 b/usr.bin/procstat/procstat.1
index 2ccfc69..4b7f3bc 100644
--- a/usr.bin/procstat/procstat.1
+++ b/usr.bin/procstat/procstat.1
@@ -38,7 +38,7 @@
.Op Fl M Ar core
.Op Fl N Ar system
.Op Fl w Ar interval
-.Op Fl b | c | e | f | i | j | k | l | r | s | S | t | v | x
+.Op Fl b | c | e | f | i | j | k | l | L | r | s | S | t | v | x
.Op Fl a | Ar pid | Ar core ...
.Sh DESCRIPTION
The
@@ -81,6 +81,8 @@ If the flag is repeated, function offsets as well as function names are
printed.
.It Fl l
Display resource limits for the process.
+.It Fl L
+Display LWP info for the process pertaining to it's signal driven exit.
.It Fl r
Display resource usage information for the process.
.It Fl s
diff --git a/usr.bin/procstat/procstat.c b/usr.bin/procstat/procstat.c
index 627ca8b..eca2790 100644
--- a/usr.bin/procstat/procstat.c
+++ b/usr.bin/procstat/procstat.c
@@ -1,6 +1,7 @@
/*-
* Copyright (c) 2007, 2011 Robert N. M. Watson
* Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
+ * Copyright (c) 2017 Dell EMC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,8 +42,8 @@
#include "procstat.h"
-static int aflag, bflag, cflag, eflag, fflag, iflag, jflag, kflag, lflag, rflag;
-static int sflag, tflag, vflag, xflag, Sflag;
+static int aflag, bflag, cflag, eflag, fflag, iflag, jflag, kflag;
+static int lflag, Lflag, rflag, sflag, tflag, vflag, xflag, Sflag;
int hflag, nflag, Cflag, Hflag;
static void
@@ -85,6 +86,8 @@ procstat(struct procstat *prstat, struct kinfo_proc *kipp)
procstat_kstack(prstat, kipp, kflag);
else if (lflag)
procstat_rlimit(prstat, kipp);
+ else if (Lflag)
+ procstat_ptlwpinfo(prstat);
else if (rflag)
procstat_rusage(prstat, kipp);
else if (sflag)
@@ -162,7 +165,7 @@ main(int argc, char *argv[])
argc = xo_parse_args(argc, argv);
xocontainer = "basic";
- while ((ch = getopt(argc, argv, "abCcefHhijklM:N:nrSstvw:x")) != -1) {
+ while ((ch = getopt(argc, argv, "abCcefHhijklLM:N:nrSstvw:x")) != -1) {
switch (ch) {
case 'C':
Cflag++;
@@ -226,6 +229,11 @@ main(int argc, char *argv[])
xocontainer = "rlimit";
break;
+ case 'L':
+ Lflag++;
+ xocontainer = "ptlwpinfo";
+ break;
+
case 'n':
nflag++;
break;
diff --git a/usr.bin/procstat/procstat.h b/usr.bin/procstat/procstat.h
index 43bd841..dd35c9c 100644
--- a/usr.bin/procstat/procstat.h
+++ b/usr.bin/procstat/procstat.h
@@ -1,6 +1,7 @@
/*-
* Copyright (c) 2007 Robert N. M. Watson
* Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
+ * Copyright (c) 2017 Dell EMC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -50,6 +51,7 @@ void procstat_env(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_files(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_kstack(struct procstat *prstat, struct kinfo_proc *kipp,
int kflag);
+void procstat_ptlwpinfo(struct procstat *prstat);
void procstat_rlimit(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_rusage(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_sigs(struct procstat *prstat, struct kinfo_proc *kipp);
diff --git a/usr.bin/procstat/procstat_ptlwpinfo.c b/usr.bin/procstat/procstat_ptlwpinfo.c
new file mode 100644
index 0000000..96068df
--- /dev/null
+++ b/usr.bin/procstat/procstat_ptlwpinfo.c
@@ -0,0 +1,91 @@
+/*-
+ * Copyright (c) 2017 Dell EMC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/ptrace.h>
+#include <sys/user.h>
+
+#include <libprocstat.h>
+
+#include "procstat.h"
+
+void
+procstat_ptlwpinfo(struct procstat *prstat)
+{
+ struct ptrace_lwpinfo *pl;
+ unsigned int count, i;
+
+ pl = procstat_getptlwpinfo(prstat, &count);
+ if (pl == NULL)
+ return;
+
+ if (!hflag)
+ xo_emit("{:/%6s %7s %5s %5s %5s %6s %5s} {[:/%d}{:/%s}{]:}"
+ " {:/%s}\n",
+ "LWPID", "EVENT", "SIGNO", "CODE", "ERRNO", "PID", "UID",
+ 2 * sizeof(void *) + 2, "ADDR", "TDNAME");
+
+ for (i = 0; i < count; i++) {
+ xo_emit("{:lpwid/%6d} ", pl[i].pl_lwpid);
+ switch (pl[i].pl_event) {
+ case PL_EVENT_NONE:
+ xo_emit("{eq:event/none}{d:event/%7s} ", "none");
+ break;
+ case PL_EVENT_SIGNAL:
+ xo_emit("{eq:event/signal}{d:event/%7s} ", "signal");
+ break;
+ default:
+ xo_emit("{eq:event/unknown}{d:event/%7s} ", "?");
+ break;
+ }
+ if ((pl[i].pl_flags & PL_FLAG_SI) != 0) {
+ siginfo_t *si;
+
+ si = &pl[i].pl_siginfo;
+ xo_emit("{:signal_number/%5d} ", si->si_signo);
+ xo_emit("{:code/%5d} ", si->si_code);
+ xo_emit("{:signal_errno/%5d} ", si->si_errno);
+ xo_emit("{:process_id/%6d} ", si->si_pid);
+ xo_emit("{:user_id/%5d} ", si->si_uid);
+ xo_emit("{[:/%d}{:address/%p}{]:} ",
+ 2 * sizeof(void *) + 2, si->si_addr);
+ } else {
+ xo_emit("{:signal_number/%5s} ", "-");
+ xo_emit("{:code/%5s} ", "-");
+ xo_emit("{:signal_errno/%5s} ", "-");
+ xo_emit("{:process_id/%6s} ", "-");
+ xo_emit("{:user_id/%5s} ", "-");
+ xo_emit("{[:/%d}{:address/%s}{]:} ",
+ 2 * sizeof(void *) + 2, "-");
+ }
+ xo_emit("{:tdname/%s}\n", pl[i].pl_tdname);
+ }
+
+ procstat_freeptlwpinfo(prstat, pl);
+}
OpenPOWER on IntegriCloud