Skip to content

Commit

Permalink
BHYVE: OS-6969 want mdb module for bhyve
Browse files Browse the repository at this point in the history
Reviewed by: John Levon <john.levon@joyent.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Approved by: John Levon <john.levon@joyent.com>
  • Loading branch information
hrosenfeld authored and citrus-it committed Dec 23, 2018
1 parent 4ab4119 commit 1753314
Show file tree
Hide file tree
Showing 6 changed files with 1,685 additions and 16 deletions.
9 changes: 8 additions & 1 deletion usr/src/cmd/mdb/common/mdb/mdb_create.c
Expand Up @@ -24,7 +24,9 @@
* Use is subject to license terms.
*/

#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Copyright 2018 Joyent, Inc.
*/

#include <mdb/mdb.h>
#include <mdb/mdb_conf.h>
Expand All @@ -51,6 +53,11 @@ mdb_create_builtin_tgts(void)

if ((mp = mdb_module_load_builtin("mdb_raw")) != NULL)
mp->mod_tgt_ctor = mdb_rawfile_tgt_create;

#ifdef __amd64
if ((mp = mdb_module_load_builtin("mdb_bhyve")) != NULL)
mp->mod_tgt_ctor = mdb_bhyve_tgt_create;
#endif
}

void
Expand Down
34 changes: 31 additions & 3 deletions usr/src/cmd/mdb/common/mdb/mdb_main.c
Expand Up @@ -25,7 +25,7 @@
*/

/*
* Copyright (c) 2014, Joyent, Inc. All rights reserved.
* Copyright (c) 2018, Joyent, Inc. All rights reserved.
*/

#include <sys/types.h>
Expand Down Expand Up @@ -323,12 +323,13 @@ static void
usage(int status)
{
mdb_iob_printf(mdb.m_err, "Usage: %s [-fkmuwyAFKMSUW] [+/-o option] "
"[-p pid] [-s dist] [-I path] [-L path]\n\t[-P prompt] "
"[-b VM] [-p pid] [-s dist] [-I path] [-L path]\n\t[-P prompt] "
"[-R root] [-V dis-version] [-e expr] "
"[object [core] | core | suffix]\n\n",
mdb.m_pname);

mdb_iob_puts(mdb.m_err,
"\t-b attach to specified bhyve VM\n"
"\t-e evaluate expr and return status\n"
"\t-f force raw file debugging mode\n"
"\t-k force kernel debugging mode\n"
Expand Down Expand Up @@ -406,6 +407,19 @@ identify_xvm_file(const char *file, int *longmode)
}
#endif /* __x86 */

#ifndef __amd64
/*
* There is no bhyve target in a 32bit x86 or any SPARC mdb. This dummy helps
* keep the code simpler.
*/
/*ARGSUSED*/
static int
mdb_bhyve_tgt_create(mdb_tgt_t *t, int argc, const char *argv[])
{
return (set_errno(EINVAL));
}
#endif

int
main(int argc, char *argv[], char *envp[])
{
Expand All @@ -425,6 +439,7 @@ main(int argc, char *argv[], char *envp[])
const char *Iflag = NULL, *Lflag = NULL, *Vflag = NULL, *pidarg = NULL;
const char *eflag = NULL;
int fflag = 0, Kflag = 0, Rflag = 0, Sflag = 0, Oflag = 0, Uflag = 0;
int bflag = 0;

int ttylike;
int longmode = 0;
Expand Down Expand Up @@ -512,8 +527,12 @@ main(int argc, char *argv[], char *envp[])

while (optind < argc) {
while ((c = getopt(argc, argv,
"e:fkmo:p:s:uwyACD:FI:KL:MOP:R:SUV:W")) != (int)EOF) {
"be:fkmo:p:s:uwyACD:FI:KL:MOP:R:SUV:W")) != (int)EOF) {
switch (c) {
case 'b':
bflag++;
tgt_ctor = mdb_bhyve_tgt_create;
break;
case 'e':
if (eflag != NULL) {
warn("-e already specified\n");
Expand Down Expand Up @@ -835,6 +854,15 @@ main(int argc, char *argv[], char *envp[])
if (fflag)
goto tcreate; /* skip re-exec and just create target */

/* bhyve: directly create target, or re-exec in case of 32bit */
if (bflag) {
#ifndef __amd64
goto reexec;
#else
goto tcreate;
#endif
}

/*
* If we just have an object file name, and that file doesn't
* exist, and it's a string of digits, infer it to be a
Expand Down
3 changes: 3 additions & 0 deletions usr/src/cmd/mdb/common/mdb/mdb_target.h
Expand Up @@ -64,6 +64,9 @@ extern int mdb_kvm_tgt_create(mdb_tgt_t *, int, const char *[]);
extern int mdb_proc_tgt_create(mdb_tgt_t *, int, const char *[]);
extern int mdb_kproc_tgt_create(mdb_tgt_t *, int, const char *[]);
extern int mdb_rawfile_tgt_create(mdb_tgt_t *, int, const char *[]);
#ifdef __amd64
extern int mdb_bhyve_tgt_create(mdb_tgt_t *, int, const char *[]);
#endif
#else
extern int kmdb_kvm_create(mdb_tgt_t *, int, const char *[]);
#endif
Expand Down
16 changes: 11 additions & 5 deletions usr/src/cmd/mdb/intel/amd64/mdb/Makefile
Expand Up @@ -22,10 +22,14 @@
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# Copyright 2018 Joyent, Inc.
#

SRCS = kvm_amd64dep.c \
kvm_isadep.c \
mdb_amd64util.c \
mdb_ia32util.c \
mdb_bhyve.c \
proc_amd64dep.c

%.o: %.c
Expand All @@ -42,12 +46,14 @@ SRCS = kvm_amd64dep.c \
%.ln: ../../mdb/%.c
$(LINT.c) -c $<

include ../../../../Makefile.cmd
include ../../../../Makefile.cmd.64
include ../../Makefile.amd64
include ../../../Makefile.mdb
include $(SRC)/cmd/Makefile.cmd
include $(SRC)/cmd/Makefile.cmd.64
include $(SRC)/cmd/mdb/intel/Makefile.amd64
include $(SRC)/cmd/mdb/Makefile.mdb
include $(SRC)/Makefile.psm

CPPFLAGS += -I../../mdb
LDLIBS += -lsaveargs

LDLIBS += -lsaveargs -lvmm

install: all $(ISAEXEC) $(ROOTPROG64) $(ROOTLINK64)

0 comments on commit 1753314

Please sign in to comment.