aboutsummaryrefslogtreecommitdiff
path: root/src/monkey/gdbmi_connect.c
blob: 7ccae081af7146ad55414b21f47c4e9a63765239 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
/**[txh]********************************************************************

  Copyright (c) 2004-2009 by Salvador E. Tropea.
  Covered by the GPL license.

  Module: Connect.
  Comments:
  This module handles the dialog with gdb, including starting and stopping
gdb.
  @<p>

GDB Bug workaround for "file -readnow": I tried to workaround a bug using
it but looks like this option also have bugs!!!! so I have to use the
command line option --readnow.
It also have a bug!!!! when the binary is changed and gdb must reload it
this option is ignored. So it looks like we have no solution but 3 gdb bugs
in a row.

***************************************************************************/

#include "platform.h"
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <string.h>
#include <stdarg.h>
#include <limits.h>
#include <errno.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/time.h>

#include "gdbmi.h"
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#ifndef TEMP_FAILURE_RETRY
 #define TEMP_FAILURE_RETRY(a) (a)
#endif

int mi_error=MI_OK;
char *mi_error_from_gdb=NULL;
static char *gdb_exe=NULL;
static char *xterm_exe=NULL;
static char *gdb_start=NULL;
static char *gdb_conn=NULL;
static char *main_func=NULL;
static char  disable_psym_search_workaround=0;

mi_h *mi_alloc_h()
{
 mi_h *h=(mi_h *)calloc(1,sizeof(mi_h));
 if (!h)
   {
    mi_error=MI_OUT_OF_MEMORY;
    return NULL;
   }
 h->to_gdb[0]=h->to_gdb[1]=h->from_gdb[0]=h->from_gdb[1]=-1;
 h->pid=-1;
 return h;
}

int mi_check_running_pid(pid_t pid)
{
 int status;

 if (pid<=0)
    return 0;
 /* If waitpid returns the number of our child means it communicated
    to as a termination status. */
 if (waitpid(pid,&status,WNOHANG)==pid)
   {
    pid=0;
    return 0;
   }
 return 1;
}

int mi_check_running(mi_h *h)
{
 return !h->died && mi_check_running_pid(h->pid);
}

void mi_kill_child(pid_t pid)
{
 kill(pid,SIGTERM);
 usleep(100000);
 if (mi_check_running_pid(pid))
   {
    int status;
    kill(pid,SIGKILL);
    waitpid(pid,&status,0);
   }
}

void mi_free_h(mi_h **handle)
{
 mi_h *h=*handle;
 if (h->to_gdb[0]>=0)
    close(h->to_gdb[0]);
 if (h->to)
    fclose(h->to);
 else if (h->to_gdb[1]>=0)
    close(h->to_gdb[1]);
 if (h->from)
    fclose(h->from);
 else if (h->from_gdb[0]>=0)
    close(h->from_gdb[0]);
 if (h->from_gdb[1]>=0)
    close(h->from_gdb[1]);
 if (mi_check_running(h))
   {/* GDB is running! */
    mi_kill_child(h->pid);
   }
 if (h->line)
    free(h->line);
 mi_free_output(h->po);
 free(h->catched_console);
 free(h);
 *handle=NULL;
}

void mi_set_nonblk(int h)
{
 int flf;
 flf=fcntl(h,F_GETFL,0);
 flf=flf | O_NONBLOCK;
 fcntl(h,F_SETFL,flf);
}

int mi_getline(mi_h *h)
{
 char c;

 while (read(h->from_gdb[0],&c,1)==1)
   {
    if (h->lread>=h->llen)
      {
       h->llen=h->lread+128;
       h->line=(char *)realloc(h->line,h->llen);
       if (!h->line)
         {
          h->llen=0;
          h->lread=0;
          return -1;
         }
      }
    if (c=='\n')
      {
       int ret=h->lread;
       h->line[ret]=0;
       h->lread=0;
       return ret;
      }
    h->line[h->lread]=c;
    h->lread++;
   }
 return 0;
}

char *get_cstr(mi_output *o)
{
 if (!o->c || o->c->type!=t_const)
    return NULL;
 return o->c->v.cstr;
}

int mi_get_response(mi_h *h)
{
 int l=mi_getline(h);
 if (!l)
    return 0;

 if (h->from_gdb_echo)
    h->from_gdb_echo(h->line,h->from_gdb_echo_data);
 if (strncmp(h->line,"(gdb)",5)==0)
   {/* End of response. */
    return 1;
   }
 else
   {/* Add to the response. */
    mi_output *o;
    int add=1, is_exit=0;
    o=mi_parse_gdb_output(h->line);

    if (!o)
       return 0;
    /* Tunneled streams callbacks. */
    if (o->type==MI_T_OUT_OF_BAND && o->stype==MI_ST_STREAM)
      {
       char *aux;
       add=0;
       switch (o->sstype)
         {
          case MI_SST_CONSOLE:
               aux=get_cstr(o);
               if (h->console)
                  h->console(aux,h->console_data);
               if (h->catch_console && aux)
                 {
                  h->catch_console--;
                  if (!h->catch_console)
                    {
                     free(h->catched_console);
                     h->catched_console=strdup(aux);
                    }
                 }
               break;
          case MI_SST_TARGET:
               /* This one seems to be useless. */
               if (h->target)
                  h->target(get_cstr(o),h->target_data);
               break;
          case MI_SST_LOG:
               if (h->log)
                  h->log(get_cstr(o),h->log_data);
               break;
         }
      }
    else if (o->type==MI_T_OUT_OF_BAND && o->stype==MI_ST_ASYNC)
      {
       if (h->async)
          h->async(o,h->async_data);
      }
    else if (o->type==MI_T_RESULT_RECORD && o->tclass==MI_CL_ERROR)
      {/* Error from gdb, record it. */
       mi_error=MI_FROM_GDB;
       free(mi_error_from_gdb);
       mi_error_from_gdb=NULL;
       if (o->c && strcmp(o->c->var,"msg")==0 && o->c->type==t_const)
          mi_error_from_gdb=strdup(o->c->v.cstr);
      }
    is_exit=(o->type==MI_T_RESULT_RECORD && o->tclass==MI_CL_EXIT);
    /* Add to the list of responses. */
    if (add)
      {
       if (h->last)
          h->last->next=o;
       else
          h->po=o;
       h->last=o;
      }
    else
       mi_free_output(o);
    /* Exit RR means gdb exited, we won't get a new prompt ;-) */
    if (is_exit)
       return 1;
   }

 return 0;
}

mi_output *mi_retire_response(mi_h *h)
{
 mi_output *ret=h->po;
 h->po=h->last=NULL;
 return ret;
}

mi_output *mi_get_response_blk(mi_h *h)
{
 int r;
 /* Sometimes gdb dies. */
 if (!mi_check_running(h))
   {
    h->died=1;
    mi_error=MI_GDB_DIED;
    return NULL;
   }
 do
   {
   /*
    That's a must. If we just keep trying to read and failing things
    become really sloooowwww. Instead we try and if it fails we wait
    until something is available.
    TODO: Implement something with the time out, a callback to ask the
    application is we have to wait or not could be a good thing.
   */
   fd_set set;
   struct timeval timeout;
   int ret;

   r=mi_get_response(h);
   if (r)
      return mi_retire_response(h);

   FD_ZERO(&set);
   FD_SET(h->from_gdb[0],&set);
   timeout.tv_sec=h->time_out;
   timeout.tv_usec=0;
   ret=TEMP_FAILURE_RETRY(select(FD_SETSIZE,&set,NULL,NULL,&timeout));
   if (!ret)
     {
      if (!mi_check_running(h))
        {
         h->died=1;
         mi_error=MI_GDB_DIED;
         return NULL;
        }
      if (h->time_out_cb)
         ret=h->time_out_cb(h->time_out_cb_data);
      if (!ret)
        {
         mi_error=MI_GDB_TIME_OUT;
         return NULL;
        }
     }
   }
 while (!r);

 return NULL;
}

void mi_send_commands(mi_h *h, const char *file)
{
 FILE *f;
 char b[PATH_MAX];

 //printf("File: %s\n",file);
 if (!file)
    return;
 f=fopen(file,"rt");
 if (!f)
    return;
 while (!feof(f))
   {
    if (fgets(b,PATH_MAX,f))
      {
	//printf("Send: %s\n",b);
	mi_send (h, "%s", b);
	mi_res_simple_done(h);
      }
   }
 fclose(f);
}

void mi_send_target_commands(mi_h *h)
{
 mi_send_commands(h,gdb_conn);
}

/**[txh]********************************************************************

  Description:
  Connect to a local copy of gdb. Note that the mi_h structure is something
similar to a "FILE *" for stdio.
  
  Return: A new mi_h structure or NULL on error.
  
***************************************************************************/

mi_h *mi_connect_local()
{
 mi_h *h;
 const char *gdb=mi_get_gdb_exe();

 /* Start without error. */
 mi_error=MI_OK;
 /* Verify we have a GDB binary. */
 if (access(gdb,X_OK))
   {
    mi_error=MI_MISSING_GDB;
    return NULL;
   }
 /* Alloc the handle structure. */
 h=mi_alloc_h();
 if (!h)
    return h;
 h->time_out=MI_DEFAULT_TIME_OUT;
 /* Create the pipes to connect with the child. */
 if (pipe(h->to_gdb) || pipe(h->from_gdb))
   {
    mi_error=MI_PIPE_CREATE;
    mi_free_h(&h);
    return NULL;
   }
 mi_set_nonblk(h->to_gdb[1]);
 mi_set_nonblk(h->from_gdb[0]);
 /* Associate streams to the file handles. */
 h->to=fdopen(h->to_gdb[1],"w");
 h->from=fdopen(h->from_gdb[0],"r");
 if (!h->to || !h->from)
   {
    mi_error=MI_PIPE_CREATE;
    mi_free_h(&h);
    return NULL;
   }
 /* Create the child. */
 h->pid=fork();
 if (h->pid==0)
   {/* We are the child. */
    char *argv[5];
    /* Connect stdin/out to the pipes. */
    dup2(h->to_gdb[0],STDIN_FILENO);
    dup2(h->from_gdb[1],STDOUT_FILENO);
    /* Pass the control to gdb. */
    argv[0]=(char *)gdb; /* Is that OK? */
    argv[1]="--interpreter=mi";
    argv[2]="--quiet";
    argv[3]=disable_psym_search_workaround ? 0 : "--readnow";
    argv[4]=0;
    execvp(argv[0],argv);
    /* We get here only if exec failed. */
    _exit(127);
   }
 /* We are the parent. */
 if (h->pid==-1)
   {/* Fork failed. */
    mi_error=MI_FORK;
    mi_free_h(&h);
    return NULL;
   }
 if (!mi_check_running(h))
   {
    mi_error=MI_DEBUGGER_RUN;
    mi_free_h(&h);
    return NULL;
   }
 /* Wait for the prompt. */
 mi_get_response_blk(h);
 /* Send the start-up commands */
 mi_send_commands(h,gdb_start);

 return h;
}

/**[txh]********************************************************************

  Description:
  Close connection. You should ask gdb to quit first gmi_gdb_exit.
  
***************************************************************************/

void mi_disconnect(mi_h *h)
{
 mi_free_h(&h);
 free(mi_error_from_gdb);
 mi_error_from_gdb=NULL;
}

void mi_set_console_cb(mi_h *h, stream_cb cb, void *data)
{
 h->console=cb;
 h->console_data=data;
}

void mi_set_target_cb(mi_h *h, stream_cb cb, void *data)
{
 h->target=cb;
 h->target_data=data;
}

void mi_set_log_cb(mi_h *h, stream_cb cb, void *data)
{
 h->log=cb;
 h->log_data=data;
}

stream_cb mi_get_console_cb(mi_h *h, void **data)
{
 if (data)
    *data=h->console_data;
 return h->console;
}

stream_cb mi_get_target_cb(mi_h *h, void **data)
{
 if (data)
    *data=h->target_data;
 return h->target;
}

stream_cb mi_get_log_cb(mi_h *h, void **data)
{
 if (data)
    *data=h->log_data;
 return h->log;
}

void mi_set_async_cb(mi_h *h, async_cb cb, void *data)
{
 h->async=cb;
 h->async_data=data;
}

async_cb mi_get_async_cb(mi_h *h, void **data)
{
 if (data)
    *data=h->async_data;
 return h->async;
}

void mi_set_to_gdb_cb(mi_h *h, stream_cb cb, void *data)
{
 h->to_gdb_echo=cb;
 h->to_gdb_echo_data=data;
}

void mi_set_from_gdb_cb(mi_h *h, stream_cb cb, void *data)
{
 h->from_gdb_echo=cb;
 h->from_gdb_echo_data=data;
}

stream_cb mi_get_to_gdb_cb(mi_h *h, void **data)
{
 if (data)
    *data=h->to_gdb_echo_data;
 return h->to_gdb_echo;
}

stream_cb mi_get_from_gdb_cb(mi_h *h, void **data)
{
 if (data)
    *data=h->from_gdb_echo_data;
 return h->from_gdb_echo;
}

void mi_set_time_out_cb(mi_h *h, tm_cb cb, void *data)
{
 h->time_out_cb=cb;
 h->time_out_cb_data=data;
}

tm_cb mi_get_time_out_cb(mi_h *h, void **data)
{
 if (data)
    *data=h->time_out_cb_data;
 return h->time_out_cb;
}

void mi_set_time_out(mi_h *h, int to)
{
 h->time_out=to;
}

int mi_get_time_out(mi_h *h)
{
 return h->time_out;
}

int mi_send(mi_h *h, const char *format, ...)
{
 int ret;
 char *str;
 va_list argptr;

 if (h->died)
    return 0;

 va_start(argptr,format);
 ret=vasprintf(&str,format,argptr);
 va_end(argptr);
 if (-1 != ret)
   {
     fputs(str,h->to);
     fflush(h->to);
     if (h->to_gdb_echo)
       h->to_gdb_echo(str,h->to_gdb_echo_data);
     free(str);
   }
 else
   {
     abort ();
   }

 return ret;
}

void mi_clean_up_globals()
{
 free(gdb_exe);
 gdb_exe=NULL;
 free(xterm_exe);
 xterm_exe=NULL;
 free(gdb_start);
 gdb_start=NULL;
 free(gdb_conn);
 gdb_conn=NULL;
 free(main_func);
 main_func=NULL;
}

void mi_register_exit()
{
 static int registered=0;
 if (!registered)
   {
    registered=1;
    atexit(mi_clean_up_globals);
   }
}

void mi_set_gdb_exe(const char *name)
{
 free(gdb_exe);
 gdb_exe=name ? strdup(name) : NULL;
 mi_register_exit();
}

void mi_set_gdb_start(const char *name)
{
 free(gdb_start);
 gdb_start=name ? strdup(name) : NULL;
 mi_register_exit();
}

void mi_set_gdb_conn(const char *name)
{
 free(gdb_conn);
 gdb_conn=name ? strdup(name) : NULL;
 mi_register_exit();
}

static
char *mi_search_in_path(const char *file)
{
 char *path, *pt, *r;
 char test[PATH_MAX];
 struct stat st;

 path=getenv("PATH");
 if (!path)
    return NULL;
 pt=strdup(path);
 r=strtok(pt,PATH_SEPARATOR_STR);
 while (r)
   {
    strcpy(test,r);
    strcat(test,"/");
    strcat(test,file);
    if (stat(test,&st)==0 && S_ISREG(st.st_mode))
      {
       free(pt);
       return strdup(test);
      }
    r=strtok(NULL,PATH_SEPARATOR_STR);
   }
 free(pt);
 return NULL;
}

const char *mi_get_gdb_exe()
{
 if (!gdb_exe)
   {/* Look for gdb in path */
    gdb_exe=mi_search_in_path("gdb");
    if (!gdb_exe)
       return "/usr/bin/gdb";
   }
 return gdb_exe;
}

const char *mi_get_gdb_start()
{
 return gdb_start;
}

const char *mi_get_gdb_conn()
{
 return gdb_conn;
}

void mi_set_xterm_exe(const char *name)
{
 free(xterm_exe);
 xterm_exe=name ? strdup(name) : NULL;
 mi_register_exit();
}

const char *mi_get_xterm_exe()
{
 if (!xterm_exe)
   {/* Look for xterm in path */
    xterm_exe=mi_search_in_path("xterm");
    if (!xterm_exe)
       return "/usr/bin/X11/xterm";
   }
 return xterm_exe;
}

void mi_set_main_func(const char *name)
{
 free(main_func);
 main_func=name ? strdup(name) : NULL;
 mi_register_exit();
}

const char *mi_get_main_func()
{
 if (main_func)
    return main_func;
 return "main";
}

/**[txh]********************************************************************

  Description:
  Opens a new xterm to be used by the child process to debug.
  
  Return: A new mi_aux_term structure, you can use gmi_end_aux_term to
release it.
  
***************************************************************************/

mi_aux_term *gmi_start_xterm()
{
 char nsh[14]="/tmp/shXXXXXX";
 char ntt[14]="/tmp/ttXXXXXX";
 const char *xterm;
 struct stat st;
 int hsh, htt=-1;
 mi_aux_term *res=NULL;
 FILE *f;
 pid_t pid;
 char buf[PATH_MAX];

 /* Verify we have an X terminal. */
 xterm=mi_get_xterm_exe();
 if (access(xterm,X_OK))
   {
    mi_error=MI_MISSING_XTERM;
    return NULL;
   }

 /* Create 2 temporals. */
 hsh=mkstemp(nsh);
 if (hsh==-1)
   {
    mi_error=MI_CREATE_TEMPORAL;
    return NULL;
   }
 htt=mkstemp(ntt);
 if (htt==-1)
   {
    close(hsh);
    unlink(nsh);
    mi_error=MI_CREATE_TEMPORAL;
    return NULL;
   }
 close(htt);
 /* Create the script. */
 f=fdopen(hsh,"w");
 if (!f)
   {
    close(hsh);
    unlink(nsh);
    unlink(ntt);
    mi_error=MI_CREATE_TEMPORAL;
    return NULL;
   }
 fprintf(f,"#!/bin/sh\n");
 fprintf(f,"tty > %s\n",ntt);
 fprintf(f,"rm %s\n",nsh);
 fprintf(f,"sleep 365d\n");
 fclose(f);
 /* Spawn xterm. */
 /* Create the child. */
 pid=fork();
 if (pid==0)
   {/* We are the child. */
    char *argv[5];
    /* Pass the control to gdb. */
    argv[0]=(char *)mi_get_xterm_exe(); /* Is that ok? */
    argv[1]="-e";
    argv[2]="/bin/sh";
    argv[3]=nsh;
    argv[4]=0;
    execvp(argv[0],argv);
    /* We get here only if exec failed. */
    unlink(nsh);
    unlink(ntt);
    _exit(127);
   }
 /* We are the parent. */
 if (pid==-1)
   {/* Fork failed. */
    unlink(nsh);
    unlink(ntt);
    mi_error=MI_FORK;
    return NULL;
   }
 /* Wait until the shell is deleted. */
 while (stat(nsh,&st)==0)
   usleep(1000);
 /* Try to read the tty name. */
 f=fopen(ntt,"rt");
 if (f)
   {
    if (fgets(buf,PATH_MAX,f))
      {
       char *s; /* Strip the \n. */
       for (s=buf; *s && *s!='\n'; s++);
       *s=0;
       res=(mi_aux_term *)malloc(sizeof(mi_aux_term));
       if (res)
         {
          res->pid=pid;
          res->tty=strdup(buf);
         }
      }
    fclose(f);
   }
 unlink(ntt);
 return res;
}

void mi_free_aux_term(mi_aux_term *t)
{
 if (!t)
    return;
 free(t->tty);
 free(t);
}

/**[txh]********************************************************************

  Description:
  Closes the auxiliar terminal and releases the allocated memory.
  
***************************************************************************/

void gmi_end_aux_term(mi_aux_term *t)
{
 if (!t)
    return;
 if (t->pid!=-1 && mi_check_running_pid(t->pid))
    mi_kill_child(t->pid);
 mi_free_aux_term(t);
}

/**[txh]********************************************************************

  Description:
  Forces the MI version. Currently the library can't detect it so you must
force it manually. GDB 5.x implemented MI v1 and 6.x v2.
  
***************************************************************************/

void mi_force_version(mi_h *h, unsigned vMajor, unsigned vMiddle,
                      unsigned vMinor)
{
 h->version=MI_VERSION2U(vMajor,vMiddle,vMinor);
}

/**[txh]********************************************************************

  Description:
  Dis/Enables the workaround for a bug in gdb.

***************************************************************************/

void mi_set_workaround(unsigned wa, int enable)
{
 switch (wa)
   {
    case MI_PSYM_SEARCH:
         disable_psym_search_workaround=enable ? 0 : 1;
         break;
   }
}

/**[txh]********************************************************************

  Description:
  Finds if the workaround for a bug in gdb is enabled.
  
  Return: !=0 if enabled.
  
***************************************************************************/

int mi_get_workaround(unsigned wa)
{
 switch (wa)
   {
    case MI_PSYM_SEARCH:
         return disable_psym_search_workaround==0;
   }
 return 0;
}