1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _MDB_H 28*7c478bd9Sstevel@tonic-gate #define _MDB_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_nv.h> 33*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_io.h> 34*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_gelf.h> 35*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_addrvec.h> 36*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_argvec.h> 37*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_target.h> 38*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_disasm.h> 39*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_demangle.h> 40*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_module.h> 41*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h> 42*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_list.h> 43*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_vcb.h> 44*7c478bd9Sstevel@tonic-gate #ifdef _KMDB 45*7c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_wr.h> 46*7c478bd9Sstevel@tonic-gate #endif 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 49*7c478bd9Sstevel@tonic-gate extern "C" { 50*7c478bd9Sstevel@tonic-gate #endif 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate #define MDB_ERR_PARSE 1 /* Error occurred in lexer or parser */ 53*7c478bd9Sstevel@tonic-gate #define MDB_ERR_NOMEM 2 /* Failed to allocate needed memory */ 54*7c478bd9Sstevel@tonic-gate #define MDB_ERR_PAGER 3 /* User quit current command from pager */ 55*7c478bd9Sstevel@tonic-gate #define MDB_ERR_SIGINT 4 /* User interrupt: abort current command */ 56*7c478bd9Sstevel@tonic-gate #define MDB_ERR_QUIT 5 /* User request: quit debugger */ 57*7c478bd9Sstevel@tonic-gate #define MDB_ERR_ASSERT 6 /* Assertion failure: abort current command */ 58*7c478bd9Sstevel@tonic-gate #define MDB_ERR_API 7 /* API function error: abort current command */ 59*7c478bd9Sstevel@tonic-gate #define MDB_ERR_ABORT 8 /* User abort or resume: abort to top level */ 60*7c478bd9Sstevel@tonic-gate #define MDB_ERR_OUTPUT 9 /* Write to m_out failed: abort to top level */ 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate #define MDB_ERR_IS_FATAL(err) \ 63*7c478bd9Sstevel@tonic-gate ((err) == MDB_ERR_QUIT || (err) == MDB_ERR_ABORT || \ 64*7c478bd9Sstevel@tonic-gate (err) == MDB_ERR_OUTPUT) 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate #define MDB_DEF_RADIX 16 /* Default output radix */ 67*7c478bd9Sstevel@tonic-gate #define MDB_DEF_NARGS 6 /* Default # of arguments in stack trace */ 68*7c478bd9Sstevel@tonic-gate #define MDB_DEF_HISTLEN 128 /* Default length of command history */ 69*7c478bd9Sstevel@tonic-gate #define MDB_DEF_SYMDIST 0x8000 /* Default symbol distance for addresses */ 70*7c478bd9Sstevel@tonic-gate #define MDB_DEF_ARRMEM 32 /* Default number of array members to print */ 71*7c478bd9Sstevel@tonic-gate #define MDB_DEF_ARRSTR 1024 /* Default number of array chars to print */ 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate #define MDB_ARR_NOLIMIT -1UL /* No limit on number of array elements */ 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate #define MDB_FL_PSYM 0x00001 /* Print dot as symbol + offset when possible */ 76*7c478bd9Sstevel@tonic-gate #define MDB_FL_LOG 0x00002 /* Logging is enabled */ 77*7c478bd9Sstevel@tonic-gate #define MDB_FL_NOMODS 0x00004 /* Skip automatic mdb module loading */ 78*7c478bd9Sstevel@tonic-gate #define MDB_FL_USECUP 0x00008 /* Use terminal cup initialization sequences */ 79*7c478bd9Sstevel@tonic-gate #define MDB_FL_ADB 0x00010 /* Enable stricter adb(1) compatibility */ 80*7c478bd9Sstevel@tonic-gate #define MDB_FL_SHOWLMID 0x00020 /* Always show link map id with symbol names */ 81*7c478bd9Sstevel@tonic-gate #define MDB_FL_IGNEOF 0x00040 /* Ignore EOF as a synonym for ::quit */ 82*7c478bd9Sstevel@tonic-gate #define MDB_FL_REPLAST 0x00080 /* Naked newline repeats previous command */ 83*7c478bd9Sstevel@tonic-gate #define MDB_FL_PAGER 0x00100 /* Enable pager by default */ 84*7c478bd9Sstevel@tonic-gate #define MDB_FL_LATEST 0x00200 /* Replace version string with "latest" */ 85*7c478bd9Sstevel@tonic-gate #define MDB_FL_VCREATE 0x00400 /* Victim process was created by debugger */ 86*7c478bd9Sstevel@tonic-gate #define MDB_FL_JOBCTL 0x00800 /* Victim process jobctl stopped on same tty */ 87*7c478bd9Sstevel@tonic-gate #define MDB_FL_DEMANGLE 0x01000 /* Demangle symbols as part of %a processing */ 88*7c478bd9Sstevel@tonic-gate #define MDB_FL_EXEC 0x02000 /* Debugger exec'd by a previous instance */ 89*7c478bd9Sstevel@tonic-gate #define MDB_FL_NOCTF 0x04000 /* Skip automatic CTF data loading */ 90*7c478bd9Sstevel@tonic-gate #define MDB_FL_BPTNOSYMSTOP 0x08000 /* Stop on deferred bkpts for unk symbols */ 91*7c478bd9Sstevel@tonic-gate #define MDB_FL_TERMGUESS 0x10000 /* m_termtype derived from userland */ 92*7c478bd9Sstevel@tonic-gate #define MDB_FL_READBACK 0x20000 /* Read value back after write */ 93*7c478bd9Sstevel@tonic-gate #ifdef _KMDB 94*7c478bd9Sstevel@tonic-gate #define MDB_FL_NOUNLOAD 0x40000 /* Don't allow debugger unload */ 95*7c478bd9Sstevel@tonic-gate #endif 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate #define MDB_FL_VOLATILE 0x0001 /* Mask of all volatile flags to save/restore */ 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate #define MDB_EM_ASK 0 /* Ask what to do on an exec */ 100*7c478bd9Sstevel@tonic-gate #define MDB_EM_STOP 1 /* Stop after an exec */ 101*7c478bd9Sstevel@tonic-gate #define MDB_EM_FOLLOW 2 /* Follow an exec */ 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate #define MDB_FM_ASK 0 /* Ask what to do on a fork */ 104*7c478bd9Sstevel@tonic-gate #define MDB_FM_PARENT 1 /* Follow parent process on a fork */ 105*7c478bd9Sstevel@tonic-gate #define MDB_FM_CHILD 2 /* Follow child process on a fork */ 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate #define MDB_PROMPTLEN 35 /* Maximum prompt length */ 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate struct kmdb_promif; 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate typedef struct mdb { 112*7c478bd9Sstevel@tonic-gate uint_t m_tgtflags; /* Target open flags (see mdb_target.h) */ 113*7c478bd9Sstevel@tonic-gate uint_t m_flags; /* Miscellaneous flags (see above) */ 114*7c478bd9Sstevel@tonic-gate uint_t m_debug; /* Debugging flags (see mdb_debug.h) */ 115*7c478bd9Sstevel@tonic-gate int m_radix; /* Default radix for output formatting */ 116*7c478bd9Sstevel@tonic-gate int m_nargs; /* Default number of arguments in stack trace */ 117*7c478bd9Sstevel@tonic-gate int m_histlen; /* Length of command history */ 118*7c478bd9Sstevel@tonic-gate size_t m_symdist; /* Distance from sym for addr match (0=smart) */ 119*7c478bd9Sstevel@tonic-gate const char *m_pname; /* Program basename from argv[0] */ 120*7c478bd9Sstevel@tonic-gate char m_promptraw[MDB_PROMPTLEN + 1]; /* Un-expanded prompt */ 121*7c478bd9Sstevel@tonic-gate char m_prompt[MDB_PROMPTLEN + 1]; /* Prompt for interactive mode */ 122*7c478bd9Sstevel@tonic-gate size_t m_promptlen; /* Length of prompt in bytes */ 123*7c478bd9Sstevel@tonic-gate const char *m_shell; /* Shell for ! commands and pipelines */ 124*7c478bd9Sstevel@tonic-gate char *m_root; /* Root for path construction */ 125*7c478bd9Sstevel@tonic-gate char *m_ipathstr; /* Path string for include path */ 126*7c478bd9Sstevel@tonic-gate char *m_lpathstr; /* Path string for library path */ 127*7c478bd9Sstevel@tonic-gate const char **m_ipath; /* Path for $< and $<< macro files */ 128*7c478bd9Sstevel@tonic-gate size_t m_ipathlen; /* Length of underlying ipath buffer */ 129*7c478bd9Sstevel@tonic-gate const char **m_lpath; /* Path for :: loadable modules */ 130*7c478bd9Sstevel@tonic-gate size_t m_lpathlen; /* Length of underlying lpath buffer */ 131*7c478bd9Sstevel@tonic-gate mdb_modinfo_t m_rminfo; /* Root debugger module information */ 132*7c478bd9Sstevel@tonic-gate mdb_module_t m_rmod; /* Root debugger module (builtins) */ 133*7c478bd9Sstevel@tonic-gate mdb_module_t *m_mhead; /* Head of module list (in load order) */ 134*7c478bd9Sstevel@tonic-gate mdb_module_t *m_mtail; /* Tail of module list (in load order) */ 135*7c478bd9Sstevel@tonic-gate mdb_list_t m_tgtlist; /* List of active target backends */ 136*7c478bd9Sstevel@tonic-gate mdb_tgt_t *m_target; /* Current debugger target backend */ 137*7c478bd9Sstevel@tonic-gate mdb_nv_t m_disasms; /* Hash of available disassemblers */ 138*7c478bd9Sstevel@tonic-gate mdb_disasm_t *m_disasm; /* Current disassembler backend */ 139*7c478bd9Sstevel@tonic-gate char *m_defdisasm; /* Deferred diassembler selection */ 140*7c478bd9Sstevel@tonic-gate mdb_nv_t m_modules; /* Name/value hash for loadable modules */ 141*7c478bd9Sstevel@tonic-gate mdb_nv_t m_dcmds; /* Name/value hash for extended commands */ 142*7c478bd9Sstevel@tonic-gate mdb_nv_t m_walkers; /* Name/value hash for walk operations */ 143*7c478bd9Sstevel@tonic-gate mdb_nv_t m_nv; /* Name/value hash for named variables */ 144*7c478bd9Sstevel@tonic-gate mdb_var_t *m_dot; /* Variable reference for '.' */ 145*7c478bd9Sstevel@tonic-gate uintmax_t m_incr; /* Current increment */ 146*7c478bd9Sstevel@tonic-gate uintmax_t m_raddr; /* Most recent address specified to a dcmd */ 147*7c478bd9Sstevel@tonic-gate uintmax_t m_dcount; /* Most recent count specified to a dcmd */ 148*7c478bd9Sstevel@tonic-gate mdb_var_t *m_rvalue; /* Most recent value printed */ 149*7c478bd9Sstevel@tonic-gate mdb_var_t *m_roffset; /* Most recent offset from an instruction */ 150*7c478bd9Sstevel@tonic-gate mdb_var_t *m_proffset; /* Previous value of m_roffset */ 151*7c478bd9Sstevel@tonic-gate mdb_var_t *m_rcount; /* Most recent count on $< dcmd */ 152*7c478bd9Sstevel@tonic-gate mdb_iob_t *m_in; /* Input stream */ 153*7c478bd9Sstevel@tonic-gate mdb_iob_t *m_out; /* Output stream */ 154*7c478bd9Sstevel@tonic-gate mdb_iob_t *m_err; /* Error stream */ 155*7c478bd9Sstevel@tonic-gate mdb_iob_t *m_null; /* Null stream */ 156*7c478bd9Sstevel@tonic-gate char *m_termtype; /* Interactive mode terminal type */ 157*7c478bd9Sstevel@tonic-gate mdb_io_t *m_term; /* Terminal for interactive mode */ 158*7c478bd9Sstevel@tonic-gate mdb_io_t *m_log; /* Log file i/o backend (NULL if not logging) */ 159*7c478bd9Sstevel@tonic-gate mdb_module_t *m_lmod; /* Pointer to loading module, if in load */ 160*7c478bd9Sstevel@tonic-gate mdb_list_t m_lastc; /* Last executed command list */ 161*7c478bd9Sstevel@tonic-gate mdb_gelf_symtab_t *m_prsym; /* Private symbol table */ 162*7c478bd9Sstevel@tonic-gate mdb_demangler_t *m_demangler; /* Demangler (see <mdb/mdb_demangle.h>) */ 163*7c478bd9Sstevel@tonic-gate mdb_list_t m_flist; /* Stack of execution frames */ 164*7c478bd9Sstevel@tonic-gate struct mdb_frame *volatile m_frame; /* Current stack frame */ 165*7c478bd9Sstevel@tonic-gate struct mdb_frame *volatile m_fmark; /* Stack marker for pager */ 166*7c478bd9Sstevel@tonic-gate uint_t m_fid; /* Next frame identifier number to assign */ 167*7c478bd9Sstevel@tonic-gate uint_t m_depth; /* Depth of m_frame stack */ 168*7c478bd9Sstevel@tonic-gate volatile uint_t m_intr; /* Don't allow SIGINT if set */ 169*7c478bd9Sstevel@tonic-gate volatile uint_t m_pend; /* Pending SIGINT count */ 170*7c478bd9Sstevel@tonic-gate pid_t m_pgid; /* Debugger process group id */ 171*7c478bd9Sstevel@tonic-gate uint_t m_rdvers; /* Librtld_db version number */ 172*7c478bd9Sstevel@tonic-gate uint_t m_ctfvers; /* Libctf version number */ 173*7c478bd9Sstevel@tonic-gate ulong_t m_armemlim; /* Limit on number of array members to print */ 174*7c478bd9Sstevel@tonic-gate ulong_t m_arstrlim; /* Limit on number of array chars to print */ 175*7c478bd9Sstevel@tonic-gate uchar_t m_execmode; /* Follow exec behavior */ 176*7c478bd9Sstevel@tonic-gate uchar_t m_forkmode; /* Follow fork behavior */ 177*7c478bd9Sstevel@tonic-gate char **m_env; /* Current environment */ 178*7c478bd9Sstevel@tonic-gate mdb_list_t m_cblist; /* List of callbacks */ 179*7c478bd9Sstevel@tonic-gate mdb_nv_t m_macaliases; /* Name/value hash of ADB macro aliases */ 180*7c478bd9Sstevel@tonic-gate #ifdef _KMDB 181*7c478bd9Sstevel@tonic-gate struct dpi_ops *m_dpi; /* DPI ops vector */ 182*7c478bd9Sstevel@tonic-gate struct kdi *m_kdi; /* KDI ops vector */ 183*7c478bd9Sstevel@tonic-gate size_t m_pagesize; /* Base page size for this machine */ 184*7c478bd9Sstevel@tonic-gate caddr_t m_dseg; /* Debugger segment address */ 185*7c478bd9Sstevel@tonic-gate size_t m_dsegsz; /* Debugger segment size */ 186*7c478bd9Sstevel@tonic-gate mdb_nv_t m_dmodctl; /* dmod name -> kmdb_modctl hash */ 187*7c478bd9Sstevel@tonic-gate kmdb_wr_t *m_drvwrhead; /* Driver work request queue */ 188*7c478bd9Sstevel@tonic-gate kmdb_wr_t *m_drvwrtail; /* Driver work request queue */ 189*7c478bd9Sstevel@tonic-gate kmdb_wr_t *m_dbgwrhead; /* Debugger request queue */ 190*7c478bd9Sstevel@tonic-gate kmdb_wr_t *m_dbgwrtail; /* Debugger request queue */ 191*7c478bd9Sstevel@tonic-gate struct cons_polledio *m_pio; /* Polled I/O struct from kernel */ 192*7c478bd9Sstevel@tonic-gate struct kmdb_promif *m_promif; /* Debugger/PROM interface state */ 193*7c478bd9Sstevel@tonic-gate #endif 194*7c478bd9Sstevel@tonic-gate } mdb_t; 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate #ifdef _MDB_PRIVATE 197*7c478bd9Sstevel@tonic-gate mdb_t mdb; 198*7c478bd9Sstevel@tonic-gate #else 199*7c478bd9Sstevel@tonic-gate extern mdb_t mdb; 200*7c478bd9Sstevel@tonic-gate #endif 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate #ifdef _MDB 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate #define MDB_CONFIG_ENV_VAR "_MDB_CONFIG" 205*7c478bd9Sstevel@tonic-gate 206*7c478bd9Sstevel@tonic-gate extern void mdb_create(const char *, const char *); 207*7c478bd9Sstevel@tonic-gate extern void mdb_destroy(void); 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate extern int mdb_call_idcmd(mdb_idcmd_t *, uintmax_t, uintmax_t, uint_t, 210*7c478bd9Sstevel@tonic-gate mdb_argvec_t *, mdb_addrvec_t *, mdb_vcb_t *); 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate extern int mdb_call(uintmax_t, uintmax_t, uint_t); 213*7c478bd9Sstevel@tonic-gate extern int mdb_run(void); 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate extern const char *mdb_get_prompt(void); 216*7c478bd9Sstevel@tonic-gate extern int mdb_set_prompt(const char *); 217*7c478bd9Sstevel@tonic-gate extern void mdb_set_ipath(const char *); 218*7c478bd9Sstevel@tonic-gate extern void mdb_set_lpath(const char *); 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate extern const char **mdb_path_alloc(const char *, size_t *); 221*7c478bd9Sstevel@tonic-gate extern const char **mdb_path_dup(const char *[], size_t, size_t *); 222*7c478bd9Sstevel@tonic-gate extern void mdb_path_free(const char *[], size_t); 223*7c478bd9Sstevel@tonic-gate 224*7c478bd9Sstevel@tonic-gate extern uintmax_t mdb_dot_incr(const char *); 225*7c478bd9Sstevel@tonic-gate extern uintmax_t mdb_dot_decr(const char *); 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate extern mdb_iwalker_t *mdb_walker_lookup(const char *); 228*7c478bd9Sstevel@tonic-gate extern mdb_idcmd_t *mdb_dcmd_lookup(const char *); 229*7c478bd9Sstevel@tonic-gate extern void mdb_dcmd_usage(const mdb_idcmd_t *, mdb_iob_t *); 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate extern void mdb_pservice_init(void); 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate extern void mdb_intr_enable(void); 234*7c478bd9Sstevel@tonic-gate extern void mdb_intr_disable(void); 235*7c478bd9Sstevel@tonic-gate 236*7c478bd9Sstevel@tonic-gate extern char *mdb_get_config(void); 237*7c478bd9Sstevel@tonic-gate extern void mdb_set_config(const char *); 238*7c478bd9Sstevel@tonic-gate 239*7c478bd9Sstevel@tonic-gate extern mdb_module_t *mdb_get_module(void); 240*7c478bd9Sstevel@tonic-gate 241*7c478bd9Sstevel@tonic-gate #endif /* _MDB */ 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 244*7c478bd9Sstevel@tonic-gate } 245*7c478bd9Sstevel@tonic-gate #endif 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate #endif /* _MDB_H */ 248