/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/resource.h>
#include <alloca.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <libctf.h>
#include <errno.h>
#include <ctype.h>
#include <kmdb/kmdb_promif.h>
#include <kmdb/kmdb_dpi.h>
#include <kmdb/kmdb_umemglue.h>
#include <kmdb/kmdb_dpi.h>
#include <kmdb/kmdb_start.h>
#include <kmdb/kmdb_kdi.h>
#include <kmdb/kmdb_kvm.h>
#include <mdb/mdb_debug.h>
#include <mdb/mdb_signal.h>
#include <mdb/mdb_string.h>
#include <mdb/mdb_modapi.h>
#include <mdb/mdb_target.h>
#include <mdb/mdb_gelf.h>
#include <mdb/mdb_conf.h>
#include <mdb/mdb_io_impl.h>
#include <mdb/mdb_frame.h>
#ifdef __sparc
#else
#endif
#if defined(_LP64)
#define KMDB_DEF_LPATH \
#else
#define KMDB_DEF_LPATH \
#endif
/*
* Similar to the panic_* variables in the kernel, we keep some relevant
* information stored in a set of global _mdb_abort_* variables; in the
* event that the debugger dumps core, these will aid core dump analysis.
*/
/*
* The kernel supplies a space-delimited list of directories
* a debugger-friendly, colon-delimited module search path. We add the kmdb
* module directory to each component and change the delimiter.
*/
static char *
{
#ifdef _LP64
#else
static const char suffix[] = "/kmdb:";
#endif
const char *c;
warn("invalid kernel module path\n");
return (NULL);
}
modpath++;
continue;
continue;
while (isspace(*c))
c++;
}
return (nlpath);
}
/*
* called while the kernel is running
*/
int
{
int i;
/*
* The beginnings of debugger initialization are a bit of a dance, due
* to interlocking dependencies between kmdb_prom_init,
* mdb_umem_startup, and mdb_create. In particular, allocator
* initialization can't begin until prom_init() is called,
* kmdb_prom_init can't finish until the allocator is ready and
* mdb_create has been called. We therefore split kmdb_prom_init into
* two pieces, and call thembefore and after umem initialization and
* mdb_create.
*/
kav->kav_pagesize);
null_io = mdb_nullio_create();
return (-1);
}
}
if (kmdb_dpi_init(kav) < 0) {
return (-1);
}
/*
* Path evaluation part 1: Create the initial module path to allow
* the target constructor to load a support module. We base kmdb's
* module path off the kernel's module path unless the user has
* explicitly supplied one.
*/
} else {
char *lpath;
} else {
}
}
if (mdb_get_prompt() == NULL)
(void) mdb_set_prompt(MDB_DEF_PROMPT);
warn("failed to initialize target");
return (-1);
}
/*
* Path evaluation part 2: Re-evaluate the path now that the target
* is ready (and thus we have access to the real platform string).
*/
/* Allocate the main debugger stack */
return (0);
}
#ifdef sun4v
void
{
}
#else
/*ARGSUSED*/
void
{
/*
* Fake function for non sun4v. See comments in kmdb_ctl.h
*/
ASSERT(0);
}
#endif
/*
* First-time kmdb startup. Run when kmdb has control of the machine for the
* first time.
*/
static void
kmdb_startup(void)
{
/*
* The terminal type wasn't specified, so we guess. If we're
* on console, we'll get a terminal type from the PROM. If not,
* we'll use the default.
*/
const char *ttype;
warn("unable to determine terminal type: "
"assuming `%s'\n", ttype);
}
/*
* The terminal type wasn't specified by the user, but a guess
* was made using either $TERM or a property from the SMF. A
* terminal type from the PROM code overrides the guess, so
* we'll use that if we can.
*/
char *promttype;
}
}
warn("failed to set terminal type to `%s', using `"
fail("failed to set terminal type to `"
KMDB_DEF_TERM_TYPE "'\n");
}
}
/*
* kmdb_init() and kctl_activate() may have been talking to each other,
* and may have left some messages for us. The driver -> debugger
* queue is normally processed during the resume path, so we have to
* do it manually here if we want it to be run for first startup.
*/
}
void
kmdb_main(void)
{
int status;
mdb_printf("\nWelcome to kmdb\n");
kmdb_startup();
/*
* Debugger termination is a bit tricky. For compatibility with kadb,
* neither an EOF on stdin nor a normal ::quit will cause the debugger
* to unload. In both cases, they get a trip to OBP, after which the
* debugger returns.
*
* The only supported way to cause the debugger to unload is to specify
* the unload flag to ::quit, or to have the driver request it. The
* driver request is the primary exit mechanism - the ::quit flag is
* provided for convenience.
*
* Both forms of "exit" (unqualified ::quit that won't cause an unload,
* and a driver request that will) are signalled by an MDB_ERR_QUIT. In
* the latter case, however, the KDI will have the unload request.
*/
for (;;) {
break;
} else if (status == MDB_ERR_OUTPUT) {
/*
* If a write failed on stdout, give up. A more
* informative error message will already have been
* printed by mdb_run().
*/
fail("write to stdout failed, exiting\n");
} else if (status != MDB_ERR_ABORT) {
fail("debugger exited abnormally (status = %s)\n",
}
}
mdb_destroy();
/*NOTREACHED*/
}