1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _MDB_TARGET_H 28 #define _MDB_TARGET_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #include <sys/utsname.h> 33 #include <sys/types.h> 34 #include <gelf.h> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 /* 41 * Forward declaration of the target structure: the target itself is defined in 42 * mdb_tgt_impl.h and is opaque with respect to callers of this interface. 43 */ 44 45 struct mdb_tgt; 46 struct mdb_arg; 47 struct ctf_file; 48 49 typedef struct mdb_tgt mdb_tgt_t; 50 51 extern void mdb_create_builtin_tgts(void); 52 extern void mdb_create_loadable_disasms(void); 53 54 /* 55 * Target Constructors 56 * 57 * These functions are used to create a complete debugger target. The 58 * constructor is passed as an argument to mdb_tgt_create(). 59 */ 60 61 extern int mdb_value_tgt_create(mdb_tgt_t *, int, const char *[]); 62 #ifndef _KMDB 63 extern int mdb_kvm_tgt_create(mdb_tgt_t *, int, const char *[]); 64 extern int mdb_proc_tgt_create(mdb_tgt_t *, int, const char *[]); 65 extern int mdb_kproc_tgt_create(mdb_tgt_t *, int, const char *[]); 66 extern int mdb_rawfile_tgt_create(mdb_tgt_t *, int, const char *[]); 67 #else 68 extern int kmdb_kvm_create(mdb_tgt_t *, int, const char *[]); 69 #endif 70 71 /* 72 * Targets are created by calling mdb_tgt_create() with an optional set of 73 * target flags, an argument list, and a target constructor (see above): 74 */ 75 76 #define MDB_TGT_F_RDWR 0x0001 /* Open for writing (else read-only) */ 77 #define MDB_TGT_F_ALLOWIO 0x0002 /* Allow I/O mem access (live only) */ 78 #define MDB_TGT_F_FORCE 0x0004 /* Force open (even if non-exclusive) */ 79 #define MDB_TGT_F_PRELOAD 0x0008 /* Preload all symbol tables */ 80 #define MDB_TGT_F_NOLOAD 0x0010 /* Do not do load-object processing */ 81 #define MDB_TGT_F_NOSTOP 0x0020 /* Do not stop target on attach */ 82 #define MDB_TGT_F_STEP 0x0040 /* Single-step is pending */ 83 #define MDB_TGT_F_STEP_OUT 0x0080 /* Step-out is pending */ 84 #define MDB_TGT_F_STEP_BRANCH 0x0100 /* Step-branch is pending */ 85 #define MDB_TGT_F_NEXT 0x0200 /* Step-over is pending */ 86 #define MDB_TGT_F_CONT 0x0400 /* Continue is pending */ 87 #define MDB_TGT_F_BUSY 0x0800 /* Target is busy executing */ 88 #define MDB_TGT_F_ASIO 0x1000 /* Use t_aread and t_awrite for i/o */ 89 #define MDB_TGT_F_UNLOAD 0x2000 /* Unload has been requested */ 90 #define MDB_TGT_F_ALL 0x3fff /* Mask of all valid flags */ 91 92 typedef int mdb_tgt_ctor_f(mdb_tgt_t *, int, const char *[]); 93 94 extern mdb_tgt_t *mdb_tgt_create(mdb_tgt_ctor_f *, int, int, const char *[]); 95 extern void mdb_tgt_destroy(mdb_tgt_t *); 96 97 extern int mdb_tgt_getflags(mdb_tgt_t *); 98 extern int mdb_tgt_setflags(mdb_tgt_t *, int); 99 extern int mdb_tgt_setcontext(mdb_tgt_t *, void *); 100 101 /* 102 * Targets are activated and de-activated by the debugger framework. An 103 * activation occurs after construction when the target becomes the current 104 * target in the debugger. A target is de-activated prior to its destructor 105 * being called by mdb_tgt_destroy, or when another target is activated. 106 * These callbacks are suitable for loading support modules and other tasks. 107 */ 108 extern void mdb_tgt_activate(mdb_tgt_t *); 109 110 /* 111 * Prior to issuing a new command prompt, the debugger framework calls the 112 * target's periodic callback to allow it to load new modules or perform 113 * other background tasks. 114 */ 115 extern void mdb_tgt_periodic(mdb_tgt_t *); 116 117 /* 118 * Convenience functions for accessing miscellaneous target information. 119 */ 120 extern const char *mdb_tgt_name(mdb_tgt_t *); 121 extern const char *mdb_tgt_isa(mdb_tgt_t *); 122 extern const char *mdb_tgt_platform(mdb_tgt_t *); 123 extern int mdb_tgt_uname(mdb_tgt_t *, struct utsname *); 124 extern int mdb_tgt_dmodel(mdb_tgt_t *); 125 126 /* 127 * Address Space Interface 128 * 129 * Each target can provide access to a set of address spaces, which may include 130 * a primary virtual address space, a physical address space, an object file 131 * address space (where virtual addresses are converted to file offsets in an 132 * object file), and an I/O port address space. Additionally, the target can 133 * provide access to alternate address spaces, which are identified by the 134 * opaque mdb_tgt_as_t type. If the 'as' parameter to mdb_tgt_aread or 135 * mdb_tgt_awrite is one of the listed constants, these calls are equivalent 136 * to mdb_tgt_{v|p|f|io}read or write. 137 */ 138 139 typedef void * mdb_tgt_as_t; /* Opaque address space id */ 140 typedef uint64_t mdb_tgt_addr_t; /* Generic unsigned address */ 141 typedef uint64_t physaddr_t; /* Physical memory address */ 142 143 #define MDB_TGT_AS_VIRT ((mdb_tgt_as_t)-1L) /* Virtual address space */ 144 #define MDB_TGT_AS_PHYS ((mdb_tgt_as_t)-2L) /* Physical address space */ 145 #define MDB_TGT_AS_FILE ((mdb_tgt_as_t)-3L) /* Object file address space */ 146 #define MDB_TGT_AS_IO ((mdb_tgt_as_t)-4L) /* I/o address space */ 147 148 extern ssize_t mdb_tgt_aread(mdb_tgt_t *, mdb_tgt_as_t, 149 void *, size_t, mdb_tgt_addr_t); 150 151 extern ssize_t mdb_tgt_awrite(mdb_tgt_t *, mdb_tgt_as_t, 152 const void *, size_t, mdb_tgt_addr_t); 153 154 extern ssize_t mdb_tgt_vread(mdb_tgt_t *, void *, size_t, uintptr_t); 155 extern ssize_t mdb_tgt_vwrite(mdb_tgt_t *, const void *, size_t, uintptr_t); 156 extern ssize_t mdb_tgt_pread(mdb_tgt_t *, void *, size_t, physaddr_t); 157 extern ssize_t mdb_tgt_pwrite(mdb_tgt_t *, const void *, size_t, physaddr_t); 158 extern ssize_t mdb_tgt_fread(mdb_tgt_t *, void *, size_t, uintptr_t); 159 extern ssize_t mdb_tgt_fwrite(mdb_tgt_t *, const void *, size_t, uintptr_t); 160 extern ssize_t mdb_tgt_ioread(mdb_tgt_t *, void *, size_t, uintptr_t); 161 extern ssize_t mdb_tgt_iowrite(mdb_tgt_t *, const void *, size_t, uintptr_t); 162 163 /* 164 * Convert an address-space's virtual address to the corresponding 165 * physical address (only useful for kernel targets): 166 */ 167 extern int mdb_tgt_vtop(mdb_tgt_t *, mdb_tgt_as_t, uintptr_t, physaddr_t *); 168 169 /* 170 * Convenience functions for reading and writing null-terminated 171 * strings from any of the target address spaces: 172 */ 173 extern ssize_t mdb_tgt_readstr(mdb_tgt_t *, mdb_tgt_as_t, 174 char *, size_t, mdb_tgt_addr_t); 175 176 extern ssize_t mdb_tgt_writestr(mdb_tgt_t *, mdb_tgt_as_t, 177 const char *, mdb_tgt_addr_t); 178 179 /* 180 * Symbol Table Interface 181 * 182 * Each target can provide access to one or more symbol tables, which can be 183 * iterated over, or used to lookup symbols by either name or address. The 184 * target can support a primary executable and primary dynamic symbol table, 185 * a symbol table for its run-time link-editor, and symbol tables for one or 186 * more loaded objects. A symbol is uniquely identified by an object name, 187 * a symbol table id, and a symbol id. Symbols can be discovered by iterating 188 * over them, looking them up by name, or looking them up by address. 189 */ 190 191 typedef struct mdb_syminfo { 192 uint_t sym_table; /* Symbol table id (see symbol_iter, below) */ 193 uint_t sym_id; /* Symbol identifier */ 194 } mdb_syminfo_t; 195 196 /* 197 * Reserved object names for mdb_tgt_lookup_by_name(): 198 */ 199 #define MDB_TGT_OBJ_EXEC ((const char *)0L) /* Executable symbols */ 200 #define MDB_TGT_OBJ_RTLD ((const char *)1L) /* Ldso/krtld symbols */ 201 #define MDB_TGT_OBJ_EVERY ((const char *)-1L) /* All known symbols */ 202 203 extern int mdb_tgt_lookup_by_scope(mdb_tgt_t *, const char *, 204 GElf_Sym *, mdb_syminfo_t *); 205 206 extern int mdb_tgt_lookup_by_name(mdb_tgt_t *, const char *, 207 const char *, GElf_Sym *, mdb_syminfo_t *); 208 209 /* 210 * Flag bit passed to mdb_tgt_lookup_by_addr(): 211 */ 212 #define MDB_TGT_SYM_FUZZY 0 /* Match closest address */ 213 #define MDB_TGT_SYM_EXACT 1 /* Match exact address only */ 214 215 #define MDB_TGT_SYM_NAMLEN 1024 /* Recommended max symbol name length */ 216 217 extern int mdb_tgt_lookup_by_addr(mdb_tgt_t *, uintptr_t, uint_t, 218 char *, size_t, GElf_Sym *, mdb_syminfo_t *); 219 220 /* 221 * Callback function prototype for mdb_tgt_symbol_iter(): 222 */ 223 typedef int mdb_tgt_sym_f(void *, const GElf_Sym *, const char *, 224 const mdb_syminfo_t *sip, const char *); 225 226 /* 227 * Values for selecting symbol tables with mdb_tgt_symbol_iter(): 228 */ 229 #define MDB_TGT_PRVSYM 0 /* User's private symbol table */ 230 #define MDB_TGT_SYMTAB 1 /* Normal symbol table (.symtab) */ 231 #define MDB_TGT_DYNSYM 2 /* Dynamic symbol table (.dynsym) */ 232 233 /* 234 * Values for selecting symbols of interest by binding and type. These flags 235 * can be used to construct a bitmask to pass to mdb_tgt_symbol_iter(): 236 */ 237 #define MDB_TGT_BIND_LOCAL 0x0001 /* Local (static-scope) symbols */ 238 #define MDB_TGT_BIND_GLOBAL 0x0002 /* Global symbols */ 239 #define MDB_TGT_BIND_WEAK 0x0004 /* Weak binding symbols */ 240 241 #define MDB_TGT_BIND_ANY 0x0007 /* Any of the above */ 242 243 #define MDB_TGT_TYPE_NOTYPE 0x0100 /* Symbol has no type */ 244 #define MDB_TGT_TYPE_OBJECT 0x0200 /* Symbol refers to data */ 245 #define MDB_TGT_TYPE_FUNC 0x0400 /* Symbol refers to text */ 246 #define MDB_TGT_TYPE_SECT 0x0800 /* Symbol refers to a section */ 247 #define MDB_TGT_TYPE_FILE 0x1000 /* Symbol refers to a source file */ 248 #define MDB_TGT_TYPE_COMMON 0x2000 /* Symbol refers to a common block */ 249 #define MDB_TGT_TYPE_TLS 0x4000 /* Symbol refers to TLS */ 250 251 #define MDB_TGT_TYPE_ANY 0x7f00 /* Any of the above */ 252 253 extern int mdb_tgt_symbol_iter(mdb_tgt_t *, const char *, uint_t, uint_t, 254 mdb_tgt_sym_f *, void *); 255 256 /* 257 * Convenience functions for reading and writing at the address specified 258 * by a given object file and symbol name: 259 */ 260 extern ssize_t mdb_tgt_readsym(mdb_tgt_t *, mdb_tgt_as_t, void *, size_t, 261 const char *, const char *); 262 263 extern ssize_t mdb_tgt_writesym(mdb_tgt_t *, mdb_tgt_as_t, const void *, size_t, 264 const char *, const char *); 265 266 /* 267 * Virtual Address Mapping and Load Object interface 268 * 269 * These interfaces allow the caller to iterate over the various virtual 270 * address space mappings, or only those mappings corresponding to load objects. 271 * The mapping name (MDB_TGT_MAPSZ) is defined to be large enough for a string 272 * of length MAXPATHLEN, plus space for "LM`<lmid>" where lmid is a hex number. 273 */ 274 275 #define MDB_TGT_MAPSZ 1048 /* Maximum length of mapping name */ 276 277 #define MDB_TGT_MAP_R 0x01 /* Mapping is readable */ 278 #define MDB_TGT_MAP_W 0x02 /* Mapping is writeable */ 279 #define MDB_TGT_MAP_X 0x04 /* Mapping is executable */ 280 #define MDB_TGT_MAP_SHMEM 0x08 /* Mapping is shared memory */ 281 #define MDB_TGT_MAP_STACK 0x10 /* Mapping is a stack of some kind */ 282 #define MDB_TGT_MAP_HEAP 0x20 /* Mapping is a heap of some kind */ 283 #define MDB_TGT_MAP_ANON 0x40 /* Mapping is anonymous memory */ 284 285 typedef struct mdb_map { 286 char map_name[MDB_TGT_MAPSZ]; /* Name of mapped object */ 287 uintptr_t map_base; /* Virtual address of base of mapping */ 288 size_t map_size; /* Size of mapping in bytes */ 289 uint_t map_flags; /* Flags (see above) */ 290 } mdb_map_t; 291 292 typedef int mdb_tgt_map_f(void *, const mdb_map_t *, const char *); 293 294 extern int mdb_tgt_mapping_iter(mdb_tgt_t *, mdb_tgt_map_f *, void *); 295 extern int mdb_tgt_object_iter(mdb_tgt_t *, mdb_tgt_map_f *, void *); 296 297 extern const mdb_map_t *mdb_tgt_addr_to_map(mdb_tgt_t *, uintptr_t); 298 extern const mdb_map_t *mdb_tgt_name_to_map(mdb_tgt_t *, const char *); 299 300 extern struct ctf_file *mdb_tgt_addr_to_ctf(mdb_tgt_t *, uintptr_t); 301 extern struct ctf_file *mdb_tgt_name_to_ctf(mdb_tgt_t *, const char *); 302 303 /* 304 * Execution Control Interface 305 * 306 * For in-situ debugging, we provide a relatively simple interface for target 307 * execution control. The target can be continued, or the representative 308 * thread of control can be single-stepped. Once the target has stopped, the 309 * status of the representative thread is returned (this status can also be 310 * obtained using mdb_tgt_status()). Upon continue, the target's internal list 311 * of software event specifiers determines what types of events will cause the 312 * target to stop and transfer control back to the debugger. The target 313 * allows any number of virtual event specifiers to be registered, along with 314 * an associated callback. These virtual specifiers are layered on top of 315 * underlying software event specifiers that are private to the target. The 316 * virtual event specifier list can be manipulated by the functions described 317 * below. We currently support the following types of traced events: 318 * breakpoints, watchpoints, system call entry, system call exit, signals, 319 * and machine faults. 320 */ 321 322 typedef uintptr_t mdb_tgt_tid_t; /* Opaque thread identifier */ 323 324 typedef struct mdb_tgt_status { 325 mdb_tgt_tid_t st_tid; /* Id of thread in question */ 326 uintptr_t st_pc; /* Program counter, if stopped */ 327 uint_t st_state; /* Program state (see below) */ 328 uint_t st_flags; /* Status flags (see below) */ 329 } mdb_tgt_status_t; 330 331 /* 332 * Program state (st_state): 333 * (MDB_STATE_* definitions in the module API need to be in sync with these) 334 */ 335 #define MDB_TGT_IDLE 0 /* Target is idle (not running yet) */ 336 #define MDB_TGT_RUNNING 1 /* Target is currently executing */ 337 #define MDB_TGT_STOPPED 2 /* Target is stopped */ 338 #define MDB_TGT_UNDEAD 3 /* Target is undead (zombie) */ 339 #define MDB_TGT_DEAD 4 /* Target is dead (core dump) */ 340 #define MDB_TGT_LOST 5 /* Target lost by debugger */ 341 342 /* 343 * Status flags (st_flags): 344 */ 345 #define MDB_TGT_ISTOP 0x1 /* Stop on event of interest */ 346 #define MDB_TGT_DSTOP 0x2 /* Stop directive is pending */ 347 #define MDB_TGT_BUSY 0x4 /* Busy in debugger */ 348 349 extern int mdb_tgt_status(mdb_tgt_t *, mdb_tgt_status_t *); 350 extern int mdb_tgt_run(mdb_tgt_t *, int, const struct mdb_arg *); 351 extern int mdb_tgt_step(mdb_tgt_t *, mdb_tgt_status_t *); 352 extern int mdb_tgt_step_out(mdb_tgt_t *, mdb_tgt_status_t *); 353 extern int mdb_tgt_step_branch(mdb_tgt_t *, mdb_tgt_status_t *); 354 extern int mdb_tgt_next(mdb_tgt_t *, mdb_tgt_status_t *); 355 extern int mdb_tgt_continue(mdb_tgt_t *, mdb_tgt_status_t *); 356 extern int mdb_tgt_signal(mdb_tgt_t *, int); 357 358 /* 359 * Iterating through the specifier list yields the integer id (VID) and private 360 * data pointer for each specifier. 361 */ 362 typedef int mdb_tgt_vespec_f(mdb_tgt_t *, void *, int, void *); 363 364 /* 365 * Each event specifier is defined to be in one of the following states. The 366 * state transitions are discussed in detail in the comments in mdb_target.c. 367 */ 368 #define MDB_TGT_SPEC_IDLE 1 /* Inactive (e.g. object not loaded) */ 369 #define MDB_TGT_SPEC_ACTIVE 2 /* Active but not armed in target */ 370 #define MDB_TGT_SPEC_ARMED 3 /* Active and armed (e.g. bkpt set) */ 371 #define MDB_TGT_SPEC_ERROR 4 /* Failed to arm event */ 372 373 /* 374 * Event specifiers may also have one or more of the following additional 375 * properties (spec_flags bits): 376 */ 377 #define MDB_TGT_SPEC_INTERNAL 0x0001 /* Internal to target implementation */ 378 #define MDB_TGT_SPEC_SILENT 0x0002 /* Do not describe when matched */ 379 #define MDB_TGT_SPEC_TEMPORARY 0x0004 /* Delete next time target stops */ 380 #define MDB_TGT_SPEC_MATCHED 0x0008 /* Specifier matched at last stop */ 381 #define MDB_TGT_SPEC_DISABLED 0x0010 /* Specifier cannot be armed */ 382 #define MDB_TGT_SPEC_DELETED 0x0020 /* Specifier has been deleted */ 383 #define MDB_TGT_SPEC_AUTODEL 0x0040 /* Delete when match limit reached */ 384 #define MDB_TGT_SPEC_AUTODIS 0x0080 /* Disable when match limit reached */ 385 #define MDB_TGT_SPEC_AUTOSTOP 0x0100 /* Stop when match limit reached */ 386 #define MDB_TGT_SPEC_STICKY 0x0200 /* Do not delete as part of :z */ 387 388 #define MDB_TGT_SPEC_HIDDEN (MDB_TGT_SPEC_INTERNAL | MDB_TGT_SPEC_SILENT) 389 390 typedef struct mdb_tgt_spec_desc { 391 int spec_id; /* Event specifier id (VID) */ 392 uint_t spec_flags; /* Flags (see above) */ 393 uint_t spec_hits; /* Count of number of times matched */ 394 uint_t spec_limit; /* Limit on number of times matched */ 395 int spec_state; /* State (see above) */ 396 int spec_errno; /* Last error code (if IDLE or ERROR) */ 397 uintptr_t spec_base; /* Start of affected memory region */ 398 size_t spec_size; /* Size of affected memory region */ 399 void *spec_data; /* Callback private data */ 400 } mdb_tgt_spec_desc_t; 401 402 /* 403 * The target provides functions to convert a VID into the private data pointer, 404 * or a complete description of the event specifier and its state. 405 */ 406 extern void *mdb_tgt_vespec_data(mdb_tgt_t *, int); 407 extern char *mdb_tgt_vespec_info(mdb_tgt_t *, int, 408 mdb_tgt_spec_desc_t *, char *, size_t); 409 410 /* 411 * The common target layer provides functions to iterate over the list of 412 * registered event specifiers, modify or disable them, and delete them. 413 */ 414 extern int mdb_tgt_vespec_iter(mdb_tgt_t *, mdb_tgt_vespec_f *, void *); 415 extern int mdb_tgt_vespec_modify(mdb_tgt_t *, int, uint_t, uint_t, void *); 416 extern int mdb_tgt_vespec_enable(mdb_tgt_t *, int); 417 extern int mdb_tgt_vespec_disable(mdb_tgt_t *, int); 418 extern int mdb_tgt_vespec_delete(mdb_tgt_t *, int); 419 420 /* 421 * The mdb_tgt_add_* functions are used to add software event specifiers to the 422 * target. The caller provides a bitmask of flags (spec_flags above), callback 423 * function pointer, and callback data as arguments. Whenever a matching event 424 * is detected, a software event callback function is invoked. The callback 425 * receives a pointer to the target, the VID of the corresponding event 426 * specifier, and a private data pointer as arguments. If no callback is 427 * desired, the caller can specify a pointer to the no_se_f default callback. 428 * Unlike other target layer functions, the mdb_tgt_add_* interfaces return the 429 * VID of the new event (which may be positive or negative), or 0 if the new 430 * event could not be created. 431 */ 432 typedef void mdb_tgt_se_f(mdb_tgt_t *, int, void *); 433 extern void no_se_f(mdb_tgt_t *, int, void *); 434 435 /* 436 * Breakpoints can be set at a specified virtual address or using MDB's 437 * symbol notation: 438 */ 439 extern int mdb_tgt_add_vbrkpt(mdb_tgt_t *, uintptr_t, 440 int, mdb_tgt_se_f *, void *); 441 442 extern int mdb_tgt_add_sbrkpt(mdb_tgt_t *, const char *, 443 int, mdb_tgt_se_f *, void *); 444 445 /* 446 * Watchpoints can be set at physical, virtual, or I/O port addresses for any 447 * combination of read, write, or execute operations. 448 */ 449 #define MDB_TGT_WA_R 0x1 /* Read watchpoint */ 450 #define MDB_TGT_WA_W 0x2 /* Write watchpoint */ 451 #define MDB_TGT_WA_X 0x4 /* Execute watchpoint */ 452 453 #define MDB_TGT_WA_RWX (MDB_TGT_WA_R | MDB_TGT_WA_W | MDB_TGT_WA_X) 454 455 extern int mdb_tgt_add_pwapt(mdb_tgt_t *, physaddr_t, size_t, uint_t, 456 int, mdb_tgt_se_f *, void *); 457 458 extern int mdb_tgt_add_vwapt(mdb_tgt_t *, uintptr_t, size_t, uint_t, 459 int, mdb_tgt_se_f *, void *); 460 461 extern int mdb_tgt_add_iowapt(mdb_tgt_t *, uintptr_t, size_t, uint_t, 462 int, mdb_tgt_se_f *, void *); 463 464 /* 465 * For user process debugging, tracepoints can be set on entry or exit from 466 * a system call, or on receipt of a software signal or fault. 467 */ 468 extern int mdb_tgt_add_sysenter(mdb_tgt_t *, int, int, mdb_tgt_se_f *, void *); 469 extern int mdb_tgt_add_sysexit(mdb_tgt_t *, int, int, mdb_tgt_se_f *, void *); 470 extern int mdb_tgt_add_signal(mdb_tgt_t *, int, int, mdb_tgt_se_f *, void *); 471 extern int mdb_tgt_add_fault(mdb_tgt_t *, int, int, mdb_tgt_se_f *, void *); 472 473 /* 474 * Machine Register Interface 475 * 476 * The machine registers for a given thread can be manipulated using the 477 * getareg and putareg interface; the caller must know the naming convention 478 * for registers for the given target architecture. For the purposes of 479 * this interface, we declare the register container to be the largest 480 * current integer container. 481 */ 482 483 typedef uint64_t mdb_tgt_reg_t; 484 485 extern int mdb_tgt_getareg(mdb_tgt_t *, mdb_tgt_tid_t, 486 const char *, mdb_tgt_reg_t *); 487 488 extern int mdb_tgt_putareg(mdb_tgt_t *, mdb_tgt_tid_t, 489 const char *, mdb_tgt_reg_t); 490 491 /* 492 * Stack Interface 493 * 494 * The target stack interface provides the ability to iterate backward through 495 * the frames of an execution stack. For the purposes of this interface, the 496 * mdb_tgt_gregset (general purpose register set) is an opaque type: there must 497 * be an implicit contract between the target implementation and any debugger 498 * modules that must interpret the contents of this structure. The callback 499 * function is provided with the only elements of a stack frame which we can 500 * reasonably abstract: the virtual address corresponding to a program counter 501 * value, and an array of arguments passed to the function call represented by 502 * this frame. The rest of the frame is presumed to be contained within the 503 * mdb_tgt_gregset_t, and is architecture-specific. 504 */ 505 506 typedef struct mdb_tgt_gregset mdb_tgt_gregset_t; 507 508 typedef int mdb_tgt_stack_f(void *, uintptr_t, uint_t, const long *, 509 const mdb_tgt_gregset_t *); 510 typedef int mdb_tgt_stack_iter_f(mdb_tgt_t *, const mdb_tgt_gregset_t *, 511 mdb_tgt_stack_f *, void *); 512 513 extern mdb_tgt_stack_iter_f mdb_tgt_stack_iter; 514 515 /* 516 * External Data Interface 517 * 518 * The external data interface provides each target with the ability to export 519 * a set of named buffers that contain data which is associated with the 520 * target, but is somehow not accessible through one of its address spaces and 521 * does not correspond to a machine register. A process credential is an 522 * example of such a buffer: the credential is associated with the given 523 * process, but is stored in the kernel (not the process's address space) and 524 * thus is not accessible through any other target interface. Since it is 525 * exported via /proc, the user process target can export this information as a 526 * named buffer for target-specific dcmds to consume. 527 */ 528 529 typedef int mdb_tgt_xdata_f(void *, const char *, const char *, size_t); 530 531 extern int mdb_tgt_xdata_iter(mdb_tgt_t *, mdb_tgt_xdata_f *, void *); 532 extern ssize_t mdb_tgt_getxdata(mdb_tgt_t *, const char *, void *, size_t); 533 534 #ifdef __cplusplus 535 } 536 #endif 537 538 #endif /* _MDB_TARGET_H */ 539