-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagc_gdbmi.c
1940 lines (1673 loc) · 51.4 KB
/
agc_gdbmi.c
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
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2008 Onno Hommes:1
This file is part of yaAGC.
yaAGC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
yaAGC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with yaAGC; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
In addition, as a special exception, permission is granted to
link the code of this program with the Orbiter SDK library (or with
modified versions of the Orbiter SDK library that use the same license as
the Orbiter SDK library), and distribute linked combinations including
the two. You must obey the GNU General Public License in all respects for
all of the code used other than the Orbiter SDK library. If you modify
this file, you may extend this exception to your version of the file,
but you are not obligated to do so. If you do not wish to do so, delete
this exception statement from your version.
Filename: agc_gdbmi.c
Purpose: This is module covers the gdb/mi subsystem of yaAGC and enables
yaAGC to be debugged in a Graphical Debugger front-end to gdb.
Compiler: GNU gcc.
Contact: Onno Hommes
Reference: http://virtualagc.googlecode.com
Mods: 01/01/08 OH Began work.
06/08/09 OH Added info variables,functions and fixed
Showing source line when not using -fullname.
06/14/09 OH Add the gdb style disassemble command
07/01/09 OH Convert to command tables to prepare for machine
independence and change to GNU formating
08/01/09 RSB Adjusted to use NormalizeSourceName().
*/
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "yaAGC.h"
#include "agc_engine.h"
#include "agc_symtab.h"
#include "agc_debug.h"
#include "agc_debugger.h"
#include "agc_disassembler.h"
#include "agc_gdbmi.h"
#include <string.h>
#include <unistd.h>
#ifdef WIN32
#include <windows.h>
#include <sys/time.h>
#include "regex.h"
#define LB "\r\n"
#else
#include <time.h>
#include <sys/times.h>
#include <regex.h>
#define LB ""
#endif
//#define VERSION(x) #x
extern char agcPrompt[16];
extern int HaveSymbols;
extern int FullNameMode;
extern int Break;
extern int DebuggerInterruptMasks[11];
extern char* CurrentSourceFile;
extern int SymbolTableSize;
extern Symbol_t *SymbolTable;
extern char SourceFiles[MAX_NUM_FILES][MAX_FILE_LENGTH];
extern int NumberFiles;
extern SymbolLine_t* FindLastLineMain(void);
extern void CheckDec (char *s);
extern char* DbgGetFrameNameByAddr(unsigned LinearAddress);
static int gdbmi_break_id = 0;
static int gdbmi_status;
//static int cli_argc;
static char* cli_arg;
static char FileName[MAX_FILE_LENGTH+1];
static agc_t* State;
static char* s;
static char* sraw;
static CustomCommand_t gdbmiCustomCmds[32];
const char disp_keep[5] = "keep";
const char disp_delete[4] = "del";
char*
GdbmiStringToUpper(char* str)
{
char* ss;
/* Ensure command s is in uppercase */
for (ss = str; *ss; *ss = toupper (*ss), ss++);
return (str);
}
/**
Adjust the command string pointer with the value given.
*/
static inline void
GdbmiAdjustCmdPtr(int i)
{
s += i;
sraw += i;
}
GdbmiResult
GdbmiParseConsoleCommands(GdbmiCommands_t* CmdTable)
{
int i=-1;
int CmdLength;
GdbmiResult GdbmiStat = GdbmiCmdUnhandled;
while(CmdTable[++i].Command)
{
CmdLength = strlen(CmdTable[i].Command);
if (!strncmp(s,CmdTable[i].Command,CmdLength))
{
GdbmiStat = CmdTable[i].Handler(CmdLength);
break;
}
}
return (GdbmiStat);
}
static char *
GdbmiBasename (const char *name)
{
const char *base;
#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
/* Skip over the disk name in MSDOS pathnames. */
if (ISALPHA (name[0]) && name[1] == ':')
name += 2;
#endif
for (base = name; *name; name++)
{
if (*name == '/' || *name == '\\')
{
base = name + 1;
}
}
return (char *) base;
}
void GdbmiDisassemble(agc_t *State,unsigned start_linear,unsigned end_linear)
{
}
void
GdbmiDisplayBreakpointForLine(SymbolLine_t* Line,int BreakpointId)
{
unsigned LinearAddress = DbgLinearAddr(&Line->CodeAddress);
printf ("Breakpoint %d, %s () at %s:%d\n",BreakpointId,
DbgGetFrameNameByAddr(LinearAddress),
Line->FileName,Line->LineNumber);
}
/* Handle the break GDB/CLI command */
static GdbmiResult
GdbmiHandleAllBreak(int j,char disp)
{
int i, vRegBB, LineNumber;
Symbol_t *Symbol = NULL;
SymbolLine_t *Line = NULL;
char SymbolName[MAX_LABEL_LENGTH + 1],*cli_char;
unsigned gdbmiAddress = 0;
Address_t agc_addr;
/* Adjust the CmdPtr to point to the next token */
GdbmiAdjustCmdPtr(j);
if (strlen(s) > 0) /* Do we have an argument */
{
s++;sraw++; /* Skip space */
/* Remove Enclosing Double Quotes */
if (sraw[0] == '\"')
{
++sraw;++s;
if (sraw[strlen(sraw)-1] == '\"')
{
sraw[strlen(sraw)-1] = 0;
s[strlen(s)-1]=0;
}
}
sraw = GdbmiBasename(sraw);
s=GdbmiBasename(s);
/* First replace ":" with space !!FIX to prevent DOS disk separator!! */
cli_char = strstr(sraw,":");
if (cli_char) *cli_char = ' '; /* replace colon with space */
if (HaveSymbols &&
(2 == sscanf (sraw, "%s %d", FileName, &LineNumber)) &&
(Line = (SymbolLine_t*) ResolveFileLineNumber(FileName, LineNumber)))
{
gdbmiAddress = DbgLinearAddr(&Line->CodeAddress);
}
else if (HaveSymbols && (1 == sscanf (s, "%d", &LineNumber)) &&
(Line = ResolveLineNumber (LineNumber)))
{
gdbmiAddress = DbgLinearAddr(&Line->CodeAddress);
}
else if (HaveSymbols && (1 == sscanf (s, "%s", SymbolName)) &&
(Symbol = ResolveSymbol (SymbolName, SYMBOL_LABEL)))
{
gdbmiAddress = DbgLinearAddr(&Symbol->Value);
}
else if (1 == sscanf (s, "*0X%x", &gdbmiAddress));
else
{
/* Insert error message not help */
printf ("Illegal syntax for break.\n");
return (GdbmiCmdDone);
}
}
else /* Default Break point is current address */
{
gdbmiAddress = DbgLinearFixedAddr(
State->Erasable[0][RegZ] & 07777,
037 & (State->Erasable[0][RegBB] >> 10),
(State->OutputChannel7 & 0100) ? 1 : 0);
}
if (gdbmiAddress < 04000)
{
printf ("Line number points to erasable memory.\n");
return (GdbmiCmdDone);
}
agc_addr = DbgNativeAddr(gdbmiAddress);
vRegBB = ((agc_addr.FB << 10) | (agc_addr.Super << 7));
if (Line == NULL)
Line = ResolveLineAGC (agc_addr.SReg,agc_addr.FB,agc_addr.Super);
for (i = 0; i < NumBreakpoints; i++)
if (Breakpoints[i].Address12 == agc_addr.SReg && Breakpoints[i].vRegBB == vRegBB &&
Breakpoints[i].WatchBreak == 0)
{
printf ("This breakpoint already exists.\n");
return (GdbmiCmdDone);
}
if (NumBreakpoints < MAX_BREAKPOINTS)
{
Breakpoints[NumBreakpoints].Id = ++gdbmi_break_id;
Breakpoints[NumBreakpoints].Hits = 0;
Breakpoints[NumBreakpoints].Enable = 'y';
Breakpoints[NumBreakpoints].Disposition = disp;
Breakpoints[NumBreakpoints].Address12 = agc_addr.SReg;
Breakpoints[NumBreakpoints].vRegBB = vRegBB;
Breakpoints[NumBreakpoints].WatchBreak = 0;
Breakpoints[NumBreakpoints].Symbol = Symbol;
Breakpoints[NumBreakpoints].Line = Line;
NumBreakpoints++;
if (Line)
printf ("Breakpoint %d at 0x%04x: file %s, line %d.\n",
NumBreakpoints,gdbmiAddress,Line->FileName,Line->LineNumber);
}
else
printf ("The maximum number of breakpoints is already defined.\n");
// FIX ME
return (GdbmiCmdDone);
}
/* Handle the temporary break GDB/CLI command */
static GdbmiResult
GdbmiHandleTmpBrk(int i)
{
return (GdbmiHandleAllBreak(i,BP_DELETE));
}
/* Handle the normal break GDB/CLI command */
static GdbmiResult
GdbmiHandleNormBrk(int i)
{
return (GdbmiHandleAllBreak(i,BP_KEEP));
}
static GdbmiResult
GdbmiHandleWatch (int j)
{
int k, i, vRegBB, WatchType, WatchValue = 0777777;
Symbol_t *Symbol = NULL;
unsigned gdbmi_address;
Address_t agc_addr;
/* Adjust the CmdPtr to point to the next token */
GdbmiAdjustCmdPtr(j);
if (strlen(sraw))
Symbol = ResolveSymbol(sraw, SYMBOL_VARIABLE | SYMBOL_REGISTER | SYMBOL_CONSTANT);
if (Symbol != NULL && !Symbol->Value.Erasable) Symbol = NULL;
if (Symbol != NULL)
{
/* Get linear address for display */
gdbmi_address = DbgLinearAddr(&Symbol->Value);
/* Watch Type 3 = for value, Watch type 1 for any change */
agc_addr = DbgNativeAddr(gdbmi_address);
WatchType = 1;
vRegBB = agc_addr.EB;
k = agc_addr.SReg;
WatchValue = State->Erasable[vRegBB][k];
}
for (i = 0; i < NumBreakpoints; i++)
if (Breakpoints[i].Address12 == k && Breakpoints[i].vRegBB == vRegBB &&
Breakpoints[i].WatchBreak == WatchType)
{
printf ("This watchpoint already exists.\n");
return(GdbmiCmdDone);
}
if (NumBreakpoints < MAX_BREAKPOINTS)
{
Breakpoints[NumBreakpoints].Id = ++gdbmi_break_id;
Breakpoints[NumBreakpoints].Hits = 0;
Breakpoints[NumBreakpoints].Enable = 'y';
Breakpoints[NumBreakpoints].Disposition = BP_KEEP;
Breakpoints[NumBreakpoints].Address12 = k;
Breakpoints[NumBreakpoints].vRegBB = vRegBB;
Breakpoints[NumBreakpoints].WatchBreak = WatchType;
Breakpoints[NumBreakpoints].Symbol = Symbol;
Breakpoints[NumBreakpoints].Line = NULL;
if (WatchType == 1)
Breakpoints[NumBreakpoints].WatchValue =
DbgGetWatch (State, &Breakpoints[NumBreakpoints]);
else
Breakpoints[NumBreakpoints].WatchValue = WatchValue;
NumBreakpoints++;
if (Symbol)
printf ("Hardware watchpoint %d: %s\n",gdbmi_break_id,Symbol->Name);
}
else
printf ("The maximum number of watchpoints is already defined.\n");
return(GdbmiCmdDone);
}
void
GdbmiHandleShowVersion(void)
{
DbgDisplayVersion();
}
static GdbmiResult
GdbmiHandleInfoRegisters(int i)
{
int cli_argc = 0;
/* Adjust the CmdPtr to point to the next token */
GdbmiAdjustCmdPtr(i);
if (strlen(s)>1)
{
cli_argc++;
cli_arg = s + 1;
}
/* Print the requested register contents */
if (!cli_argc || !strcmp(cli_arg,"A"))
printf("A\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegA],
0177777 & State->Erasable[0][RegA]);
if (!cli_argc || !strcmp(cli_arg,"L"))
printf("L\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegL],
0177777 & State->Erasable[0][RegL]);
if (!cli_argc || !strcmp(cli_arg,"Q"))
printf("Q\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegQ],
0177777 & State->Erasable[0][RegQ]);
if (!cli_argc || !strcmp(cli_arg,"EB"))
printf("EB\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegEB],
0177777 & State->Erasable[0][RegEB]);
if (!cli_argc || !strcmp(cli_arg,"FB"))
printf("FB\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegFB],
0177777 & State->Erasable[0][RegFB]);
if (!cli_argc || !strcmp(cli_arg,"Z"))
printf("Z\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegZ],
0177777 & State->Erasable[0][RegZ]);
if (!cli_argc || !strcmp(cli_arg,"BB"))
printf("BB\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegBB],
0177777 & State->Erasable[0][RegBB]);
if (!cli_argc || !strcmp(cli_arg,"ARUPT"))
printf("ARUPT\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegARUPT],
0177777 & State->Erasable[0][RegARUPT]);
if (!cli_argc || !strcmp(cli_arg,"LRUPT"))
printf("LRUPT\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegLRUPT],
0177777 & State->Erasable[0][RegLRUPT]);
if (!cli_argc || !strcmp(cli_arg,"QRUPT"))
printf("QRUPT\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegQRUPT],
0177777 & State->Erasable[0][RegQRUPT]);
if (!cli_argc || !strcmp(cli_arg,"ZRUPT"))
printf("ZRUPT\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegZRUPT],
0177777 & State->Erasable[0][RegZRUPT]);
if (!cli_argc || !strcmp(cli_arg,"BBRUPT"))
printf("BBRUPT\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegBBRUPT],
0177777 & State->Erasable[0][RegBBRUPT]);
if (!cli_argc || !strcmp(cli_arg,"BRUPT"))
printf("BRUPT\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegBRUPT],
0177777 & State->Erasable[0][RegBRUPT]);
if (!cli_argc || !strcmp(cli_arg,"CHAN07"))
printf("CHAN07\t\t0x%04x\t%d\n",
0177777 & State->InputChannel[7],
0177777 & State->InputChannel[7]);
if (!cli_argc || !strcmp(cli_arg,"CYR"))
printf("CYR\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegCYR],
0177777 & State->Erasable[0][RegCYR]);
if (!cli_argc || !strcmp(cli_arg,"SR"))
printf("SR\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegSR],
0177777 & State->Erasable[0][RegSR]);
if (!cli_argc || !strcmp(cli_arg,"CYL"))
printf("CYL\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegCYL],
0177777 & State->Erasable[0][RegCYL]);
if (!cli_argc || !strcmp(cli_arg,"EDOP"))
printf("EDOP\t\t0x%04x\t%d\n",
0177777 & State->Erasable[0][RegEDOP],
0177777 & State->Erasable[0][RegEDOP]);
if (!cli_argc || !strcmp(cli_arg,"INDEX"))
printf("INDEX\t\t0x%04x\t%d\n",
0177777 & State->IndexValue,
0177777 & State->IndexValue);
if (!cli_argc || !strcmp(cli_arg,"EXTEND"))
printf("EXTEND\t\t0x%04x\t%d\n",
0177777 & State->ExtraCode,
0177777 & State->ExtraCode);
if (!cli_argc || !strcmp(cli_arg,"IRQMSK"))
printf("IRQMSK\t\t0x%04x\t%d\n",
0177777 & State->AllowInterrupt,
0177777 & State->AllowInterrupt);
if (!cli_argc || !strcmp(cli_arg,"ISR"))
printf("ISR\t\t0x%04x\t%d\n",
0177777 & State->InIsr,
0177777 & State->InIsr);
return(GdbmiCmdDone);
}
GdbmiResult
GdbmiHandleInfoBreakpoints(int j)
{
int i;
char* disposition;
/* No CmdPtr adjust ment necessary so ignore input */
if (NumBreakpoints == 0)
printf ("No breakpoints or watchpoints.\n");
else
printf ("Num\tType\t\tDisp\tEnb\tAddress\tWhat\n");
for (i = 0; i < NumBreakpoints; i++)
{
int Address12, vRegBB;
if (Breakpoints[i].Disposition == BP_KEEP)disposition=(char*)disp_keep;
else disposition = (char*)disp_delete;
if (Breakpoints[i].WatchBreak > 0)
{
if (Breakpoints[i].Symbol != NULL)
{
printf ("%d\thw watchpoint\t%s\t%c\t %s",
Breakpoints[i].Id,
disposition,
Breakpoints[i].Enable,
Breakpoints[i].Symbol->Name);
}
}
else
{
printf ("%d\tbreakpoint\t%s\t%c\t",
Breakpoints[i].Id,
disposition,
Breakpoints[i].Enable);
}
Address12 = Breakpoints[i].Address12;
vRegBB = Breakpoints[i].vRegBB;
if (Address12 < 01400 || Address12 >= 04000)
printf ("0x%04x", DbgLinearFixedAddr(Address12,0,0));
else if (Address12 >= 02000 && Address12 < 04000)
{
int Bank;
Bank = (vRegBB >> 10) & 037;
if (0 != (vRegBB & 0100) && Bank >= 030) Bank += 010;
printf ("0x%04x", DbgLinearFixedAddr(Address12,Bank,0));
}
// Print out the file,line if set for the breakpoint
if (HaveSymbols)
{
if (Breakpoints[i].Symbol != NULL && !Breakpoints[i].WatchBreak)
printf(" in file %s:%d",
Breakpoints[i].Symbol->FileName,
Breakpoints[i].Symbol->LineNumber);
else if (Breakpoints[i].Line != NULL && !Breakpoints[i].WatchBreak)
printf(" in file %s:%d",
Breakpoints[i].Line->FileName,
Breakpoints[i].Line->LineNumber);
}
printf ("\n");
if (Breakpoints[i].Hits == 1)
printf("\tbreakpoint already hit %d time\n",Breakpoints[i].Hits);
else if (Breakpoints[i].Hits > 1)
printf("\tbreakpoint already hit %d times\n",Breakpoints[i].Hits);
}
return(GdbmiCmdDone);
}
void
GdbmiPrintFullNameFrame(SymbolLine_t *Line)
{
printf("\032\032%s:%d:%d:beg:0x%04x\n",
NormalizeSourceName (SourcePathName, Line->FileName),
Line->LineNumber,Line->LineNumber,
DbgLinearFixedAddr(Line->CodeAddress.SReg,
Line->CodeAddress.FB,
Line->CodeAddress.Super));
}
static char* CurrentFileName = 0;
void
GdbmiPrintSourceFrame(SymbolLine_t *Line)
{
if (CurrentFileName == 0 || strcmp(CurrentFileName,Line->FileName))
{
/* Looks like a source file switch print the file info */
unsigned Address = DbgLinearAddr(&Line->CodeAddress);
printf("%s () at %s:%d\n",
DbgGetFrameNameByAddr(Address),
Line->FileName,
Line->LineNumber);
CurrentFileName = Line->FileName;
}
ListSourceLine(Line->FileName,Line->LineNumber,0);
}
GdbmiResult
GdbmiHandleInfoLine(int i)
{
int LineNumber;
SymbolLine_t *Line = NULL;
char *cli_char = NULL;
/* Adjust the CmdPtr to point to the next token */
GdbmiAdjustCmdPtr(i);
if (*s == ' ')
{
cli_char = strstr(sraw,":");
*cli_char = ' ';
if (2 == sscanf (sraw+1, "%s %d", FileName, &LineNumber))
{
Line = (SymbolLine_t*)ResolveFileLineNumber(FileName,LineNumber);
}
}
else
{
int CurrentZ = State->Erasable[0][RegZ] & 07777;
int FB = 037 & (State->Erasable[0][RegBB] >> 10);
int SBB = (State->OutputChannel7 & 0100) ? 1 : 0;
Line = ResolveLineAGC(CurrentZ, FB, SBB);
}
if (Line)
{
unsigned Addr = DbgLinearAddr(&Line->CodeAddress);
char* FrameName = DbgGetFrameNameByAddr(Addr);
printf("Line %d of \"%s\" starts at address 0x%04x <%s>\n",
Line->LineNumber,Line->FileName,
Addr,FrameName);
printf(" and ends at 0x%04x <%s>.\n",
Addr,FrameName);
if (FullNameMode) GdbmiPrintFullNameFrame(Line);
}
return(GdbmiCmdDone);
}
GdbmiResult
GdbmiHandleInfoTarget(int i)
{
printf("Symbols from \"%s\".\n",SymbolFile);
printf("Local exec file:\n");
printf("\tfile type ropes-agc.\n");
printf("\tEntry point: 0x0800\n");
printf("\t0x0000 - 0x02ff is .unswitched_eraseable\n");
printf("\t0x0300 - 0x07ff is .switched_eraseable\n");
printf("\t0x0800 - 0x0fff is .fixed_fixed\n");
printf("\t0x1000 - 0x17ff is .common_fixed\n");
printf("\t0x1800 - 0x1fff is .fixed_fixed\n");
printf("\t0x2000 - 0x6fff is .common_fixed\n");
printf("\t0x7000 - 0x9fff is .super_bank\n");
return(GdbmiCmdDone);
}
GdbmiResult
GdbmiHandleInfoChannels(int i)
{
int chx;
unsigned value;
int select = -1;
/* Adjust the CmdPtr to point to the next token */
GdbmiAdjustCmdPtr(i);
/* Check for a channel argument */
if (strlen(s) > 0)
{
select = strtol(s,0,0);
}
for (chx=0;chx<NUM_CHANNELS;chx++)
{
value = ReadIO(State,chx);
if (select < 0 || select == chx)
{
printf("CHAN%o\t0x%04x %5d\n",chx,value,value);
}
}
return(GdbmiCmdDone);
}
typedef struct io_regs_tag
{
char name[8];
int offset;
} t_io_regs;
#define NUM_IO_REGS 23
const t_io_regs io_registers[NUM_IO_REGS] =
{
{"CDUX",032},
{"CDUY",033},
{"CDUZ",034},
{"OPTY",035},
{"OPTX",036},
{"PIPAX",037},
{"PIPAY",040},
{"PIPAZ",041},
{"RHCP",042},
{"RHCY",043},
{"RHCR",044},
{"INLINK",045},
{"RNRAD",046},
{"GYROCMD",047},
{"CDUXCMD",050},
{"CDUYCMD",051},
{"CDUZCMD",052},
{"OPTYCMD",053},
{"OPTXCMD",054},
{"THRUST",055},
{"LEMONM",056},
{"OUTLINK",057},
{"ALTM",060}
};
static GdbmiResult
GdbmiHandleInfoIoRegisters(int j)
{
int io_select = 0;
int i;
unsigned value;
/* Adjust the CmdPtr to point to the next token */
GdbmiAdjustCmdPtr(j);
if (strlen(s++) > 1) io_select = 1;
for (i=0;i< NUM_IO_REGS;i++)
{
if (io_select == 0 || !strcmp(s,io_registers[i].name))
{
value = 0177777 & State->Erasable[0][io_registers[i].offset];
printf("%s\t\t0x%04x\t%u\n",io_registers[i].name,value,value);
}
}
return(GdbmiCmdDone);
}
static GdbmiResult
GdbmiHandleInfoAllRegisters(int i)
{
/* Adjust the CmdPtr to point to the next token */
GdbmiAdjustCmdPtr(i);
GdbmiHandleInfoRegisters(0);
GdbmiHandleInfoIoRegisters(0);
return(GdbmiCmdDone);
}
static GdbmiResult
GdbmiHandleInfoProgram(int i)
{
printf("\tUsing the running image of child process 0.\n");
printf("Program stopped at 0x%04x.\n",DbgLinearFixedAddr(
State->Erasable[0][RegZ] & 07777,
037 & (State->Erasable[0][RegBB] >> 10),
(State->OutputChannel7 & 0100) ? 1 : 0));
printf("It stopped after being stepped.\n");
return(GdbmiCmdDone);
}
/**
* Display the thread summaries of all currently known threads
* If no ISR is active only one thread the default execution
* thread will be shown. If an ISR is running (only one can run
* at a time then both the ISR as well as the default execution
* thread will be shown. With the ISR marked as the active thread
*/
static GdbmiResult
GdbmiHandleInfoThreads(int i)
{
SymbolLine_t* Line = NULL;
char threadName[10] = "main";
unsigned LinearAddress;
/* Adjust the CmdPtr to point to the next token */
GdbmiAdjustCmdPtr(i);
/* Check if we are dealing with 2 threads (i.e. in an ISR) */
if (State->InIsr)
{
/* Determine the thread name to be verbose when showing info */
switch(State->InterruptRequests[0])
{
case 1:
strcpy(threadName,"TIMER6");
break;
case 2:
strcpy(threadName,"TIMER5");
break;
case 3:
strcpy(threadName,"TIMER3");
break;
case 4:
strcpy(threadName,"TIMER4");
break;
case 5:
strcpy(threadName,"KEYBD1");
break;
case 6:
strcpy(threadName,"KEYBD2");
break;
case 7:
strcpy(threadName,"UPLINK");
break;
case 8:
strcpy(threadName,"DNLINK");
break;
case 9:
strcpy(threadName,"RADAR");
break;
case 10:
strcpy(threadName,"JOYSTK");
break;
default:
strcpy(threadName,"MAIN");
break;
}
/* Get head of the stack of ISR thread */
Line = DbgResolveCurrentLine();
if (Line)
{
LinearAddress = DbgLinearAddr(&Line->CodeAddress);
printf("* 2 thread %d (%s)\t0x%04x in %s ()\n",
State->InterruptRequests[0],
threadName,
LinearAddress,
DbgGetFrameNameByAddr(LinearAddress)
);
printf(" at %s:%d\n",Line->FileName,Line->LineNumber);
}
Line = FindLastLineMain();
if (Line)
{
LinearAddress = DbgLinearAddr(&Line->CodeAddress);
printf(" 1 thread 0 (MAIN)\t0x%04x in %s ()\n",
LinearAddress,DbgGetFrameNameByAddr(LinearAddress));
}
}
else
{
Line = DbgResolveCurrentLine();
if (Line)
{
LinearAddress = DbgLinearAddr(&Line->CodeAddress);
printf("* 1 thread 0 (MAIN)\t0x%04x in %s ()\n",
LinearAddress,DbgGetFrameNameByAddr(LinearAddress));
printf(" at %s:%d\n",Line->FileName,Line->LineNumber);
}
}
return(GdbmiCmdDone);
}
static GdbmiResult
GdbmiHandleBacktrace(int i)
{
int LimitList = MAX_BACKTRACE_POINTS;
/* Adjust the CmdPtr to point to the next token */
GdbmiAdjustCmdPtr(i);
sscanf (s, "%d", &LimitList);
BacktraceDisplay(State,LimitList);
return(GdbmiCmdDone);
}
//Current source file is main.c
//Compilation directory is C:/Code/virtualagc/yaAGC/
//Located in C:/Code/virtualagc/yaAGC/main.c
//Contains 1733 lines.
//Source language is c.
//Compiled with stabs debugging format.
static GdbmiResult
GdbmiHandleInfoSource(int i)
{
printf("Current source file is \"%s\"\n",CurrentSourceFile);
printf("Current source directory is \"%s\"\n", SourcePathName);
printf("Located in %s\n", NormalizeSourceName (SourcePathName, CurrentSourceFile));
printf("Source language is assembler.\n");
printf("Compiled with proprietary debugging format.\n");
return(GdbmiCmdDone);
}
/**
Display the list of source files for which symbols are loaded.
Since the list can be quite long the command allows for a pattern
to be passed to reduce the output list in console mode.
*/
static GdbmiResult
GdbmiHandleInfoSources(int i)
{
int j;
regex_t preg;
int UsePattern = 0;
int Match = 0;
GdbmiResult GdbmiStat = GdbmiCmdUnhandled;
/* Adjust the CmdPtr to point to the next token */
GdbmiAdjustCmdPtr(i);
/* Check if a pattern search is used */
if (strlen(s) > 0)
{
GdbmiAdjustCmdPtr(1);
j = regcomp (&preg, sraw, REG_ICASE | REG_NOSUB | REG_EXTENDED);
if (j)
{
printf ("Illegal regular-expression.\n");
regfree (&preg);
GdbmiStat = GdbmiCmdError;
}
else UsePattern = 1;
}
if (GdbmiStat != GdbmiCmdError)
{
printf("Source files for which symbols have been read in:\n\n");
/* Loop through and print out the file names */
for (j = 0; j < NumberFiles; j++)
{
Match = 0;
if (UsePattern)
{
if (0 == regexec (&preg, SourceFiles[j], 0, NULL, 0))
{
Match = 1;
}
}
else Match = 1;
if (Match)
{
printf("%s\n", NormalizeSourceName (SourcePathName, SourceFiles[j]));
}
}
fflush (stdout);
if (UsePattern) regfree (&preg);
GdbmiStat = GdbmiCmdUnhandled;
}
return GdbmiStat;
}
static GdbmiResult
GdbmiHandleInfoInterrupts(int j)
{
int i;
GdbmiAdjustCmdPtr(j);
if (!DebuggerInterruptMasks[0]) printf ("All interrupts are blocked.\n");
else printf ("Interrupts are allowed.\n");
printf ("Debugger interrupt mask:");
for (i = 1; i <= NUM_INTERRUPT_TYPES; i++)
printf (" %d", !DebuggerInterruptMasks[i]);
printf ("\nInterrupt-request flags:");
for (i = 1; i <= NUM_INTERRUPT_TYPES; i++)
printf (" %d", State->InterruptRequests[i]);
if (State->InIsr) printf ("\nIn ISR #%d.\n", State->InterruptRequests[0]);
else printf ("\nLast ISR: #%d.\n",State->InterruptRequests[0]);
return(GdbmiCmdDone);
}
static GdbmiResult
GdbmiHandleInfoSymbols(int i,int type)
{
int j;
regex_t preg;
int UsePattern = 0;
int Match = 0;
char* LastFileName = (char*)0;
GdbmiResult GdbmiStat = GdbmiCmdUnhandled;
GdbmiAdjustCmdPtr(i);
/* Check if a pattern search is used */
if (strlen(s) > 0)
{
GdbmiAdjustCmdPtr(1);
j = regcomp (&preg, sraw, REG_ICASE | REG_NOSUB | REG_EXTENDED);
if (j)
{
printf ("Illegal regular-expression.\n");
regfree (&preg);
GdbmiStat = GdbmiCmdError;
}
else UsePattern = 1;
}
if (GdbmiStat != GdbmiCmdError)
{