diff options
Diffstat (limited to 'usr/src')
| -rw-r--r-- | usr/src/cmd/mdb/common/kmdb/kmdb_kvm.c | 21 | ||||
| -rw-r--r-- | usr/src/cmd/mdb/common/mdb/mdb_ks.h | 6 | ||||
| -rw-r--r-- | usr/src/cmd/mdb/common/mdb/mdb_kvm.c | 22 | ||||
| -rw-r--r-- | usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c | 82 |
4 files changed, 111 insertions, 20 deletions
diff --git a/usr/src/cmd/mdb/common/kmdb/kmdb_kvm.c b/usr/src/cmd/mdb/common/kmdb/kmdb_kvm.c index 16bbb46a3c..95e309e58c 100644 --- a/usr/src/cmd/mdb/common/kmdb/kmdb_kvm.c +++ b/usr/src/cmd/mdb/common/kmdb/kmdb_kvm.c @@ -22,7 +22,7 @@ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013 by Delphix. All rights reserved. * - * Copyright 2018 Joyent, Inc. + * Copyright (c) 2019, Joyent, Inc. */ #include <kmdb/kmdb_kvm.h> @@ -49,6 +49,7 @@ #include <sys/kobj.h> #include <sys/kobj_impl.h> #include <sys/bitmap.h> +#include <sys/uuid.h> #include <vm/as.h> static const char KMT_RTLD_NAME[] = "krtld"; @@ -554,7 +555,7 @@ static int kmt_status_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { struct utsname uts; - char uuid[37]; + char uuid[UUID_PRINTABLE_STRING_LENGTH]; kreg_t tt; if (mdb_tgt_readsym(mdb.m_target, MDB_TGT_AS_VIRT, &uts, sizeof (uts), @@ -570,16 +571,14 @@ kmt_status_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) mdb_printf("operating system: %s %s (%s)\n", uts.release, uts.version, uts.machine); - if (mdb_tgt_readsym(mdb.m_target, MDB_TGT_AS_VIRT, uuid, sizeof (uuid), - "genunix", "dump_osimage_uuid") != sizeof (uuid)) { - warn("failed to read 'dump_osimage_uuid' string from kernel\n"); - (void) strcpy(uuid, "(error)"); - } else if (*uuid == '\0') { - (void) strcpy(uuid, "(not set)"); - } else if (uuid[36] != '\0') { - (void) strcpy(uuid, "(invalid)"); + mdb_print_gitstatus(); + + if (mdb_readsym(uuid, sizeof (uuid), + "dump_osimage_uuid") == sizeof (uuid) && + uuid[sizeof (uuid) - 1] == '\0') { + mdb_printf("image uuid: %s\n", uuid[0] != '\0' ? + uuid : "(not set)"); } - mdb_printf("image uuid: %s\n", uuid); mdb_printf("DTrace state: %s\n", (kmdb_kdi_dtrace_get_state() == KDI_DTSTATE_DTRACE_ACTIVE ? "active (debugger breakpoints cannot " diff --git a/usr/src/cmd/mdb/common/mdb/mdb_ks.h b/usr/src/cmd/mdb/common/mdb/mdb_ks.h index 1fe64fbc55..0717e2acce 100644 --- a/usr/src/cmd/mdb/common/mdb/mdb_ks.h +++ b/usr/src/cmd/mdb/common/mdb/mdb_ks.h @@ -23,6 +23,10 @@ * Use is subject to license terms. */ +/* + * Copyright (c) 2019, Joyent, Inc. + */ + #ifndef _MDB_KS_H #define _MDB_KS_H @@ -140,6 +144,8 @@ extern const char *mdb_dlpi_prim(int); /* Generic function for working with MAC (network layer 2) addresses. */ extern void mdb_mac_addr(const uint8_t *, size_t, char *, size_t); +extern void mdb_print_gitstatus(void); + /* * Target-specific interfaces * diff --git a/usr/src/cmd/mdb/common/mdb/mdb_kvm.c b/usr/src/cmd/mdb/common/mdb/mdb_kvm.c index 6b6c982184..8cbeb8e5d6 100644 --- a/usr/src/cmd/mdb/common/mdb/mdb_kvm.c +++ b/usr/src/cmd/mdb/common/mdb/mdb_kvm.c @@ -23,7 +23,7 @@ */ /* - * Copyright (c) 2018, Joyent, Inc. All rights reserved. + * Copyright (c) 2019, Joyent, Inc. */ /* @@ -51,6 +51,7 @@ #include <sys/panic.h> #include <sys/dumphdr.h> #include <sys/dumpadm.h> +#include <sys/uuid.h> #include <dlfcn.h> #include <libctf.h> @@ -68,6 +69,7 @@ #include <mdb/mdb_kvm.h> #include <mdb/mdb_module.h> #include <mdb/mdb_kb.h> +#include <mdb/mdb_ks.h> #include <mdb/mdb.h> #define KT_RELOC_BUF(buf, obase, nbase) \ @@ -94,6 +96,8 @@ typedef struct kt_maparg { static const char KT_MODULE[] = "mdb_ks"; static const char KT_CTFPARENT[] = "genunix"; +static void (*print_gitstatus)(void); + static void kt_load_module(kt_data_t *kt, mdb_tgt_t *t, kt_module_t *km) { @@ -485,6 +489,9 @@ kt_status_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) mdb_printf("operating system: %s %s (%s)\n", uts.release, uts.version, uts.machine); + if (print_gitstatus != NULL) + print_gitstatus(); + if (kt->k_dumphdr) { dumphdr_t *dh = kt->k_dumphdr; @@ -494,11 +501,13 @@ kt_status_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) kt->k_dump_print_content(dh, kt->k_dumpcontent); } else { - char uuid[37]; + char uuid[UUID_PRINTABLE_STRING_LENGTH]; - if (mdb_readsym(uuid, 37, "dump_osimage_uuid") == 37 && - uuid[36] == '\0') { - mdb_printf("image uuid: %s\n", uuid); + if (mdb_readsym(uuid, sizeof (uuid), + "dump_osimage_uuid") == sizeof (uuid) && + uuid[sizeof (uuid) - 1] == '\0') { + mdb_printf("image uuid: %s\n", uuid[0] != '\0' ? + uuid : "(not set)"); } } @@ -582,6 +591,9 @@ kt_activate(mdb_tgt_t *t) "some modules may not load\n"); } + print_gitstatus = (void (*)(void))dlsym(RTLD_NEXT, + "mdb_print_gitstatus"); + if (mdb_prop_postmortem && kt->k_dumphdr != NULL) { sym = dlsym(RTLD_NEXT, "mdb_dump_print_content"); if (sym != NULL) diff --git a/usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c b/usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c index a801d4d39f..8b30105399 100644 --- a/usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c +++ b/usr/src/cmd/mdb/common/modules/mdb_ks/mdb_ks.c @@ -20,7 +20,7 @@ */ /* * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2017 Joyent, Inc. + * Copyright (c) 2019, Joyent, Inc. */ /* @@ -60,6 +60,12 @@ #define MDB_PATH_NELEM 256 /* Maximum path components */ +/* + * Due to mdb_param.h shenanigans, there's no simple way to include string.h + * here... + */ +extern char *strtok(char *restrict, const char *restrict); + typedef struct mdb_path { size_t mdp_nelem; /* Number of components */ uint_t mdp_complete; /* Path completely resolved? */ @@ -1012,9 +1018,9 @@ find_mbind(const char *name, uintptr_t *hashtab) int mdb_name_to_major(const char *name, major_t *major) { - uintptr_t mbind; - uintptr_t mb_hashtab[MOD_BIND_HASHSIZE]; - struct bind mbind_local; + uintptr_t mbind; + uintptr_t mb_hashtab[MOD_BIND_HASHSIZE]; + struct bind mbind_local; if (mdb_readsym(mb_hashtab, sizeof (mb_hashtab), "mb_hashtab") == -1) { @@ -1810,3 +1816,71 @@ mdb_get_lbolt(void) return ((ts/nsec) - lbi.lbi_debug_time); } + +#define startswith(a, b) (strncmp((a), (b), strlen(b)) == 0) + +/* + * Dig out the branch and revision of the illumos-joyent repo, if we were + * provided with it. This is a rather fragile JSON parser, in that it requires + * JSON formatted exactly as per the boot_archive.gitstatus file that + * "gitstatus_start" is built from. + */ +void +mdb_print_gitstatus(void) +{ + boolean_t in_joyent = B_FALSE; + GElf_Sym sym; + + if (mdb_lookup_by_name("gitstatus_start", &sym) != 0) + return; + + char *str = mdb_zalloc(4096, UM_SLEEP | UM_GC); + + if (mdb_readstr(str, 4096, sym.st_value) < 1) + return; + + /* + * Each line is of the form + * + * "repo": "smartos-live", + */ + for (char *line = strtok(str, "\n"); line != NULL; + line = strtok(NULL, "\n")) { + /* skip whitespace and first " */ + line += strspn(line, " \t\""); + + if (startswith(line, "repo")) { + line += sizeof ("repo") - 1; + line += strspn(line, " \t\":"); + + if (startswith(line, "illumos-joyent")) + in_joyent = B_TRUE; + else if (in_joyent) + return; + continue; + } + + if (!in_joyent) + continue; + + if (startswith(line, "branch")) { + char *trail = strrchr(line, '"'); + if (trail != NULL) + *trail = '\0'; + line += sizeof ("branch") - 1; + line += strspn(line, " \t\":"); + mdb_printf("git branch: %s\n", line); + continue; + } + + if (startswith(line, "rev")) { + char *trail = strrchr(line, '"'); + if (trail != NULL) + *trail = '\0'; + line += sizeof ("rev") - 1; + line += strspn(line, " \t\":"); + mdb_printf("git rev: %s\n", line); + continue; + } + } +} |
