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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
|
/* $Id: DBGCOps.cpp $ */
/** @file
* DBGC - Debugger Console, Operators.
*/
/*
* Copyright (C) 2006-2019 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*********************************************************************************************************************************
* Header Files *
*********************************************************************************************************************************/
#define LOG_GROUP LOG_GROUP_DBGC
#include <VBox/dbg.h>
#include <VBox/vmm/dbgf.h>
#include <VBox/param.h>
#include <VBox/err.h>
#include <VBox/log.h>
#include <iprt/assert.h>
#include <iprt/mem.h>
#include <iprt/string.h>
#include "DBGCInternal.h"
/*********************************************************************************************************************************
* Internal Functions *
*********************************************************************************************************************************/
static DECLCALLBACK(int) dbgcOpMinus(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpPluss(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpBooleanNot(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpBitwiseNot(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpVar(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpAddrFar(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpMult(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpDiv(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpMod(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpAdd(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpSub(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpBitwiseShiftLeft(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpBitwiseShiftRight(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpBitwiseAnd(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpBitwiseXor(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpBitwiseOr(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpBooleanAnd(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpBooleanOr(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpRangeLength(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpRangeLengthBytes(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
static DECLCALLBACK(int) dbgcOpRangeTo(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult);
/*********************************************************************************************************************************
* Defined Constants And Macros *
*********************************************************************************************************************************/
/**
* Generic implementation of a binary operator.
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
* @param Operator The C operator.
* @param fIsDiv Set if it's division and we need to check for zero on the
* right hand side.
*/
#define DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, Operator, fIsDiv) \
do \
{ \
if ((pArg1)->enmType == DBGCVAR_TYPE_STRING) \
return VERR_DBGC_PARSE_INVALID_OPERATION; \
\
/* Get the 64-bit right side value. */ \
uint64_t u64Right; \
int rc = dbgcOpHelperGetNumber((pDbgc), (pArg2), &u64Right); \
if ((fIsDiv) && RT_SUCCESS(rc) && !u64Right) /* div/0 kludge */ \
DBGCVAR_INIT_NUMBER((pResult), UINT64_MAX); \
else if (RT_SUCCESS(rc)) \
{ \
/* Apply it to the left hand side. */ \
if ((pArg1)->enmType == DBGCVAR_TYPE_SYMBOL) \
{ \
rc = dbgcSymbolGet((pDbgc), (pArg1)->u.pszString, DBGCVAR_TYPE_ANY, (pResult)); \
if (RT_FAILURE(rc)) \
return rc; \
} \
else \
*(pResult) = *(pArg1); \
switch ((pResult)->enmType) \
{ \
case DBGCVAR_TYPE_GC_FLAT: \
(pResult)->u.GCFlat = (pResult)->u.GCFlat Operator u64Right; \
break; \
case DBGCVAR_TYPE_GC_FAR: \
(pResult)->u.GCFar.off = (pResult)->u.GCFar.off Operator u64Right; \
break; \
case DBGCVAR_TYPE_GC_PHYS: \
(pResult)->u.GCPhys = (pResult)->u.GCPhys Operator u64Right; \
break; \
case DBGCVAR_TYPE_HC_FLAT: \
(pResult)->u.pvHCFlat = (void *)((uintptr_t)(pResult)->u.pvHCFlat Operator u64Right); \
break; \
case DBGCVAR_TYPE_HC_PHYS: \
(pResult)->u.HCPhys = (pResult)->u.HCPhys Operator u64Right; \
break; \
case DBGCVAR_TYPE_NUMBER: \
(pResult)->u.u64Number = (pResult)->u.u64Number Operator u64Right; \
break; \
default: \
return VERR_DBGC_PARSE_INCORRECT_ARG_TYPE; \
} \
} \
return rc; \
} while (0)
/**
* Switch the factors/whatever so we preserve pointers.
* Far pointers are considered more important that physical and flat pointers.
*
* @param pArg1 The left side argument. Input & output.
* @param pArg2 The right side argument. Input & output.
*/
#define DBGC_GEN_ARIT_POINTER_TO_THE_LEFT(pArg1, pArg2) \
do \
{ \
if ( DBGCVAR_ISPOINTER((pArg2)->enmType) \
&& ( !DBGCVAR_ISPOINTER((pArg1)->enmType) \
|| ( DBGCVAR_IS_FAR_PTR((pArg2)->enmType) \
&& !DBGCVAR_IS_FAR_PTR((pArg1)->enmType)))) \
{ \
PCDBGCVAR pTmp = (pArg1); \
(pArg2) = (pArg1); \
(pArg1) = pTmp; \
} \
} while (0)
/*********************************************************************************************************************************
* Global Variables *
*********************************************************************************************************************************/
/** Operators. */
const DBGCOP g_aDbgcOps[] =
{
/* szName is initialized as a 4 char array because of M$C elsewise optimizing it away in /Ox mode (the 'const char' vs 'char' problem). */
/* szName, cchName, fBinary, iPrecedence, pfnHandlerUnary, pfnHandlerBitwise */
{ {'-'}, 1, false, 1, dbgcOpMinus, NULL, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Unary minus." },
{ {'+'}, 1, false, 1, dbgcOpPluss, NULL, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Unary plus." },
{ {'!'}, 1, false, 1, dbgcOpBooleanNot, NULL, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Boolean not." },
{ {'~'}, 1, false, 1, dbgcOpBitwiseNot, NULL, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Bitwise complement." },
{ {':'}, 1, true, 2, NULL, dbgcOpAddrFar, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Far pointer." },
{ {'%'}, 1, false, 3, dbgcOpAddrFlat, NULL, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Flat address." },
{ {'%','%'}, 2, false, 3, dbgcOpAddrPhys, NULL, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Physical address." },
{ {'#'}, 1, false, 3, dbgcOpAddrHost, NULL, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Flat host address." },
{ {'#','%','%'}, 3, false, 3, dbgcOpAddrHostPhys, NULL, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Physical host address." },
{ {'$'}, 1, false, 3, dbgcOpVar, NULL, DBGCVAR_CAT_SYMBOL, DBGCVAR_CAT_ANY, "Reference a variable." },
{ {'@'}, 1, false, 3, dbgcOpRegister, NULL, DBGCVAR_CAT_SYMBOL, DBGCVAR_CAT_ANY, "Reference a register." },
{ {'*'}, 1, true, 10, NULL, dbgcOpMult, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Multiplication." },
{ {'/'}, 1, true, 11, NULL, dbgcOpDiv, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Division." },
{ {'m','o','d'}, 3, true, 12, NULL, dbgcOpMod, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Modulus." },
{ {'+'}, 1, true, 13, NULL, dbgcOpAdd, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Addition." },
{ {'-'}, 1, true, 14, NULL, dbgcOpSub, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Subtraction." },
{ {'<','<'}, 2, true, 15, NULL, dbgcOpBitwiseShiftLeft, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Bitwise left shift." },
{ {'>','>'}, 2, true, 16, NULL, dbgcOpBitwiseShiftRight, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Bitwise right shift." },
{ {'&'}, 1, true, 17, NULL, dbgcOpBitwiseAnd, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Bitwise and." },
{ {'^'}, 1, true, 18, NULL, dbgcOpBitwiseXor, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Bitwise exclusiv or." },
{ {'|'}, 1, true, 19, NULL, dbgcOpBitwiseOr, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Bitwise inclusive or." },
{ {'&','&'}, 2, true, 20, NULL, dbgcOpBooleanAnd, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Boolean and." },
{ {'|','|'}, 2, true, 21, NULL, dbgcOpBooleanOr, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Boolean or." },
{ {'L'}, 1, true, 22, NULL, dbgcOpRangeLength, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Range elements." },
{ {'L','B'}, 2, true, 23, NULL, dbgcOpRangeLengthBytes, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Range bytes." },
{ {'T'}, 1, true, 24, NULL, dbgcOpRangeTo, DBGCVAR_CAT_ANY, DBGCVAR_CAT_ANY, "Range to." }
};
/** Number of operators in the operator array. */
const uint32_t g_cDbgcOps = RT_ELEMENTS(g_aDbgcOps);
/**
* Converts an argument to a number value.
*
* @returns VBox status code.
* @param pDbgc The DBGC instance.
* @param pArg The argument to convert.
* @param pu64Ret Where to return the value.
*/
static int dbgcOpHelperGetNumber(PDBGC pDbgc, PCDBGCVAR pArg, uint64_t *pu64Ret)
{
DBGCVAR Var = *pArg;
switch (Var.enmType)
{
case DBGCVAR_TYPE_GC_FLAT:
*pu64Ret = Var.u.GCFlat;
break;
case DBGCVAR_TYPE_GC_FAR:
*pu64Ret = Var.u.GCFar.off;
break;
case DBGCVAR_TYPE_GC_PHYS:
*pu64Ret = Var.u.GCPhys;
break;
case DBGCVAR_TYPE_HC_FLAT:
*pu64Ret = (uintptr_t)Var.u.pvHCFlat;
break;
case DBGCVAR_TYPE_HC_PHYS:
*pu64Ret = Var.u.HCPhys;
break;
case DBGCVAR_TYPE_NUMBER:
*pu64Ret = Var.u.u64Number;
break;
case DBGCVAR_TYPE_SYMBOL:
{
int rc = dbgcSymbolGet(pDbgc, Var.u.pszString, DBGCVAR_TYPE_NUMBER, &Var);
if (RT_FAILURE(rc))
return rc;
}
RT_FALL_THRU();
case DBGCVAR_TYPE_STRING:
default:
return VERR_DBGC_PARSE_INCORRECT_ARG_TYPE;
}
return VINF_SUCCESS;
}
/**
* @callback_method_impl{FNDBGCOPUNARY, Negate (unary).}
*/
static DECLCALLBACK(int) dbgcOpMinus(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult)
{
RT_NOREF1(enmCat);
LogFlow(("dbgcOpMinus\n"));
*pResult = *pArg;
switch (pArg->enmType)
{
case DBGCVAR_TYPE_GC_FLAT:
pResult->u.GCFlat = -(RTGCINTPTR)pResult->u.GCFlat;
break;
case DBGCVAR_TYPE_GC_FAR:
pResult->u.GCFar.off = -(int32_t)pResult->u.GCFar.off;
break;
case DBGCVAR_TYPE_GC_PHYS:
pResult->u.GCPhys = (RTGCPHYS) -(int64_t)pResult->u.GCPhys;
break;
case DBGCVAR_TYPE_HC_FLAT:
pResult->u.pvHCFlat = (void *) -(intptr_t)pResult->u.pvHCFlat;
break;
case DBGCVAR_TYPE_HC_PHYS:
pResult->u.HCPhys = (RTHCPHYS) -(int64_t)pResult->u.HCPhys;
break;
case DBGCVAR_TYPE_NUMBER:
pResult->u.u64Number = -(int64_t)pResult->u.u64Number;
break;
case DBGCVAR_TYPE_STRING:
case DBGCVAR_TYPE_SYMBOL:
default:
return VERR_DBGC_PARSE_INCORRECT_ARG_TYPE;
}
NOREF(pDbgc);
return VINF_SUCCESS;
}
/**
* @callback_method_impl{FNDBGCOPUNARY, Plus (unary).}
*/
static DECLCALLBACK(int) dbgcOpPluss(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult)
{
RT_NOREF1(enmCat);
LogFlow(("dbgcOpPluss\n"));
*pResult = *pArg;
switch (pArg->enmType)
{
case DBGCVAR_TYPE_GC_FLAT:
case DBGCVAR_TYPE_GC_FAR:
case DBGCVAR_TYPE_GC_PHYS:
case DBGCVAR_TYPE_HC_FLAT:
case DBGCVAR_TYPE_HC_PHYS:
case DBGCVAR_TYPE_NUMBER:
break;
case DBGCVAR_TYPE_STRING:
case DBGCVAR_TYPE_SYMBOL:
default:
return VERR_DBGC_PARSE_INCORRECT_ARG_TYPE;
}
NOREF(pDbgc);
return VINF_SUCCESS;
}
/**
* @callback_method_impl{FNDBGCOPUNARY, Boolean not (unary).}
*/
static DECLCALLBACK(int) dbgcOpBooleanNot(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult)
{
RT_NOREF1(enmCat);
LogFlow(("dbgcOpBooleanNot\n"));
*pResult = *pArg;
switch (pArg->enmType)
{
case DBGCVAR_TYPE_GC_FLAT:
pResult->u.u64Number = !pResult->u.GCFlat;
break;
case DBGCVAR_TYPE_GC_FAR:
pResult->u.u64Number = !pResult->u.GCFar.off && pResult->u.GCFar.sel <= 3;
break;
case DBGCVAR_TYPE_GC_PHYS:
pResult->u.u64Number = !pResult->u.GCPhys;
break;
case DBGCVAR_TYPE_HC_FLAT:
pResult->u.u64Number = !pResult->u.pvHCFlat;
break;
case DBGCVAR_TYPE_HC_PHYS:
pResult->u.u64Number = !pResult->u.HCPhys;
break;
case DBGCVAR_TYPE_NUMBER:
pResult->u.u64Number = !pResult->u.u64Number;
break;
case DBGCVAR_TYPE_STRING:
case DBGCVAR_TYPE_SYMBOL:
pResult->u.u64Number = !pResult->u64Range;
break;
case DBGCVAR_TYPE_UNKNOWN:
default:
return VERR_DBGC_PARSE_INCORRECT_ARG_TYPE;
}
pResult->enmType = DBGCVAR_TYPE_NUMBER;
NOREF(pDbgc);
return VINF_SUCCESS;
}
/**
* @callback_method_impl{FNDBGCOPUNARY, Bitwise not (unary).}
*/
static DECLCALLBACK(int) dbgcOpBitwiseNot(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult)
{
RT_NOREF1(enmCat);
LogFlow(("dbgcOpBitwiseNot\n"));
*pResult = *pArg;
switch (pArg->enmType)
{
case DBGCVAR_TYPE_GC_FLAT:
pResult->u.GCFlat = ~pResult->u.GCFlat;
break;
case DBGCVAR_TYPE_GC_FAR:
pResult->u.GCFar.off = ~pResult->u.GCFar.off;
break;
case DBGCVAR_TYPE_GC_PHYS:
pResult->u.GCPhys = ~pResult->u.GCPhys;
break;
case DBGCVAR_TYPE_HC_FLAT:
pResult->u.pvHCFlat = (void *)~(uintptr_t)pResult->u.pvHCFlat;
break;
case DBGCVAR_TYPE_HC_PHYS:
pResult->u.HCPhys = ~pResult->u.HCPhys;
break;
case DBGCVAR_TYPE_NUMBER:
pResult->u.u64Number = ~pResult->u.u64Number;
break;
case DBGCVAR_TYPE_STRING:
case DBGCVAR_TYPE_SYMBOL:
default:
return VERR_DBGC_PARSE_INCORRECT_ARG_TYPE;
}
NOREF(pDbgc);
return VINF_SUCCESS;
}
/**
* @callback_method_impl{FNDBGCOPUNARY, Reference variable (unary).}
*/
static DECLCALLBACK(int) dbgcOpVar(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult)
{
RT_NOREF1(enmCat);
LogFlow(("dbgcOpVar: %s\n", pArg->u.pszString));
AssertReturn(pArg->enmType == DBGCVAR_TYPE_SYMBOL, VERR_DBGC_PARSE_BUG);
/*
* Lookup the variable.
*/
const char *pszVar = pArg->u.pszString;
for (unsigned iVar = 0; iVar < pDbgc->cVars; iVar++)
{
if (!strcmp(pszVar, pDbgc->papVars[iVar]->szName))
{
*pResult = pDbgc->papVars[iVar]->Var;
return VINF_SUCCESS;
}
}
return VERR_DBGC_PARSE_VARIABLE_NOT_FOUND;
}
/**
* @callback_method_impl{FNDBGCOPUNARY, Reference register (unary).}
*/
DECLCALLBACK(int) dbgcOpRegister(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult)
{
LogFlow(("dbgcOpRegister: %s\n", pArg->u.pszString));
AssertReturn(pArg->enmType == DBGCVAR_TYPE_SYMBOL, VERR_DBGC_PARSE_BUG);
/* Detect references to hypervisor registers. */
const char *pszReg = pArg->u.pszString;
VMCPUID idCpu = pDbgc->idCpu;
if (pszReg[0] == '.')
{
pszReg++;
idCpu |= DBGFREG_HYPER_VMCPUID;
}
/*
* If the desired result is a symbol, pass the argument along unmodified.
* This is a great help for "r @eax" and such, since it will be translated to "r eax".
*/
if (enmCat == DBGCVAR_CAT_SYMBOL)
{
int rc = DBGFR3RegNmValidate(pDbgc->pUVM, idCpu, pszReg);
if (RT_SUCCESS(rc))
DBGCVAR_INIT_STRING(pResult, pArg->u.pszString);
return rc;
}
/*
* Get the register.
*/
DBGFREGVALTYPE enmType;
DBGFREGVAL Value;
int rc = DBGFR3RegNmQuery(pDbgc->pUVM, idCpu, pszReg, &Value, &enmType);
if (RT_SUCCESS(rc))
{
switch (enmType)
{
case DBGFREGVALTYPE_U8:
DBGCVAR_INIT_NUMBER(pResult, Value.u8);
return VINF_SUCCESS;
case DBGFREGVALTYPE_U16:
DBGCVAR_INIT_NUMBER(pResult, Value.u16);
return VINF_SUCCESS;
case DBGFREGVALTYPE_U32:
DBGCVAR_INIT_NUMBER(pResult, Value.u32);
return VINF_SUCCESS;
case DBGFREGVALTYPE_U64:
DBGCVAR_INIT_NUMBER(pResult, Value.u64);
return VINF_SUCCESS;
case DBGFREGVALTYPE_U128:
DBGCVAR_INIT_NUMBER(pResult, Value.u128.s.Lo);
return VINF_SUCCESS;
case DBGFREGVALTYPE_U256:
DBGCVAR_INIT_NUMBER(pResult, Value.u256.QWords.qw0);
return VINF_SUCCESS;
case DBGFREGVALTYPE_U512:
DBGCVAR_INIT_NUMBER(pResult, Value.u512.QWords.qw0);
return VINF_SUCCESS;
case DBGFREGVALTYPE_R80:
#ifdef RT_COMPILER_WITH_80BIT_LONG_DOUBLE
DBGCVAR_INIT_NUMBER(pResult, (uint64_t)Value.r80Ex.lrd);
#else
DBGCVAR_INIT_NUMBER(pResult, (uint64_t)Value.r80Ex.sj64.u63Fraction);
#endif
return VINF_SUCCESS;
case DBGFREGVALTYPE_DTR:
DBGCVAR_INIT_NUMBER(pResult, Value.dtr.u64Base);
return VINF_SUCCESS;
case DBGFREGVALTYPE_INVALID:
case DBGFREGVALTYPE_END:
case DBGFREGVALTYPE_32BIT_HACK:
break;
}
rc = VERR_INTERNAL_ERROR_5;
}
return rc;
}
/**
* @callback_method_impl{FNDBGCOPUNARY, Flat address (unary).}
*/
DECLCALLBACK(int) dbgcOpAddrFlat(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult)
{
RT_NOREF1(enmCat);
LogFlow(("dbgcOpAddrFlat\n"));
DBGCVARTYPE enmType = DBGCVAR_ISHCPOINTER(pArg->enmType) ? DBGCVAR_TYPE_HC_FLAT : DBGCVAR_TYPE_GC_FLAT;
return DBGCCmdHlpConvert(&pDbgc->CmdHlp, pArg, enmType, true /*fConvSyms*/, pResult);
}
/**
* @callback_method_impl{FNDBGCOPUNARY, Physical address (unary).}
*/
DECLCALLBACK(int) dbgcOpAddrPhys(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult)
{
RT_NOREF1(enmCat);
LogFlow(("dbgcOpAddrPhys\n"));
DBGCVARTYPE enmType = DBGCVAR_ISHCPOINTER(pArg->enmType) ? DBGCVAR_TYPE_HC_PHYS : DBGCVAR_TYPE_GC_PHYS;
return DBGCCmdHlpConvert(&pDbgc->CmdHlp, pArg, enmType, true /*fConvSyms*/, pResult);
}
/**
* @callback_method_impl{FNDBGCOPUNARY, Physical host address (unary).}
*/
DECLCALLBACK(int) dbgcOpAddrHostPhys(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult)
{
RT_NOREF1(enmCat);
LogFlow(("dbgcOpAddrPhys\n"));
return DBGCCmdHlpConvert(&pDbgc->CmdHlp, pArg, DBGCVAR_TYPE_HC_PHYS, true /*fConvSyms*/, pResult);
}
/**
* @callback_method_impl{FNDBGCOPUNARY, Host address (unary).}
*/
DECLCALLBACK(int) dbgcOpAddrHost(PDBGC pDbgc, PCDBGCVAR pArg, DBGCVARCAT enmCat, PDBGCVAR pResult)
{
RT_NOREF1(enmCat);
LogFlow(("dbgcOpAddrHost\n"));
return DBGCCmdHlpConvert(&pDbgc->CmdHlp, pArg, DBGCVAR_TYPE_HC_FLAT, true /*fConvSyms*/, pResult);
}
/**
* @callback_method_impl{FNDBGCOPUNARY, Far address (unary).}
*/
static DECLCALLBACK(int) dbgcOpAddrFar(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpAddrFar\n"));
int rc;
switch (pArg1->enmType)
{
case DBGCVAR_TYPE_SYMBOL:
rc = dbgcSymbolGet(pDbgc, pArg1->u.pszString, DBGCVAR_TYPE_NUMBER, pResult);
if (RT_FAILURE(rc))
return rc;
break;
case DBGCVAR_TYPE_NUMBER:
*pResult = *pArg1;
break;
default:
return VERR_DBGC_PARSE_INCORRECT_ARG_TYPE;
}
pResult->u.GCFar.sel = (RTSEL)pResult->u.u64Number;
/* common code for the two types we support. */
switch (pArg2->enmType)
{
case DBGCVAR_TYPE_GC_FLAT:
pResult->u.GCFar.off = pArg2->u.GCFlat;
pResult->enmType = DBGCVAR_TYPE_GC_FAR;
break;
case DBGCVAR_TYPE_HC_FLAT:
pResult->u.pvHCFlat = (void *)(uintptr_t)pArg2->u.GCFlat;
pResult->enmType = DBGCVAR_TYPE_GC_FAR;
break;
case DBGCVAR_TYPE_NUMBER:
pResult->u.GCFar.off = (RTGCPTR)pArg2->u.u64Number;
pResult->enmType = DBGCVAR_TYPE_GC_FAR;
break;
case DBGCVAR_TYPE_SYMBOL:
{
DBGCVAR Var;
rc = dbgcSymbolGet(pDbgc, pArg2->u.pszString, DBGCVAR_TYPE_NUMBER, &Var);
if (RT_FAILURE(rc))
return rc;
pResult->u.GCFar.off = (RTGCPTR)Var.u.u64Number;
pResult->enmType = DBGCVAR_TYPE_GC_FAR;
break;
}
default:
return VERR_DBGC_PARSE_INCORRECT_ARG_TYPE;
}
return VINF_SUCCESS;
}
/**
* Multiplication operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpMult(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpMult\n"));
DBGC_GEN_ARIT_POINTER_TO_THE_LEFT(pArg1, pArg2);
DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, *, false);
}
/**
* Division operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpDiv(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpDiv\n"));
DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, /, true);
}
/**
* Modulus operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpMod(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpMod\n"));
DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, %, false);
}
/**
* Addition operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpAdd(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpAdd\n"));
/*
* An addition operation will return (when possible) the left side type in the
* expression. We make an omission for numbers, where we'll take the right side
* type instead. An expression where only the left hand side is a symbol we'll
* use the right hand type to try resolve it.
*/
if ( pArg1->enmType == DBGCVAR_TYPE_STRING
|| pArg2->enmType == DBGCVAR_TYPE_STRING)
return VERR_DBGC_PARSE_INVALID_OPERATION; /** @todo string contactenation later. */
if ( (pArg1->enmType == DBGCVAR_TYPE_NUMBER && pArg2->enmType != DBGCVAR_TYPE_SYMBOL)
|| (pArg1->enmType == DBGCVAR_TYPE_SYMBOL && pArg2->enmType != DBGCVAR_TYPE_SYMBOL))
{
PCDBGCVAR pTmp = pArg2;
pArg2 = pArg1;
pArg1 = pTmp;
}
DBGCVAR Sym1, Sym2;
if (pArg1->enmType == DBGCVAR_TYPE_SYMBOL)
{
int rc = dbgcSymbolGet(pDbgc, pArg1->u.pszString, DBGCVAR_TYPE_ANY, &Sym1);
if (RT_FAILURE(rc))
return rc;
pArg1 = &Sym1;
rc = dbgcSymbolGet(pDbgc, pArg2->u.pszString, DBGCVAR_TYPE_ANY, &Sym2);
if (RT_FAILURE(rc))
return rc;
pArg2 = &Sym2;
}
int rc;
DBGCVAR Var;
DBGCVAR Var2;
switch (pArg1->enmType)
{
/*
* GC Flat
*/
case DBGCVAR_TYPE_GC_FLAT:
switch (pArg2->enmType)
{
case DBGCVAR_TYPE_HC_FLAT:
case DBGCVAR_TYPE_HC_PHYS:
return VERR_DBGC_PARSE_INVALID_OPERATION;
default:
*pResult = *pArg1;
rc = dbgcOpAddrFlat(pDbgc, pArg2, DBGCVAR_CAT_ANY, &Var);
if (RT_FAILURE(rc))
return rc;
pResult->u.GCFlat += pArg2->u.GCFlat;
break;
}
break;
/*
* GC Far
*/
case DBGCVAR_TYPE_GC_FAR:
switch (pArg2->enmType)
{
case DBGCVAR_TYPE_HC_FLAT:
case DBGCVAR_TYPE_HC_PHYS:
return VERR_DBGC_PARSE_INVALID_OPERATION;
case DBGCVAR_TYPE_NUMBER:
*pResult = *pArg1;
pResult->u.GCFar.off += (RTGCPTR)pArg2->u.u64Number;
break;
default:
rc = dbgcOpAddrFlat(pDbgc, pArg1, DBGCVAR_CAT_ANY, pResult);
if (RT_FAILURE(rc))
return rc;
rc = dbgcOpAddrFlat(pDbgc, pArg2, DBGCVAR_CAT_ANY, &Var);
if (RT_FAILURE(rc))
return rc;
pResult->u.GCFlat += pArg2->u.GCFlat;
break;
}
break;
/*
* GC Phys
*/
case DBGCVAR_TYPE_GC_PHYS:
switch (pArg2->enmType)
{
case DBGCVAR_TYPE_HC_FLAT:
case DBGCVAR_TYPE_HC_PHYS:
return VERR_DBGC_PARSE_INVALID_OPERATION;
default:
*pResult = *pArg1;
rc = dbgcOpAddrPhys(pDbgc, pArg2, DBGCVAR_CAT_ANY, &Var);
if (RT_FAILURE(rc))
return rc;
if (Var.enmType != DBGCVAR_TYPE_GC_PHYS)
return VERR_DBGC_PARSE_INVALID_OPERATION;
pResult->u.GCPhys += Var.u.GCPhys;
break;
}
break;
/*
* HC Flat
*/
case DBGCVAR_TYPE_HC_FLAT:
*pResult = *pArg1;
rc = dbgcOpAddrHost(pDbgc, pArg2, DBGCVAR_CAT_ANY, &Var2);
if (RT_FAILURE(rc))
return rc;
rc = dbgcOpAddrFlat(pDbgc, &Var2, DBGCVAR_CAT_ANY, &Var);
if (RT_FAILURE(rc))
return rc;
pResult->u.pvHCFlat = (char *)pResult->u.pvHCFlat + (uintptr_t)Var.u.pvHCFlat;
break;
/*
* HC Phys
*/
case DBGCVAR_TYPE_HC_PHYS:
*pResult = *pArg1;
rc = dbgcOpAddrHostPhys(pDbgc, pArg2, DBGCVAR_CAT_ANY, &Var);
if (RT_FAILURE(rc))
return rc;
pResult->u.HCPhys += Var.u.HCPhys;
break;
/*
* Numbers (see start of function)
*/
case DBGCVAR_TYPE_NUMBER:
*pResult = *pArg1;
switch (pArg2->enmType)
{
case DBGCVAR_TYPE_SYMBOL:
rc = dbgcSymbolGet(pDbgc, pArg2->u.pszString, DBGCVAR_TYPE_NUMBER, &Var);
if (RT_FAILURE(rc))
return rc;
RT_FALL_THRU();
case DBGCVAR_TYPE_NUMBER:
pResult->u.u64Number += pArg2->u.u64Number;
break;
default:
return VERR_DBGC_PARSE_INVALID_OPERATION;
}
break;
default:
return VERR_DBGC_PARSE_INVALID_OPERATION;
}
return VINF_SUCCESS;
}
/**
* Subtraction operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpSub(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpSub\n"));
/*
* An subtraction operation will return the left side type in the expression.
* However, if the left hand side is a number and the right hand a pointer of
* some kind we'll convert the left hand side to the same type as the right hand.
* Any symbols will be resolved, strings will be rejected.
*/
DBGCVAR Sym1, Sym2;
if ( pArg2->enmType == DBGCVAR_TYPE_SYMBOL
&& ( pArg1->enmType == DBGCVAR_TYPE_NUMBER
|| pArg1->enmType == DBGCVAR_TYPE_SYMBOL))
{
int rc = dbgcSymbolGet(pDbgc, pArg2->u.pszString, DBGCVAR_TYPE_ANY, &Sym2);
if (RT_FAILURE(rc))
return rc;
pArg2 = &Sym2;
}
if ( pArg1->enmType == DBGCVAR_TYPE_STRING
|| pArg2->enmType == DBGCVAR_TYPE_STRING)
return VERR_DBGC_PARSE_INVALID_OPERATION;
if (pArg1->enmType == DBGCVAR_TYPE_SYMBOL)
{
DBGCVARTYPE enmType;
switch (pArg2->enmType)
{
case DBGCVAR_TYPE_NUMBER:
enmType = DBGCVAR_TYPE_ANY;
break;
case DBGCVAR_TYPE_GC_FLAT:
case DBGCVAR_TYPE_GC_PHYS:
case DBGCVAR_TYPE_HC_FLAT:
case DBGCVAR_TYPE_HC_PHYS:
enmType = pArg2->enmType;
break;
case DBGCVAR_TYPE_GC_FAR:
enmType = DBGCVAR_TYPE_GC_FLAT;
break;
default: AssertFailedReturn(VERR_DBGC_IPE);
}
if (enmType != DBGCVAR_TYPE_STRING)
{
int rc = dbgcSymbolGet(pDbgc, pArg1->u.pszString, DBGCVAR_TYPE_ANY, &Sym1);
if (RT_FAILURE(rc))
return rc;
pArg1 = &Sym1;
}
}
else if (pArg1->enmType == DBGCVAR_TYPE_NUMBER)
{
PFNDBGCOPUNARY pOp = NULL;
switch (pArg2->enmType)
{
case DBGCVAR_TYPE_GC_FAR:
case DBGCVAR_TYPE_GC_FLAT:
pOp = dbgcOpAddrFlat;
break;
case DBGCVAR_TYPE_GC_PHYS:
pOp = dbgcOpAddrPhys;
break;
case DBGCVAR_TYPE_HC_FLAT:
pOp = dbgcOpAddrHost;
break;
case DBGCVAR_TYPE_HC_PHYS:
pOp = dbgcOpAddrHostPhys;
break;
case DBGCVAR_TYPE_NUMBER:
break;
default: AssertFailedReturn(VERR_DBGC_IPE);
}
if (pOp)
{
int rc = pOp(pDbgc, pArg1, DBGCVAR_CAT_ANY, &Sym1);
if (RT_FAILURE(rc))
return rc;
pArg1 = &Sym1;
}
}
/*
* Normal processing.
*/
int rc;
DBGCVAR Var;
DBGCVAR Var2;
switch (pArg1->enmType)
{
/*
* GC Flat
*/
case DBGCVAR_TYPE_GC_FLAT:
switch (pArg2->enmType)
{
case DBGCVAR_TYPE_HC_FLAT:
case DBGCVAR_TYPE_HC_PHYS:
return VERR_DBGC_PARSE_INVALID_OPERATION;
default:
*pResult = *pArg1;
rc = dbgcOpAddrFlat(pDbgc, pArg2, DBGCVAR_CAT_ANY, &Var);
if (RT_FAILURE(rc))
return rc;
pResult->u.GCFlat -= pArg2->u.GCFlat;
break;
}
break;
/*
* GC Far
*/
case DBGCVAR_TYPE_GC_FAR:
switch (pArg2->enmType)
{
case DBGCVAR_TYPE_HC_FLAT:
case DBGCVAR_TYPE_HC_PHYS:
return VERR_DBGC_PARSE_INVALID_OPERATION;
case DBGCVAR_TYPE_NUMBER:
*pResult = *pArg1;
pResult->u.GCFar.off -= (RTGCPTR)pArg2->u.u64Number;
break;
default:
rc = dbgcOpAddrFlat(pDbgc, pArg1, DBGCVAR_CAT_ANY, pResult);
if (RT_FAILURE(rc))
return rc;
rc = dbgcOpAddrFlat(pDbgc, pArg2, DBGCVAR_CAT_ANY, &Var);
if (RT_FAILURE(rc))
return rc;
pResult->u.GCFlat -= pArg2->u.GCFlat;
break;
}
break;
/*
* GC Phys
*/
case DBGCVAR_TYPE_GC_PHYS:
switch (pArg2->enmType)
{
case DBGCVAR_TYPE_HC_FLAT:
case DBGCVAR_TYPE_HC_PHYS:
return VERR_DBGC_PARSE_INVALID_OPERATION;
default:
*pResult = *pArg1;
rc = dbgcOpAddrPhys(pDbgc, pArg2, DBGCVAR_CAT_ANY, &Var);
if (RT_FAILURE(rc))
return rc;
if (Var.enmType != DBGCVAR_TYPE_GC_PHYS)
return VERR_DBGC_PARSE_INVALID_OPERATION;
pResult->u.GCPhys -= Var.u.GCPhys;
break;
}
break;
/*
* HC Flat
*/
case DBGCVAR_TYPE_HC_FLAT:
*pResult = *pArg1;
rc = dbgcOpAddrHost(pDbgc, pArg2, DBGCVAR_CAT_ANY, &Var2);
if (RT_FAILURE(rc))
return rc;
rc = dbgcOpAddrFlat(pDbgc, &Var2, DBGCVAR_CAT_ANY, &Var);
if (RT_FAILURE(rc))
return rc;
pResult->u.pvHCFlat = (char *)pResult->u.pvHCFlat - (uintptr_t)Var.u.pvHCFlat;
break;
/*
* HC Phys
*/
case DBGCVAR_TYPE_HC_PHYS:
*pResult = *pArg1;
rc = dbgcOpAddrHostPhys(pDbgc, pArg2, DBGCVAR_CAT_ANY, &Var);
if (RT_FAILURE(rc))
return rc;
pResult->u.HCPhys -= Var.u.HCPhys;
break;
/*
* Numbers (see start of function)
*/
case DBGCVAR_TYPE_NUMBER:
*pResult = *pArg1;
switch (pArg2->enmType)
{
case DBGCVAR_TYPE_SYMBOL:
rc = dbgcSymbolGet(pDbgc, pArg2->u.pszString, DBGCVAR_TYPE_NUMBER, &Var);
if (RT_FAILURE(rc))
return rc;
RT_FALL_THRU();
case DBGCVAR_TYPE_NUMBER:
pResult->u.u64Number -= pArg2->u.u64Number;
break;
default:
return VERR_DBGC_PARSE_INVALID_OPERATION;
}
break;
default:
return VERR_DBGC_PARSE_INVALID_OPERATION;
}
return VINF_SUCCESS;
}
/**
* Bitwise shift left operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpBitwiseShiftLeft(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpBitwiseShiftLeft\n"));
DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, <<, false);
}
/**
* Bitwise shift right operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpBitwiseShiftRight(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpBitwiseShiftRight\n"));
DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, >>, false);
}
/**
* Bitwise and operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpBitwiseAnd(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpBitwiseAnd\n"));
DBGC_GEN_ARIT_POINTER_TO_THE_LEFT(pArg1, pArg2);
DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, &, false);
}
/**
* Bitwise exclusive or operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpBitwiseXor(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpBitwiseXor\n"));
DBGC_GEN_ARIT_POINTER_TO_THE_LEFT(pArg1, pArg2);
DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, ^, false);
}
/**
* Bitwise inclusive or operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpBitwiseOr(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpBitwiseOr\n"));
DBGC_GEN_ARIT_POINTER_TO_THE_LEFT(pArg1, pArg2);
DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, |, false);
}
/**
* Boolean and operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpBooleanAnd(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpBooleanAnd\n"));
/** @todo force numeric return value? */
DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, &&, false);
}
/**
* Boolean or operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpBooleanOr(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpBooleanOr\n"));
/** @todo force numeric return value? */
DBGC_GEN_ARIT_BINARY_OP(pDbgc, pArg1, pArg2, pResult, ||, false);
}
/**
* Range to operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpRangeLength(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpRangeLength\n"));
if (pArg1->enmType == DBGCVAR_TYPE_STRING)
return VERR_DBGC_PARSE_INVALID_OPERATION;
/*
* Make result. Symbols needs to be resolved.
*/
if (pArg1->enmType == DBGCVAR_TYPE_SYMBOL)
{
int rc = dbgcSymbolGet(pDbgc, pArg1->u.pszString, DBGCVAR_TYPE_ANY, pResult);
if (RT_FAILURE(rc))
return rc;
}
else
*pResult = *pArg1;
/*
* Convert 2nd argument to element count.
*/
pResult->enmRangeType = DBGCVAR_RANGE_ELEMENTS;
switch (pArg2->enmType)
{
case DBGCVAR_TYPE_NUMBER:
pResult->u64Range = pArg2->u.u64Number;
break;
case DBGCVAR_TYPE_SYMBOL:
{
int rc = dbgcSymbolGet(pDbgc, pArg2->u.pszString, DBGCVAR_TYPE_NUMBER, pResult);
if (RT_FAILURE(rc))
return rc;
pResult->u64Range = pArg2->u.u64Number;
break;
}
case DBGCVAR_TYPE_STRING:
default:
return VERR_DBGC_PARSE_INVALID_OPERATION;
}
return VINF_SUCCESS;
}
/**
* Range to operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpRangeLengthBytes(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpRangeLengthBytes\n"));
int rc = dbgcOpRangeLength(pDbgc, pArg1, pArg2, pResult);
if (RT_SUCCESS(rc))
pResult->enmRangeType = DBGCVAR_RANGE_BYTES;
return rc;
}
/**
* Range to operator (binary).
*
* @returns VINF_SUCCESS on success.
* @returns VBox evaluation / parsing error code on failure.
* The caller does the bitching.
* @param pDbgc Debugger console instance data.
* @param pArg1 The first argument.
* @param pArg2 The 2nd argument.
* @param pResult Where to store the result.
*/
static DECLCALLBACK(int) dbgcOpRangeTo(PDBGC pDbgc, PCDBGCVAR pArg1, PCDBGCVAR pArg2, PDBGCVAR pResult)
{
LogFlow(("dbgcOpRangeTo\n"));
/*
* Calc number of bytes between the two args.
*/
DBGCVAR Diff;
int rc = dbgcOpSub(pDbgc, pArg2, pArg1, &Diff);
if (RT_FAILURE(rc))
return rc;
/*
* Use the diff as the range of Arg1.
*/
*pResult = *pArg1;
pResult->enmRangeType = DBGCVAR_RANGE_BYTES;
switch (Diff.enmType)
{
case DBGCVAR_TYPE_GC_FLAT:
pResult->u64Range = (RTGCUINTPTR)Diff.u.GCFlat;
break;
case DBGCVAR_TYPE_GC_PHYS:
pResult->u64Range = Diff.u.GCPhys;
break;
case DBGCVAR_TYPE_HC_FLAT:
pResult->u64Range = (uintptr_t)Diff.u.pvHCFlat;
break;
case DBGCVAR_TYPE_HC_PHYS:
pResult->u64Range = Diff.u.HCPhys;
break;
case DBGCVAR_TYPE_NUMBER:
pResult->u64Range = Diff.u.u64Number;
break;
case DBGCVAR_TYPE_GC_FAR:
case DBGCVAR_TYPE_STRING:
case DBGCVAR_TYPE_SYMBOL:
default:
AssertMsgFailed(("Impossible!\n"));
return VERR_DBGC_PARSE_INVALID_OPERATION;
}
return VINF_SUCCESS;
}
/**
* Searches for an operator descriptor which matches the start of
* the expression given us.
*
* @returns Pointer to the operator on success.
* @param pDbgc The debug console instance.
* @param pszExpr Pointer to the expression string which might start with an operator.
* @param fPreferBinary Whether to favour binary or unary operators.
* Caller must assert that it's the desired type! Both types will still
* be returned, this is only for resolving duplicates.
* @param chPrev The previous char. Some operators requires a blank in front of it.
*/
PCDBGCOP dbgcOperatorLookup(PDBGC pDbgc, const char *pszExpr, bool fPreferBinary, char chPrev)
{
PCDBGCOP pOp = NULL;
for (unsigned iOp = 0; iOp < RT_ELEMENTS(g_aDbgcOps); iOp++)
{
if ( g_aDbgcOps[iOp].szName[0] == pszExpr[0]
&& (!g_aDbgcOps[iOp].szName[1] || g_aDbgcOps[iOp].szName[1] == pszExpr[1])
&& (!g_aDbgcOps[iOp].szName[2] || g_aDbgcOps[iOp].szName[2] == pszExpr[2]))
{
/*
* Check that we don't mistake it for some other operator which have more chars.
*/
unsigned j;
for (j = iOp + 1; j < RT_ELEMENTS(g_aDbgcOps); j++)
if ( g_aDbgcOps[j].cchName > g_aDbgcOps[iOp].cchName
&& g_aDbgcOps[j].szName[0] == pszExpr[0]
&& (!g_aDbgcOps[j].szName[1] || g_aDbgcOps[j].szName[1] == pszExpr[1])
&& (!g_aDbgcOps[j].szName[2] || g_aDbgcOps[j].szName[2] == pszExpr[2]) )
break;
if (j < RT_ELEMENTS(g_aDbgcOps))
continue; /* we'll catch it later. (for theoretical +,++,+++ cases.) */
pOp = &g_aDbgcOps[iOp];
/*
* Preferred type?
*/
if (g_aDbgcOps[iOp].fBinary == fPreferBinary)
break;
}
}
if (pOp)
Log2(("dbgcOperatorLookup: pOp=%p %s\n", pOp, pOp->szName));
NOREF(pDbgc); NOREF(chPrev);
return pOp;
}
|