diff options
Diffstat (limited to 'usr/src/cmd/mdb/common/modules')
-rw-r--r-- | usr/src/cmd/mdb/common/modules/genunix/Makefile.files | 3 | ||||
-rw-r--r-- | usr/src/cmd/mdb/common/modules/genunix/genunix.c | 61 | ||||
-rw-r--r-- | usr/src/cmd/mdb/common/modules/genunix/refstr.c | 43 |
3 files changed, 96 insertions, 11 deletions
diff --git a/usr/src/cmd/mdb/common/modules/genunix/Makefile.files b/usr/src/cmd/mdb/common/modules/genunix/Makefile.files index 44ed819316..d371cf70fe 100644 --- a/usr/src/cmd/mdb/common/modules/genunix/Makefile.files +++ b/usr/src/cmd/mdb/common/modules/genunix/Makefile.files @@ -21,7 +21,7 @@ # # Copyright 2011 Nexenta Systems, Inc. All rights reserved. # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. -# Copyright 2019, Joyent, Inc. +# Copyright 2019 Joyent, Inc. # Copyright (c) 2013 by Delphix. All rights reserved. # @@ -73,6 +73,7 @@ GENUNIX_SRCS = \ pg.c \ rctl.c \ refhash.c \ + refstr.c \ sobj.c \ streams.c \ sysevent.c \ diff --git a/usr/src/cmd/mdb/common/modules/genunix/genunix.c b/usr/src/cmd/mdb/common/modules/genunix/genunix.c index 4c7c5ef5c1..f524a4c60c 100644 --- a/usr/src/cmd/mdb/common/modules/genunix/genunix.c +++ b/usr/src/cmd/mdb/common/modules/genunix/genunix.c @@ -61,6 +61,7 @@ #include <sys/panic.h> #include <regex.h> #include <sys/port_impl.h> +#include <sys/contract/process_impl.h> #include "avl.h" #include "bio.h" @@ -141,6 +142,7 @@ pstat2ch(uchar_t state) #define PS_TASKS 0x8 #define PS_PROJECTS 0x10 #define PS_ZONES 0x20 +#define PS_SERVICES 0x40 static int ps_threadprint(uintptr_t addr, const void *data, void *private) @@ -270,6 +272,7 @@ typedef struct mdb_ps_proc { struct sess *p_sessp; struct task *p_task; struct zone *p_zone; + struct cont_process *p_ct_process; pid_t p_ppid; uint_t p_flag; struct { @@ -278,6 +281,12 @@ typedef struct mdb_ps_proc { } p_user; } mdb_ps_proc_t; +/* + * A reasonable enough limit. Note that we purposefully let this column over-run + * if needed. + */ +#define FMRI_LEN (128) + int ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { @@ -289,6 +298,8 @@ ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) task_t tk; kproject_t pj; zone_t zn; + struct cont_process cp; + char fmri[FMRI_LEN] = ""; if (!(flags & DCMD_ADDRSPEC)) { if (mdb_walk_dcmd("proc", "ps", argc, argv) == -1) { @@ -301,6 +312,7 @@ ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) if (mdb_getopts(argc, argv, 'f', MDB_OPT_SETBITS, PS_PSARGS, &prt_flags, 'l', MDB_OPT_SETBITS, PS_PRTLWPS, &prt_flags, + 's', MDB_OPT_SETBITS, PS_SERVICES, &prt_flags, 'T', MDB_OPT_SETBITS, PS_TASKS, &prt_flags, 'P', MDB_OPT_SETBITS, PS_PROJECTS, &prt_flags, 'z', MDB_OPT_SETBITS, PS_ZONES, &prt_flags, @@ -308,15 +320,17 @@ ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) return (DCMD_USAGE); if (DCMD_HDRSPEC(flags)) { - mdb_printf("%<u>%1s %6s %6s %6s %6s ", + mdb_printf("%<u>%-1s %-6s %-6s %-6s %-6s ", "S", "PID", "PPID", "PGID", "SID"); if (prt_flags & PS_TASKS) - mdb_printf("%5s ", "TASK"); + mdb_printf("%-5s ", "TASK"); if (prt_flags & PS_PROJECTS) - mdb_printf("%5s ", "PROJ"); + mdb_printf("%-5s ", "PROJ"); if (prt_flags & PS_ZONES) - mdb_printf("%5s ", "ZONE"); - mdb_printf("%6s %10s %?s %s%</u>\n", + mdb_printf("%-5s ", "ZONE"); + if (prt_flags & PS_SERVICES) + mdb_printf("%-40s ", "SERVICE"); + mdb_printf("%-6s %-10s %-?s %-s%</u>\n", "UID", "FLAGS", "ADDR", "NAME"); } @@ -334,17 +348,39 @@ ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) mdb_vread(&pj, sizeof (pj), (uintptr_t)tk.tk_proj); if (prt_flags & PS_ZONES) mdb_vread(&zn, sizeof (zn), (uintptr_t)pr.p_zone); + if ((prt_flags & PS_SERVICES) && pr.p_ct_process != NULL) { + mdb_vread(&cp, sizeof (cp), (uintptr_t)pr.p_ct_process); + + if (mdb_read_refstr((uintptr_t)cp.conp_svc_fmri, fmri, + sizeof (fmri)) <= 0) + (void) strlcpy(fmri, "?", sizeof (fmri)); + + /* Strip any standard prefix and suffix. */ + if (strncmp(fmri, "svc:/", sizeof ("svc:/") - 1) == 0) { + char *i = fmri; + char *j = fmri + sizeof ("svc:/") - 1; + for (; *j != '\0'; i++, j++) { + if (strcmp(j, ":default") == 0) + break; + *i = *j; + } - mdb_printf("%c %6d %6d %6d %6d ", + *i = '\0'; + } + } + + mdb_printf("%-c %-6d %-6d %-6d %-6d ", pstat2ch(pr.p_stat), pid.pid_id, pr.p_ppid, pgid.pid_id, sid.pid_id); if (prt_flags & PS_TASKS) - mdb_printf("%5d ", tk.tk_tkid); + mdb_printf("%-5d ", tk.tk_tkid); if (prt_flags & PS_PROJECTS) - mdb_printf("%5d ", pj.kpj_id); + mdb_printf("%-5d ", pj.kpj_id); if (prt_flags & PS_ZONES) - mdb_printf("%5d ", zn.zone_id); - mdb_printf("%6d 0x%08x %0?p %s\n", + mdb_printf("%-5d ", zn.zone_id); + if (prt_flags & PS_SERVICES) + mdb_printf("%-40s ", fmri); + mdb_printf("%-6d 0x%08x %0?p %-s\n", cred.cr_uid, pr.p_flag, addr, (prt_flags & PS_PSARGS) ? pr.p_user.u_psargs : pr.p_user.u_comm); @@ -363,6 +399,7 @@ ps_help(void) " -l\tDisplay LWPs\n" " -T\tDisplay tasks\n" " -P\tDisplay projects\n" + " -s\tDisplay SMF FMRI\n" " -z\tDisplay zones\n" " -t\tDisplay threads\n\n"); @@ -386,6 +423,7 @@ ps_help(void) mdb_printf("TASK\tThe task id of the process.\n"); mdb_printf("PROJ\tThe project id of the process.\n"); mdb_printf("ZONE\tThe zone id of the process.\n"); + mdb_printf("SERVICE The SMF service FMRI of the process.\n"); mdb_printf("UID\tThe user id of the process.\n"); mdb_printf("FLAGS\tThe process flags (see ::pflags).\n"); mdb_printf("ADDR\tThe kernel address of the proc_t structure of the " @@ -4053,6 +4091,8 @@ time_help(void) " -x report times in hexadecimal\n"); } +extern int cmd_refstr(uintptr_t, uint_t, int, const mdb_arg_t *); + static const mdb_dcmd_t dcmds[] = { /* from genunix.c */ @@ -4083,6 +4123,7 @@ static const mdb_dcmd_t dcmds[] = { { "pgrep", "[-x] [-n | -o] pattern", "pattern match against all processes", pgrep }, { "ptree", NULL, "print process tree", ptree }, + { "refstr", NULL, "print string from a refstr_t", cmd_refstr, NULL }, { "sysevent", "?[-sv]", "print sysevent pending or sent queue", sysevent}, { "sysevent_channel", "?", "print sysevent channel database", diff --git a/usr/src/cmd/mdb/common/modules/genunix/refstr.c b/usr/src/cmd/mdb/common/modules/genunix/refstr.c new file mode 100644 index 0000000000..5b5fcec14c --- /dev/null +++ b/usr/src/cmd/mdb/common/modules/genunix/refstr.c @@ -0,0 +1,43 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2019 Joyent, Inc. + */ + +#include <mdb/mdb_modapi.h> +#include <mdb/mdb_ks.h> +#include <sys/refstr.h> + +#define REFSTR_LEN (1024) + +int +cmd_refstr(uintptr_t addr, uint_t flags __unused, + int argc, const mdb_arg_t *argv) +{ + if (!(flags & DCMD_ADDRSPEC)) { + mdb_warn("address is required\n"); + return (DCMD_ERR); + } + + if (mdb_getopts(argc, argv, NULL) != argc) + return (DCMD_USAGE); + + char *buf = mdb_alloc(REFSTR_LEN, UM_SLEEP | UM_GC); + + if (mdb_read_refstr(addr, buf, REFSTR_LEN) < 0) { + mdb_warn("couldn't read refstr from %p", addr); + return (DCMD_ERR); + } + + mdb_printf("%s\n", buf); + return (DCMD_OK); +} |