4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2013 by Delphix. All rights reserved.
25 * Copyright (c) 2012 Joyent, Inc. All rights reserved.
26 */
27
28 #ifndef _MDB_MODAPI_H
29 #define _MDB_MODAPI_H
30
31 /*
32 * MDB Module API
33 *
34 * The debugger provides a set of interfaces for use in writing loadable
35 * debugger modules. Modules that call functions not listed in this header
36 * file may not be compatible with future versions of the debugger.
37 */
38
39 #include <sys/types.h>
40 #include <sys/null.h>
41 #include <gelf.h>
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
49 * so module writers can depend on these macros and defines.
50 * Make sure NULL is available to module writers by including <sys/null.h>.
51 */
52
53 #ifndef TRUE
54 #define TRUE 1
55 #endif
56
57 #ifndef FALSE
58 #define FALSE 0
59 #endif
60
61 #ifndef MIN
62 #define MIN(x, y) ((x) < (y) ? (x) : (y))
63 #endif
64
65 #ifndef MAX
66 #define MAX(x, y) ((x) > (y) ? (x) : (y))
67 #endif
68
69 #define MDB_API_VERSION 4 /* Current API version number */
70
71 /*
72 * Debugger command function flags:
73 */
74 #define DCMD_ADDRSPEC 0x01 /* Dcmd invoked with explicit address */
75 #define DCMD_LOOP 0x02 /* Dcmd invoked in loop with ,cnt syntax */
76 #define DCMD_LOOPFIRST 0x04 /* Dcmd invoked as first iteration of LOOP */
77 #define DCMD_PIPE 0x08 /* Dcmd invoked with input from pipe */
78 #define DCMD_PIPE_OUT 0x10 /* Dcmd invoked with output set to pipe */
79
80 #define DCMD_HDRSPEC(fl) (((fl) & DCMD_LOOPFIRST) || !((fl) & DCMD_LOOP))
81
82 /*
83 * Debugger tab command function flags
84 */
85 #define DCMD_TAB_SPACE 0x01 /* Tab cb invoked with trailing space */
86
87 /*
88 * Debugger command function return values:
89 */
90 #define DCMD_OK 0 /* Dcmd completed successfully */
91 #define DCMD_ERR 1 /* Dcmd failed due to an error */
92 #define DCMD_USAGE 2 /* Dcmd usage error; abort and print usage */
93 #define DCMD_NEXT 3 /* Invoke next dcmd in precedence list */
94 #define DCMD_ABORT 4 /* Dcmd failed; abort current loop or pipe */
95
96 #define OFFSETOF(s, m) (size_t)(&(((s *)0)->m))
97
98 extern int mdb_prop_postmortem; /* Are we looking at a static dump? */
99 extern int mdb_prop_kernel; /* Are we looking at a kernel? */
100
101 typedef enum {
102 MDB_TYPE_STRING, /* a_un.a_str is valid */
103 MDB_TYPE_IMMEDIATE, /* a_un.a_val is valid */
104 MDB_TYPE_CHAR /* a_un.a_char is valid */
105 } mdb_type_t;
106
107 typedef struct mdb_arg {
108 mdb_type_t a_type;
109 union {
110 const char *a_str;
111 uintmax_t a_val;
112 char a_char;
113 } a_un;
114 } mdb_arg_t;
115
116 typedef struct mdb_tab_cookie mdb_tab_cookie_t;
117 typedef int mdb_dcmd_f(uintptr_t, uint_t, int, const mdb_arg_t *);
118 typedef int mdb_dcmd_tab_f(mdb_tab_cookie_t *, uint_t, int,
119 const mdb_arg_t *);
120
121 typedef struct mdb_dcmd {
122 const char *dc_name; /* Command name */
123 const char *dc_usage; /* Usage message (optional) */
124 const char *dc_descr; /* Description */
125 mdb_dcmd_f *dc_funcp; /* Command function */
126 void (*dc_help)(void); /* Command help function (or NULL) */
127 mdb_dcmd_tab_f *dc_tabp; /* Tab completion function */
128 } mdb_dcmd_t;
129
130 #define WALK_ERR -1 /* Walk fatal error (terminate walk) */
131 #define WALK_NEXT 0 /* Walk should continue to next step */
132 #define WALK_DONE 1 /* Walk is complete (no errors) */
133
134 typedef int (*mdb_walk_cb_t)(uintptr_t, const void *, void *);
135
136 typedef struct mdb_walk_state {
137 mdb_walk_cb_t walk_callback; /* Callback to issue */
138 void *walk_cbdata; /* Callback private data */
139 uintptr_t walk_addr; /* Current address */
140 void *walk_data; /* Walk private data */
141 void *walk_arg; /* Walk private argument */
142 const void *walk_layer; /* Data from underlying layer */
143 } mdb_walk_state_t;
144
145 typedef struct mdb_walker {
146 const char *walk_name; /* Walk type name */
147 const char *walk_descr; /* Walk description */
324 extern int mdb_symbol_iter(const char *, uint_t, uint_t, mdb_symbol_cb_t,
325 void *);
326
327 #define MDB_STATE_IDLE 0 /* Target is idle (not running yet) */
328 #define MDB_STATE_RUNNING 1 /* Target is currently executing */
329 #define MDB_STATE_STOPPED 2 /* Target is stopped */
330 #define MDB_STATE_UNDEAD 3 /* Target is undead (zombie) */
331 #define MDB_STATE_DEAD 4 /* Target is dead (core dump) */
332 #define MDB_STATE_LOST 5 /* Target lost by debugger */
333
334 extern int mdb_get_state(void);
335
336 #define MDB_CALLBACK_STCHG 1
337 #define MDB_CALLBACK_PROMPT 2
338
339 typedef void (*mdb_callback_f)(void *);
340
341 extern void *mdb_callback_add(int, mdb_callback_f, void *);
342 extern void mdb_callback_remove(void *);
343
344 #define MDB_TABC_ALL_TYPES 0x1 /* Include array types in type output */
345 #define MDB_TABC_MEMBERS 0x2 /* Tab comp. types with members */
346 #define MDB_TABC_NOPOINT 0x4 /* Tab comp. everything but pointers */
347 #define MDB_TABC_NOARRAY 0x8 /* Don't include array data in output */
348
349 /*
350 * Module's interaction path
351 */
352 extern void mdb_tab_insert(mdb_tab_cookie_t *, const char *);
353 extern void mdb_tab_setmbase(mdb_tab_cookie_t *, const char *);
354
355 /*
356 * Tab completion utility functions for modules.
357 */
358 extern int mdb_tab_complete_type(mdb_tab_cookie_t *, const char *, uint_t);
359 extern int mdb_tab_complete_member(mdb_tab_cookie_t *, const char *,
360 const char *);
361 extern int mdb_tab_typename(int *, const mdb_arg_t **, char *buf, size_t len);
362
363 /*
364 * Tab completion functions for common signatures.
365 */
366 extern int mdb_tab_complete_mt(mdb_tab_cookie_t *, uint_t, int,
367 const mdb_arg_t *);
368
369 extern size_t strlcat(char *, const char *, size_t);
370 extern char *strcat(char *, const char *);
371 extern char *strcpy(char *, const char *);
372 extern char *strncpy(char *, const char *, size_t);
373
374 /* Need to be consistent with <string.h> C++ definitions */
375 #if __cplusplus >= 199711L
376 extern const char *strchr(const char *, int);
377 #ifndef _STRCHR_INLINE
378 #define _STRCHR_INLINE
379 extern "C++" {
380 inline char *strchr(char *__s, int __c) {
381 return (char *)strchr((const char *)__s, __c);
382 }
383 }
384 #endif /* _STRCHR_INLINE */
385 extern const char *strrchr(const char *, int);
386 #ifndef _STRRCHR_INLINE
387 #define _STRRCHR_INLINE
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2013 Joyent, Inc. All rights reserved.
25 * Copyright (c) 2013 by Delphix. All rights reserved.
26 */
27
28 #ifndef _MDB_MODAPI_H
29 #define _MDB_MODAPI_H
30
31 /*
32 * MDB Module API
33 *
34 * The debugger provides a set of interfaces for use in writing loadable
35 * debugger modules. Modules that call functions not listed in this header
36 * file may not be compatible with future versions of the debugger.
37 */
38
39 #include <sys/types.h>
40 #include <sys/null.h>
41 #include <gelf.h>
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
49 * so module writers can depend on these macros and defines.
50 * Make sure NULL is available to module writers by including <sys/null.h>.
51 */
52
53 #ifndef TRUE
54 #define TRUE 1
55 #endif
56
57 #ifndef FALSE
58 #define FALSE 0
59 #endif
60
61 #ifndef MIN
62 #define MIN(x, y) ((x) < (y) ? (x) : (y))
63 #endif
64
65 #ifndef MAX
66 #define MAX(x, y) ((x) > (y) ? (x) : (y))
67 #endif
68
69 #ifdef MDB_API_VERSION
70 #if (MDB_API_VERSION != 3 && MDB_API_VERSION != 4)
71 #error "Only modapi versions three and four are supported."
72 #endif
73 #else /* !MDB_API_VERISON */
74 #define MDB_API_VERSION 4 /* Current API version number */
75 #endif /* MDB_API_VERISON */
76
77 /*
78 * Debugger command function flags:
79 */
80 #define DCMD_ADDRSPEC 0x01 /* Dcmd invoked with explicit address */
81 #define DCMD_LOOP 0x02 /* Dcmd invoked in loop with ,cnt syntax */
82 #define DCMD_LOOPFIRST 0x04 /* Dcmd invoked as first iteration of LOOP */
83 #define DCMD_PIPE 0x08 /* Dcmd invoked with input from pipe */
84 #define DCMD_PIPE_OUT 0x10 /* Dcmd invoked with output set to pipe */
85
86 #define DCMD_HDRSPEC(fl) (((fl) & DCMD_LOOPFIRST) || !((fl) & DCMD_LOOP))
87
88 /*
89 * Debugger command function return values:
90 */
91 #define DCMD_OK 0 /* Dcmd completed successfully */
92 #define DCMD_ERR 1 /* Dcmd failed due to an error */
93 #define DCMD_USAGE 2 /* Dcmd usage error; abort and print usage */
94 #define DCMD_NEXT 3 /* Invoke next dcmd in precedence list */
95 #define DCMD_ABORT 4 /* Dcmd failed; abort current loop or pipe */
96
97 #define OFFSETOF(s, m) (size_t)(&(((s *)0)->m))
98
99 extern int mdb_prop_postmortem; /* Are we looking at a static dump? */
100 extern int mdb_prop_kernel; /* Are we looking at a kernel? */
101
102 typedef enum {
103 MDB_TYPE_STRING, /* a_un.a_str is valid */
104 MDB_TYPE_IMMEDIATE, /* a_un.a_val is valid */
105 MDB_TYPE_CHAR /* a_un.a_char is valid */
106 } mdb_type_t;
107
108 typedef struct mdb_arg {
109 mdb_type_t a_type;
110 union {
111 const char *a_str;
112 uintmax_t a_val;
113 char a_char;
114 } a_un;
115 } mdb_arg_t;
116
117 #if (MDB_API_VERSION >= 4)
118 /*
119 * Debugger tab command function flags
120 */
121 #define DCMD_TAB_SPACE 0x01 /* Tab cb invoked with trailing space */
122
123 typedef struct mdb_tab_cookie mdb_tab_cookie_t;
124 typedef int mdb_dcmd_tab_f(mdb_tab_cookie_t *, uint_t, int,
125 const mdb_arg_t *);
126 #endif /* MDB_API_VERSION >= 4 */
127
128 typedef int mdb_dcmd_f(uintptr_t, uint_t, int, const mdb_arg_t *);
129
130 typedef struct mdb_dcmd {
131 const char *dc_name; /* Command name */
132 const char *dc_usage; /* Usage message (optional) */
133 const char *dc_descr; /* Description */
134 mdb_dcmd_f *dc_funcp; /* Command function */
135 void (*dc_help)(void); /* Command help function (or NULL) */
136 #if (MDB_API_VERSION >= 4)
137 mdb_dcmd_tab_f *dc_tabp; /* Tab completion function */
138 #endif
139 } mdb_dcmd_t;
140
141 #define WALK_ERR -1 /* Walk fatal error (terminate walk) */
142 #define WALK_NEXT 0 /* Walk should continue to next step */
143 #define WALK_DONE 1 /* Walk is complete (no errors) */
144
145 typedef int (*mdb_walk_cb_t)(uintptr_t, const void *, void *);
146
147 typedef struct mdb_walk_state {
148 mdb_walk_cb_t walk_callback; /* Callback to issue */
149 void *walk_cbdata; /* Callback private data */
150 uintptr_t walk_addr; /* Current address */
151 void *walk_data; /* Walk private data */
152 void *walk_arg; /* Walk private argument */
153 const void *walk_layer; /* Data from underlying layer */
154 } mdb_walk_state_t;
155
156 typedef struct mdb_walker {
157 const char *walk_name; /* Walk type name */
158 const char *walk_descr; /* Walk description */
335 extern int mdb_symbol_iter(const char *, uint_t, uint_t, mdb_symbol_cb_t,
336 void *);
337
338 #define MDB_STATE_IDLE 0 /* Target is idle (not running yet) */
339 #define MDB_STATE_RUNNING 1 /* Target is currently executing */
340 #define MDB_STATE_STOPPED 2 /* Target is stopped */
341 #define MDB_STATE_UNDEAD 3 /* Target is undead (zombie) */
342 #define MDB_STATE_DEAD 4 /* Target is dead (core dump) */
343 #define MDB_STATE_LOST 5 /* Target lost by debugger */
344
345 extern int mdb_get_state(void);
346
347 #define MDB_CALLBACK_STCHG 1
348 #define MDB_CALLBACK_PROMPT 2
349
350 typedef void (*mdb_callback_f)(void *);
351
352 extern void *mdb_callback_add(int, mdb_callback_f, void *);
353 extern void mdb_callback_remove(void *);
354
355 #if (MDB_API_VERSION >= 4)
356 #define MDB_TABC_ALL_TYPES 0x1 /* Include array types in type output */
357 #define MDB_TABC_MEMBERS 0x2 /* Tab comp. types with members */
358 #define MDB_TABC_NOPOINT 0x4 /* Tab comp. everything but pointers */
359 #define MDB_TABC_NOARRAY 0x8 /* Don't include array data in output */
360
361 /*
362 * Module's interaction path
363 */
364 extern void mdb_tab_insert(mdb_tab_cookie_t *, const char *);
365 extern void mdb_tab_setmbase(mdb_tab_cookie_t *, const char *);
366
367 /*
368 * Tab completion utility functions for modules.
369 */
370 extern int mdb_tab_complete_type(mdb_tab_cookie_t *, const char *, uint_t);
371 extern int mdb_tab_complete_member(mdb_tab_cookie_t *, const char *,
372 const char *);
373 extern int mdb_tab_typename(int *, const mdb_arg_t **, char *buf, size_t len);
374
375 /*
376 * Tab completion functions for common signatures.
377 */
378 extern int mdb_tab_complete_mt(mdb_tab_cookie_t *, uint_t, int,
379 const mdb_arg_t *);
380 #endif /* MDB_API_VERSION >= 4 */
381
382 extern size_t strlcat(char *, const char *, size_t);
383 extern char *strcat(char *, const char *);
384 extern char *strcpy(char *, const char *);
385 extern char *strncpy(char *, const char *, size_t);
386
387 /* Need to be consistent with <string.h> C++ definitions */
388 #if __cplusplus >= 199711L
389 extern const char *strchr(const char *, int);
390 #ifndef _STRCHR_INLINE
391 #define _STRCHR_INLINE
392 extern "C++" {
393 inline char *strchr(char *__s, int __c) {
394 return (char *)strchr((const char *)__s, __c);
395 }
396 }
397 #endif /* _STRCHR_INLINE */
398 extern const char *strrchr(const char *, int);
399 #ifndef _STRRCHR_INLINE
400 #define _STRRCHR_INLINE
|