1 /* vi:set ts=8 sts=4 sw=4:
2  *
3  * Copyright (C) 2004 Xavier de Gaye.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program (see the file COPYING); if not, write to the
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
19  *
20  * $Id: gdb.h 148 2007-07-21 16:35:40Z xavier $
21  */
22 
23 #ifndef GDB_H
24 # define GDB_H
25 
26 #define obstack_chunk_alloc  malloc
27 #define obstack_chunk_free   free
28 #define obstack_strsave(o,s) (char_u *)obstack_copy0((o), (s), STRLEN((s)))
29 #define obstack_strcat(o,s)			    \
30 ( (s) ? obstack_grow((o), (s), STRLEN((s))) : 0)
31 #define obstack_strcat0(o,s)			    \
32 ( (s)						    \
33   ? obstack_grow0((o), (s), STRLEN((s)))	    \
34   : obstack_grow0((o), "", 0))
35 
36 #define GDB_LVL2_SUPPORT
37 #define GDB_LVL3_SUPPORT
38 /*#define GDB_MI_SUPPORT */
39 
40 /* |+gdb| modes */
41 #define GDB_MODE_LVL2		1   /* CLI with annotations level 2 */
42 #define GDB_MODE_LVL3		2   /* CLI with annotations level 3 and GDB/MI */
43 #define GDB_MODE_MI		3   /* GDB/MI */
44 
45 #if defined(GDB_LVL2_SUPPORT) || defined(GDB_LVL3_SUPPORT)
46 /*
47  * GDB does not send ANO_BP_INVALID annotation when hitting a breakpoint
48  * that has been 'enable once'.
49  * Undefine BP_INVALID_ANO_MISSING after GDB fixes this
50  */
51 # define BP_INVALID_ANO_MISSING
52 #endif
53 
54 #define KEY_INTERUPT	Ctrl_Z	/* interrupt */
55 #define MAX_BUFFSIZE	1024
56 
57 /* The breakpoint info record structure */
58 typedef struct bpinfo_struct bpinfo_T;
59 
60 struct bpinfo_struct
61 {
62     int id;		/* breakpoint number */
63     int typenr;		/* sign type number, for Clewn: sequence sign type number in this buffer */
64 #ifdef BP_INVALID_ANO_MISSING
65     int disposition;	/* TRUE when keep, FALSE when disabled */
66 #endif
67     int enabled;	/* TRUE when enabled */
68     int cont;		/* TRUE when 'commands' includes continue */
69 #ifdef FEAT_GDB
70     buf_T *buf;		/* breakpoint buffer */
71 #else
72     int buf;		/* Clewn buffer number */
73     int typenr_en;	/* enabled breakpoint sequence number */
74     int typenr_dis;	/* disabled breakpoint sequence number */
75 #endif
76     linenr_T lnum;	/* breakpoint line number */
77     bpinfo_T *next;
78 };
79 
80 #if defined(GDB_LVL2_SUPPORT) || defined(GDB_LVL3_SUPPORT)
81 /* Annotation types */
82 # define ANO_NONE		0
83 # define ANO_ANY		1	/* some unrecognized annotation */
84 
85 /* level 2 and level 3 annotations */
86 # define ANO_PREPROMPT		101
87 # define ANO_PROMPT		102
88 # define ANO_POSTPROMPT		103
89 # define ANO_PRECMDS		104
90 # define ANO_CMDS		105
91 # define ANO_PREOVERLOAD	106
92 # define ANO_OVERLOAD		107
93 # define ANO_PREQUERY		108
94 # define ANO_QUERY		109
95 # define ANO_PREPMT_FORMORE	110
96 # define ANO_PMT_FORMORE	111
97 # define ANO_POSTPMT_FORMORE	112
98 # define ANO_QUIT		113
99 # define ANO_ERROR_BEG		114
100 # define ANO_FRAME_INVALID	115
101 # define ANO_BP_INVALID		116
102 # define ANO_STARTING		117
103 # define ANO_STOPPED		118
104 # define ANO_EXITED		119
105 # define ANO_SIGNALLED		120
106 # define ANO_BREAKPOINT		121
107 # define ANO_SOURCE		122
108 
109 # define KEY_KILL	Ctrl_U	/* readline 'unix-line-discard' */
110 # define LPP_LINES	500	/* large output interruption interval */
111 
112 /* Command completion states */
113 # define CS_START	0
114 # define CS_PENDING	1
115 # define CS_CHOICE	2
116 # define CS_DONE	3
117 # define CS_QUERY	4
118 
119 /* The gdb CLI cmd */
120 typedef struct
121 {
122     int state;		/* cmd completion state */
123     int cnt;		/* lines output by gdb since last cmd */
124     char_u *gdb;	/* partial cmd sent to gdb */
125     char_u *readline;	/* gdb readline content */
126     char_u *echoed;	/* echoed cmd */
127 } cli_cmd_T;
128 
129 /* breakpoint states */
130 # define BPS_INVALID	0x0100	/* got "breakpoints-invalid" annotation */
131 # define BPS_BP_HIT	0x0200	/* got "breakpoint" annotation */
132 # define BPS_FR_INVALID 0x0400	/* got "frames-invalid" annotation */
133 # define BPS_BP_SET	0x0800	/* a break type GDB cmd is being processed */
134 # define BPS_RECORD	0x1000	/* parsing a record in the breakpoint table */
135 # define BPS_START	0x2000	/* start of a record */
136 #endif /* defined(GDB_LVL2_SUPPORT) || defined(GDB_LVL3_SUPPORT) */
137 
138 #ifdef GDB_LVL2_SUPPORT
139 /* level 2 annotations */
140 # define ANO_FRAME_BEGIN	201
141 # define ANO_FRAME_END		202
142 # define ANO_BP_HEADER		203
143 # define ANO_BP_TABLE		204
144 # define ANO_BP_RECORD		205
145 # define ANO_BP_FIELD0		206	/* Number */
146 # define ANO_BP_FIELD1		207	/* Type */
147 # define ANO_BP_FIELD2		208	/* Disposition */
148 # define ANO_BP_FIELD3		209	/* Enable */
149 # define ANO_BP_FIELD4		210	/* Address */
150 # define ANO_BP_FIELD5		211	/* What */
151 # define ANO_BP_FIELD6		212	/* Frame */
152 # define ANO_BP_FIELD7		213	/* Condition */
153 # define ANO_BP_FIELD8		214	/* Ignore-count */
154 # define ANO_BP_FIELD9		215	/* Commands */
155 # define ANO_BP_END		216
156 # define ANO_DISP_BEG		217
157 # define ANO_DISP_NUMEND	218
158 # define ANO_DISP_FMT		219
159 # define ANO_DISP_EXP		220
160 # define ANO_DISP_EXPEND	221
161 # define ANO_DISP_VALUE		222	/* not output by GDB */
162 # define ANO_DISP_END		223
163 # define ANO_FIELD_BEG		224
164 # define ANO_FIELD_NAMEND	225
165 # define ANO_FIELD_VALUE	226
166 # define ANO_FIELD_END		227
167 # define ANO_ARRAY_BEG		228
168 # define ANO_ARRAY_ELT		229
169 # define ANO_ARRAY_ELTREP	230
170 # define ANO_ARRAY_ELTEND	231
171 # define ANO_ARRAY_END		232
172 
173 /* breakpoints */
174 # define IS_RECORD(s)		((s) & BPS_RECORD)
175 # define RECORD_INDEX(s)	((s) & 0xff)
176 # define SET_RECORD_IDX(s, i)	(((s) & ~0xff) | (i))
177 
178 /* breakpoint annotation fields indexes */
179 # define BI_NUM		0
180 # define BI_TYPE	1
181 # define BI_DISPO	2
182 # define BI_ENABLE	3
183 # define BI_ADDRESS	4
184 # define BI_WHAT	5
185 # define BI_FRAME	6
186 # define BI_COND	7
187 # define BI_COUNT	8
188 # define BI_CMMDS	9	/* commands */
189 # define BI_FIELDS	10	/* number of bp info annotation fields */
190 
191 /* The display object structure */
192 typedef struct gdbdisp_struct gdbdisp_T;
193 
194 struct gdbdisp_struct
195 {
196     int num;		/* display number */
197     int state;		/* highlighted or/and changed */
198     gdbdisp_T * next;
199 };
200 
201 /* display states */
202 # define DSP_INIT	0
203 # define DSP_STOPPED	1
204 
205 /* The display list structure */
206 typedef struct
207 {
208     int state;
209     gdbdisp_T * list;
210 } displist_T;
211 
212 /* The display entry structure used to store a GDB display output */
213 typedef struct
214 {
215     char_u * num;	/* display item number */
216     char_u * expression;/* display item format and expression */
217     char_u * value;	/* display item value */
218 } doutput_T;
219 
220 /* The lvl2 mode structure: lvl2 specific data */
221 typedef struct
222 {
223     /* breakpoints */
224     char_u *info[BI_FIELDS]; /* breakpoint info record contents */
225 
226     /* variables (display) window */
227     displist_T varlist;	/* list of display items */
228     doutput_T dentry;	/* current GDB display output entry */
229     int doing_value;	/* when TRUE: currently handling a display value */
230     char_u *dispinfostr;/* current line output after "info display" */
231     char_u *dispinfo;	/* all item numbers result of a "info display" */
232 } lvl2_T;
233 #endif /* GDB_LVL2_SUPPORT */
234 
235 #ifdef GDB_LVL3_SUPPORT
236 /* The variable object structure */
237 typedef struct varobj_struct varobj_T;
238 
239 /* varobj states */
240 #define VS_INIT	    0x01    /* object creation */
241 #define VS_ERROR    0x02    /* a command on this object produced an error */
242 
243 struct varobj_struct
244 {
245     int state;
246     char_u *name;	/* variable name ("NNN" in "varNNN") */
247     int children;	/* TRUE when has children */
248     char_u *format;	/* print format is "/[tdxo]"*/
249     char_u *expression;	/* variable expression */
250     varobj_T * next;
251 };
252 
253 /* GDB/MI var commands */
254 # define VCMD_INIT	0
255 # define VCMD_CREATE	1
256 # define VCMD_DELETE	2
257 # define VCMD_CHILDREN	3
258 # define VCMD_UPDATE	4
259 # define VCMD_PRINT	5
260 # define VCMD_EVALUATE	6
261 # define VCMD_FORMAT	7
262 
263 /* The lvl3 mode structure: lvl3 specific data */
264 typedef struct
265 {
266     char_u *result;	/* result of a GDB/MI command */
267 
268     int get_source_list;
269     char_u *source_cur;	/* result of -file-list-exec-source-file */
270     char_u *source_list;/* result of -file-list-exec-source-files */
271 
272     /* variables window */
273     varobj_T *varlist;	/* list of variable objects */
274     varobj_T *varitem;  /* current object in varlist */
275     int varcmd;		/* GDB/MI var cmd being processed */
276     int varnext_cmd;	/* GDB/MI var next cmd to process */
277 } lvl3_T;
278 #endif /* GDB_LVL3_SUPPORT */
279 
280 /* Command types */
281 #define CMD_ANY		0
282 #ifdef FEAT_GDB
283 # define CMD_DIR	1
284 #endif
285 #define CMD_DETACH	2
286 #define CMD_SHELL	3
287 #define CMD_STEPI	4	/* instruction stepping cmds */
288 #define CMD_EXECF	5	/* invalidating asm buffers cmds */
289 #define CMD_BREAK	6
290 #define CMD_DISPLAY	7
291 #define CMD_CREATEVAR	8
292 #define CMD_UP		9
293 #define CMD_DOWN	10
294 #define CMD_FRAME	11
295 #define CMD_DISABLE	12
296 #define CMD_DELETE	13
297 #define CMD_UP_SILENT	14
298 #define CMD_DOWN_SILENT	15
299 #define CMD_SLECT_FRAME 16
300 #define CMD_SYMF	17
301 #define CMD_RESTART	18
302 #define CMD_QUIT	19
303 
304 #define ASM_MAX_BUFF	64	    /* asm buffers pool size */
305 #define ASM_BUF_NAME	"gdb-asm-"  /* asm buffer name prefix */
306 #define ASM_OLD	(char_u)(~0U)	    /* asm buffer max age */
307 
308 /* The assembly buffer pool */
309 typedef struct
310 {
311 #ifdef FEAT_GDB
312     int max;			/* buffers in use */
313     int idx;			/* current buffer */
314     buf_T * buf[ASM_MAX_BUFF];	/* asm buffers */
315     char_u age[ASM_MAX_BUFF];	/* buffer's age */
316     int last;			/* used for generating unique asm names */
317 #else
318     int buf;			/* number of the asm buffer being disassembled */
319     FILE *fd;			/* stream descriptor of asm file being written to */
320     char_u *name;		/* file name of the function being disassembled */
321     long line_offset;		/* offset of start of last line in file */
322 #endif
323     linenr_T lnum;		/* highlited line number */
324     int hilite;			/* TRUE when $pc in asm is highlited */
325 } asm_T;
326 
327 /* The gdb structure */
328 typedef struct gdb_struct gdb_T;
329 
330 /* Out of band states */
331 #define OS_CMD    0x01		/* a cmd is being processed */
332 #define OS_INTR   0x02		/* interrupt sent to gdb */
333 #define OS_QUIT   0x04		/* 'quit' annotation received */
334 
335 /* Out of Band */
336 #define OOB_CMD		0
337 #define OOB_COLLECT	1
338 #define OOB_COMPLETE	2
339 #define IS_OOBACTIVE(t) (((t)->oob.idx) >= 0)
340 
341 /* The out of band process */
342 typedef struct
343 {
344     int state;			/* oob state */
345     int idx;			/* current function index */
346     int cnt;			/* asm output lines count */
347 } oob_T;
348 
349 /*
350  * oobfunc_T function:
351  *
352  * When an oobfunc_T[] array is processed by gdb_oob_send() and
353  * gdb_oob_receive(), each oob function in the array is called with
354  * successive state values of:
355  *
356  * OOB_CMD:	called at each 'prompt'; should return the GDB cmd
357  *		to send to GDB or NULL when no command must be sent;
358  *		in this case the next oob function in the oobfunc_T[]
359  *		array is processed next with OOB_CMD
360  *
361  * OOB_COLLECT:	oob may process chunk, a (possibly partial) line from GDB
362  *		result of GDB command; may be invoked more than once, or not at all
363  *
364  * OOB_COMPLETE:indicates end of GDB output; oob may do any final processing;
365  *		if oob returns a non NULL value, the same oob function is
366  *		called once again with OOB_CMD and the same cycle starts again;
367  *		if oob returns a NULL value, the next oob function in the
368  *		oobfunc_T[] array is processed with OOB_CMD
369  *
370  * Return:	NULL, except when state is OOB_CMD or OOB_COMPLETE
371  */
372 
373 typedef struct {
374     char * (*oob)(gdb_T *, int state, char_u *chunk, struct obstack *);
375 } oobfunc_T;
376 
377 /* gdb states */
378 #define GDB_STATE(i,s) (((i) != NULL) ? ((((gdb_T *)(i))->state) & (s)):FALSE)
379 #define GS_INIT	    0		/* initial state */
380 #define GS_CLOSING  0x001	/* gdb process closing */
381 #define GS_UP	    0x002	/* gdb up and running */
382 #define GS_STARTED  0x004	/* gdb just started */
383 #define GS_ALLOWED  0x008	/* select on pty is allowed */
384 #define GS_EVENT    0x010	/* got SIGCHLD or gdb output some data */
385 #define GS_SIGCHLD  0x020	/* got SIGCHLD from gdb */
386 #define GS_STOPPED  0x040	/* debuggee is stopped */
387 #define GS_ANO	    0x080	/* parsing an annotation table or list */
388 #define GS_QUITTING 0x100	/* quitting clewn */
389 
390 /* parser states */
391 #define PS_ANY		0
392 #define PS_PREPROMPT	1	/* before the prompt, after any output from GDB */
393 #define PS_PROMPT	2	/* after prompt, but before user input */
394 
395 /* project file sourced states */
396 #define PROJ_INIT	0
397 #define PROJ_SOURCEIT	1
398 #define PROJ_DONE	2
399 
400 /* The gdb structure */
401 struct gdb_struct
402 {
403     /* process */
404     int instance;	/* gdb instance number */
405     int fd;		/* pty file descriptor */
406     pid_t pid;		/* process id */
407 #if defined(GDB_LVL2_SUPPORT) || defined(GDB_LVL3_SUPPORT)
408     int height;		/* pseudo tty height, non zero when ioctl set */
409     int intr_sent;	/* hack: an interrupt has been sent by the user */
410 #endif
411     int state;		/* gdb state */
412     char_u *status;	/* gdb status */
413     int recurse;	/* disable GS_ALLOWED when calling safe_vgetc */
414 
415     /* cmds */
416     int cmd_type;	/* cmd type */
417 #if defined(GDB_LVL2_SUPPORT) || defined(GDB_LVL3_SUPPORT)
418     cli_cmd_T cli_cmd;	/* current CLI cmd (common to lvl2 and lvl3) */
419 #endif
420     char_u *firstcmd;	/* first cmd in new GDB session */
421     int parser;		/* parser states */
422     int syntax;		/* when TRUE, enable syntax highlighting */
423     char_u *line;	/* last incomplete line */
424     char_u *winput_cmd; /* cmd inserted in input-line window */
425     char_u *directories;/* gdb search path for source files */
426 #ifndef FEAT_GDB
427     char_u *prompt;	/* the current GDB prompt */
428     char * version;	/* clewn version */
429     char_u * pwd;	/* current working directory */
430     char_u * args;	/* debugge command line arguments */
431 #endif
432     char_u *sfile;	/* symbol file name */
433 
434 #if defined(GDB_LVL2_SUPPORT) || defined(GDB_LVL3_SUPPORT)
435     /* annotations */
436     int note;		/* annotation type */
437     int annoted;	/* TRUE when parsing an annotation */
438     int newline;	/* pending NL, possibly an annotation first char */
439     int valid_note;	/* last non prompt-for-more annotation type */
440     int prev_note;	/* previous annotation type */
441     char_u *annotation;	/* last incomplete annotation */
442 #endif
443 
444     /* disassembly */
445     asm_T pool;		/* asm buffers pool */
446     char_u *pc;		/* program counter where debuggee is stopped */
447     char_u *frame_pc;	/* current frame program counter */
448     char_u *oob_result;	/* result of oob gdb_get_frame */
449     char_u *asm_add;	/* address whose function must be disassembled */
450     char_u *asm_func;	/* asm function name */
451 
452     /* breakpoints */
453 #if defined(GDB_LVL2_SUPPORT) || defined(GDB_LVL3_SUPPORT)
454     int bp_state;	/* breakpoint annotation state (and index) */
455     bpinfo_T *tmplist;	/* tmp new bp list when reading "info beakpoints" */
456 #endif
457     bpinfo_T *record;	/* current record  */
458     int bufIsChanged;	/* TRUE when curbuf is changed after edit failed */
459     int cont;		/* TRUE when pgm is continuing at this bp */
460     bpinfo_T *bpinfo;	/* breakpoints info table */
461     int frame_curlvl;	/* current frame level */
462     linenr_T frame_lnum;/* current frame line number */
463     char_u * frame_fname;/* current frame file name */
464 
465 #ifdef FEAT_GDB
466     buf_T *buf;		/* gdb buffer */
467     buf_T *fr_buf;	/* frame sign buffer */
468     buf_T *var_buf;	/* variables window buffer */
469 #else /* Clewn implementation */
470     linenr_T lastline;	/* lastline being disassembled */
471     int fr_buf;		/* frame sign buffer number */
472     linenr_T lnum;	/* frame sign line number */
473     int var_buf;	/* variables buffer number */
474     char_u *var_name;	/* variables file name */
475     char_u *balloon_txt;/* text over which is pointed the mouse */
476     char * project_file;/* project file name */
477     int project_state;	/* project file sourced state */
478 #endif
479     oob_T oob;		/* out of band data */
480 
481     /* |+gdb| modes */
482     int mode;		/* current |+gdb| mode */
483 #ifdef GDB_LVL2_SUPPORT
484     lvl2_T lvl2;	/* annotations level 2 */
485 #endif
486 #ifdef GDB_LVL3_SUPPORT
487     lvl3_T lvl3;	/* annotations level 3 and GDB/MI */
488 #endif
489 
490     /* pointers to mode specific functions */
491     oobfunc_T *oobfunc;		    /* the current oob functions array */
492     oobfunc_T *std_oobfunc;	    /* the standard oob functions array */
493     int (*parse_output)(gdb_T *);   /* parser function */
494     void (*gdb_docmd)(gdb_T *, char_u *);/* GDB command input function */
495     void (*var_delete)(gdb_T *);    /* delete all variables function */
496     void (*clear_gdb_T)(gdb_T *);   /* clear mode specific stuff */
497 };
498 
499 /* Regexp patterns */
500 #define PAT_DIR		1
501 #define PAT_CHG_ANNO	2
502 #define PAT_ADD		3
503 #define PAT_PID		4
504 
505 #if defined(GDB_LVL2_SUPPORT) || defined(GDB_LVL3_SUPPORT)
506 # define PAT_SOURCE	101
507 # define PAT_QUERY	102
508 # define PAT_YES	103
509 # define PAT_SFILE	104
510 # define PAT_BP_CONT	105
511 # define PAT_ASM_FUNC	106
512 # define PAT_ASM_FUNC_P	107
513 # define PAT_FRAME	108
514 # define PAT_HEIGHT	109
515 #endif
516 
517 #ifdef GDB_LVL2_SUPPORT
518 # define PAT_BP_ASM	201
519 # define PAT_BP_SOURCE	202
520 # define PAT_DISPLAY	203
521 # define PAT_DISPINFO	204
522 # define PAT_CREATEVAR	205
523 #endif
524 
525 # ifdef GDB_LVL3_SUPPORT
526 # define PAT_CRVAR_FMT	301
527 # define PAT_INFO_FRAME	302
528 #endif
529 
530 /* User interface */
531 #if defined(GDB_LVL2_SUPPORT) || defined(GDB_LVL3_SUPPORT)
532 void gdb_docmd_cli __ARGS((gdb_T *, char_u *));
533 void gdb_send_cmd __ARGS((gdb_T *, char_u *));
534 #endif
535 
536 /* Vim low level hook */
537 #if defined(GDB_LVL2_SUPPORT) || defined(GDB_LVL3_SUPPORT)
538 int gdb_parse_output_cli __ARGS((gdb_T *));
539 #endif
540 
541 /* Gdb process mgmt */
542 void gdb_close __ARGS((gdb_T *));
543 #if defined(GDB_LVL2_SUPPORT) || defined(GDB_LVL3_SUPPORT)
544 int gdb_setup_cli __ARGS((gdb_T *));
545 #endif
546 
547 /* Gdb mode initialization */
548 #ifdef GDB_LVL2_SUPPORT
549 void gdb_lvl2_init __ARGS((gdb_T *));
550 #endif
551 #ifdef GDB_LVL3_SUPPORT
552 void gdb_lvl3_init __ARGS((gdb_T *));
553 #endif
554 
555 /* Sign highliting */
556 #define FRAME_SIGN 1
557 #ifdef FEAT_GDB
558 # define PHANTOM_SIGN 2
559 # define BP_SIGN_ID(n) ((n)+2)	/* reserved sign ids: 1 frame, 2 phantom */
560 void gdb_fr_lite __ARGS((gdb_T *, buf_T *, linenr_T, struct obstack *));
561 int gdb_define_sign __ARGS((int, int));
562 void gdb_undefine_sign __ARGS((int));
563 buf_T * gdb_unlite __ARGS((int));
564 #else
565 # define BP_SIGN_ID(n) ((n)+1)	/* reserved sign id: 1 frame */
566 void gdb_fr_lite __ARGS((gdb_T *, int, linenr_T, struct obstack *));
567 int gdb_define_bpsign __ARGS((bpinfo_T *, struct obstack *));
568 void gdb_unlite __ARGS((int));
569 #endif
570 int gdb_as_frset __ARGS((gdb_T *, struct obstack *));
571 int gdb_fr_set __ARGS((gdb_T *, char_u *, linenr_T *, struct obstack *));
572 void gdb_fr_unlite __ARGS((gdb_T *));
573 
574 /* Window and buffer mgmt */
575 #ifdef FEAT_GDB
576 win_T *gdb_btowin __ARGS((buf_T *));
577 void gdb_as_setname __ARGS((char_u *));
578 void gdb_clear_asmbuf __ARGS((gdb_T *, buf_T *));
579 win_T * gdb_edit_file __ARGS((gdb_T *, buf_T *, char_u *, linenr_T, struct obstack *));
580 void gdb_set_cursor __ARGS((win_T *, linenr_T));
581 void gdb_popup_console __ARGS((gdb_T *));
582 void gdb_redraw __ARGS((buf_T *));
583 #else
584 int gdb_edit_file __ARGS((int, char_u *, linenr_T, int, struct obstack *));
585 #endif
586 void gdb_msg_busy __ARGS((char_u *));
587 void gdb_showBalloon __ARGS((char_u *, struct obstack *));
588 void gdb_status __ARGS((gdb_T *, char_u *, struct obstack *));
589 void gdb_write_buf __ARGS((gdb_T *, char_u *, int));
590 
591 /* Out Of Band */
592 void gdb_oob_send __ARGS((gdb_T *, struct obstack *));
593 void gdb_oob_receive __ARGS((gdb_T *, char_u *, struct obstack *));
594 #if defined(GDB_LVL2_SUPPORT) || defined(GDB_LVL3_SUPPORT)
595 char * gdb_print_value __ARGS((gdb_T *, int, char_u *, struct obstack *));
596 char * gdb_get_pc __ARGS((gdb_T *, int, char_u *, struct obstack *));
597 char * gdb_get_frame __ARGS((gdb_T *, int, char_u *, struct obstack *));
598 char * gdb_info_frame __ARGS((gdb_T *, int, char_u *, struct obstack *));
599 char * gdb_stack_frame __ARGS((gdb_T *, int, char_u *, struct obstack *));
600 char * gdb_get_sfile __ARGS((gdb_T *, int, char_u *, struct obstack *));
601 #ifndef FEAT_GDB
602 char * gdb_source_project __ARGS((gdb_T *, int, char_u *, struct obstack *));
603 char * gdb_get_pwd __ARGS((gdb_T *, int, char_u *, struct obstack *));
604 char * gdb_get_args __ARGS((gdb_T *, int, char_u *, struct obstack *));
605 #endif
606 char * gdb_source_cur __ARGS((gdb_T *, int, char_u *, struct obstack *));
607 char * gdb_source_list __ARGS((gdb_T *, int, char_u *, struct obstack *));
608 char * gdb_get_sourcedir __ARGS((gdb_T *, int, char_u *, struct obstack *));
609 char * gdb_get_asmfunc __ARGS((gdb_T *, int, char_u *, struct obstack *));
610 char * gdb_get_asmfunc_hack __ARGS((gdb_T *, int, char_u *, struct obstack *));
611 char * gdb_get_asm __ARGS((gdb_T *, int, char_u *, struct obstack *));
612 void gdb_process_record __ARGS((gdb_T *, char_u *, char_u *, char_u *, char_u *, struct obstack *));
613 #endif
614 
615 /* Variables window management */
616 #ifdef GDB_LVL2_SUPPORT
617 void gdb_process_display __ARGS((gdb_T *, char_u *, struct obstack *));
618 #endif
619 
620 /* Utilities */
621 #ifndef MIN
622 #define MIN(a,b) (((a)<(b))?(a):(b))
623 #endif
624 #ifndef ABS
625 #define ABS(x) (((x)<0)?(-(x)):(x))
626 #endif
627 #define STRCHR(s,c) (char_u *)strchr((char *)(s),(int)(c))
628 #define STRSTR(h,n) (char_u *)strstr((char *)(h),(char *)(n))
629 #define FREE(p) {xfree((p)); (p) = NULL;}
630 #define IS_ANNOTATION(l) (STRSTR((l),"\032\032") == (l))
631 #define BUFLASTL(b) (!(((b)->b_ml.ml_flags) & ML_EMPTY)?((b)->b_ml.ml_line_count):0)
632 int gdb_read __ARGS((gdb_T *, char_u *, int, int));
633 void gdb_free_bplist __ARGS((bpinfo_T **));
634 void gdb_cmd_type __ARGS((gdb_T *, char_u *));
635 void gdb_cat __ARGS((char_u **, char_u *));
636 char_u * gdb_regexec __ARGS((char_u *, int, int, struct obstack *));
637 char_u * gdb_itoa __ARGS((int));
638 
639 /* Gdb memory leaks mtrace */
640 #if defined(GDB_MTRACE) && defined(HAVE_MTRACE)
641 # include <malloc.h>
642 # include <mcheck.h>
643 /* storage for mtrace hooks */
644 extern __ptr_t (*s_malloc) (size_t, const void *);
645 extern void (*s_free) (void *, const void *);
646 extern __ptr_t (*s_realloc) (void *, size_t, const void *);
647 
648 # define mv_hooks() do {	\
649     s_malloc = __malloc_hook;	\
650     s_free = __free_hook;	\
651     s_realloc = __realloc_hook;	\
652     __malloc_hook = NULL;	\
653     __free_hook = NULL;		\
654     __realloc_hook = NULL;	\
655     } while (0)
656 
657 # define get_hooks() do {	\
658     __malloc_hook = s_malloc;	\
659     __free_hook = s_free;	\
660     __realloc_hook = s_realloc;	\
661     } while (0)
662 
663 /* we do call sometimes vim_free directly and allocation is not mtraced:
664  * when the called Vim function does not free all its allocated memory
665  * after it returns */
666 # define xmalloc(s) ({char_u *mret; get_hooks(); mret=xmalloc((s)); mv_hooks(); mret;})
667 # define xcalloc(s) ({char_u *mret; get_hooks(); mret=xcalloc((s)); mv_hooks(); mret;})
668 # define xrealloc(m,s) ({char_u *mret; get_hooks(); mret=xrealloc((m),(s)); mv_hooks(); mret;})
669 
670 # define xfree(x) do {		\
671     get_hooks();		\
672     xfree((x));			\
673     mv_hooks();			\
674     } while (0)
675 
676 # define clewn_strsave(s) ({char_u *mret; get_hooks(); mret=clewn_strsave((s)); mv_hooks(); mret;})
677 # define clewn_strnsave(s,l) ({char_u *mret; get_hooks(); mret=clewn_strnsave((s),(l)); mv_hooks(); mret;})
678 
679 # define vim_strsave_escaped(s,e) ({char_u *mret; get_hooks(); mret=vim_strsave_escaped((s),(e)); mv_hooks(); mret;})
680 # define vim_regcomp(s,m) ({regprog_T *mret; get_hooks(); mret=vim_regcomp((s),(m)); mv_hooks(); mret;})
681 # define FullName_save(n,f) ({char_u *mret; get_hooks(); mret=FullName_save((n),(f)); mv_hooks(); mret;})
682 # define get_option_value(n,u,s,o) ({int r; get_hooks(); r=get_option_value((n),(u),(s),(o)); mv_hooks(); r;})
683 #endif	/* GDB_MTRACE */
684 #endif	/* GDB_H */
685 
686