17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5186f7fbfSEdward Pilatowicz * Common Development and Distribution License (the "License"). 6186f7fbfSEdward Pilatowicz * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22186f7fbfSEdward Pilatowicz * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 263b6e0a59SMatt Amdur /* 273b6e0a59SMatt Amdur * Copyright (c) 2012 by Delphix. All rights reserved. 28*f76ff24cSBryan Cantrill * Copyright (c) 2017 Joyent, Inc. All rights reserved. 293b6e0a59SMatt Amdur */ 303b6e0a59SMatt Amdur 317c478bd9Sstevel@tonic-gate #ifndef _MDB_H 327c478bd9Sstevel@tonic-gate #define _MDB_H 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <mdb/mdb_nv.h> 357c478bd9Sstevel@tonic-gate #include <mdb/mdb_io.h> 367c478bd9Sstevel@tonic-gate #include <mdb/mdb_gelf.h> 377c478bd9Sstevel@tonic-gate #include <mdb/mdb_addrvec.h> 387c478bd9Sstevel@tonic-gate #include <mdb/mdb_argvec.h> 397c478bd9Sstevel@tonic-gate #include <mdb/mdb_target.h> 407c478bd9Sstevel@tonic-gate #include <mdb/mdb_disasm.h> 417c478bd9Sstevel@tonic-gate #include <mdb/mdb_demangle.h> 427c478bd9Sstevel@tonic-gate #include <mdb/mdb_module.h> 437c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h> 447c478bd9Sstevel@tonic-gate #include <mdb/mdb_list.h> 457c478bd9Sstevel@tonic-gate #include <mdb/mdb_vcb.h> 460a47c91cSRobert Mustacchi #include <mdb/mdb_ctf.h> 473b6e0a59SMatt Amdur #include <mdb/mdb_tab.h> 487c478bd9Sstevel@tonic-gate #ifdef _KMDB 497c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_wr.h> 507c478bd9Sstevel@tonic-gate #endif 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #ifdef __cplusplus 537c478bd9Sstevel@tonic-gate extern "C" { 547c478bd9Sstevel@tonic-gate #endif 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #define MDB_ERR_PARSE 1 /* Error occurred in lexer or parser */ 577c478bd9Sstevel@tonic-gate #define MDB_ERR_NOMEM 2 /* Failed to allocate needed memory */ 587c478bd9Sstevel@tonic-gate #define MDB_ERR_PAGER 3 /* User quit current command from pager */ 597c478bd9Sstevel@tonic-gate #define MDB_ERR_SIGINT 4 /* User interrupt: abort current command */ 607c478bd9Sstevel@tonic-gate #define MDB_ERR_QUIT 5 /* User request: quit debugger */ 617c478bd9Sstevel@tonic-gate #define MDB_ERR_ASSERT 6 /* Assertion failure: abort current command */ 627c478bd9Sstevel@tonic-gate #define MDB_ERR_API 7 /* API function error: abort current command */ 637c478bd9Sstevel@tonic-gate #define MDB_ERR_ABORT 8 /* User abort or resume: abort to top level */ 647c478bd9Sstevel@tonic-gate #define MDB_ERR_OUTPUT 9 /* Write to m_out failed: abort to top level */ 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #define MDB_ERR_IS_FATAL(err) \ 677c478bd9Sstevel@tonic-gate ((err) == MDB_ERR_QUIT || (err) == MDB_ERR_ABORT || \ 687c478bd9Sstevel@tonic-gate (err) == MDB_ERR_OUTPUT) 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #define MDB_DEF_RADIX 16 /* Default output radix */ 717c478bd9Sstevel@tonic-gate #define MDB_DEF_NARGS 6 /* Default # of arguments in stack trace */ 727c478bd9Sstevel@tonic-gate #define MDB_DEF_HISTLEN 128 /* Default length of command history */ 737c478bd9Sstevel@tonic-gate #define MDB_DEF_SYMDIST 0x8000 /* Default symbol distance for addresses */ 747c478bd9Sstevel@tonic-gate #define MDB_DEF_ARRMEM 32 /* Default number of array members to print */ 757c478bd9Sstevel@tonic-gate #define MDB_DEF_ARRSTR 1024 /* Default number of array chars to print */ 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate #define MDB_ARR_NOLIMIT -1UL /* No limit on number of array elements */ 787c478bd9Sstevel@tonic-gate 79*f76ff24cSBryan Cantrill #define MDB_FL_PSYM 0x000001 /* Print dot as symbol + offset */ 80*f76ff24cSBryan Cantrill #define MDB_FL_LOG 0x000002 /* Logging is enabled */ 81*f76ff24cSBryan Cantrill #define MDB_FL_NOMODS 0x000004 /* Skip automatic mdb module loading */ 82*f76ff24cSBryan Cantrill #define MDB_FL_USECUP 0x000008 /* Use term cup init sequences */ 83*f76ff24cSBryan Cantrill #define MDB_FL_ADB 0x000010 /* Enable stricter adb(1) compat */ 84*f76ff24cSBryan Cantrill #define MDB_FL_SHOWLMID 0x000020 /* Show link map id with symbol names */ 85*f76ff24cSBryan Cantrill #define MDB_FL_IGNEOF 0x000040 /* Ignore EOF as a synonym for ::quit */ 86*f76ff24cSBryan Cantrill #define MDB_FL_REPLAST 0x000080 /* Naked newline repeats prev command */ 87*f76ff24cSBryan Cantrill #define MDB_FL_PAGER 0x000100 /* Enable pager by default */ 88*f76ff24cSBryan Cantrill #define MDB_FL_LATEST 0x000200 /* Replace verstring with "latest" */ 89*f76ff24cSBryan Cantrill #define MDB_FL_VCREATE 0x000400 /* Victim process created by debugger */ 90*f76ff24cSBryan Cantrill #define MDB_FL_JOBCTL 0x000800 /* Victim process jobctl on same tty */ 91*f76ff24cSBryan Cantrill #define MDB_FL_DEMANGLE 0x001000 /* Demangle symbols as part of %a */ 92*f76ff24cSBryan Cantrill #define MDB_FL_EXEC 0x002000 /* Debugger exec'd by a prev instance */ 93*f76ff24cSBryan Cantrill #define MDB_FL_NOCTF 0x004000 /* Skip automatic CTF data loading */ 94*f76ff24cSBryan Cantrill #define MDB_FL_BPTNOSYMSTOP 0x008000 /* Stop on def bkpts for unk symbols */ 95*f76ff24cSBryan Cantrill #define MDB_FL_TERMGUESS 0x010000 /* m_termtype derived from userland */ 96*f76ff24cSBryan Cantrill #define MDB_FL_READBACK 0x020000 /* Read value back after write */ 977c478bd9Sstevel@tonic-gate #ifdef _KMDB 98*f76ff24cSBryan Cantrill #define MDB_FL_NOUNLOAD 0x040000 /* Don't allow debugger unload */ 997c478bd9Sstevel@tonic-gate #endif 100*f76ff24cSBryan Cantrill #define MDB_FL_LMRAW 0x080000 /* Show unres link map object names */ 101*f76ff24cSBryan Cantrill #define MDB_FL_AUTOWRAP 0x100000 /* Autowrap lines at term width */ 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate #define MDB_FL_VOLATILE 0x0001 /* Mask of all volatile flags to save/restore */ 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate #define MDB_EM_ASK 0 /* Ask what to do on an exec */ 1067c478bd9Sstevel@tonic-gate #define MDB_EM_STOP 1 /* Stop after an exec */ 1077c478bd9Sstevel@tonic-gate #define MDB_EM_FOLLOW 2 /* Follow an exec */ 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate #define MDB_FM_ASK 0 /* Ask what to do on a fork */ 1107c478bd9Sstevel@tonic-gate #define MDB_FM_PARENT 1 /* Follow parent process on a fork */ 1117c478bd9Sstevel@tonic-gate #define MDB_FM_CHILD 2 /* Follow child process on a fork */ 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate #define MDB_PROMPTLEN 35 /* Maximum prompt length */ 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate struct kmdb_promif; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate typedef struct mdb { 1187c478bd9Sstevel@tonic-gate uint_t m_tgtflags; /* Target open flags (see mdb_target.h) */ 1197c478bd9Sstevel@tonic-gate uint_t m_flags; /* Miscellaneous flags (see above) */ 1207c478bd9Sstevel@tonic-gate uint_t m_debug; /* Debugging flags (see mdb_debug.h) */ 1217c478bd9Sstevel@tonic-gate int m_radix; /* Default radix for output formatting */ 1227c478bd9Sstevel@tonic-gate int m_nargs; /* Default number of arguments in stack trace */ 1237c478bd9Sstevel@tonic-gate int m_histlen; /* Length of command history */ 1247c478bd9Sstevel@tonic-gate size_t m_symdist; /* Distance from sym for addr match (0=smart) */ 1257c478bd9Sstevel@tonic-gate const char *m_pname; /* Program basename from argv[0] */ 1267c478bd9Sstevel@tonic-gate char m_promptraw[MDB_PROMPTLEN + 1]; /* Un-expanded prompt */ 1277c478bd9Sstevel@tonic-gate char m_prompt[MDB_PROMPTLEN + 1]; /* Prompt for interactive mode */ 1287c478bd9Sstevel@tonic-gate size_t m_promptlen; /* Length of prompt in bytes */ 1297c478bd9Sstevel@tonic-gate const char *m_shell; /* Shell for ! commands and pipelines */ 1307c478bd9Sstevel@tonic-gate char *m_root; /* Root for path construction */ 1317c478bd9Sstevel@tonic-gate char *m_ipathstr; /* Path string for include path */ 1327c478bd9Sstevel@tonic-gate char *m_lpathstr; /* Path string for library path */ 1337c478bd9Sstevel@tonic-gate const char **m_ipath; /* Path for $< and $<< macro files */ 1347c478bd9Sstevel@tonic-gate size_t m_ipathlen; /* Length of underlying ipath buffer */ 1357c478bd9Sstevel@tonic-gate const char **m_lpath; /* Path for :: loadable modules */ 1367c478bd9Sstevel@tonic-gate size_t m_lpathlen; /* Length of underlying lpath buffer */ 1377c478bd9Sstevel@tonic-gate mdb_modinfo_t m_rminfo; /* Root debugger module information */ 1387c478bd9Sstevel@tonic-gate mdb_module_t m_rmod; /* Root debugger module (builtins) */ 1397c478bd9Sstevel@tonic-gate mdb_module_t *m_mhead; /* Head of module list (in load order) */ 1407c478bd9Sstevel@tonic-gate mdb_module_t *m_mtail; /* Tail of module list (in load order) */ 1417c478bd9Sstevel@tonic-gate mdb_list_t m_tgtlist; /* List of active target backends */ 1427c478bd9Sstevel@tonic-gate mdb_tgt_t *m_target; /* Current debugger target backend */ 1437c478bd9Sstevel@tonic-gate mdb_nv_t m_disasms; /* Hash of available disassemblers */ 1447c478bd9Sstevel@tonic-gate mdb_disasm_t *m_disasm; /* Current disassembler backend */ 1457c478bd9Sstevel@tonic-gate char *m_defdisasm; /* Deferred diassembler selection */ 1467c478bd9Sstevel@tonic-gate mdb_nv_t m_modules; /* Name/value hash for loadable modules */ 1477c478bd9Sstevel@tonic-gate mdb_nv_t m_dcmds; /* Name/value hash for extended commands */ 1487c478bd9Sstevel@tonic-gate mdb_nv_t m_walkers; /* Name/value hash for walk operations */ 1497c478bd9Sstevel@tonic-gate mdb_nv_t m_nv; /* Name/value hash for named variables */ 1507c478bd9Sstevel@tonic-gate mdb_var_t *m_dot; /* Variable reference for '.' */ 1517c478bd9Sstevel@tonic-gate uintmax_t m_incr; /* Current increment */ 1527c478bd9Sstevel@tonic-gate uintmax_t m_raddr; /* Most recent address specified to a dcmd */ 1537c478bd9Sstevel@tonic-gate uintmax_t m_dcount; /* Most recent count specified to a dcmd */ 1547c478bd9Sstevel@tonic-gate mdb_var_t *m_rvalue; /* Most recent value printed */ 1557c478bd9Sstevel@tonic-gate mdb_var_t *m_roffset; /* Most recent offset from an instruction */ 1567c478bd9Sstevel@tonic-gate mdb_var_t *m_proffset; /* Previous value of m_roffset */ 1577c478bd9Sstevel@tonic-gate mdb_var_t *m_rcount; /* Most recent count on $< dcmd */ 1587c478bd9Sstevel@tonic-gate mdb_iob_t *m_in; /* Input stream */ 1597c478bd9Sstevel@tonic-gate mdb_iob_t *m_out; /* Output stream */ 1607c478bd9Sstevel@tonic-gate mdb_iob_t *m_err; /* Error stream */ 1617c478bd9Sstevel@tonic-gate mdb_iob_t *m_null; /* Null stream */ 1627c478bd9Sstevel@tonic-gate char *m_termtype; /* Interactive mode terminal type */ 1637c478bd9Sstevel@tonic-gate mdb_io_t *m_term; /* Terminal for interactive mode */ 1647c478bd9Sstevel@tonic-gate mdb_io_t *m_log; /* Log file i/o backend (NULL if not logging) */ 1657c478bd9Sstevel@tonic-gate mdb_module_t *m_lmod; /* Pointer to loading module, if in load */ 1667c478bd9Sstevel@tonic-gate mdb_list_t m_lastc; /* Last executed command list */ 1677c478bd9Sstevel@tonic-gate mdb_gelf_symtab_t *m_prsym; /* Private symbol table */ 1687c478bd9Sstevel@tonic-gate mdb_demangler_t *m_demangler; /* Demangler (see <mdb/mdb_demangle.h>) */ 1697c478bd9Sstevel@tonic-gate mdb_list_t m_flist; /* Stack of execution frames */ 1707c478bd9Sstevel@tonic-gate struct mdb_frame *volatile m_frame; /* Current stack frame */ 1717c478bd9Sstevel@tonic-gate struct mdb_frame *volatile m_fmark; /* Stack marker for pager */ 1727c478bd9Sstevel@tonic-gate uint_t m_fid; /* Next frame identifier number to assign */ 1737c478bd9Sstevel@tonic-gate uint_t m_depth; /* Depth of m_frame stack */ 1747c478bd9Sstevel@tonic-gate volatile uint_t m_intr; /* Don't allow SIGINT if set */ 1757c478bd9Sstevel@tonic-gate volatile uint_t m_pend; /* Pending SIGINT count */ 1767c478bd9Sstevel@tonic-gate pid_t m_pgid; /* Debugger process group id */ 1777c478bd9Sstevel@tonic-gate uint_t m_rdvers; /* Librtld_db version number */ 1787c478bd9Sstevel@tonic-gate uint_t m_ctfvers; /* Libctf version number */ 1797c478bd9Sstevel@tonic-gate ulong_t m_armemlim; /* Limit on number of array members to print */ 1807c478bd9Sstevel@tonic-gate ulong_t m_arstrlim; /* Limit on number of array chars to print */ 1817c478bd9Sstevel@tonic-gate uchar_t m_execmode; /* Follow exec behavior */ 1827c478bd9Sstevel@tonic-gate uchar_t m_forkmode; /* Follow fork behavior */ 1837c478bd9Sstevel@tonic-gate char **m_env; /* Current environment */ 1847c478bd9Sstevel@tonic-gate mdb_list_t m_cblist; /* List of callbacks */ 1857c478bd9Sstevel@tonic-gate mdb_nv_t m_macaliases; /* Name/value hash of ADB macro aliases */ 1860a47c91cSRobert Mustacchi ctf_file_t *m_synth; /* Container for synthetic types */ 1870a47c91cSRobert Mustacchi int m_lastret; /* Result of running the last command */ 1887c478bd9Sstevel@tonic-gate #ifdef _KMDB 1897c478bd9Sstevel@tonic-gate struct dpi_ops *m_dpi; /* DPI ops vector */ 1907c478bd9Sstevel@tonic-gate struct kdi *m_kdi; /* KDI ops vector */ 1917c478bd9Sstevel@tonic-gate size_t m_pagesize; /* Base page size for this machine */ 1927c478bd9Sstevel@tonic-gate caddr_t m_dseg; /* Debugger segment address */ 1937c478bd9Sstevel@tonic-gate size_t m_dsegsz; /* Debugger segment size */ 1947c478bd9Sstevel@tonic-gate mdb_nv_t m_dmodctl; /* dmod name -> kmdb_modctl hash */ 1957c478bd9Sstevel@tonic-gate kmdb_wr_t *m_drvwrhead; /* Driver work request queue */ 1967c478bd9Sstevel@tonic-gate kmdb_wr_t *m_drvwrtail; /* Driver work request queue */ 1977c478bd9Sstevel@tonic-gate kmdb_wr_t *m_dbgwrhead; /* Debugger request queue */ 1987c478bd9Sstevel@tonic-gate kmdb_wr_t *m_dbgwrtail; /* Debugger request queue */ 1997c478bd9Sstevel@tonic-gate struct cons_polledio *m_pio; /* Polled I/O struct from kernel */ 2007c478bd9Sstevel@tonic-gate struct kmdb_promif *m_promif; /* Debugger/PROM interface state */ 2017c478bd9Sstevel@tonic-gate #endif 2027c478bd9Sstevel@tonic-gate } mdb_t; 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate #ifdef _MDB_PRIVATE 2057c478bd9Sstevel@tonic-gate mdb_t mdb; 2067c478bd9Sstevel@tonic-gate #else 2077c478bd9Sstevel@tonic-gate extern mdb_t mdb; 2087c478bd9Sstevel@tonic-gate #endif 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate #ifdef _MDB 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate #define MDB_CONFIG_ENV_VAR "_MDB_CONFIG" 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate extern void mdb_create(const char *, const char *); 2157c478bd9Sstevel@tonic-gate extern void mdb_destroy(void); 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate extern int mdb_call_idcmd(mdb_idcmd_t *, uintmax_t, uintmax_t, uint_t, 2187c478bd9Sstevel@tonic-gate mdb_argvec_t *, mdb_addrvec_t *, mdb_vcb_t *); 2193b6e0a59SMatt Amdur extern void mdb_call_tab(mdb_idcmd_t *, mdb_tab_cookie_t *, uint_t, uintmax_t, 2203b6e0a59SMatt Amdur mdb_arg_t *); 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate extern int mdb_call(uintmax_t, uintmax_t, uint_t); 2237c478bd9Sstevel@tonic-gate extern int mdb_run(void); 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate extern const char *mdb_get_prompt(void); 2267c478bd9Sstevel@tonic-gate extern int mdb_set_prompt(const char *); 2277c478bd9Sstevel@tonic-gate extern void mdb_set_ipath(const char *); 2287c478bd9Sstevel@tonic-gate extern void mdb_set_lpath(const char *); 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate extern const char **mdb_path_alloc(const char *, size_t *); 2317c478bd9Sstevel@tonic-gate extern const char **mdb_path_dup(const char *[], size_t, size_t *); 2327c478bd9Sstevel@tonic-gate extern void mdb_path_free(const char *[], size_t); 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate extern uintmax_t mdb_dot_incr(const char *); 2357c478bd9Sstevel@tonic-gate extern uintmax_t mdb_dot_decr(const char *); 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate extern mdb_iwalker_t *mdb_walker_lookup(const char *); 2387c478bd9Sstevel@tonic-gate extern mdb_idcmd_t *mdb_dcmd_lookup(const char *); 2397c478bd9Sstevel@tonic-gate extern void mdb_dcmd_usage(const mdb_idcmd_t *, mdb_iob_t *); 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate extern void mdb_pservice_init(void); 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate extern void mdb_intr_enable(void); 2447c478bd9Sstevel@tonic-gate extern void mdb_intr_disable(void); 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate extern char *mdb_get_config(void); 2477c478bd9Sstevel@tonic-gate extern void mdb_set_config(const char *); 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate extern mdb_module_t *mdb_get_module(void); 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate #endif /* _MDB */ 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2547c478bd9Sstevel@tonic-gate } 2557c478bd9Sstevel@tonic-gate #endif 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate #endif /* _MDB_H */ 258