mdb_modapi.h revision 4870e0a7381ec2ec57437062574e6ddc3dd48d7f
/*
* 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 (c) 2013 by Delphix. All rights reserved.
* Copyright (c) 2012 Joyent, Inc. All rights reserved.
*/
#ifndef _MDB_MODAPI_H
#define _MDB_MODAPI_H
/*
* MDB Module API
*
* The debugger provides a set of interfaces for use in writing loadable
* debugger modules. Modules that call functions not listed in this header
* file may not be compatible with future versions of the debugger.
*/
#include <gelf.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Make sure that TRUE, FALSE, MIN, and MAX have the usual definitions
* so module writers can depend on these macros and defines.
*/
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef MIN
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#endif
/*
* Debugger command function flags:
*/
/*
* Debugger tab command function flags
*/
/*
* Debugger command function return values:
*/
#define DCMD_OK 0 /* Dcmd completed successfully */
extern int mdb_prop_postmortem; /* Are we looking at a static dump? */
extern int mdb_prop_kernel; /* Are we looking at a kernel? */
typedef enum {
MDB_TYPE_STRING, /* a_un.a_str is valid */
MDB_TYPE_IMMEDIATE, /* a_un.a_val is valid */
MDB_TYPE_CHAR /* a_un.a_char is valid */
} mdb_type_t;
typedef struct mdb_arg {
union {
const char *a_str;
char a_char;
} a_un;
} mdb_arg_t;
typedef struct mdb_tab_cookie mdb_tab_cookie_t;
const mdb_arg_t *);
typedef struct mdb_dcmd {
const char *dc_name; /* Command name */
const char *dc_usage; /* Usage message (optional) */
const char *dc_descr; /* Description */
void (*dc_help)(void); /* Command help function (or NULL) */
} mdb_dcmd_t;
#define WALK_NEXT 0 /* Walk should continue to next step */
typedef int (*mdb_walk_cb_t)(uintptr_t, const void *, void *);
typedef struct mdb_walk_state {
void *walk_cbdata; /* Callback private data */
void *walk_data; /* Walk private data */
void *walk_arg; /* Walk private argument */
const void *walk_layer; /* Data from underlying layer */
typedef struct mdb_walker {
const char *walk_name; /* Walk type name */
const char *walk_descr; /* Walk description */
void *walk_init_arg; /* Walk constructor argument */
} mdb_walker_t;
typedef struct mdb_modinfo {
typedef struct mdb_bitmask {
const char *bm_name; /* String name to print */
typedef struct mdb_pipe {
} mdb_pipe_t;
typedef struct mdb_object {
const char *obj_name; /* name of object */
const char *obj_fullname; /* full name of object */
} mdb_object_t;
typedef struct mdb_symbol {
const char *sym_name; /* name of symbol */
const char *sym_object; /* name of containing object */
} mdb_symbol_t;
extern int mdb_walk(const char *, mdb_walk_cb_t, void *);
extern int mdb_pwalk_dcmd(const char *, const char *,
extern int mdb_walk_dcmd(const char *, const char *, int, const mdb_arg_t *);
extern int mdb_layered_walk(const char *, mdb_walk_state_t *);
extern int mdb_call_dcmd(const char *, uintptr_t,
extern int mdb_add_walker(const mdb_walker_t *);
extern int mdb_remove_walker(const char *);
extern ssize_t mdb_readvar(void *, const char *);
extern ssize_t mdb_writevar(const void *, const char *);
#define MDB_SYM_FUZZY 0 /* Match closest address */
#define MDB_OBJ_EXEC ((const char *)0L) /* Primary executable file */
extern int mdb_lookup_by_name(const char *, GElf_Sym *);
extern int mdb_lookup_by_obj(const char *, const char *, GElf_Sym *);
extern int mdb_getopts(int, const mdb_arg_t *, ...);
extern u_longlong_t mdb_strtoull(const char *);
extern void mdb_printf(const char *, ...);
extern void mdb_warn(const char *, ...);
extern void mdb_flush(void);
extern void mdb_nhconvert(void *, const void *, size_t);
extern const char *mdb_one_bit(int, int, int);
extern const char *mdb_inval_bits(int, int, int);
extern int mdb_eval(const char *);
extern void mdb_set_dot(uintmax_t);
extern uintmax_t mdb_get_dot(void);
extern void mdb_get_pipe(mdb_pipe_t *);
extern void mdb_set_pipe(const mdb_pipe_t *);
typedef int (*mdb_object_cb_t)(mdb_object_t *, void *);
extern int mdb_object_iter(mdb_object_cb_t, void *);
typedef int (*mdb_symbol_cb_t)(mdb_symbol_t *, void *);
void *);
#define MDB_STATE_IDLE 0 /* Target is idle (not running yet) */
extern int mdb_get_state(void);
#define MDB_CALLBACK_STCHG 1
#define MDB_CALLBACK_PROMPT 2
typedef void (*mdb_callback_f)(void *);
extern void *mdb_callback_add(int, mdb_callback_f, void *);
extern void mdb_callback_remove(void *);
/*
* Module's interaction path
*/
extern void mdb_tab_insert(mdb_tab_cookie_t *, const char *);
extern void mdb_tab_setmbase(mdb_tab_cookie_t *, const char *);
/*
* Tab completion utility functions for modules.
*/
extern int mdb_tab_complete_member(mdb_tab_cookie_t *, const char *,
const char *);
/*
* Tab completion functions for common signatures.
*/
const mdb_arg_t *);
extern char *strcat(char *, const char *);
extern char *strcpy(char *, const char *);
/* Need to be consistent with <string.h> C++ definitions */
#if __cplusplus >= 199711L
extern const char *strchr(const char *, int);
#ifndef _STRCHR_INLINE
#define _STRCHR_INLINE
extern "C++" {
}
}
#endif /* _STRCHR_INLINE */
extern const char *strrchr(const char *, int);
#ifndef _STRRCHR_INLINE
#define _STRRCHR_INLINE
extern "C++" {
}
}
#endif /* _STRRCHR_INLINE */
extern const char *strstr(const char *, const char *);
#ifndef _STRSTR_INLINE
#define _STRSTR_INLINE
extern "C++" {
}
}
#endif /* _STRSTR_INLINE */
#else
extern char *strchr(const char *, int);
extern char *strrchr(const char *, int);
extern char *strstr(const char *, const char *);
#endif /* __cplusplus >= 199711L */
extern int strcmp(const char *, const char *);
extern int strcasecmp(const char *, const char *);
extern int strncasecmp(const char *, const char *, size_t);
/* Need to be consistent with <string.h> C++ definitions */
#if __cplusplus >= 199711L
#ifndef _MEMCHR_INLINE
#define _MEMCHR_INLINE
extern "C++" {
}
}
#endif /* _MEMCHR_INLINE */
#else
#endif /* __cplusplus >= 199711L */
int (*)(const void *, const void *));
int (*)(const void *, const void *));
#ifdef __cplusplus
}
#endif
#endif /* _MDB_MODAPI_H */