diff --git a/CMakeLists.txt b/CMakeLists.txt index e726bfbd..4a734e33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,8 +197,11 @@ endif(ENABLE_FFMPEG) SET(SRC_GBA src/gba/agbprint.cpp src/gba/bios.cpp + src/gba/BreakpointStructures.cpp src/gba/Cheats.cpp src/gba/CheatSearch.cpp + src/gba/debugger-expr-lex.cpp + src/gba/debugger-expr-yacc.cpp src/gba/EEprom.cpp src/gba/ereader.cpp src/gba/Flash.cpp @@ -243,7 +246,6 @@ SET(SRC_APU ) SET(SRC_SDL - src/sdl/debugger.cpp src/sdl/SDL.cpp src/sdl/filters.cpp src/sdl/text.cpp diff --git a/project/vc2008_mfc/VBA2008.vcproj b/project/vc2008_mfc/VBA2008.vcproj index f7200b0d..69028815 100644 --- a/project/vc2008_mfc/VBA2008.vcproj +++ b/project/vc2008_mfc/VBA2008.vcproj @@ -446,6 +446,26 @@ RelativePath="..\..\src\gba\bios.h" > + + + + + + + + + + diff --git a/project/vs2010_mfc/VBA2010.vcxproj b/project/vs2010_mfc/VBA2010.vcxproj index 16733b6b..e4afd7c7 100644 --- a/project/vs2010_mfc/VBA2010.vcxproj +++ b/project/vs2010_mfc/VBA2010.vcxproj @@ -110,7 +110,7 @@ AnySuitable Speed ..\..\src;..\..\fex;..\..\..\dependencies\libpng;..\..\..\dependencies\msvc;..\..\..\dependencies\SFML\include;..\..\..\dependencies\SubWCRev;..\..\..\dependencies\zlib;%(AdditionalIncludeDirectories) - WIN32;_WINDOWS;NO_OAL;NDEBUG;GBA_LOGGING;OEMRESOURCE;MMX;ASM;FINAL_VERSION;BKPT_SUPPORT;_CRT_SECURE_NO_DEPRECATE;HAS_FILE_EXTRACTOR;%(PreprocessorDefinitions) + WIN32;_WINDOWS;NDEBUG;GBA_LOGGING;OEMRESOURCE;MMX;ASM;FINAL_VERSION;BKPT_SUPPORT;_CRT_SECURE_NO_DEPRECATE;HAS_FILE_EXTRACTOR;%(PreprocessorDefinitions) MultiThreaded StreamingSIMDExtensions Fast @@ -167,7 +167,9 @@ + + @@ -295,6 +297,9 @@ + + + diff --git a/project/vs2010_mfc/VBA2010.vcxproj.filters b/project/vs2010_mfc/VBA2010.vcxproj.filters index 42e79aec..7c50887e 100644 --- a/project/vs2010_mfc/VBA2010.vcxproj.filters +++ b/project/vs2010_mfc/VBA2010.vcxproj.filters @@ -115,6 +115,12 @@ Core\GBA + + Core\GBA + + + Core\GBA + Core\GBA @@ -484,6 +490,15 @@ Core\GBA + + Core\GBA + + + Core\GBA + + + Core\GBA + Core\GBA diff --git a/project/vs2013_mfc/VBA2013.vcxproj b/project/vs2013_mfc/VBA2013.vcxproj index fa2ffe80..f791178b 100644 --- a/project/vs2013_mfc/VBA2013.vcxproj +++ b/project/vs2013_mfc/VBA2013.vcxproj @@ -174,6 +174,8 @@ + + @@ -302,6 +304,9 @@ + + + diff --git a/project/vs2013_mfc/VBA2013.vcxproj.filters b/project/vs2013_mfc/VBA2013.vcxproj.filters index d4a40f95..9c9dab05 100644 --- a/project/vs2013_mfc/VBA2013.vcxproj.filters +++ b/project/vs2013_mfc/VBA2013.vcxproj.filters @@ -112,6 +112,12 @@ Core\GBA + + Core\GBA + + + Core\GBA + Core\GBA @@ -484,6 +490,15 @@ Core\GBA + + Core\GBA + + + Core\GBA + + + Core\GBA + Core\GBA diff --git a/src/gba/BreakpointStructures.cpp b/src/gba/BreakpointStructures.cpp new file mode 100644 index 00000000..0b74c92d --- /dev/null +++ b/src/gba/BreakpointStructures.cpp @@ -0,0 +1,856 @@ +/*New code made for the new breakpoint system. + +Each breakpoint is now marked by a halfword in an array on map, +breakpoint array. Each bit means one different type of breakpoint. +Bit Value +0 - write +1 - read +2 - ARM +3 - THUMB +4 - Always on Write +5 - Always on Read +6 - Always on ARM +7 - Always on THUMB + +Each flag is independant, and can be used as such, as well as together. +You can define a break on access (0xf), break on IO (0x3), break on +execution(0xc) or any other combination you need. 0xf0 will always break on +any passage through the address + +This structure is accompanied by two other structures for the accesses. +One of them is the Conditional structure. It's available for all types. + +The breaking address header is placed at ConditionalBreak. The type_flags +indicate the type of break, in the format indicated above. +Then, it links to the several conditions needed for the break to take place. + +Those conditions are then sequentially executed, and if all are true, the +break takes place. +They are composed of an address to test, a value to test against, the value's +type, the flag conditons to test and a link to the next condition to test if +that was true. Address and value are stored as Evaluatable expressions, +according to the already defined eval from expr.c +However, be reminded that sometimes registers and memory positions may contain +values that are not addresses at some times. If such is the case, the program +will show garbage results or crash. + +The flags are bit-based +Bit Value +0 - equal +1 - greater +2 - lesser +3 - force Signed comparison + +Bit Value +0,1 - addr is: 00 - byte, 01 - halfword, 10 - word, 11 - undefined, assume word +2 - addr_is_signed +3 - addr_is_array of values (not implemented yet) +4,5 - 00 is byte, 01 is halfword, 10 is word, 11 undefined +6 - val_is_signed +7 - val_is_array (also not implemented) +Usage: +Instructions that accept this kind of implementation will follow this pattern +if [<;>OR<||>OR<&&> [repeat] +if indicates that the following there is a condition. no If counts as always break + is the first value expression, that unlike what the name implies, may be +anything. + is one of the comparation Operands. Full list bellow + is the value to compare to. +Following can be a ||(or), that adds a second, independant break condition, or +a &&(and), that specifies that the next condition is a conjoined requisite to the break. +EX: [0x03005000] == 0x77777777 && 0x50 == [0x03005000] + Would be impossible, but tested anyway, and make it never break due to this condition. + [0x03005000] == 0x77777777 || 0x50 == [0x03005000] + Would make it break when the contents of 0x03005000 were either 0x77777777 or 0x50 + +Ex: to implement stop only when r2 is 0xf, use + if r2 == 0xf + to implement stop when PC is above 0x08005000 and 0x03005000 is signed halfword 0x2500 + if pc > 0x08005000 && 0x03005000 == +0x2500 +*/ + +/* +Full Operands lists +Op1, op2, ...,opN --> Meaning + +== , =, eq --> equal + +<, lt --> lesser than + +<=, le --> less or equal to + +> gt --> greater than + +>=, ge --> greater or equal to + +!=, <>, ne --> not equal to + + +valid content types +b, byte, u8 --> byte +sb, sbyte, s8 --> signed byte +h,hw, halfword, u16, ushort --> halfword +sh, shw, shalfword, s16 short --> signed halfword +w, word, u32 --> word +sw, sword, s32, int --> signed word +*/ + +#include +#include +#include +#include + +#include "BreakpointStructures.h" +#include "remote.h" + +extern bool dexp_eval(char *, u32*); + +//struct intToString{ +// int value; +// char mapping[20]; +//}; + +struct ConditionalBreak* conditionals[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}; + +//struct intToString breakFlagMapping[] = { +// {0x80,"Thumb"}, +// {0x40,"ARM"}, +// {0x20,"Read"}, +// {0x10,"Write"}, +// {0x8,"Thumb"}, +// {0x4,"ARM"}, +// {0x2,"Read"}, +// {0x1,"Write"}, +// {0x0,"None"} +//}; +/* +struct intToString compareFlagMapping[] = { + {0x7,"Always"}, + {0x6,"!="}, + {0x5,"<="}, + {0x4,"<"}, + {0x3,">="}, + {0x2,">"}, + {0x1,"=="}, + {0x0,"Never"} +};*/ + +//char* typeMapping[] = {"'u8","'u16","'u32","'u32","'s8","'s16","'s32","'s32"}; +// +//char* compareFlagMapping[] = {"Never","==",">",">=","<","<=","!=","<=>"}; + + + + +//Constructors + //case '*': flag = 0xf; break; + //case 't': flag = 0x8; break; // thumb + //case 'a': flag = 0x4; break; // arm + //case 'x': flag = 0xC; break; + //case 'r': flag = 0x2; break; // mem read + //case 'w': flag = 0x1; break; // mem write + //case 'i': flag = 0x3; break; +struct ConditionalBreak* addConditionalBreak(u32 address, u8 flag){ + u8 condIndex = address>>24; + struct ConditionalBreak* cond = NULL; + BreakSet((&map[condIndex])->breakPoints,address & (&map[condIndex])->mask,((flag&0xf)|(flag>>4))); + if(flag & 0xf0){ + struct ConditionalBreak* base = conditionals[condIndex]; + struct ConditionalBreak* prev = conditionals[condIndex]; + if(conditionals[condIndex]){ + while((base) && (address >= base->break_address)){ + if(base->break_address == address){ + if(base->type_flags & 0xf0){ + base->type_flags |= (flag&0xf0); + flag &= 0xf; + cond = base; + goto addCB_nextHandle; + }else{ + goto condCreateForFlagAlways; + } + }else{ + prev = base; + base = base->next; + } + } + } +condCreateForFlagAlways: + cond = (struct ConditionalBreak*)malloc(sizeof(struct ConditionalBreak)); + cond->break_address = address; + cond->type_flags = flag&0xf0; + cond->next = base; + cond->firstCond = NULL; + if(prev == conditionals[condIndex]) + conditionals[condIndex] = cond; + else + prev->next = cond; + } + flag &= 0xf; + +addCB_nextHandle: + if(flag == 0) + return cond; + + cond = (struct ConditionalBreak*)malloc(sizeof(struct ConditionalBreak)); + cond->break_address = address; + cond->type_flags = flag; + cond->next = NULL; + cond->firstCond = NULL; + if(conditionals[condIndex] == NULL){ + conditionals[condIndex] = cond; + return cond; + }else{ + struct ConditionalBreak *curr, *prev; + curr = conditionals[condIndex]; + prev = conditionals[condIndex]; + while(curr){ + if(curr->break_address > address){ + if(prev == curr){ + conditionals[condIndex] = cond; + }else{ + prev->next = cond; + } + cond->next = curr; + return cond; + } + prev = curr; + curr = prev->next; + } + prev->next = cond; + return cond; + } +} + + +void addCondition(struct ConditionalBreak* base, struct ConditionalBreakNode* toAdd){ + if(base->firstCond){ + struct ConditionalBreakNode* curr, *prev; + curr = base->firstCond; + prev = base->firstCond; + while(curr){ + prev = curr; + curr = curr->next; + } + prev->next = toAdd; + }else{ + base->firstCond = toAdd; + } +} + +//destructors +void freeConditionalBreak(struct ConditionalBreak* toFree){ + struct ConditionalBreakNode* freeMe; + while(toFree->firstCond){ + freeMe = toFree->firstCond; + toFree->firstCond = toFree->firstCond->next; + free(freeMe); + } + free(toFree); +} + +void freeConditionalNode(struct ConditionalBreakNode* toDel){ + if(toDel->next) + freeConditionalNode(toDel->next); + if(toDel->address) + free(toDel->address); + if(toDel->value) + free(toDel->value); + free(toDel); +} + +void freeAllConditionals(){ + for(int i = 0; i<16; i++){ + while(conditionals[i]){ + struct ConditionalBreak* tmp = conditionals[i]; + conditionals[i] = conditionals[i]->next; + freeConditionalBreak(tmp); + } + } + } + +int removeConditionalBreak(struct ConditionalBreak* toDelete){ + if(toDelete){ + u8 condIndex = toDelete->break_address>>24; + struct ConditionalBreak* base = conditionals[condIndex]; + struct ConditionalBreak* prev = conditionals[condIndex]; + while(base){ + if(base == toDelete){ + if(base == prev){ + conditionals[condIndex] = base->next; + }else{ + prev->next = base->next; + } + freeConditionalBreak(toDelete); + return 0; + } + prev = base; + base = base->next; + } + return -1; //failed to remove + } + return -2; //delete failed because container was not there +} + +/* +int removeConditionalBreak(u32 address, u8 num, u8 flag){ + u8 condIndex = address>>24; + struct ConditionalBreak* base = conditionals[condIndex]; + struct ConditionalBreak* prev = conditionals[condIndex]; + u8 counter = 0; + while(base){ + if(base->break_address > address) + return -2; //failed to remove + if(base->break_address == address){ + counter++; + } + if(counter == num){ + base->type_flags &= ~flag; + if(base->type_flags == 0){ + if(prev == base){ + conditionals[condIndex] = base->next; + }else{ + prev->next = base->next; + } + freeConditionalBreak(base); + return 0; + } + return 1; + } + prev = base; + base = base->next; + } + return -2; +} + +bool removeCondition(struct ConditionalBreak* base, struct ConditionalBreakNode* toDel){ + if(base->firstCond){ + if(toDel == base->firstCond){ + base->firstCond = toDel->next; + freeConditionalNode(toDel); + return true; + } + struct ConditionalBreakNode* curr, *prev; + curr = base->firstCond; + prev = base->firstCond; + while(curr){ + if(curr == toDel){ + prev->next = curr->next; + freeConditionalNode(toDel); + return true; + } + prev = curr; + curr = curr->next; + } + } + freeConditionalNode(toDel); + return false; +} + +bool removeCondition(u32 address, u8 flags, u8 num){ + struct ConditionalBreak* base = conditionals[address>>24]; + while(base && base->break_address < address){ + base = base->next; + } + if(base && base->break_address == address){ + struct ConditionalBreakNode* curr = base->firstCond; + for(int i = 0; i < num; i++){ + if(!curr && ((!base) || (!base->next))){ + return false; + }if(!curr){ + while(!curr){ + base = base->next; + if(base->break_address > address) + return false; + + curr = base->firstCond; + } + } + } + } +}*/ + +/* +int removeAllConditions(u32 address, u8 flags){ + struct ConditionalBreak* base = conditionals[address>>24]; + while(base && base->break_address < address){ + base = base->next; + } + struct ConditionalBreak* curr = base; + while(base && base->break_address == address){ + base->type_flags &= ~flags; + if(!base->type_flags){ + curr = base; + base = base->next; + removeCondition(base); + } + } + return true; +}*/ + +void recountFlagsForAddress(u32 address){ + struct ConditionalBreak* base = conditionals[address>>24]; + u8 flags = 0; + while(base){ + if(base->break_address < address){ + base = base->next; + }else{ + if(base->break_address == address){ + flags |= base->type_flags; + }else{ + BreakClear((&map[address>>24])->breakPoints,address & (&map[address>>24])->mask,0xff); + BreakSet((&map[address>>24])->breakPoints,address & (&map[address>>24])->mask,((flags>>4) | (flags&0x8))); + return; + } + base = base->next; + } + } + BreakClear((&map[address>>24])->breakPoints,address & (&map[address>>24])->mask,0xff); + BreakSet((&map[address>>24])->breakPoints,address & (&map[address>>24])->mask,((flags>>4) | (flags&0x8))); +} + + +//Removers +int removeConditionalBreakNo(u32 addrNo, u8 number){ +if(conditionals[addrNo>>24]){ + struct ConditionalBreak* base = conditionals[addrNo>>24]; + struct ConditionalBreak* curr = conditionals[addrNo>>24]; + u8 count = 1; + while (curr->break_address < addrNo){ + base = curr; + curr = curr->next; + } + if(curr->break_address == addrNo){ + if(number == 1){ + if(base == curr){ + conditionals[addrNo>>24] = curr->next; + freeConditionalBreak(curr); + }else{ + base->next = curr->next; + freeConditionalBreak(curr); + } + recountFlagsForAddress(addrNo); + return 0; + }else{ + int count = 1; + while(curr && (curr->break_address == addrNo)){ + if(count == number){ + base->next = curr->next; + freeConditionalBreak(curr); + recountFlagsForAddress(addrNo); + return 1; + } + count++; + base = curr; + curr = curr->next; + } + return -1; + } + } + } + return -2; +} + +int removeFlagFromConditionalBreakNo(u32 addrNo, u8 number, u8 flag){ + if(conditionals[addrNo>>24]){ + struct ConditionalBreak* base = conditionals[addrNo>>24]; + struct ConditionalBreak* curr = conditionals[addrNo>>24]; + u8 count = 1; + while (curr->break_address < addrNo){ + base = curr; + curr = curr->next; + } + if(curr->break_address == addrNo){ + if(number == 1){ + curr->type_flags &= ~flag; + if(curr->type_flags == 0){ + if(base == curr){ + conditionals[addrNo>>24] = curr->next; + freeConditionalBreak(curr); + }else{ + base->next = curr->next; + freeConditionalBreak(curr); + } + } + recountFlagsForAddress(addrNo); + return 0; + }else{ + int count = 1; + while(curr && (curr->break_address == addrNo)){ + if(count == number){ + curr->type_flags &= ~flag; + if(!curr->type_flags){ + base->next = curr->next; + freeConditionalBreak(curr); + recountFlagsForAddress(addrNo); + return 1; + } + recountFlagsForAddress(addrNo); + return 0; + } + count++; + base = curr; + curr = curr->next; + } + return -1; + } + } + } + return -2; +} + +int removeConditionalWithAddress(u32 address){ + u8 addrNo = address>>24; + if(conditionals[addrNo] != NULL){ + struct ConditionalBreak* base = conditionals[addrNo]; + struct ConditionalBreak* curr = conditionals[addrNo]; + u8 count = 0; + u8 flags = 0; + while(curr && address >= curr->break_address){ + if(curr->break_address == address){ + base->next = curr->next; + flags |= curr->type_flags; + freeConditionalBreak(curr); + curr = base->next; + count++; + }else{ + base = curr; + curr = curr->next; + } + } + BreakClear((&map[address>>24])->breakPoints,address & (&map[address>>24])->mask,((flags&0xf)|(flags>>4))); + return count; + } + return -2; +} + +int removeConditionalWithFlag(u8 flag, bool orMode){ + for(u8 addrNo = 0; addrNo < 16;addrNo++){ + if(conditionals[addrNo] != NULL){ + struct ConditionalBreak* base = conditionals[addrNo]; + struct ConditionalBreak* curr = conditionals[addrNo]; + u8 count = 0; + while(curr){ + if(((curr->type_flags & flag) == curr->type_flags) || (orMode && (curr->type_flags & flag))){ + curr->type_flags &= ~flag; + BreakClear((&map[addrNo])->breakPoints,curr->break_address & (&map[addrNo])->mask,((flag&0xf)|(flag>>4))); + if(curr->type_flags == 0){ + if(base == conditionals[addrNo]){ + conditionals[addrNo]= curr->next; + base = curr->next; + curr = base; + } + else{ + base->next = curr->next; + freeConditionalBreak(curr); + curr = base->next; + } + count++; + }else{ + base = curr; + curr = curr->next; + } + }else{ + base = curr; + curr = curr->next; + } + } + return count; + } + } + return -2; +} + +int removeConditionalWithAddressAndFlag(u32 address, u8 flag, bool orMode){ + u8 addrNo = address>>24; + if(conditionals[addrNo] != NULL){ + struct ConditionalBreak* base = conditionals[addrNo]; + struct ConditionalBreak* curr = conditionals[addrNo]; + u8 count = 0; + while(curr && address >= curr->break_address){ + if((curr->break_address == address) && + (((curr->type_flags & flag) == curr->type_flags) || (orMode && (curr->type_flags & flag)))){ + curr->type_flags &= ~flag; + BreakClear((&map[address>>24])->breakPoints,curr->break_address & (&map[address>>24])->mask,((flag&0xf)|(flag>>4))); + if(curr->type_flags == 0){ + if(curr == conditionals[addrNo]){ + conditionals[addrNo] = curr->next; + freeConditionalBreak(curr); + curr = conditionals[addrNo]; + } + else{ + base->next = curr->next; + freeConditionalBreak(curr); + curr = base->next; + } + count++; + }else{ + base = curr; + curr = curr->next; + } + }else{ + base = curr; + curr = curr->next; + } + } + return count; + } + return -2; +} + + + +//true creating code for a given expression. +//It assumes an if was found, and that all up to the if was removed. +//receives an array of chars following the pattern: +//{',,,',,, (repeats) +//next = 0; + now->exp_type_flags = 0; + if(exp[i][0] == '\''){ + now->exp_type_flags |= parseExpressionType(&exp[i][1]); + i++; + if(i >= n) goto fail; + }else{ + now->exp_type_flags |= 6; //assume signed word + } + now->address = strdup(exp[i]); + i++; + if(i >= n) goto fail; + char* operandName = exp[i]; + now->cond_flags = parseConditionOperand(exp[i]); + i++; + if(i >= n) goto fail; + + if(exp[i][0] == '\''){ + now->exp_type_flags |= (parseExpressionType(&exp[i][1])<<4); + i++; + if(i >= n) goto fail; + }else{ + now->exp_type_flags |= 0x60; //assume signed word + } + now->value = strdup(exp[i]); + i++; + u32 val; + if(!dexp_eval(now->value, &val) || !dexp_eval(now->address, &val)){ + printf("Invalid expression.\n"); + if(workBreak) + removeConditionalBreak(workBreak); + return; + } + if(i < n){ + if(strcmp(exp[i], "&&") == 0){ + now = (struct ConditionalBreakNode*)malloc(sizeof(struct ConditionalBreakNode)); + toAdd->next = now; + }else if (strcmp(exp[i], "||") == 0){ + addCondition(workBreak,toAdd); + printf("Added break on address %08x, with condition:\n%s %s %s\n", address, now->address, operandName,now->value); + workBreak = addConditionalBreak(address, flags); + now = (struct ConditionalBreakNode*)malloc(sizeof(struct ConditionalBreakNode)); + toAdd = now; + } + }else{ + addCondition(workBreak,toAdd); + printf("Added break on address %08x, ending with condition: \n%s %s %s\n", address, now->address, operandName,now->value); + return; + } + } + return; + + fail: + printf("Not enough material (expressions) to work with."); + removeConditionalBreak(workBreak); + return; +} + +//aux +u8 parseExpressionType(char* given_type){ + u8 flags = 0; + //for such a small string, pays off to convert first + char* type = strdup(given_type); + for(int i = 0; type[i] != '\0'; i++){ + type[i] = toupper(type[i]); + } + if((type[0] == 'S') || type[0] == 'U'){ + flags |= (4 - ((type[0]-'S')<<1)); + type++; + if(type[0] == 'H'){ + type[0] = '1'; + type[1] = '6'; + type[2] = '\0'; + }else if(type[0] == 'W'){ + type[0] = '3'; + type[1] = '2'; + type[2] = '\0'; + }else if(type[0] == 'B'){ + type[0] = '8'; + type[1] = '\0'; + } + int size; + sscanf(type, "%d",&size); + size = (size>>3) - 1; + flags |= (size >= 2 ? 2: ((u8)size)); + free(type); + return flags; + } + if(strcmp(type, "INT")==0){ + flags = 6; + } + if(type[0] == 'H'){ + flags = 1; + }else if(type[0] == 'W'){ + flags = 2; + }else if(type[0] == 'B'){ + flags = 0; + }else{ + flags = 6; + } + free(type); + return flags; +} + +u8 parseConditionOperand(char* type){ + u8 flag = 0; + if(toupper(type[0]) == 'S'){ + flag = 8; + type++; + } + switch(type[0]){ + case '!': if(type[1] == '=' || type[1] == '\0') + return flag | 0x6; + break; + case '=': if(type[1] == '=' || type[1] == '\0') + return flag | 0x1; + break; + case '<': if(type[1] == '>') + return flag | 0x6; + if(type[1] == '=') + return flag | 0x5; + if(type[1] == '\0') + return flag | 0x4; + break; + case '>': if(type[1] == '<') + return flag | 0x6; + if(type[1] == '=') + return flag | 0x3; + if(type[1] == '\0') + return flag | 0x2; + break; + default: ; + } + switch(tolower(type[0])){ + case 'l': if(tolower(type[1]) == 'e') + return flag | 0x5; + if(tolower(type[1]) == 't') + return flag | 0x4; + break; + case 'g': if(tolower(type[1]) == 'e') + return flag | 0x3; + if(tolower(type[1]) == 't') + return flag | 0x2; + + case 'e': if(tolower(type[1]) == 'q') + return flag | 0x1; + if(type[1] == '\0') + return flag | 0x1; + case 'n': if(tolower(type[1]) == 'e') + return flag | 0x6; + default:; + } + return flag; +} + +u32 calculateFinalValue(char* expToEval, u8 type_of_flags){ + u32 val; + if(!dexp_eval(expToEval, &val)){ + printf("Invalid expression.\n"); + return 0; + } + if(type_of_flags&0x4){ + switch(type_of_flags&0x3){ + case 0: return (s8)(val&0xff); + case 1: return (s16)(val&0xffff); + default: return (int)val; + } + }else{ + switch(type_of_flags&0x3){ + case 0: return (u8)(val&0xff); + case 1: return (u16)(val&0xffff); + default: return val; + } + } +} + +//check for execution +bool isCorrectBreak(struct ConditionalBreak* toTest, u8 accessType){ + + return (toTest->type_flags & accessType); +} + + +bool doBreak(struct ConditionalBreak* toTest){ + struct ConditionalBreakNode* toExamine = toTest->firstCond; + + bool globalVeredict = true; + bool veredict = false; + while(toExamine && globalVeredict){ + u32 address = calculateFinalValue(toExamine->address, toExamine->exp_type_flags&0xf); + u32 value = calculateFinalValue(toExamine->value, toExamine->exp_type_flags>>4); + if((toExamine->cond_flags &0x7) != 0){ + veredict = veredict || ((toExamine->cond_flags&1)? (address == value):false); + veredict = veredict || ((toExamine->cond_flags&4)? ((toExamine->cond_flags&8)? ((int)address < (int)value) : (address < value)) : false); + veredict = veredict || ((toExamine->cond_flags&2)? ((toExamine->cond_flags&8)? ((int)address > (int)value) : (address > value)) : false); + } + toExamine = toExamine->next; + globalVeredict = veredict && globalVeredict; + + } + return globalVeredict; +} + +bool doesBreak(u32 address, u8 allowedFlags){ + u8 addrNo = address>>24; + if(conditionals[addrNo]){ + struct ConditionalBreak* base = conditionals[addrNo]; + while(base && base->break_address < address){ + base = base->next; + } + while(base && base->break_address == address){ + if(base->type_flags & allowedFlags &0xf0){ + return true; + } + if(isCorrectBreak(base,allowedFlags) && doBreak(base)){ + return true; + } + base = base->next; + } + } + return false; +} + +/* +//Test main +int main (int argc, char** args){ + char* argv[] = {"r7","s==","0", "||","'byte","0x25","ge","'hword","0x0001"}; + parseAndCreateConditionalBreaks(0x0203fd00, 0x1f, argv, 9); + parseAndCreateConditionalBreaks(0x0203fd00, 0x10, argv, 9); + parseAndCreateConditionalBreaks(0x0203fd00, 0x40, argv, 9); + parseAndCreateConditionalBreaks(0x0203fd04, 0x04, argv, 9); + printAllFlagConditionals(0xff, true); + removeFlagFromConditionalBreakNo(0x0203fd00, 0x3,0xff); + printf("after\n"); + printAllFlagConditionals(0xff, true); + + getchar(); +} +*/ diff --git a/src/gba/BreakpointStructures.h b/src/gba/BreakpointStructures.h new file mode 100644 index 00000000..32203ace --- /dev/null +++ b/src/gba/BreakpointStructures.h @@ -0,0 +1,73 @@ +#ifndef VBA_BKS_H +#define VBA_BKS_H + +#include "../common/Types.h" + +#define readWord(addr) \ + ((map[(addr)>>24].address[(addr) & map[(addr)>>24].mask])+\ + ((map[(addr+1)>>24].address[(addr+1) & map[(addr+1)>>24].mask])<<8)+\ + ((map[(addr+2)>>24].address[(addr+2) & map[(addr+2)>>24].mask])<<16)+\ + ((map[(addr+3)>>24].address[(addr+3) & map[(addr+3)>>24].mask])<<24)) + +#define readHalfWord(addr) \ + ((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask])+\ + ((&map[(addr+1)>>24].address[(addr+1) & map[(addr+1)>>24].mask])<<8)) + +#define readByte(addr) \ + map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] + + +struct ConditionalBreakNode{ + char* address; + char* value; + u8 cond_flags; + u8 exp_type_flags; + struct ConditionalBreakNode* next; +}; + +struct ConditionalBreak{ + u32 break_address; + u8 type_flags; + struct ConditionalBreakNode* firstCond; + struct ConditionalBreak* next; +}; + +extern struct ConditionalBreak* conditionals[16]; + +//conditional break manipulators +//case '*': flag = 0xf; break; +//case 't': flag = 0x8; break; // thumb +//case 'a': flag = 0x4; break; // arm +//case 'x': flag = 0xC; break; +//case 'r': flag = 0x2; break; // mem read +//case 'w': flag = 0x1; break; // mem write +//case 'i': flag = 0x3; break; +struct ConditionalBreak* addConditionalBreak(u32 address, u8 flag); + +int removeConditionalBreakNo(u32 address, u8 number); +int removeFlagFromConditionalBreakNo(u32 address, u8 number, u8 flag); +int removeConditionalWithAddress(u32 address); +int removeConditionalWithFlag(u8 flag, bool orMode); +int removeConditionalWithAddressAndFlag(u32 address, u8 flag, bool orMode); +//void freeConditionalBreak(struct ConditionalBreak* toFree); + +void addCondition(struct ConditionalBreak* base, struct ConditionalBreakNode* toAdd); +//bool removeCondition(struct ConditionalBreak* base, struct ConditionalBreakNode* toDel); +//bool removeCondition(u32 address, u8 flags, u8 num); + +void freeConditionalNode(struct ConditionalBreakNode* toDel); + + +void parseAndCreateConditionalBreaks(u32 address, u8 flags, char** exp, int n); + +bool isCorrectBreak(struct ConditionalBreak* toTest, u8 accessType); +bool doesBreak(u32 address, u8 allowedFlags); +bool doBreak(struct ConditionalBreak* toTest); + +//printing the structure(AKA list Breaks) +//void printConditionalBreak(struct ConditionalBreak* toPrint, bool printAddress); +//void printAllConditionals(); +//u8 printConditionalsFromAddress(u32 address); +//void printAllFlagConditionals(u8 flag, bool orMode); +//void printAllFlagConditionalsWithAddress(u32 address, u8 flag, bool orMode); +#endif \ No newline at end of file diff --git a/src/gba/Cheats.cpp b/src/gba/Cheats.cpp index 0288800b..834d279c 100644 --- a/src/gba/Cheats.cpp +++ b/src/gba/Cheats.cpp @@ -2846,7 +2846,6 @@ static u8 cheatsGetType(u32 address) void cheatsWriteMemory(u32 address, u32 value) { #ifdef BKPT_SUPPORT -#ifdef SDL if(cheatsNumber == 0) { int type = cheatsGetType(address); u32 oldValue = debuggerReadMemory(address); @@ -2857,13 +2856,11 @@ void cheatsWriteMemory(u32 address, u32 value) debuggerWriteMemory(address, value); } #endif -#endif } void cheatsWriteHalfWord(u32 address, u16 value) { #ifdef BKPT_SUPPORT -#ifdef SDL if(cheatsNumber == 0) { int type = cheatsGetType(address); u16 oldValue = debuggerReadHalfWord(address); @@ -2874,17 +2871,11 @@ void cheatsWriteHalfWord(u32 address, u16 value) debuggerWriteHalfWord(address, value); } #endif -#endif } -#if defined BKPT_SUPPORT && defined SDL void cheatsWriteByte(u32 address, u8 value) -#else -void cheatsWriteByte(u32, u8) -#endif { #ifdef BKPT_SUPPORT -#ifdef SDL if(cheatsNumber == 0) { int type = cheatsGetType(address); u8 oldValue = debuggerReadByte(address); @@ -2895,6 +2886,5 @@ void cheatsWriteByte(u32, u8) debuggerWriteByte(address, value); } #endif -#endif } #endif diff --git a/src/gba/GBA-arm.cpp b/src/gba/GBA-arm.cpp index 732f4474..b0633ca7 100644 --- a/src/gba/GBA-arm.cpp +++ b/src/gba/GBA-arm.cpp @@ -19,6 +19,8 @@ #include "../Util.h" #include "../System.h" #include "agbprint.h" +#include "remote.h" + #ifdef PROFILING #include "prof/prof.h" #endif @@ -2890,8 +2892,20 @@ int armExecute() #endif armNextPC = reg[15].I; - reg[15].I += 4; - ARM_PREFETCH_NEXT; + reg[15].I += 4; + ARM_PREFETCH_NEXT; + +#ifdef BKPT_SUPPORT + u32 memAddr = armNextPC; + memoryMap *m = &map[memAddr >> 24]; + if (m->breakPoints && BreakARMCheck(m->breakPoints, memAddr & m->mask)) { + if (debuggerBreakOnExecution(memAddr, armState)){ + // Revert tickcount? + debugger = true; + return 0; + } + } +#endif int cond = opcode >> 28; bool cond_res = true; @@ -2955,13 +2969,50 @@ int armExecute() #ifdef INSN_COUNTER count(opcode, cond_res); #endif + +#ifdef BKPT_SUPPORT + if (enableRegBreak){ + if (lowRegBreakCounter[0]) + breakReg_check(0); + if (lowRegBreakCounter[1]) + breakReg_check(1); + if (lowRegBreakCounter[2]) + breakReg_check(2); + if (lowRegBreakCounter[3]) + breakReg_check(3); + if (medRegBreakCounter[0]) + breakReg_check(4); + if (medRegBreakCounter[1]) + breakReg_check(5); + if (medRegBreakCounter[2]) + breakReg_check(6); + if (medRegBreakCounter[3]) + breakReg_check(7); + if (highRegBreakCounter[0]) + breakReg_check(8); + if (highRegBreakCounter[1]) + breakReg_check(9); + if (highRegBreakCounter[2]) + breakReg_check(10); + if (highRegBreakCounter[3]) + breakReg_check(11); + if (statusRegBreakCounter[0]) + breakReg_check(12); + if (statusRegBreakCounter[1]) + breakReg_check(13); + if (statusRegBreakCounter[2]) + breakReg_check(14); + if (statusRegBreakCounter[3]) + breakReg_check(15); + } +#endif if (clockTicks < 0) return 0; if (clockTicks == 0) clockTicks = 1 + codeTicksAccessSeq32(oldArmNextPC); cpuTotalTicks += clockTicks; - } while (cpuTotalTicks> 24]; + if (m->breakPoints && BreakThumbCheck(m->breakPoints, memAddr & m->mask)) { + if (debuggerBreakOnExecution(memAddr, armState)){ + // Revert tickcount? + debugger = true; + return 0 ; + } + } +#endif + (*thumbInsnTable[opcode>>6])(opcode); + +#ifdef BKPT_SUPPORT + if (enableRegBreak){ + if (lowRegBreakCounter[0]) + breakReg_check(0); + if (lowRegBreakCounter[1]) + breakReg_check(1); + if (lowRegBreakCounter[2]) + breakReg_check(2); + if (lowRegBreakCounter[3]) + breakReg_check(3); + if (medRegBreakCounter[0]) + breakReg_check(4); + if (medRegBreakCounter[1]) + breakReg_check(5); + if (medRegBreakCounter[2]) + breakReg_check(6); + if (medRegBreakCounter[3]) + breakReg_check(7); + if (highRegBreakCounter[0]) + breakReg_check(8); + if (highRegBreakCounter[1]) + breakReg_check(9); + if (highRegBreakCounter[2]) + breakReg_check(10); + if (highRegBreakCounter[3]) + breakReg_check(11); + if (statusRegBreakCounter[0]) + breakReg_check(12); + if (statusRegBreakCounter[1]) + breakReg_check(13); + if (statusRegBreakCounter[2]) + breakReg_check(14); + if (statusRegBreakCounter[3]) + breakReg_check(15); + } +#endif + if (clockTicks < 0) return 0; if (clockTicks==0) clockTicks = codeTicksAccessSeq16(oldArmNextPC) + 1; cpuTotalTicks += clockTicks; - } while (cpuTotalTicks < cpuNextEvent && !armState && !holdState && !SWITicks); + } while (cpuTotalTicks < cpuNextEvent && !armState && !holdState && !SWITicks && !debugger); return 1; } diff --git a/src/gba/GBA.cpp b/src/gba/GBA.cpp index 6009dbbf..775e87c8 100644 --- a/src/gba/GBA.cpp +++ b/src/gba/GBA.cpp @@ -32,6 +32,7 @@ #endif extern int emulating; +bool debugger; int SWITicks = 0; int IRQTicks = 0; @@ -1600,6 +1601,40 @@ int CPULoadRom(const char *szFile) CPUUpdateRenderBuffers(true); +#ifdef BKPT_SUPPORT + map[0].size = 0x4000; + map[1].size = 0x0; + map[2].size = 0x40000; + map[3].size = 0x8000; + map[4].size = 0x400; + map[5].size = 0x400; + map[6].size = 0x18000; + map[7].size = 0x400; + map[8].size = 0x01000000; + map[9].size = 0x01000000; + map[14].size = 0x10000; + + for (int i = 0; i < 16; i++) { + if (map[i].size > 0) { + map[i].trace = (u8 *)calloc(map[i].size >> 3, sizeof(u8)); + + map[i].breakPoints = (u8 *)calloc(map[i].size >> 1, sizeof(u8)); //\\ + + if (map[i].trace == NULL || map[i].breakPoints == NULL) { + systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"), + "TRACE"); + } + } + else { + map[i].trace = NULL; + map[i].breakPoints = NULL; //\\ + + } + } + clearBreakRegList(); + +#endif + return romSize; } @@ -3644,6 +3679,7 @@ void CPULoop(int ticks) { int clockTicks; int timerOverflow = 0; + u32 memAddr = 0; // variable used by the CPU core cpuTotalTicks = 0; @@ -3690,10 +3726,14 @@ void CPULoop(int ticks) armOpcodeCount++; if (!armExecute()) return; + if (debugger) + return; } else { thumbOpcodeCount++; if (!thumbExecute()) return; + if (debugger) + return; } clockTicks = 0; } else diff --git a/src/gba/GBA.h b/src/gba/GBA.h index 5feca67c..5a94c757 100644 --- a/src/gba/GBA.h +++ b/src/gba/GBA.h @@ -18,6 +18,12 @@ typedef struct { u8 *address; u32 mask; +#ifdef BKPT_SUPPORT + u8 *breakPoints; + u8 *searchMatch; + u8* trace; + u32 size; +#endif } memoryMap; typedef union { @@ -54,16 +60,8 @@ typedef union { extern memoryMap map[256]; #endif -extern reg_pair reg[45]; extern u8 biosProtected[4]; -extern bool N_FLAG; -extern bool Z_FLAG; -extern bool C_FLAG; -extern bool V_FLAG; -extern bool armIrqEnable; -extern bool armState; -extern int armMode; extern void (*cpuSaveGameFunc)(u32,u8); #ifdef BKPT_SUPPORT @@ -75,6 +73,7 @@ extern u8 freezePRAM[0x400]; extern bool debugger_last; extern int oldreg[18]; extern char oldbuffer[10]; +extern bool debugger; #endif extern bool CPUReadGSASnapshot(const char *); diff --git a/src/gba/GBAinline.h b/src/gba/GBAinline.h index 5fc97928..5bfced85 100644 --- a/src/gba/GBAinline.h +++ b/src/gba/GBAinline.h @@ -8,6 +8,7 @@ #include "agbprint.h" #include "GBAcpu.h" #include "GBALink.h" +#include "remote.h" extern const u32 objTilesAddress[3]; @@ -44,8 +45,18 @@ extern int cpuTotalTicks; #define CPUReadMemoryQuick(addr) \ READ32LE(((u32*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask])) +extern u32 myROM[]; + static inline u32 CPUReadMemory(u32 address) { +#ifdef BKPT_SUPPORT + memoryMap *m = &map[address >> 24]; + if (m->breakPoints && BreakReadCheck(m->breakPoints, address & m->mask)) { + if (debuggerBreakOnRead(address, 2)){ + //CPU_BREAK_LOOP_2; + } + } +#endif u32 value; u32 oldAddress = address; @@ -184,10 +195,17 @@ unreadable: return value; } -extern u32 myROM[]; - static inline u32 CPUReadHalfWord(u32 address) { +#ifdef BKPT_SUPPORT + memoryMap *m = &map[address >> 24]; + if (m->breakPoints && BreakReadCheck(m->breakPoints, address & m->mask)) { + if (debuggerBreakOnRead(address, 1)){ + //CPU_BREAK_LOOP_2; + } + } +#endif + u32 value; u32 oldAddress = address; @@ -334,6 +352,15 @@ static inline s16 CPUReadHalfWordSigned(u32 address) static inline u8 CPUReadByte(u32 address) { +#ifdef BKPT_SUPPORT + memoryMap *m = &map[address >> 24]; + if (m->breakPoints && BreakReadCheck(m->breakPoints, address & m->mask)) { + if (debuggerBreakOnRead(address, 0)){ + //CPU_BREAK_LOOP_2; + } + } +#endif + switch(address >> 24) { case 0: if (reg[15].I >> 24) { @@ -428,6 +455,15 @@ static inline void CPUWriteMemory(u32 address, u32 value) } #endif +#ifdef BKPT_SUPPORT + memoryMap *m = &map[address >> 24]; + if (m->breakPoints && BreakWriteCheck(m->breakPoints, address & m->mask)) { + if (debuggerBreakOnWrite(address, value, 1)){ + //CPU_BREAK_LOOP_2; + } + } +#endif + address &= 0xFFFFFFFC; switch(address >> 24) { @@ -528,6 +564,15 @@ static inline void CPUWriteHalfWord(u32 address, u16 value) } #endif +#ifdef BKPT_SUPPORT + memoryMap *m = &map[address >> 24]; + if (m->breakPoints && BreakWriteCheck(m->breakPoints, address & m->mask)) { + if (debuggerBreakOnWrite(address, value, 1)){ + //CPU_BREAK_LOOP_2; + } + } +#endif + address &= 0xFFFFFFFE; switch(address >> 24) { @@ -622,6 +667,15 @@ unwritable: static inline void CPUWriteByte(u32 address, u8 b) { +#ifdef BKPT_SUPPORT + memoryMap *m = &map[address >> 24]; + if (m->breakPoints && BreakWriteCheck(m->breakPoints, address & m->mask)) { + if (debuggerBreakOnWrite(address, b, 1)){ + //CPU_BREAK_LOOP_2; + } + } +#endif + switch(address >> 24) { case 2: #ifdef BKPT_SUPPORT diff --git a/src/gba/debugger-expr-lex.c b/src/gba/debugger-expr-lex.c new file mode 100644 index 00000000..6df02371 --- /dev/null +++ b/src/gba/debugger-expr-lex.c @@ -0,0 +1 @@ +#include "debugger-expr-lex.cpp" \ No newline at end of file diff --git a/src/gba/debugger-expr-lex.cpp b/src/gba/debugger-expr-lex.cpp new file mode 100644 index 00000000..70cba369 --- /dev/null +++ b/src/gba/debugger-expr-lex.cpp @@ -0,0 +1,1970 @@ +#line 2 "debugger-expr-lex.cpp" + +#line 4 "debugger-expr-lex.cpp" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define yy_create_buffer dexp__create_buffer +#define yy_delete_buffer dexp__delete_buffer +#define yy_flex_debug dexp__flex_debug +#define yy_init_buffer dexp__init_buffer +#define yy_flush_buffer dexp__flush_buffer +#define yy_load_buffer_state dexp__load_buffer_state +#define yy_switch_to_buffer dexp__switch_to_buffer +#define yyin dexp_in +#define yyleng dexp_leng +#define yylex dexp_lex +#define yylineno dexp_lineno +#define yyout dexp_out +#define yyrestart dexp_restart +#define yytext dexp_text +#define yywrap dexp_wrap +#define yyalloc dexp_alloc +#define yyrealloc dexp_realloc +#define yyfree dexp_free + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE dexp_restart(dexp_in ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +extern int dexp_leng; + +extern FILE *dexp_in, *dexp_out; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up dexp_text. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up dexp_text again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via dexp_restart()), so that the user can continue scanning by + * just pointing dexp_in at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when dexp_text is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int dexp_leng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow dexp_wrap()'s to do buffer switches + * instead of setting up a fresh dexp_in. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void dexp_restart (FILE *input_file ); +void dexp__switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE dexp__create_buffer (FILE *file,int size ); +void dexp__delete_buffer (YY_BUFFER_STATE b ); +void dexp__flush_buffer (YY_BUFFER_STATE b ); +void dexp_push_buffer_state (YY_BUFFER_STATE new_buffer ); +void dexp_pop_buffer_state (void ); + +static void dexp_ensure_buffer_stack (void ); +static void dexp__load_buffer_state (void ); +static void dexp__init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER dexp__flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE dexp__scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE dexp__scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE dexp__scan_bytes (yyconst char *bytes,int len ); + +void *dexp_alloc (yy_size_t ); +void *dexp_realloc (void *,yy_size_t ); +void dexp_free (void * ); + +#define yy_new_buffer dexp__create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + dexp_ensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + dexp__create_buffer(dexp_in,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + dexp_ensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + dexp__create_buffer(dexp_in,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +#define dexp_wrap(n) 1 +#define YY_SKIP_YYWRAP + +typedef unsigned char YY_CHAR; + +FILE *dexp_in = (FILE *) 0, *dexp_out = (FILE *) 0; + +typedef int yy_state_type; + +extern int dexp_lineno; + +int dexp_lineno = 1; + +extern char *dexp_text; +#define yytext_ptr dexp_text + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up dexp_text. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + dexp_leng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 30 +#define YY_END_OF_BUFFER 31 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[51] = + { 0, + 0, 0, 31, 28, 30, 27, 25, 28, 23, 20, + 21, 17, 14, 15, 16, 11, 10, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 9, 8, 24, 28, + 22, 26, 13, 11, 0, 10, 18, 19, 29, 5, + 6, 3, 4, 2, 7, 1, 1, 1, 12, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 3, 4, 1, 1, 5, 1, 6, 1, 7, + 8, 9, 10, 1, 11, 1, 12, 13, 14, 15, + 15, 15, 15, 16, 16, 16, 16, 1, 1, 17, + 1, 18, 1, 1, 19, 20, 21, 19, 19, 19, + 22, 23, 22, 22, 22, 24, 22, 22, 22, 25, + 22, 26, 27, 22, 22, 22, 28, 29, 22, 22, + 30, 1, 31, 32, 22, 1, 19, 20, 21, 19, + + 19, 19, 22, 23, 22, 22, 22, 24, 22, 22, + 22, 25, 22, 33, 27, 22, 22, 22, 28, 29, + 22, 22, 1, 34, 1, 35, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[36] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 2, 2, 2, 1, 1, 2, 2, + 2, 3, 3, 3, 3, 3, 3, 3, 4, 1, + 1, 1, 3, 1, 1 + } ; + +static yyconst flex_int16_t yy_base[55] = + { 0, + 0, 0, 71, 72, 72, 72, 72, 0, 72, 72, + 72, 72, 72, 72, 72, 41, 23, 52, 50, 0, + 37, 36, 14, 44, 39, 33, 72, 72, 72, 28, + 72, 72, 0, 33, 0, 35, 72, 72, 0, 72, + 72, 0, 0, 0, 72, 32, 39, 0, 0, 72, + 55, 54, 57, 52 + } ; + +static yyconst flex_int16_t yy_def[55] = + { 0, + 50, 1, 50, 50, 50, 50, 50, 51, 50, 50, + 50, 50, 50, 50, 50, 52, 50, 50, 50, 53, + 53, 53, 53, 53, 53, 53, 50, 50, 50, 53, + 50, 50, 51, 52, 54, 50, 50, 50, 53, 50, + 50, 53, 53, 53, 50, 30, 30, 53, 54, 0, + 50, 50, 50, 50 + } ; + +static yyconst flex_int16_t yy_nxt[108] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 17, 17, 18, 19, 20, 21, + 20, 20, 22, 23, 24, 20, 25, 26, 20, 27, + 28, 29, 30, 31, 32, 36, 36, 36, 36, 42, + 46, 47, 48, 48, 48, 48, 42, 36, 36, 36, + 36, 48, 48, 49, 39, 34, 33, 34, 39, 39, + 39, 50, 45, 44, 43, 41, 40, 38, 37, 35, + 50, 3, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + + 50, 50, 50, 50, 50, 50, 50 + } ; + +static yyconst flex_int16_t yy_chk[108] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 17, 17, 17, 17, 23, + 30, 30, 30, 30, 46, 46, 23, 36, 36, 36, + 36, 47, 47, 54, 47, 52, 51, 52, 53, 53, + 53, 34, 26, 25, 24, 22, 21, 19, 18, 16, + 3, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + + 50, 50, 50, 50, 50, 50, 50 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int dexp__flex_debug; +int dexp__flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *dexp_text; +#line 1 "debugger-expr.l" +#line 2 "debugger-expr.l" +#include +#include +#include "debugger-expr-yacc.hpp" + +#ifdef _MSC_VER +#define YY_NO_UNISTD_H +#include +#define isatty _isatty +#endif + +extern YYSTYPE dexp_lval; + +char *dexprString; +int dexprCol; + +#define YY_INPUT(buf,result,max_size) \ + { \ + int c = *dexprString++; \ + dexprCol++;\ + result = (c == 0) ? YY_NULL : (buf[0] = c, 1); \ + } + +#line 543 "debugger-expr-lex.cpp" + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int dexp_lex_destroy (void ); + +int dexp_get_debug (void ); + +void dexp_set_debug (int debug_flag ); + +YY_EXTRA_TYPE dexp_get_extra (void ); + +void dexp_set_extra (YY_EXTRA_TYPE user_defined ); + +FILE *dexp_get_in (void ); + +void dexp_set_in (FILE * in_str ); + +FILE *dexp_get_out (void ); + +void dexp_set_out (FILE * out_str ); + +int dexp_get_leng (void ); + +char *dexp_get_text (void ); + +int dexp_get_lineno (void ); + +void dexp_set_lineno (int line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int dexp_wrap (void ); +#else +extern int dexp_wrap (void ); +#endif +#endif + + static void yyunput (int c,char *buf_ptr ); + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( dexp_text, dexp_leng, 1, dexp_out )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( dexp_in )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( dexp_in ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, dexp_in))==0 && ferror(dexp_in)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(dexp_in); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int dexp_lex (void); + +#define YY_DECL int dexp_lex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after dexp_text and dexp_leng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 31 "debugger-expr.l" + +#line 732 "debugger-expr-lex.cpp" + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! dexp_in ) + dexp_in = stdin; + + if ( ! dexp_out ) + dexp_out = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + dexp_ensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + dexp__create_buffer(dexp_in,YY_BUF_SIZE ); + } + + dexp__load_buffer_state( ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of dexp_text. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 51 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 72 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 32 "debugger-expr.l" +dexp_lval.number=atoi((char *)(dexp_text+1)); return TOK_REGISTER; + YY_BREAK +case 2: +YY_RULE_SETUP +#line 33 "debugger-expr.l" +dexp_lval.number = 13; return TOK_REGISTER; + YY_BREAK +case 3: +YY_RULE_SETUP +#line 34 "debugger-expr.l" +dexp_lval.number = 14; return TOK_REGISTER; + YY_BREAK +case 4: +YY_RULE_SETUP +#line 35 "debugger-expr.l" +dexp_lval.number = 15; return TOK_REGISTER; + YY_BREAK +case 5: +YY_RULE_SETUP +#line 36 "debugger-expr.l" +return TOK_BBRACKET; + YY_BREAK +case 6: +YY_RULE_SETUP +#line 37 "debugger-expr.l" +return TOK_HBRACKET; + YY_BREAK +case 7: +YY_RULE_SETUP +#line 38 "debugger-expr.l" +return TOK_WBRACKET; + YY_BREAK +case 8: +YY_RULE_SETUP +#line 39 "debugger-expr.l" +return TOK_RBRACKET; + YY_BREAK +case 9: +YY_RULE_SETUP +#line 40 "debugger-expr.l" +return TOK_LBRACKET; + YY_BREAK +case 10: +YY_RULE_SETUP +#line 41 "debugger-expr.l" +dexp_lval.number=atoi(dexp_text); return TOK_NUMBER; + YY_BREAK +case 11: +YY_RULE_SETUP +#line 42 "debugger-expr.l" +sscanf(dexp_text, "%x", &dexp_lval.number); return TOK_NUMBER; + YY_BREAK +case 12: +YY_RULE_SETUP +#line 43 "debugger-expr.l" +sscanf((char *)(dexp_text + 2), "%x", &dexp_lval.number); return TOK_NUMBER; + YY_BREAK +case 13: +YY_RULE_SETUP +#line 44 "debugger-expr.l" +sscanf((char *)(dexp_text + 1), "%x", &dexp_lval.number); return TOK_NUMBER; + YY_BREAK +case 14: +YY_RULE_SETUP +#line 45 "debugger-expr.l" +return TOK_PLUS; + YY_BREAK +case 15: +YY_RULE_SETUP +#line 46 "debugger-expr.l" +return TOK_MINUS; + YY_BREAK +case 16: +YY_RULE_SETUP +#line 47 "debugger-expr.l" +return TOK_DIVIDE; + YY_BREAK +case 17: +YY_RULE_SETUP +#line 48 "debugger-expr.l" +return TOK_MULTIPLY; + YY_BREAK +case 18: +YY_RULE_SETUP +#line 49 "debugger-expr.l" +return TOK_LSHIFT; + YY_BREAK +case 19: +YY_RULE_SETUP +#line 50 "debugger-expr.l" +return TOK_RSHIFT; + YY_BREAK +case 20: +YY_RULE_SETUP +#line 51 "debugger-expr.l" +return TOK_LPAREN; + YY_BREAK +case 21: +YY_RULE_SETUP +#line 52 "debugger-expr.l" +return TOK_RPAREN; + YY_BREAK +case 22: +YY_RULE_SETUP +#line 53 "debugger-expr.l" +return TOK_OR; + YY_BREAK +case 23: +YY_RULE_SETUP +#line 54 "debugger-expr.l" +return TOK_AND; + YY_BREAK +case 24: +YY_RULE_SETUP +#line 55 "debugger-expr.l" +return TOK_XOR; + YY_BREAK +case 25: +YY_RULE_SETUP +#line 56 "debugger-expr.l" +return TOK_NEGATE; + YY_BREAK +case 26: +YY_RULE_SETUP +#line 57 "debugger-expr.l" +return TOK_NEGATE; + YY_BREAK +case 27: +YY_RULE_SETUP +#line 58 "debugger-expr.l" +; + YY_BREAK +case 28: +YY_RULE_SETUP +#line 59 "debugger-expr.l" +printf("Unrecognised token: %s\n", dexp_text); + YY_BREAK +case 29: +YY_RULE_SETUP +#line 60 "debugger-expr.l" +dexp_lval.string=dexp_text; return TOK_ID; + YY_BREAK +case 30: +YY_RULE_SETUP +#line 62 "debugger-expr.l" +ECHO; + YY_BREAK +#line 965 "debugger-expr-lex.cpp" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed dexp_in at a new source and called + * dexp_lex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = dexp_in; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( dexp_wrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * dexp_text, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of dexp_lex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + dexp_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), (size_t) num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + dexp_restart(dexp_in ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) dexp_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 51 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + register int yy_is_jam; + register char *yy_cp = (yy_c_buf_p); + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 51 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 50); + + return yy_is_jam ? 0 : yy_current_state; +} + + static void yyunput (int c, register char * yy_bp ) +{ + register char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up dexp_text */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = (yy_n_chars) + 2; + register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + register char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + dexp_restart(dexp_in ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( dexp_wrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve dexp_text */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void dexp_restart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + dexp_ensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + dexp__create_buffer(dexp_in,YY_BUF_SIZE ); + } + + dexp__init_buffer(YY_CURRENT_BUFFER,input_file ); + dexp__load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void dexp__switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * dexp_pop_buffer_state(); + * dexp_push_buffer_state(new_buffer); + */ + dexp_ensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + dexp__load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (dexp_wrap()) processing, but the only time this flag + * is looked at is after dexp_wrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void dexp__load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + dexp_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE dexp__create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) dexp_alloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in dexp__create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) dexp_alloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in dexp__create_buffer()" ); + + b->yy_is_our_buffer = 1; + + dexp__init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with dexp__create_buffer() + * + */ + void dexp__delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + dexp_free((void *) b->yy_ch_buf ); + + dexp_free((void *) b ); +} + +#ifndef __cplusplus +extern int isatty (int ); +#endif /* __cplusplus */ + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a dexp_restart() or at EOF. + */ + static void dexp__init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + dexp__flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then dexp__init_buffer was _probably_ + * called from dexp_restart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void dexp__flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + dexp__load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void dexp_push_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + dexp_ensure_buffer_stack(); + + /* This block is copied from dexp__switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from dexp__switch_to_buffer. */ + dexp__load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void dexp_pop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + dexp__delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + dexp__load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void dexp_ensure_buffer_stack (void) +{ + int num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)dexp_alloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in dexp_ensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)dexp_realloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in dexp_ensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE dexp__scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) dexp_alloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in dexp__scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + dexp__switch_to_buffer(b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to dexp_lex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * dexp__scan_bytes() instead. + */ +YY_BUFFER_STATE dexp__scan_string (yyconst char * yystr ) +{ + + return dexp__scan_bytes(yystr,strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to dexp_lex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE dexp__scan_bytes (yyconst char * yybytes, int _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) dexp_alloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in dexp__scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = dexp__scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in dexp__scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up dexp_text. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + dexp_text[dexp_leng] = (yy_hold_char); \ + (yy_c_buf_p) = dexp_text + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + dexp_leng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int dexp_get_lineno (void) +{ + + return dexp_lineno; +} + +/** Get the input stream. + * + */ +FILE *dexp_get_in (void) +{ + return dexp_in; +} + +/** Get the output stream. + * + */ +FILE *dexp_get_out (void) +{ + return dexp_out; +} + +/** Get the length of the current token. + * + */ +int dexp_get_leng (void) +{ + return dexp_leng; +} + +/** Get the current token. + * + */ + +char *dexp_get_text (void) +{ + return dexp_text; +} + +/** Set the current line number. + * @param line_number + * + */ +void dexp_set_lineno (int line_number ) +{ + + dexp_lineno = line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * + * @see dexp__switch_to_buffer + */ +void dexp_set_in (FILE * in_str ) +{ + dexp_in = in_str ; +} + +void dexp_set_out (FILE * out_str ) +{ + dexp_out = out_str ; +} + +int dexp_get_debug (void) +{ + return dexp__flex_debug; +} + +void dexp_set_debug (int bdebug ) +{ + dexp__flex_debug = bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from dexp_lex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + dexp_in = stdin; + dexp_out = stdout; +#else + dexp_in = (FILE *) 0; + dexp_out = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * dexp_lex_init() + */ + return 0; +} + +/* dexp_lex_destroy is for both reentrant and non-reentrant scanners. */ +int dexp_lex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + dexp__delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + dexp_pop_buffer_state(); + } + + /* Destroy the stack itself. */ + dexp_free((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * dexp_lex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *dexp_alloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *dexp_realloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void dexp_free (void * ptr ) +{ + free( (char *) ptr ); /* see dexp_realloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 62 "debugger-expr.l" + + + +void dexp_flush() +{ + dexp__flush_buffer(YY_CURRENT_BUFFER); +} + diff --git a/src/gba/debugger-expr-yacc.cpp b/src/gba/debugger-expr-yacc.cpp new file mode 100644 index 00000000..c3a1840d --- /dev/null +++ b/src/gba/debugger-expr-yacc.cpp @@ -0,0 +1,1830 @@ +/* A Bison parser, made by GNU Bison 2.3. */ + +/* Skeleton implementation for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + + This program 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, or (at your option) + any later version. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.3" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Using locations. */ +#define YYLSP_NEEDED 0 + +#define yyparse dexp_parse +#define yylex dexp_lex +#define yyerror dexp_error +#define yylval dexp_lval +#define yychar dexp_char +#define yydebug dexp_debug +#define yynerrs dexp_nerrs + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + TOK_PLUS = 258, + TOK_MINUS = 259, + TOK_DIVIDE = 260, + TOK_MULTIPLY = 261, + TOK_LSHIFT = 262, + TOK_RSHIFT = 263, + TOK_LPAREN = 264, + TOK_RPAREN = 265, + TOK_OR = 266, + TOK_AND = 267, + TOK_XOR = 268, + TOK_NEGATE = 269, + TOK_BBRACKET = 270, + TOK_HBRACKET = 271, + TOK_WBRACKET = 272, + TOK_LBRACKET = 273, + TOK_RBRACKET = 274, + TOK_REGISTER = 275, + TOK_NUMBER = 276, + TOK_ID = 277 + }; +#endif +/* Tokens. */ +#define TOK_PLUS 258 +#define TOK_MINUS 259 +#define TOK_DIVIDE 260 +#define TOK_MULTIPLY 261 +#define TOK_LSHIFT 262 +#define TOK_RSHIFT 263 +#define TOK_LPAREN 264 +#define TOK_RPAREN 265 +#define TOK_OR 266 +#define TOK_AND 267 +#define TOK_XOR 268 +#define TOK_NEGATE 269 +#define TOK_BBRACKET 270 +#define TOK_HBRACKET 271 +#define TOK_WBRACKET 272 +#define TOK_LBRACKET 273 +#define TOK_RBRACKET 274 +#define TOK_REGISTER 275 +#define TOK_NUMBER 276 +#define TOK_ID 277 + + + + +/* Copy the first part of user declarations. */ +#line 1 "src/sdl/debugger-expr.y" + +#include + +#include "../System.h" +#include "GBA.h" +#include "../Common/Port.h" + +#include +#include +#include + +unsigned int dexp_result = 0; +extern int dexp_error(char *); +extern int dexp_lex(); +extern char *dexp_text; + +std::map dexp_vars; + +#define readWord(addr) \ + READ32LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask])) + +#define readHalfWord(addr) \ + READ16LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask])) + +#define readByte(addr) \ + map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] + + + + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +#line 44 "src/sdl/debugger-expr.y" +{ + unsigned int number; + char *string; +} +/* Line 187 of yacc.c. */ +#line 175 "src/sdl/debugger-expr-yacc.cpp" + YYSTYPE; +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +# define YYSTYPE_IS_TRIVIAL 1 +#endif + + + +/* Copy the second part of user declarations. */ + + +/* Line 216 of yacc.c. */ +#line 188 "src/sdl/debugger-expr-yacc.cpp" + +#ifdef short +# undef short +#endif + +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else +typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; +#elif (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +typedef signed char yytype_int8; +#else +typedef short int yytype_int8; +#endif + +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; +#else +typedef unsigned short int yytype_uint16; +#endif + +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned int +# endif +#endif + +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) + +#ifndef YY_ +# if YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(e) ((void) (e)) +#else +# define YYUSE(e) /* empty */ +#endif + +/* Identity function, used to suppress warnings about constant conditions. */ +#ifndef lint +# define YYID(n) (n) +#else +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static int +YYID (int i) +#else +static int +YYID (i) + int i; +#endif +{ + return i; +} +#endif + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined _STDLIB_H \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef _STDLIB_H +# define _STDLIB_H 1 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yytype_int16 yyss; + YYSTYPE yyvs; + }; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack, Stack, yysize); \ + Stack = &yyptr->Stack; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (YYID (0)) + +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 20 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 135 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 23 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 3 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 21 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 44 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 277 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const yytype_uint8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const yytype_uint8 yyprhs[] = +{ + 0, 0, 3, 5, 7, 9, 13, 17, 20, 23, + 27, 31, 35, 39, 43, 47, 51, 55, 57, 61, + 65, 69 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yytype_int8 yyrhs[] = +{ + 24, 0, -1, 25, -1, 21, -1, 22, -1, 25, + 3, 25, -1, 25, 4, 25, -1, 4, 25, -1, + 14, 25, -1, 25, 5, 25, -1, 25, 6, 25, + -1, 25, 7, 25, -1, 25, 8, 25, -1, 9, + 25, 10, -1, 25, 12, 25, -1, 25, 11, 25, + -1, 25, 13, 25, -1, 20, -1, 15, 25, 19, + -1, 16, 25, 19, -1, 17, 25, 19, -1, 18, + 25, 19, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const yytype_uint8 yyrline[] = +{ + 0, 56, 56, 59, 60, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, + 83, 84 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "TOK_PLUS", "TOK_MINUS", "TOK_DIVIDE", + "TOK_MULTIPLY", "TOK_LSHIFT", "TOK_RSHIFT", "TOK_LPAREN", "TOK_RPAREN", + "TOK_OR", "TOK_AND", "TOK_XOR", "TOK_NEGATE", "TOK_BBRACKET", + "TOK_HBRACKET", "TOK_WBRACKET", "TOK_LBRACKET", "TOK_RBRACKET", + "TOK_REGISTER", "TOK_NUMBER", "TOK_ID", "$accept", "final", "exp", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const yytype_uint16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 23, 24, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 1, 1, 1, 3, 3, 2, 2, 3, + 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, + 3, 3 +}; + +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 17, 3, + 4, 0, 2, 7, 0, 8, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 13, 18, 19, 20, 21, 5, 6, 9, 10, 11, + 12, 15, 14, 16 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int8 yydefgoto[] = +{ + -1, 11, 12 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -2 +static const yytype_int8 yypact[] = +{ + 25, 25, 25, 25, 25, 25, 25, 25, -2, -2, + -2, 13, 113, 122, 4, 122, 45, 62, 79, 96, + -2, 25, 25, 25, 25, 25, 25, 25, 25, 25, + -2, -2, -2, -2, -2, 122, 122, 24, 24, 48, + 48, 6, 17, -2 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int8 yypgoto[] = +{ + -2, -2, -1 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -1 +static const yytype_uint8 yytable[] = +{ + 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, + 24, 25, 26, 20, 30, 27, 28, 29, 28, 29, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 1, + 29, 25, 26, 0, 2, 27, 28, 29, 0, 3, + 4, 5, 6, 7, 0, 8, 9, 10, 21, 22, + 23, 24, 25, 26, 0, 0, 27, 28, 29, 27, + 28, 29, 0, 0, 31, 21, 22, 23, 24, 25, + 26, 0, 0, 27, 28, 29, 0, 0, 0, 0, + 0, 32, 21, 22, 23, 24, 25, 26, 0, 0, + 27, 28, 29, 0, 0, 0, 0, 0, 33, 21, + 22, 23, 24, 25, 26, 0, 0, 27, 28, 29, + 0, 0, 0, 0, 0, 34, 21, 22, 23, 24, + 25, 26, 0, 0, 27, 28, 29, 23, 24, 25, + 26, 0, 0, 27, 28, 29 +}; + +static const yytype_int8 yycheck[] = +{ + 1, 2, 3, 4, 5, 6, 7, 3, 4, 5, + 6, 7, 8, 0, 10, 11, 12, 13, 12, 13, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 4, + 13, 7, 8, -1, 9, 11, 12, 13, -1, 14, + 15, 16, 17, 18, -1, 20, 21, 22, 3, 4, + 5, 6, 7, 8, -1, -1, 11, 12, 13, 11, + 12, 13, -1, -1, 19, 3, 4, 5, 6, 7, + 8, -1, -1, 11, 12, 13, -1, -1, -1, -1, + -1, 19, 3, 4, 5, 6, 7, 8, -1, -1, + 11, 12, 13, -1, -1, -1, -1, -1, 19, 3, + 4, 5, 6, 7, 8, -1, -1, 11, 12, 13, + -1, -1, -1, -1, -1, 19, 3, 4, 5, 6, + 7, 8, -1, -1, 11, 12, 13, 5, 6, 7, + 8, -1, -1, 11, 12, 13 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 4, 9, 14, 15, 16, 17, 18, 20, 21, + 22, 24, 25, 25, 25, 25, 25, 25, 25, 25, + 0, 3, 4, 5, 6, 7, 8, 11, 12, 13, + 10, 19, 19, 19, 19, 25, 25, 25, 25, 25, + 25, 25, 25, 25 +}; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ + +#define YYFAIL goto yyerrlab + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yytoken = YYTRANSLATE (yychar); \ + YYPOPSTACK (1); \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ +while (YYID (0)) + + +#define YYTERROR 1 +#define YYERRCODE 256 + + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (YYID (0)) +#endif + + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#ifdef YYLEX_PARAM +# define YYLEX yylex (YYLEX_PARAM) +#else +# define YYLEX yylex () +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (YYID (0)) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (YYID (0)) + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +#else +static void +yy_symbol_value_print (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; +#endif +{ + if (!yyvaluep) + return; +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# else + YYUSE (yyoutput); +# endif + switch (yytype) + { + default: + break; + } +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +#else +static void +yy_symbol_print (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; +#endif +{ + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + yy_symbol_value_print (yyoutput, yytype, yyvaluep); + YYFPRINTF (yyoutput, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_stack_print (yytype_int16 *bottom, yytype_int16 *top) +#else +static void +yy_stack_print (bottom, top) + yytype_int16 *bottom; + yytype_int16 *top; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (; bottom <= top; ++bottom) + YYFPRINTF (stderr, " %d", *bottom); + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (YYID (0)) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_reduce_print (YYSTYPE *yyvsp, int yyrule) +#else +static void +yy_reduce_print (yyvsp, yyrule) + YYSTYPE *yyvsp; + int yyrule; +#endif +{ + int yynrhs = yyr2[yyrule]; + int yyi; + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + fprintf (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + &(yyvsp[(yyi + 1) - (yynrhs)]) + ); + fprintf (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyvsp, Rule); \ +} while (YYID (0)) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static YYSIZE_T +yystrlen (const char *yystr) +#else +static YYSIZE_T +yystrlen (yystr) + const char *yystr; +#endif +{ + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static char * +yystpcpy (char *yydest, const char *yysrc) +#else +static char * +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +#endif +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +/* Copy into YYRESULT an error message about the unexpected token + YYCHAR while in state YYSTATE. Return the number of bytes copied, + including the terminating null byte. If YYRESULT is null, do not + copy anything; just return the number of bytes that would be + copied. As a special case, return 0 if an ordinary "syntax error" + message will do. Return YYSIZE_MAXIMUM if overflow occurs during + size calculation. */ +static YYSIZE_T +yysyntax_error (char *yyresult, int yystate, int yychar) +{ + int yyn = yypact[yystate]; + + if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) + return 0; + else + { + int yytype = YYTRANSLATE (yychar); + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + int yysize_overflow = 0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + int yyx; + +# if 0 + /* This is so xgettext sees the translatable formats that are + constructed on the fly. */ + YY_("syntax error, unexpected %s"); + YY_("syntax error, unexpected %s, expecting %s"); + YY_("syntax error, unexpected %s, expecting %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); +# endif + char *yyfmt; + char const *yyf; + static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyexpecting[] = ", expecting %s"; + static char const yyor[] = " or %s"; + char yyformat[sizeof yyunexpected + + sizeof yyexpecting - 1 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) + * (sizeof yyor - 1))]; + char const *yyprefix = yyexpecting; + + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 1; + + yyarg[0] = yytname[yytype]; + yyfmt = yystpcpy (yyformat, yyunexpected); + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + yyformat[sizeof yyunexpected - 1] = '\0'; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + yyfmt = yystpcpy (yyfmt, yyprefix); + yyprefix = yyor; + } + + yyf = YY_(yyformat); + yysize1 = yysize + yystrlen (yyf); + yysize_overflow |= (yysize1 < yysize); + yysize = yysize1; + + if (yysize_overflow) + return YYSIZE_MAXIMUM; + + if (yyresult) + { + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + char *yyp = yyresult; + int yyi = 0; + while ((*yyp = *yyf) != '\0') + { + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyf += 2; + } + else + { + yyp++; + yyf++; + } + } + } + return yysize; + } +} +#endif /* YYERROR_VERBOSE */ + + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +#else +static void +yydestruct (yymsg, yytype, yyvaluep) + const char *yymsg; + int yytype; + YYSTYPE *yyvaluep; +#endif +{ + YYUSE (yyvaluep); + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } +} + + +/* Prevent warnings from -Wmissing-prototypes. */ + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (void); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + + +/* The look-ahead symbol. */ +int yychar; + +/* The semantic value of the look-ahead symbol. */ +YYSTYPE yylval; + +/* Number of syntax errors so far. */ +int yynerrs; + + + +/*----------. +| yyparse. | +`----------*/ + +#ifdef YYPARSE_PARAM +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void *YYPARSE_PARAM) +#else +int +yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +#endif +#else /* ! YYPARSE_PARAM */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void) +#else +int +yyparse () + +#endif +#endif +{ + + int yystate; + int yyn; + int yyresult; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + /* Look-ahead token as an internal (translated) token number. */ + int yytoken = 0; +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif + + /* Three stacks and their tools: + `yyss': related to states, + `yyvs': related to semantic values, + `yyls': related to locations. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss = yyssa; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp; + + + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + + YYSIZE_T yystacksize = YYINITDEPTH; + + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + + yyssp = yyss; + yyvsp = yyvs; + + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss); + YYSTACK_RELOCATE (yyvs); + +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + + /* Do appropriate processing given the current state. Read a + look-ahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to look-ahead token. */ + yyn = yypact[yystate]; + if (yyn == YYPACT_NINF) + goto yydefault; + + /* Not known => get a look-ahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yyn == 0 || yyn == YYTABLE_NINF) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + if (yyn == YYFINAL) + YYACCEPT; + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the look-ahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the shifted token unless it is eof. */ + if (yychar != YYEOF) + yychar = YYEMPTY; + + yystate = yyn; + *++yyvsp = yylval; + + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 2: +#line 56 "src/sdl/debugger-expr.y" + {dexp_result = (yyvsp[(1) - (1)].number);} + break; + + case 3: +#line 59 "src/sdl/debugger-expr.y" + { (yyval.number) = (yyvsp[(1) - (1)].number); } + break; + + case 4: +#line 60 "src/sdl/debugger-expr.y" + { + std::string v((yyvsp[(1) - (1)].string)); + if (dexp_vars.count(v) == 0) { + printf("Variable %s not defined.\n", (yyvsp[(1) - (1)].string)); + YYABORT; + } + (yyval.number) = dexp_vars[v]; +} + break; + + case 5: +#line 68 "src/sdl/debugger-expr.y" + { (yyval.number) = (yyvsp[(1) - (3)].number) + (yyvsp[(3) - (3)].number); } + break; + + case 6: +#line 69 "src/sdl/debugger-expr.y" + { (yyval.number) = (yyvsp[(1) - (3)].number) - (yyvsp[(3) - (3)].number);} + break; + + case 7: +#line 70 "src/sdl/debugger-expr.y" + { (yyval.number) = -(yyvsp[(2) - (2)].number);} + break; + + case 8: +#line 71 "src/sdl/debugger-expr.y" + { (yyval.number) = ~(yyvsp[(2) - (2)].number);} + break; + + case 9: +#line 72 "src/sdl/debugger-expr.y" + { (yyval.number) = (yyvsp[(1) - (3)].number) / (yyvsp[(3) - (3)].number);} + break; + + case 10: +#line 73 "src/sdl/debugger-expr.y" + { (yyval.number) = (yyvsp[(1) - (3)].number) * (yyvsp[(3) - (3)].number);} + break; + + case 11: +#line 74 "src/sdl/debugger-expr.y" + { (yyval.number) = (yyvsp[(1) - (3)].number) << (yyvsp[(3) - (3)].number);} + break; + + case 12: +#line 75 "src/sdl/debugger-expr.y" + { (yyval.number) = (yyvsp[(1) - (3)].number) >> (yyvsp[(3) - (3)].number);} + break; + + case 13: +#line 76 "src/sdl/debugger-expr.y" + { (yyval.number)=(yyvsp[(2) - (3)].number);} + break; + + case 14: +#line 77 "src/sdl/debugger-expr.y" + { (yyval.number) = (yyvsp[(1) - (3)].number) & (yyvsp[(3) - (3)].number);} + break; + + case 15: +#line 78 "src/sdl/debugger-expr.y" + { (yyval.number) = (yyvsp[(1) - (3)].number) | (yyvsp[(3) - (3)].number);} + break; + + case 16: +#line 79 "src/sdl/debugger-expr.y" + { (yyval.number) = (yyvsp[(1) - (3)].number) ^ (yyvsp[(3) - (3)].number); } + break; + + case 17: +#line 80 "src/sdl/debugger-expr.y" + { (yyval.number) = reg[(yyvsp[(1) - (1)].number)].I; } + break; + + case 18: +#line 81 "src/sdl/debugger-expr.y" + { (yyval.number) = readByte((yyvsp[(2) - (3)].number)); } + break; + + case 19: +#line 82 "src/sdl/debugger-expr.y" + { (yyval.number) = readHalfWord((yyvsp[(2) - (3)].number)); } + break; + + case 20: +#line 83 "src/sdl/debugger-expr.y" + { (yyval.number) = readWord((yyvsp[(2) - (3)].number)); } + break; + + case 21: +#line 84 "src/sdl/debugger-expr.y" + { (yyval.number) = readWord((yyvsp[(2) - (3)].number)); } + break; + + +/* Line 1267 of yacc.c. */ +#line 1534 "src/sdl/debugger-expr-yacc.cpp" + default: break; + } + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (YY_("syntax error")); +#else + { + YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); + if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) + { + YYSIZE_T yyalloc = 2 * yysize; + if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) + yyalloc = YYSTACK_ALLOC_MAXIMUM; + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yyalloc); + if (yymsg) + yymsg_alloc = yyalloc; + else + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + } + } + + if (0 < yysize && yysize <= yymsg_alloc) + { + (void) yysyntax_error (yymsg, yystate, yychar); + yyerror (yymsg); + } + else + { + yyerror (YY_("syntax error")); + if (yysize != 0) + goto yyexhaustedlab; + } + } +#endif + } + + + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse look-ahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse look-ahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (/*CONSTCOND*/ 0) + goto yyerrorlab; + + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYPACT_NINF) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + + yydestruct ("Error: popping", + yystos[yystate], yyvsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + if (yyn == YYFINAL) + YYACCEPT; + + *++yyvsp = yylval; + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#ifndef yyoverflow +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: + if (yychar != YYEOF && yychar != YYEMPTY) + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + /* Make sure YYID is used. */ + return YYID (yyresult); +} + + +#line 86 "src/sdl/debugger-expr.y" + + +bool dexp_eval(char *expr, u32 *result) +{ + extern void dexp_flush(); + extern char *dexprString; + extern int dexprCol; + + dexp_flush(); + + + dexprString = expr; + dexprCol = 0; + + if(!dexp_parse()) { + *result = dexp_result; + return true; + } else { + return false; + } +} + +int dexp_error(char *s) +{ + return 0; +} + +void dexp_setVar(char *name, u32 value) +{ + std::string a(name); + dexp_vars[a] = value; +} + +void dexp_listVars() +{ + std::map::iterator iter; + + for (iter = dexp_vars.begin(); iter != dexp_vars.end(); iter++) { + printf("%s = %08X\n", iter->first.c_str(), iter->second); + } +} + +void dexp_saveVars(char *file) +{ + std::map::iterator iter; + + FILE *f = fopen(file, "w"); + if (!f) { + printf("Could not open file %s\n", file); + return; + } + + for (iter = dexp_vars.begin(); iter != dexp_vars.end(); iter++) { + fprintf(f, "%s = %08X\n", iter->first.c_str(), iter->second); + } + fclose(f); +} + +void dexp_loadVars(char *file) +{ + std::map::iterator iter; + char buffer[500]; + char name[500]; + u32 val; + + FILE *f = fopen(file, "r"); + if (!f) { + printf("Could not open file %s\n", file); + return; + } + + while (fgets(buffer, 500, f) != NULL) { + if (sscanf(buffer, "%s = %x",name,&val) == 2) { + dexp_setVar(name, val); + } + } +} diff --git a/src/gba/debugger-expr-yacc.hpp b/src/gba/debugger-expr-yacc.hpp new file mode 100644 index 00000000..c77534e8 --- /dev/null +++ b/src/gba/debugger-expr-yacc.hpp @@ -0,0 +1,105 @@ +/* A Bison parser, made by GNU Bison 2.3. */ + +/* Skeleton interface for Bison's Yacc-like parsers in C + + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + + This program 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, or (at your option) + any later version. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + TOK_PLUS = 258, + TOK_MINUS = 259, + TOK_DIVIDE = 260, + TOK_MULTIPLY = 261, + TOK_LSHIFT = 262, + TOK_RSHIFT = 263, + TOK_LPAREN = 264, + TOK_RPAREN = 265, + TOK_OR = 266, + TOK_AND = 267, + TOK_XOR = 268, + TOK_NEGATE = 269, + TOK_BBRACKET = 270, + TOK_HBRACKET = 271, + TOK_WBRACKET = 272, + TOK_LBRACKET = 273, + TOK_RBRACKET = 274, + TOK_REGISTER = 275, + TOK_NUMBER = 276, + TOK_ID = 277 + }; +#endif +/* Tokens. */ +#define TOK_PLUS 258 +#define TOK_MINUS 259 +#define TOK_DIVIDE 260 +#define TOK_MULTIPLY 261 +#define TOK_LSHIFT 262 +#define TOK_RSHIFT 263 +#define TOK_LPAREN 264 +#define TOK_RPAREN 265 +#define TOK_OR 266 +#define TOK_AND 267 +#define TOK_XOR 268 +#define TOK_NEGATE 269 +#define TOK_BBRACKET 270 +#define TOK_HBRACKET 271 +#define TOK_WBRACKET 272 +#define TOK_LBRACKET 273 +#define TOK_RBRACKET 274 +#define TOK_REGISTER 275 +#define TOK_NUMBER 276 +#define TOK_ID 277 + + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +#line 44 "src/sdl/debugger-expr.y" +{ + unsigned int number; + char *string; +} +/* Line 1489 of yacc.c. */ +#line 98 "src/sdl/debugger-expr-yacc.hpp" + YYSTYPE; +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +# define YYSTYPE_IS_TRIVIAL 1 +#endif + +extern YYSTYPE yylval; + diff --git a/src/gba/debugger-expr.l b/src/gba/debugger-expr.l new file mode 100644 index 00000000..18247ec9 --- /dev/null +++ b/src/gba/debugger-expr.l @@ -0,0 +1,67 @@ +%{ +#include +#include +#include "debugger-expr-yacc.hpp" + +#ifdef _MSC_VER +#define YY_NO_UNISTD_H +#include +#define isatty _isatty +#endif + +extern YYSTYPE dexp_lval; + +char *dexprString; +int dexprCol; + +#define YY_INPUT(buf,result,max_size) \ + { \ + int c = *dexprString++; \ + dexprCol++;\ + result = (c == 0) ? YY_NULL : (buf[0] = c, 1); \ + } + +%} + +%option nomain +%option noyywrap + +HEX [0-9a-fA-F] + +%% +r(0?[0-9]|1[0-5]) dexp_lval.number=atoi((char *)(dexp_text+1)); return TOK_REGISTER; +[sS][pP] dexp_lval.number = 13; return TOK_REGISTER; +[lL][rR] dexp_lval.number = 14; return TOK_REGISTER; +[pP][cC] dexp_lval.number = 15; return TOK_REGISTER; +[bB]"[" return TOK_BBRACKET; +[hH]"[" return TOK_HBRACKET; +[wW]"[" return TOK_WBRACKET; +"]" return TOK_RBRACKET; +"[" return TOK_LBRACKET; +[1-9][0-9]* dexp_lval.number=atoi(dexp_text); return TOK_NUMBER; +0{HEX}* sscanf(dexp_text, "%x", &dexp_lval.number); return TOK_NUMBER; +0[xX]{HEX}+ sscanf((char *)(dexp_text + 2), "%x", &dexp_lval.number); return TOK_NUMBER; +"$"{HEX}+ sscanf((char *)(dexp_text + 1), "%x", &dexp_lval.number); return TOK_NUMBER; +"+" return TOK_PLUS; +"-" return TOK_MINUS; +"/" return TOK_DIVIDE; +"*" return TOK_MULTIPLY; +"<<" return TOK_LSHIFT; +">>" return TOK_RSHIFT; +"(" return TOK_LPAREN; +")" return TOK_RPAREN; +"|" return TOK_OR; +"&" return TOK_AND; +"^" return TOK_XOR; +"!" return TOK_NEGATE; +"~" return TOK_NEGATE; +" " ; +. printf("Unrecognised token: %s\n", dexp_text); +[A-Za-z_][A-Za-z0-9_]* dexp_lval.string=dexp_text; return TOK_ID; + +%% + +void dexp_flush() +{ + dexp__flush_buffer(YY_CURRENT_BUFFER); +} diff --git a/src/gba/debugger-expr.y b/src/gba/debugger-expr.y new file mode 100644 index 00000000..aa27510a --- /dev/null +++ b/src/gba/debugger-expr.y @@ -0,0 +1,164 @@ +%{ +#include + +#include "../System.h" +#include "GBA.h" +#include "../Port.h" + +#include +#include +#include + +unsigned int dexp_result = 0; +extern int dexp_error(char *); +extern int dexp_lex(); +extern char *dexp_text; + +std::map dexp_vars; + +#define readWord(addr) \ + READ32LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask])) + +#define readHalfWord(addr) \ + READ16LE((&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask])) + +#define readByte(addr) \ + map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] + + +%} + +%token TOK_PLUS TOK_MINUS +%token TOK_DIVIDE TOK_MULTIPLY TOK_LSHIFT TOK_RSHIFT +%token TOK_LPAREN TOK_RPAREN TOK_OR TOK_AND TOK_XOR TOK_NEGATE +%token TOK_BBRACKET TOK_HBRACKET TOK_WBRACKET +%token TOK_LBRACKET TOK_RBRACKET +%left TOK_MINUS TOK_PLUS TOK_NEGATE +%left TOK_MULTIPLY TOK_DIVIDE +%left TOK_LSHIFT TOK_RSHIFT +%left TOK_OR +%left TOK_AND +%left TOK_XOR + +%union +{ + unsigned int number; + char *string; +} + +%token TOK_REGISTER +%token TOK_NUMBER +%token TOK_ID +%type final +%type exp +%% + +final: exp {dexp_result = $1;} +; + +exp: TOK_NUMBER { $$ = $1; } +| TOK_ID { + std::string v($1); + if (dexp_vars.count(v) == 0) { + printf("Variable %s not defined.\n", $1); + YYABORT; + } + $$ = dexp_vars[v]; +} +| exp TOK_PLUS exp { $$ = $1 + $3; } +| exp TOK_MINUS exp { $$ = $1 - $3;} +| TOK_MINUS exp { $$ = -$2;} +| TOK_NEGATE exp { $$ = ~$2;} +| exp TOK_DIVIDE exp { $$ = $1 / $3;} +| exp TOK_MULTIPLY exp { $$ = $1 * $3;} +| exp TOK_LSHIFT exp { $$ = $1 << $3;} +| exp TOK_RSHIFT exp { $$ = $1 >> $3;} +| TOK_LPAREN exp TOK_RPAREN { $$=$2;} +| exp TOK_AND exp { $$ = $1 & $3;} +| exp TOK_OR exp { $$ = $1 | $3;} +| exp TOK_XOR exp { $$ = $1 ^ $3; } +| TOK_REGISTER { $$ = reg[$1].I; } +| TOK_BBRACKET exp TOK_RBRACKET { $$ = readByte($2); } +| TOK_HBRACKET exp TOK_RBRACKET { $$ = readHalfWord($2); } +| TOK_WBRACKET exp TOK_RBRACKET { $$ = readWord($2); } +| TOK_LBRACKET exp TOK_RBRACKET { $$ = readWord($2); } +; +%% + +bool dexp_eval(char *expr, u32 *result) +{ + extern void dexp_flush(); + extern char *dexprString; + extern int dexprCol; + + dexp_flush(); + + + dexprString = expr; + dexprCol = 0; + + if(!dexp_parse()) { + *result = dexp_result; + return true; + } else { + return false; + } +} + +int dexp_error(char *s) +{ + return 0; +} + +void dexp_setVar(char *name, u32 value) +{ + std::string a(name); + dexp_vars[a] = value; +} + +void dexp_listVars() +{ + std::map::iterator iter; + + for (iter = dexp_vars.begin(); iter != dexp_vars.end(); iter++) { + printf("%s = %08X\n", iter->first.c_str(), iter->second); + } +} + +void dexp_saveVars(char *file) +{ + std::map::iterator iter; + + FILE *f = fopen(file, "w"); + if (!f) { + printf("Could not open file %s\n", file); + return; + } + + for (iter = dexp_vars.begin(); iter != dexp_vars.end(); iter++) { + fprintf(f, "%s = %08X\n", iter->first.c_str(), iter->second); + } + fclose(f); +} + +void dexp_loadVars(char *file) +{ + std::map::iterator iter; + char buffer[500]; + char name[500]; + u32 val; + + FILE *f = fopen(file, "r"); + if (!f) { + printf("Could not open file %s\n", file); + return; + } + + while (fgets(buffer, 500, f) != NULL) { + if (sscanf(buffer, "%s = %x",name,&val) == 2) { + dexp_setVar(name, val); + } + } +} + + diff --git a/src/gba/remote.cpp b/src/gba/remote.cpp index 06a9e181..22ce8619 100644 --- a/src/gba/remote.cpp +++ b/src/gba/remote.cpp @@ -3,6 +3,10 @@ #include #include +#include +#include +#include + #ifndef _WIN32 # include # include @@ -25,15 +29,16 @@ # define write _write #endif // _WIN32 +#include "remote.h" +#include "BreakpointStructures.h" #include "GBA.h" +#include +#include +#include "elf.h" extern bool debugger; +extern int emulating; extern void CPUUpdateCPSR(); -#ifdef SDL -extern void (*dbgMain)(); -extern void debuggerMain(); -extern void debuggerSignal(int,int); -#endif int remotePort = 55555; int remoteSignal = 5; @@ -55,6 +60,2610 @@ void remoteSetSockets(SOCKET l, SOCKET r) } #endif +#define debuggerReadMemory(addr) \ + (*(u32*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]) + +#define debuggerReadHalfWord(addr) \ + (*(u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]) + +#define debuggerReadByte(addr) \ + map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] + +#define debuggerWriteMemory(addr, value) \ + *(u32*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] = (value) + +#define debuggerWriteHalfWord(addr, value) \ + *(u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] = (value) + +#define debuggerWriteByte(addr, value) \ + map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] = (value) + +bool dontBreakNow = false; +int debuggerNumOfDontBreak = 0; +int debuggerRadix = 0; + +#define NUMBEROFDB 1000 +u32 debuggerNoBreakpointList[NUMBEROFDB]; + +char* cmdAliasTable[] = { "help", "?", "h", "?", "continue", "c", "next", "n", +"cpyb", "copyb", "cpyh", "copyh", "cpyw", "copyw", +"exe", "execute", "exec", "execute", +NULL, NULL }; + +struct DebuggerCommand { + char *name; + void(*function)(int, char **); + char *help; + char *syntax; +}; + +char monbuf[1000]; +void monprintf(std::string line); +std::string StringToHex(std::string &cmd); +std::string HexToString(char * p); +void debuggerUsage(char *cmd); +void debuggerHelp(int n, char **args); +void printFlagHelp(); +void dbgExecute(std::string &cmd); + +extern bool debuggerBreakOnWrite(u32, u32, int); +extern bool debuggerBreakOnRegisterCondition(u8, u32, u32, u8); +extern bool debuggerBreakOnExecution(u32, u8); + +regBreak* breakRegList[16]; +u8 lowRegBreakCounter[4]; //(r0-r3) +u8 medRegBreakCounter[4]; //(r4-r7) +u8 highRegBreakCounter[4]; //(r8-r11) +u8 statusRegBreakCounter[4]; //(r12-r15) +u8* regBreakCounter[4] = { + &lowRegBreakCounter[0], + &medRegBreakCounter[0], + &highRegBreakCounter[0], + &statusRegBreakCounter[0] +}; +u32 lastWasBranch = 0; + +struct regBreak* getFromBreakRegList(u8 regnum, int location){ + if (location > regBreakCounter[regnum >> 2][regnum & 3]) + return NULL; + + struct regBreak* ans = breakRegList[regnum]; + for (int i = 0; i < location && ans; i++){ + ans = ans->next; + } + return ans; +} + +bool enableRegBreak = false; +reg_pair oldReg[16]; +u32 regDiff[16]; + +void breakReg_check(int i){ + struct regBreak* brkR = breakRegList[i]; + bool notFound = true; + u8 counter = regBreakCounter[i >> 2][i & 3]; + for (int bri = 0; (bri < counter) && notFound; bri++){ + if (!brkR){ + regBreakCounter[i >> 2][i & 3] = (u8)bri; + break; + } + else{ + if (brkR->flags != 0){ + u32 regVal = (i == 15 ? (armState ? reg[15].I - 4 : reg[15].I - 2) : reg[i].I); + if ((brkR->flags & 0x1) && (regVal == brkR->intVal)){ + debuggerBreakOnRegisterCondition(i, brkR->intVal, regVal, 1); + notFound = false; + } + if ((brkR->flags & 0x8)){ + if ((brkR->flags & 0x4) && ((int)regVal < (int)brkR->intVal)){ + debuggerBreakOnRegisterCondition(i, brkR->intVal, regVal, 4); + notFound = false; + } + if ((brkR->flags & 0x2) && ((int)regVal >(int)brkR->intVal)){ + debuggerBreakOnRegisterCondition(i, brkR->intVal, regVal, 5); + notFound = false; + } + } + if ((brkR->flags & 0x4) && (regVal < brkR->intVal)){ + debuggerBreakOnRegisterCondition(i, brkR->intVal, regVal, 2); + notFound = false; + } + if ((brkR->flags & 0x2) && (regVal > brkR->intVal)){ + debuggerBreakOnRegisterCondition(i, brkR->intVal, regVal, 3); + notFound = false; + } + } + brkR = brkR->next; + } + } + if (!notFound){ + //CPU_BREAK_LOOP_2; + } +} + +void clearParticularRegListBreaks(int regNum){ + + while (breakRegList[regNum]){ + struct regBreak* ans = breakRegList[regNum]->next; + free(breakRegList[regNum]); + breakRegList[regNum] = ans; + } + regBreakCounter[regNum >> 2][regNum & 3] = 0; +} + +void clearBreakRegList(){ + for (int i = 0; i<16; i++){ + clearParticularRegListBreaks(i); + } +} + +void deleteFromBreakRegList(u8 regNum, int num){ + int counter = regBreakCounter[regNum >> 2][regNum & 3]; + if (num >= counter){ + return; + } + struct regBreak* ans = breakRegList[regNum]; + struct regBreak* prev = NULL; + for (int i = 0; i < num; i++){ + prev = ans; + ans = ans->next; + } + if (prev){ + prev->next = ans->next; + } + else{ + breakRegList[regNum] = ans->next; + + } + free(ans); + regBreakCounter[regNum >> 2][regNum & 3]--; +} + +void addBreakRegToList(u8 regnum, u8 flags, u32 value){ + struct regBreak* ans = (struct regBreak*)malloc(sizeof(struct regBreak)); + ans->flags = flags; + ans->intVal = value; + ans->next = breakRegList[regnum]; + breakRegList[regnum] = ans; + regBreakCounter[regnum >> 2][regnum & 3]++; +} + +void printBreakRegList(bool verbose){ + char* flagsToOP[] = { "never", "==", ">", ">=", "<", "<=", "!=", "always" }; + bool anyPrint = false; + for (int i = 0; i<4; i++){ + for (int k = 0; k<4; k++){ + if (regBreakCounter[i][k]){ + if (!anyPrint){ + { sprintf(monbuf, "Register breakpoint list:\n"); monprintf(monbuf); } + { sprintf(monbuf, "-------------------------\n"); monprintf(monbuf); } + anyPrint = true; + } + struct regBreak* tmp = breakRegList[i * 4 + k]; + for (int j = 0; j < regBreakCounter[i][k]; j++){ + if (tmp->flags & 8) + { + sprintf(monbuf, "No. %d:\tBreak if (signed)%s %08x\n", j, flagsToOP[tmp->flags], tmp->intVal); monprintf(monbuf); + } + else + { + sprintf(monbuf, "No. %d:\tBreak if %s %08x\n", j, flagsToOP[tmp->flags], tmp->intVal); monprintf(monbuf); + } + tmp = tmp->next; + } + { sprintf(monbuf, "-------------------------\n"); monprintf(monbuf); } + } + else{ + if (verbose){ + if (!anyPrint){ + { sprintf(monbuf, "Register breakpoint list:\n"); monprintf(monbuf); } + { sprintf(monbuf, "-------------------------\n"); monprintf(monbuf); } + anyPrint = true; + } + { sprintf(monbuf, "No breaks on r%d.\n", i); monprintf(monbuf); } + { sprintf(monbuf, "-------------------------\n"); monprintf(monbuf); } + } + } + } + } + if (!verbose && !anyPrint){ + { sprintf(monbuf, "No Register breaks found.\n"); monprintf(monbuf); } + } + +} + +// checks that the given address is in the DB list +bool debuggerInDB(u32 address) +{ + + for (int i = 0; i < debuggerNumOfDontBreak; i++) + { + if (debuggerNoBreakpointList[i] == address) + return true; + } + + return false; + +} + +void debuggerDontBreak(int n, char **args) +{ + if (n == 2) { + u32 address = 0; + sscanf(args[1], "%x", &address); + int i = debuggerNumOfDontBreak; + if (i > NUMBEROFDB) + { + monprintf("Can't have this many DB entries"); + return; + } + debuggerNoBreakpointList[i] = address; + debuggerNumOfDontBreak++; + { sprintf(monbuf, "Added Don't Break at %08x\n", address); monprintf(monbuf); } + } + else + debuggerUsage("db"); +} + +void debuggerDontBreakClear(int n, char **args) +{ + if (n == 1) { + debuggerNumOfDontBreak = 0; + { sprintf(monbuf, "Cleared Don't Break list.\n"); monprintf(monbuf); } + } + else + debuggerUsage("dbc"); +} + +void debuggerDumpLoad(int n, char** args) +{ + u32 address; + char *file; + FILE *f; + int c; + + if (n == 3){ + file = args[1]; + + if (!dexp_eval(args[2], &address)){ + { sprintf(monbuf, "Invalid expression in address.\n"); monprintf(monbuf); } + return; + } + + f = fopen(file, "rb"); + if (f == NULL){ + { sprintf(monbuf, "Error opening file.\n"); monprintf(monbuf); } + return; + } + + fseek(f, 0, SEEK_END); + int size = ftell(f); + fseek(f, 0, SEEK_SET); + + for (int i = 0; i= 3) { + u32 address; + u32 value; + if (!dexp_eval(args[1], &address)) { + { sprintf(monbuf, "Invalid expression in address.\n"); monprintf(monbuf); } + return; + } + for (u32 i = 2; i < n; i++){ + if (!dexp_eval(args[i], &value)) { + { sprintf(monbuf, "Invalid expression in %d value.Ignored.\n", (i - 1)); monprintf(monbuf); } + } + debuggerWriteByte(address, (u16)value); + address++; + } + } + else + debuggerUsage("eb"); +} + +void debuggerEditHalfWord(int n, char **args) +{ + if (n >= 3) { + u32 address; + u32 value; + if (!dexp_eval(args[1], &address)) { + { sprintf(monbuf, "Invalid expression in address.\n"); monprintf(monbuf); } + return; + } + if (address & 1) { + { sprintf(monbuf, "Error: address must be half-word aligned\n"); monprintf(monbuf); } + return; + } + for (u32 i = 2; i < n; i++){ + if (!dexp_eval(args[i], &value)) { + { sprintf(monbuf, "Invalid expression in %d value.Ignored.\n", (i - 1)); monprintf(monbuf); } + } + debuggerWriteHalfWord(address, (u16)value); + address += 2; + } + } + else + debuggerUsage("eh"); +} + +void debuggerEditWord(int n, char **args) +{ + if (n >= 3) { + u32 address; + u32 value; + if (!dexp_eval(args[1], &address)) { + { sprintf(monbuf, "Invalid expression in address.\n"); monprintf(monbuf); } + return; + } + if (address & 3) { + { sprintf(monbuf, "Error: address must be word aligned\n"); monprintf(monbuf); } + return; + } + for (u32 i = 2; i < n; i++){ + if (!dexp_eval(args[i], &value)) { + { sprintf(monbuf, "Invalid expression in %d value.Ignored.\n", (i - 1)); monprintf(monbuf); } + } + debuggerWriteMemory(address, (u32)value); + address += 4; + } + } + else + debuggerUsage("ew"); +} + +bool debuggerBreakOnRegisterCondition(u8 registerName, u32 compareVal, u32 regVal, u8 type){ + char* typeName; + switch (type){ + case 1: + typeName = "equal to"; + break; + case 2: + typeName = "greater (unsigned) than"; + break; + case 3: + typeName = "smaller (unsigned) than"; + break; + case 4: + typeName = "greater (signed) than"; + break; + case 5: + typeName = "smaller (signed) than"; + break; + default: + typeName = "unknown"; + } + { sprintf(monbuf, "Breakpoint on R%02d : %08x is %s register content (%08x)\n", registerName, compareVal, typeName, regVal); monprintf(monbuf); } + if (debuggerInDB(armState ? reg[15].I - 4 : reg[15].I - 2)){ + { sprintf(monbuf, "But this address is marked not to break, so skipped\n"); monprintf(monbuf); } + return false; + } + debugger = true; + return true; +} + +void debuggerBreakRegisterList(bool verbose){ + printBreakRegList(verbose); +} + +int getRegisterNumber(char* regName){ + int r = -1; + if (toupper(regName[0]) == 'P' && toupper(regName[1]) == 'C'){ + r = 15; + } + else if (toupper(regName[0]) == 'L' && toupper(regName[1]) == 'R'){ + r = 14; + } + else if (toupper(regName[0]) == 'S' && toupper(regName[1]) == 'P'){ + r = 13; + } + else if (toupper(regName[0]) == 'R') { + sscanf((char *)(regName + 1), "%d", &r); + } + else { + sscanf(regName, "%d", &r); + } + + return r; +} + +void debuggerEditRegister(int n, char **args) +{ + if (n == 3) { + int r = getRegisterNumber(args[1]); + u32 val; + if (r > 16) { + { sprintf(monbuf, "Error: Register must be valid (0-16)\n"); monprintf(monbuf); } + return; + } + if (!dexp_eval(args[2], &val)) { + { sprintf(monbuf, "Invalid expression in value.\n"); monprintf(monbuf); } + return; + } + reg[r].I = val; + { sprintf(monbuf, "R%02d=%08X\n", r, val); monprintf(monbuf); } + } + else + debuggerUsage("er"); +} + +void debuggerEval(int n, char **args) +{ + if (n == 2) { + u32 result = 0; + if (dexp_eval(args[1], &result)) { + { sprintf(monbuf, " =$%08X\n", result); monprintf(monbuf); } + } + else { + { sprintf(monbuf, "Invalid expression\n"); monprintf(monbuf); } + } + } + else + debuggerUsage("eval"); +} + +void debuggerFillByte(int n, char **args) +{ + if (n == 4) { + u32 address; + u32 value; + u32 reps; + if (!dexp_eval(args[1], &address)) { + { sprintf(monbuf, "Invalid expression in address.\n"); monprintf(monbuf); } + return; + } + if (!dexp_eval(args[2], &value)) { + { sprintf(monbuf, "Invalid expression in value.\n"); monprintf(monbuf); } + } + if (!dexp_eval(args[3], &reps)) { + { sprintf(monbuf, "Invalid expression in repetition number.\n"); monprintf(monbuf); } + } + for (u32 i = 0; i < reps; i++){ + debuggerWriteByte(address, (u8)value); + address++; + } + } + else + debuggerUsage("fillb"); +} + +void debuggerFillHalfWord(int n, char **args) +{ + if (n == 4) { + u32 address; + u32 value; + u32 reps; + if (!dexp_eval(args[1], &address)) { + { sprintf(monbuf, "Invalid expression in address.\n"); monprintf(monbuf); } + return; + }/* + if(address & 1) { + { sprintf(monbuf, "Error: address must be halfword aligned\n"); monprintf(monbuf); } + return; + }*/ + if (!dexp_eval(args[2], &value)) { + { sprintf(monbuf, "Invalid expression in value.\n"); monprintf(monbuf); } + } + if (!dexp_eval(args[3], &reps)) { + { sprintf(monbuf, "Invalid expression in repetition number.\n"); monprintf(monbuf); } + } + for (u32 i = 0; i < reps; i++){ + debuggerWriteHalfWord(address, (u16)value); + address += 2; + } + } + else + debuggerUsage("fillh"); +} + +void debuggerFillWord(int n, char **args) +{ + if (n == 4) { + u32 address; + u32 value; + u32 reps; + if (!dexp_eval(args[1], &address)) { + { sprintf(monbuf, "Invalid expression in address.\n"); monprintf(monbuf); } + return; + }/* + if(address & 3) { + { sprintf(monbuf, "Error: address must be word aligned\n"); monprintf(monbuf); } + return; + }*/ + if (!dexp_eval(args[2], &value)) { + { sprintf(monbuf, "Invalid expression in value.\n"); monprintf(monbuf); } + } + if (!dexp_eval(args[3], &reps)) { + { sprintf(monbuf, "Invalid expression in repetition number.\n"); monprintf(monbuf); } + } + for (u32 i = 0; i< reps; i++){ + debuggerWriteMemory(address, (u32)value); + address += 4; + } + } + else + debuggerUsage("fillw"); +} + +unsigned int SearchStart = 0xFFFFFFFF; +unsigned int SearchMaxMatches = 5; +u8 SearchData[64]; // It actually doesn't make much sense to search for more than 64 bytes, does it? +unsigned int SearchLength = 0; +unsigned int SearchResults; + +unsigned int AddressToGBA(u8* mem) +{ + if (mem >= &bios[0] && mem <= &bios[0x3fff]) + return 0x00000000 + (mem - &bios[0]); + else if (mem >= &workRAM[0] && mem <= &workRAM[0x3ffff]) + return 0x02000000 + (mem - &workRAM[0]); + else if (mem >= &internalRAM[0] && mem <= &internalRAM[0x7fff]) + return 0x03000000 + (mem - &internalRAM[0]); + else if (mem >= &ioMem[0] && mem <= &ioMem[0x3ff]) + return 0x04000000 + (mem - &ioMem[0]); + else if (mem >= &paletteRAM[0] && mem <= &paletteRAM[0x3ff]) + return 0x05000000 + (mem - &paletteRAM[0]); + else if (mem >= &vram[0] && mem <= &vram[0x1ffff]) + return 0x06000000 + (mem - &vram[0]); + else if (mem >= &oam[0] && mem <= &oam[0x3ff]) + return 0x07000000 + (mem - &oam[0]); + else if (mem >= &rom[0] && mem <= &rom[0x1ffffff]) + return 0x08000000 + (mem - &rom[0]); + else + return 0xFFFFFFFF; +}; + +void debuggerDoSearch() +{ + int count = 0; + + while (true) + { + unsigned int final = SearchStart + SearchLength - 1; + u8* end; + u8* start; + + switch (SearchStart >> 24) + { + case 0: + if (final > 0x00003FFF) { SearchStart = 0x02000000; continue; } + else { start = bios + (SearchStart & 0x3FFF); end = bios + 0x3FFF; break; }; + case 2: + if (final > 0x0203FFFF) { SearchStart = 0x03000000; continue; } + else { start = workRAM + (SearchStart & 0x3FFFF); end = workRAM + 0x3FFFF; break; }; + case 3: + if (final > 0x03007FFF) { SearchStart = 0x04000000; continue; } + else { start = internalRAM + (SearchStart & 0x7FFF); end = internalRAM + 0x7FFF; break; }; + case 4: + if (final > 0x040003FF) { SearchStart = 0x05000000; continue; } + else { start = ioMem + (SearchStart & 0x3FF); end = ioMem + 0x3FF; break; }; + case 5: + if (final > 0x050003FF) { SearchStart = 0x06000000; continue; } + else { start = paletteRAM + (SearchStart & 0x3FF); end = paletteRAM + 0x3FF; break; }; + case 6: + if (final > 0x0601FFFF) { SearchStart = 0x07000000; continue; } + else { start = vram + (SearchStart & 0x1FFFF); end = vram + 0x1FFFF; break; }; + case 7: + if (final > 0x070003FF) { SearchStart = 0x08000000; continue; } + else { start = oam + (SearchStart & 0x3FF); end = oam + 0x3FF; break; }; + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + if (final <= 0x09FFFFFF) + { + start = rom + (SearchStart & 0x01FFFFFF); end = rom + 0x01FFFFFF; break; + }; + default: + { sprintf(monbuf, "Search completed.\n"); monprintf(monbuf); } + SearchLength = 0; + return; + }; + + end -= SearchLength - 1; + u8 firstbyte = SearchData[0]; + while (start <= end) + { + while ((start <= end) && (*start != firstbyte)) + start++; + + if (start > end) + break; + + unsigned int p = 1; + while ((start[p] == SearchData[p]) && (p < SearchLength)) + p++; + + if (p == SearchLength) + { + { sprintf(monbuf, "Search result (%d): %08x\n", count + SearchResults, AddressToGBA(start)); monprintf(monbuf); } + count++; + if (count == SearchMaxMatches) + { + SearchStart = AddressToGBA(start + p); + SearchResults += count; + return; + }; + + start += p; // assume areas don't overlap; alternative: start++; + } + else + start++; + }; + + SearchStart = AddressToGBA(end + SearchLength - 1) + 1; + }; +}; + +void debuggerFindText(int n, char **args) +{ + if ((n == 4) || (n == 3)) + { + SearchResults = 0; + if (!dexp_eval(args[1], &SearchStart)){ + { sprintf(monbuf, "Invalid expression.\n"); monprintf(monbuf); } + return; + } + + if (n == 4) + { + sscanf(args[2], "%u", &SearchMaxMatches); + strncpy((char*)SearchData, args[3], 64); + SearchLength = strlen(args[3]); + } + else if (n == 3) + { + strncpy((char*)SearchData, args[2], 64); + SearchLength = strlen(args[2]); + }; + + if (SearchLength > 64) + { + { sprintf(monbuf, "Entered string (length: %d) is longer than 64 bytes and was cut.\n", SearchLength); monprintf(monbuf); } + SearchLength = 64; + }; + + debuggerDoSearch(); + + } + else + debuggerUsage("ft"); +}; + +void debuggerFindHex(int n, char **args) +{ + if ((n == 4) || (n == 3)) + { + SearchResults = 0; + if (!dexp_eval(args[1], &SearchStart)){ + { sprintf(monbuf, "Invalid expression.\n"); monprintf(monbuf); } + return; + } + + char SearchHex[128]; + if (n == 4) + { + sscanf(args[2], "%u", &SearchMaxMatches); + strncpy(SearchHex, args[3], 128); + SearchLength = strlen(args[3]); + } + else if (n == 3) + { + strncpy(SearchHex, args[2], 128); + SearchLength = strlen(args[2]); + }; + + if (SearchLength & 1) + { sprintf(monbuf, "Unaligned bytecount: %d,5. Last digit (%c) cut.\n", SearchLength / 2, SearchHex[SearchLength - 1]); monprintf(monbuf); } + + SearchLength /= 2; + + if (SearchLength > 64) + { + { sprintf(monbuf, "Entered string (length: %d) is longer than 64 bytes and was cut.\n", SearchLength); monprintf(monbuf); } + SearchLength = 64; + }; + + for (unsigned int i = 0; i < SearchLength; i++) + { + unsigned int cbuf = 0; + sscanf(&SearchHex[i << 1], "%02x", &cbuf); + SearchData[i] = cbuf; + }; + + debuggerDoSearch(); + + } + else + debuggerUsage("fh"); +}; + +void debuggerFindResume(int n, char **args) +{ + if ((n == 1) || (n == 2)) + { + if (SearchLength == 0) + { + { sprintf(monbuf, "Error: No search in progress. Start a search with ft or fh.\n"); monprintf(monbuf); } + debuggerUsage("fr"); + return; + }; + + if (n == 2) + sscanf(args[1], "%u", &SearchMaxMatches); + + debuggerDoSearch(); + + } + else + debuggerUsage("fr"); +}; + +void debuggerCopyByte(int n, char **args) +{ + u32 source; + u32 dest; + u32 number = 1; + u32 reps = 1; + if (n>5 || n<3){ + debuggerUsage("copyb"); + } + + if (n == 5) { + if (!dexp_eval(args[4], &reps)) { + { sprintf(monbuf, "Invalid expression in repetition number.\n"); monprintf(monbuf); } + } + } + if (n > 3){ + if (!dexp_eval(args[3], &number)) { + { sprintf(monbuf, "Invalid expression in number of copy units.\n"); monprintf(monbuf); } + } + } + if (!dexp_eval(args[1], &source)) { + { sprintf(monbuf, "Invalid expression in source address.\n"); monprintf(monbuf); } + return; + } + if (!dexp_eval(args[2], &dest)) { + { sprintf(monbuf, "Invalid expression in destination address.\n"); monprintf(monbuf); } + } + + for (u32 j = 0; j < reps; j++){ + for (u32 i = 0; i < number; i++){ + debuggerWriteByte(dest + i, debuggerReadByte(source + i)); + } + dest += number; + } +} + +void debuggerCopyHalfWord(int n, char **args) +{ + u32 source; + u32 dest; + u32 number = 2; + u32 reps = 1; + if (n>5 || n<3){ + debuggerUsage("copyh"); + } + + if (n == 5) { + if (!dexp_eval(args[4], &reps)) { + { sprintf(monbuf, "Invalid expression in repetition number.\n"); monprintf(monbuf); } + } + } + if (n > 3){ + if (!dexp_eval(args[3], &number)) { + { sprintf(monbuf, "Invalid expression in number of copy units.\n"); monprintf(monbuf); } + } + number = number << 1; + } + if (!dexp_eval(args[1], &source)) { + { sprintf(monbuf, "Invalid expression in source address.\n"); monprintf(monbuf); } + return; + } + if (!dexp_eval(args[2], &dest)) { + { sprintf(monbuf, "Invalid expression in destination address.\n"); monprintf(monbuf); } + } + + for (u32 j = 0; j < reps; j++){ + for (u32 i = 0; i < number; i += 2){ + debuggerWriteHalfWord(dest + i, debuggerReadHalfWord(source + i)); + } + dest += number; + } +} + +void debuggerCopyWord(int n, char **args) +{ + u32 source; + u32 dest; + u32 number = 4; + u32 reps = 1; + if (n>5 || n<3){ + debuggerUsage("copyw"); + } + + if (n == 5) { + if (!dexp_eval(args[4], &reps)) { + { sprintf(monbuf, "Invalid expression in repetition number.\n"); monprintf(monbuf); } + } + } + if (n > 3){ + if (!dexp_eval(args[3], &number)) { + { sprintf(monbuf, "Invalid expression in number of copy units.\n"); monprintf(monbuf); } + } + number = number << 2; + } + if (!dexp_eval(args[1], &source)) { + { sprintf(monbuf, "Invalid expression in source address.\n"); monprintf(monbuf); } + return; + } + if (!dexp_eval(args[2], &dest)) { + { sprintf(monbuf, "Invalid expression in destination address.\n"); monprintf(monbuf); } + } + + for (u32 j = 0; j < reps; j++){ + for (u32 i = 0; i < number; i += 4){ + debuggerWriteMemory(dest + i, debuggerReadMemory(source + i)); + } + dest += number; + } +} + +void debuggerIoVideo() +{ + { sprintf(monbuf, "DISPCNT = %04x\n", DISPCNT); monprintf(monbuf); } + { sprintf(monbuf, "DISPSTAT = %04x\n", DISPSTAT); monprintf(monbuf); } + { sprintf(monbuf, "VCOUNT = %04x\n", VCOUNT); monprintf(monbuf); } + { sprintf(monbuf, "BG0CNT = %04x\n", BG0CNT); monprintf(monbuf); } + { sprintf(monbuf, "BG1CNT = %04x\n", BG1CNT); monprintf(monbuf); } + { sprintf(monbuf, "BG2CNT = %04x\n", BG2CNT); monprintf(monbuf); } + { sprintf(monbuf, "BG3CNT = %04x\n", BG3CNT); monprintf(monbuf); } + { sprintf(monbuf, "WIN0H = %04x\n", WIN0H); monprintf(monbuf); } + { sprintf(monbuf, "WIN0V = %04x\n", WIN0V); monprintf(monbuf); } + { sprintf(monbuf, "WIN1H = %04x\n", WIN1H); monprintf(monbuf); } + { sprintf(monbuf, "WIN1V = %04x\n", WIN1V); monprintf(monbuf); } + { sprintf(monbuf, "WININ = %04x\n", WININ); monprintf(monbuf); } + { sprintf(monbuf, "WINOUT = %04x\n", WINOUT); monprintf(monbuf); } + { sprintf(monbuf, "MOSAIC = %04x\n", MOSAIC); monprintf(monbuf); } + { sprintf(monbuf, "BLDMOD = %04x\n", BLDMOD); monprintf(monbuf); } + { sprintf(monbuf, "COLEV = %04x\n", COLEV); monprintf(monbuf); } + { sprintf(monbuf, "COLY = %04x\n", COLY); monprintf(monbuf); } +} + +void debuggerIoVideo2() +{ + { sprintf(monbuf, "BG0HOFS = %04x\n", BG0HOFS); monprintf(monbuf); } + { sprintf(monbuf, "BG0VOFS = %04x\n", BG0VOFS); monprintf(monbuf); } + { sprintf(monbuf, "BG1HOFS = %04x\n", BG1HOFS); monprintf(monbuf); } + { sprintf(monbuf, "BG1VOFS = %04x\n", BG1VOFS); monprintf(monbuf); } + { sprintf(monbuf, "BG2HOFS = %04x\n", BG2HOFS); monprintf(monbuf); } + { sprintf(monbuf, "BG2VOFS = %04x\n", BG2VOFS); monprintf(monbuf); } + { sprintf(monbuf, "BG3HOFS = %04x\n", BG3HOFS); monprintf(monbuf); } + { sprintf(monbuf, "BG3VOFS = %04x\n", BG3VOFS); monprintf(monbuf); } + { sprintf(monbuf, "BG2PA = %04x\n", BG2PA); monprintf(monbuf); } + { sprintf(monbuf, "BG2PB = %04x\n", BG2PB); monprintf(monbuf); } + { sprintf(monbuf, "BG2PC = %04x\n", BG2PC); monprintf(monbuf); } + { sprintf(monbuf, "BG2PD = %04x\n", BG2PD); monprintf(monbuf); } + { sprintf(monbuf, "BG2X = %08x\n", (BG2X_H << 16) | BG2X_L); monprintf(monbuf); } + { sprintf(monbuf, "BG2Y = %08x\n", (BG2Y_H << 16) | BG2Y_L); monprintf(monbuf); } + { sprintf(monbuf, "BG3PA = %04x\n", BG3PA); monprintf(monbuf); } + { sprintf(monbuf, "BG3PB = %04x\n", BG3PB); monprintf(monbuf); } + { sprintf(monbuf, "BG3PC = %04x\n", BG3PC); monprintf(monbuf); } + { sprintf(monbuf, "BG3PD = %04x\n", BG3PD); monprintf(monbuf); } + { sprintf(monbuf, "BG3X = %08x\n", (BG3X_H << 16) | BG3X_L); monprintf(monbuf); } + { sprintf(monbuf, "BG3Y = %08x\n", (BG3Y_H << 16) | BG3Y_L); monprintf(monbuf); } +} + +void debuggerIoDMA() +{ + { sprintf(monbuf, "DM0SAD = %08x\n", (DM0SAD_H << 16) | DM0SAD_L); monprintf(monbuf); } + { sprintf(monbuf, "DM0DAD = %08x\n", (DM0DAD_H << 16) | DM0DAD_L); monprintf(monbuf); } + { sprintf(monbuf, "DM0CNT = %08x\n", (DM0CNT_H << 16) | DM0CNT_L); monprintf(monbuf); } + { sprintf(monbuf, "DM1SAD = %08x\n", (DM1SAD_H << 16) | DM1SAD_L); monprintf(monbuf); } + { sprintf(monbuf, "DM1DAD = %08x\n", (DM1DAD_H << 16) | DM1DAD_L); monprintf(monbuf); } + { sprintf(monbuf, "DM1CNT = %08x\n", (DM1CNT_H << 16) | DM1CNT_L); monprintf(monbuf); } + { sprintf(monbuf, "DM2SAD = %08x\n", (DM2SAD_H << 16) | DM2SAD_L); monprintf(monbuf); } + { sprintf(monbuf, "DM2DAD = %08x\n", (DM2DAD_H << 16) | DM2DAD_L); monprintf(monbuf); } + { sprintf(monbuf, "DM2CNT = %08x\n", (DM2CNT_H << 16) | DM2CNT_L); monprintf(monbuf); } + { sprintf(monbuf, "DM3SAD = %08x\n", (DM3SAD_H << 16) | DM3SAD_L); monprintf(monbuf); } + { sprintf(monbuf, "DM3DAD = %08x\n", (DM3DAD_H << 16) | DM3DAD_L); monprintf(monbuf); } + { sprintf(monbuf, "DM3CNT = %08x\n", (DM3CNT_H << 16) | DM3CNT_L); monprintf(monbuf); } +} + +void debuggerIoTimer() +{ + { sprintf(monbuf, "TM0D = %04x\n", TM0D); monprintf(monbuf); } + { sprintf(monbuf, "TM0CNT = %04x\n", TM0CNT); monprintf(monbuf); } + { sprintf(monbuf, "TM1D = %04x\n", TM1D); monprintf(monbuf); } + { sprintf(monbuf, "TM1CNT = %04x\n", TM1CNT); monprintf(monbuf); } + { sprintf(monbuf, "TM2D = %04x\n", TM2D); monprintf(monbuf); } + { sprintf(monbuf, "TM2CNT = %04x\n", TM2CNT); monprintf(monbuf); } + { sprintf(monbuf, "TM3D = %04x\n", TM3D); monprintf(monbuf); } + { sprintf(monbuf, "TM3CNT = %04x\n", TM3CNT); monprintf(monbuf); } +} + +void debuggerIoMisc() +{ + { sprintf(monbuf, "P1 = %04x\n", P1); monprintf(monbuf); } + { sprintf(monbuf, "IE = %04x\n", IE); monprintf(monbuf); } + { sprintf(monbuf, "IF = %04x\n", IF); monprintf(monbuf); } + { sprintf(monbuf, "IME = %04x\n", IME); monprintf(monbuf); } +} + +void debuggerIo(int n, char **args) +{ + if (n == 1) { + debuggerIoVideo(); + return; + } + if (!strcmp(args[1], "video")) + debuggerIoVideo(); + else if (!strcmp(args[1], "video2")) + debuggerIoVideo2(); + else if (!strcmp(args[1], "dma")) + debuggerIoDMA(); + else if (!strcmp(args[1], "timer")) + debuggerIoTimer(); + else if (!strcmp(args[1], "misc")) + debuggerIoMisc(); + else { sprintf(monbuf, "Unrecognized option %s\n", args[1]); monprintf(monbuf); } +} + +#define ASCII(c) (c) < 32 ? '.' : (c) > 127 ? '.' : (c) + +bool canUseTbl = true; +bool useWordSymbol = false; +bool thereIsATable = false; +char** wordSymbol; +bool isTerminator[256]; +bool isNewline[256]; +bool isTab[256]; +u8 largestSymbol = 1; + +void freeWordSymbolContents(){ + for (int i = 0; i<256; i++){ + if (wordSymbol[i]) + free(wordSymbol[i]); + wordSymbol[i] = NULL; + isTerminator[i] = false; + isNewline[i] = false; + isTab[i] = false; + } +} + +void freeWordSymbol(){ + useWordSymbol = false; + thereIsATable = false; + free(wordSymbol); + largestSymbol = 1; +} + +void debuggerReadCharTable(int n, char** args){ + if (n == 2){ + if (!canUseTbl){ + { sprintf(monbuf, "Cannot operate over character table, as it was disabled.\n"); monprintf(monbuf); } + return; + } + if (strcmp(args[1], "none") == 0){ + freeWordSymbol(); + { sprintf(monbuf, "Cleared table. Reverted to ASCII.\n"); monprintf(monbuf); } + return; + } + FILE* tlb = fopen(args[1], "r"); + if (!tlb){ + { sprintf(monbuf, "Could not open specified file. Abort.\n"); monprintf(monbuf); } + return; + } + char buffer[30]; + u32 slot; + char* character = (char*)calloc(10, sizeof(char)); + wordSymbol = (char**)calloc(256, sizeof(char*)); + while (fgets(buffer, 30, tlb)){ + + sscanf(buffer, "%02x=%s", &slot, character); + + if (character[0]){ + if (strlen(character) == 4){ + if ((character[0] == '<') && + (character[1] == '\\') && + (character[3] == '>')){ + if (character[2] == '0'){ + isTerminator[slot] = true; + }if (character[2] == 'n'){ + isNewline[slot] = true; + }if (character[2] == 't'){ + isTab[slot] = true; + } + continue; + } + else + wordSymbol[slot] = character; + } + else + wordSymbol[slot] = character; + } + else + wordSymbol[slot] = " "; + + if (largestSymbol < strlen(character)) + largestSymbol = strlen(character); + + character = (char*)malloc(10); + } + useWordSymbol = true; + thereIsATable = true; + + } + else{ + debuggerUsage("tbl"); + } +} + +void printCharGroup(u32 addr, bool useAscii){ + for (int i = 0; i<16; i++){ + if (useWordSymbol && !useAscii){ + char* c = wordSymbol[debuggerReadByte(addr + i)]; + int j; + if (c){ + { sprintf(monbuf, "%s", c); monprintf(monbuf); } + j = strlen(c); + } + else{ + j = 0; + } + while (j {flag} {value}\n"); monprintf(monbuf); } + printFlagHelp(); + return; + } + u8 reg = (u8)getRegisterNumber(args[0]); + u8 flag = getFlags(args[1]); + u32 value; + if (!dexp_eval(args[2], &value)){ + { sprintf(monbuf, "Invalid expression.\n"); monprintf(monbuf); } + return; + } + if (flag != 0){ + addBreakRegToList(reg, flag, value); + { sprintf(monbuf, "Added breakpoint on register R%02d, value %08x\n", reg, value); monprintf(monbuf); } + } + return; +} + +void debuggerBreakRegisterClear(int n, char** args){ + if (n > 0){ + int r = getRegisterNumber(args[0]); + if (r >= 0){ + clearParticularRegListBreaks(r); + { sprintf(monbuf, "Cleared all Register breakpoints for %s.\n", args[0]); monprintf(monbuf); } + } + } + else{ + clearBreakRegList(); + { sprintf(monbuf, "Cleared all Register breakpoints.\n"); monprintf(monbuf); } + } +} + +void debuggerBreakRegisterDelete(int n, char** args){ + if (n < 2){ + { sprintf(monbuf, "Illegal use of Break register delete:\n Correct usage requires .\n"); monprintf(monbuf); } + return; + } + int r = getRegisterNumber(args[0]); + if ((r < 0) || (r>16)){ + { sprintf(monbuf, "Could not find a correct register number:\n Correct usage requires .\n"); monprintf(monbuf); } + return; + } + u32 num; + if (!dexp_eval(args[1], &num)){ + { sprintf(monbuf, "Could not parse the breakpoint number:\n Correct usage requires .\n"); monprintf(monbuf); } + return; + } + deleteFromBreakRegList(r, num); + { sprintf(monbuf, "Deleted Breakpoint %d of regsiter %s.\n", num, args[0]); monprintf(monbuf); } +} + +//WARNING: Some old particle to new code conversion may convert a single command +//into two or more words. Such words are separated by space, so a new tokenizer can +//find them. +char* replaceAlias(char* lower_cmd, char** aliasTable){ + for (int i = 0; aliasTable[i]; i = i + 2){ + if (strcmp(lower_cmd, aliasTable[i]) == 0){ + return aliasTable[i + 1]; + } + } + return lower_cmd; +} + +char* breakAliasTable[] = { + + //actual beginning + "break", "b 0 0", + "breakpoint", "b 0 0", + "bp", "b 0 0", + "b", "b 0 0", + + //break types + "thumb", "t", + "arm", "a", + "execution", "x", + "exec", "x", + "e", "x", + "exe", "x", + "x", "x", + "read", "r", + "write", "w", + "access", "i", + "acc", "i", + "io", "i", + "register", "g", + "reg", "g", + "any", "*", + + //code modifiers + "clear", "c", + "clean", "c", + "cls", "c", + "list", "l", + "lst", "l", + "delete", "d", + "del", "d", + "make", "m", + /* + //old parts made to look like the new code parts + "bt", "b t m", + "ba", "b a m", + "bd", "b * d", + "bl", "b * l", + "bpr","b r m", + "bprc","b r c", + "bpw", "b w m", + "bpwc", "b w c", + "bt", "b t m", + */ + //and new parts made to look like old parts + "breg", "b g m", + "bregc", "b g c", + "bregd", "b g d", + "bregl", "b g l", + + "blist", "b * l", + /* + "btc", "b t c", + "btd", "b t d", + "btl", "b t l", + + "bac", "b a c", + "bad", "b a d", + "bal", "b a l", + + "bx", "b x m", + "bxc", "b x c", + "bxd", "b x d", + "bxl", "b x l", + + "bw", "b w m", + "bwc", "b w c", + "bwd", "b w d", + "bwl", "b w l", + + "br", "b r m", + "brc", "b r c", + "brd", "b r d", + "brl", "b r l", + */ + "bio", "b i m", + "bioc", "b i c", + "biod", "b i d", + "biol", "b i l", + + "bpio", "b i m", + "bpioc", "b i c", + "bpiod", "b i d", + "bpiol", "b i l", + /* + "bprd", "b r d", + "bprl", "b r l", + + "bpwd", "b w d", + "bpwl", "b w l", + */ + NULL, NULL + +}; + + +char* breakSymbolCombo(char * command, int* length){ + char * res = (char*)malloc(6); + res[0] = 'b'; + res[1] = ' '; + res[2] = '0'; + res[3] = ' '; + res[4] = '0'; + int i = 1; + if (command[1] == 'p'){ + i++; + } + while (i < *length){ + switch (command[i]){ + case 'l': + case 'c': + case 'd': + case 'm': if (res[4] == '0') + res[4] = command[i]; + else{ + free(res); + return command; + } + break; + case '*': + case 't': + case 'a': + case 'x': + case 'r': + case 'w': + case 'i': if (res[2] == '0') + res[2] = command[i]; + else{ + free(res); + return command; + } + break; + default: + free(res); + return command; + } + i++; + } + if (res[2] == '0') + res[2] = '*'; + if (res[4] == '0') + res[4] = 'm'; + *length = 5; + return res; +} + +char* typeMapping[] = { "'u8", "'u16", "'u32", "'u32", "'s8", "'s16", "'s32", "'s32" }; + +char* compareFlagMapping[] = { "Never", "==", ">", ">=", "<", "<=", "!=", "<=>" }; + +struct intToString{ + int value; + char mapping[20]; +}; + +struct intToString breakFlagMapping[] = { + { 0x80, "Thumb" }, + { 0x40, "ARM" }, + { 0x20, "Read" }, + { 0x10, "Write" }, + { 0x8, "Thumb" }, + { 0x4, "ARM" }, + { 0x2, "Read" }, + { 0x1, "Write" }, + { 0x0, "None" } +}; + +//printers +void printCondition(struct ConditionalBreakNode* toPrint){ + if (toPrint){ + char* firstType = typeMapping[toPrint->exp_type_flags & 0x7]; + char* secondType = typeMapping[(toPrint->exp_type_flags >> 4) & 0x7]; + char* operand = compareFlagMapping[toPrint->cond_flags & 0x7]; + { sprintf(monbuf, "%s %s %s%s %s %s", firstType, toPrint->address, + ((toPrint->cond_flags & 8) ? "s" : ""), operand, + secondType, toPrint->value); + monprintf(monbuf); } + if (toPrint->next){ + { sprintf(monbuf, " &&\n\t\t"); monprintf(monbuf); } + printCondition(toPrint->next); + } + else{ + { sprintf(monbuf, "\n"); monprintf(monbuf); } + return; + } + } +} + +void printConditionalBreak(struct ConditionalBreak* toPrint, bool printAddress){ + if (toPrint){ + if (printAddress) + { sprintf(monbuf, "At %08x, ", toPrint->break_address); monprintf(monbuf); } + if (toPrint->type_flags & 0xf0) + { sprintf(monbuf, "Break Always on"); monprintf(monbuf); } + bool hasPrevCond = false; + u8 flgs = 0x80; + while (flgs != 0){ + if (toPrint->type_flags & flgs){ + if (hasPrevCond) { sprintf(monbuf, ","); monprintf(monbuf); } + for (int i = 0; i < 9; i++){ + if (breakFlagMapping[i].value == flgs){ + { sprintf(monbuf, "\t%s", breakFlagMapping[i].mapping); monprintf(monbuf); } + hasPrevCond = true; + } + } + } + flgs = flgs >> 1; + if ((flgs == 0x8) && (toPrint->type_flags & 0xf)){ + { sprintf(monbuf, "\n\t\tBreak conditional on"); monprintf(monbuf); } + hasPrevCond = false; + } + } + { sprintf(monbuf, "\n"); monprintf(monbuf); } + if (toPrint->type_flags & 0xf && toPrint->firstCond){ + { sprintf(monbuf, "With conditions:\n\t\t"); monprintf(monbuf); } + printCondition(toPrint->firstCond); + } + else if (toPrint->type_flags & 0xf){ + //should not happen + { sprintf(monbuf, "No conditions detected, but conditional. Assumed always by default.\n"); monprintf(monbuf); } + } + } +} + +void printAllConditionals(){ + + for (int i = 0; i<16; i++){ + + if (conditionals[i] != NULL){ + { sprintf(monbuf, "Address range 0x%02x000000 breaks:\n", i); monprintf(monbuf); } + { sprintf(monbuf, "-------------------------\n"); monprintf(monbuf); } + struct ConditionalBreak* base = conditionals[i]; + int count = 1; + u32 lastAddress = base->break_address; + { sprintf(monbuf, "Address %08x\n-------------------------\n", lastAddress); monprintf(monbuf); } + while (base){ + if (lastAddress != base->break_address){ + lastAddress = base->break_address; + count = 1; + { sprintf(monbuf, "-------------------------\n"); monprintf(monbuf); } + { sprintf(monbuf, "Address %08x\n-------------------------\n", lastAddress); monprintf(monbuf); } + } + { sprintf(monbuf, "No.%d\t-->\t", count); monprintf(monbuf); } + printConditionalBreak(base, false); + count++; + base = base->next; + } + } + } +} + +u8 printConditionalsFromAddress(u32 address){ + u8 count = 1; + if (conditionals[address >> 24] != NULL){ + struct ConditionalBreak* base = conditionals[address >> 24]; + while (base){ + if (address == base->break_address){ + if (count == 1){ + { sprintf(monbuf, "Address %08x\n-------------------------\n", address); monprintf(monbuf); } + } + { sprintf(monbuf, "No.%d\t-->\t", count); monprintf(monbuf); } + printConditionalBreak(base, false); + count++; + } + if (address < base->break_address) + break; + base = base->next; + } + } + if (count == 1){ + { sprintf(monbuf, "None\n"); monprintf(monbuf); } + } + return count; +} + +void printAllFlagConditionals(u8 flag, bool orMode){ + int count = 1; + int actualCount = 1; + for (int i = 0; i<16; i++){ + if (conditionals[i] != NULL){ + bool isCondStart = true; + struct ConditionalBreak* base = conditionals[i]; + + u32 lastAddress = base->break_address; + + while (base){ + if (lastAddress != base->break_address){ + lastAddress = base->break_address; + count = 1; + actualCount = 1; + } + if (((base->type_flags & flag) == base->type_flags) || (orMode && (base->type_flags & flag))){ + if (actualCount == 1){ + if (isCondStart){ + { sprintf(monbuf, "Address range 0x%02x000000 breaks:\n", i); monprintf(monbuf); } + { sprintf(monbuf, "-------------------------\n"); monprintf(monbuf); } + isCondStart = false; + } + { sprintf(monbuf, "Address %08x\n-------------------------\n", lastAddress); monprintf(monbuf); } + } + { sprintf(monbuf, "No.%d\t-->\t", count); monprintf(monbuf); } + printConditionalBreak(base, false); + actualCount++; + } + base = base->next; + count++; + } + } + } +} + +void printAllFlagConditionalsWithAddress(u32 address, u8 flag, bool orMode){ + int count = 1; + int actualCount = 1; + for (int i = 0; i<16; i++){ + if (conditionals[i] != NULL){ + bool isCondStart = true; + struct ConditionalBreak* base = conditionals[i]; + + u32 lastAddress = base->break_address; + + while (base){ + if (lastAddress != base->break_address){ + lastAddress = base->break_address; + count = 1; + actualCount = 1; + } + if ((lastAddress == address) && + (((base->type_flags & flag) == base->type_flags) || (orMode && (base->type_flags & flag)))){ + if (actualCount == 1){ + if (isCondStart){ + { sprintf(monbuf, "Address range 0x%02x000000 breaks:\n", i); monprintf(monbuf); } + { sprintf(monbuf, "-------------------------\n"); monprintf(monbuf); } + isCondStart = false; + } + { sprintf(monbuf, "Address %08x\n-------------------------\n", lastAddress); monprintf(monbuf); } + } + { sprintf(monbuf, "No.%d\t-->\t", count); monprintf(monbuf); } + printConditionalBreak(base, false); + actualCount++; + } + base = base->next; + count++; + } + } + } +} + +void makeBreak(u32 address, u8 flags, char** expression, int n){ + if (n >= 1){ + if (tolower(expression[0][0]) == 'i' && tolower(expression[0][1]) == 'f'){ + expression = expression + 1; + n--; + if (n != 0){ + parseAndCreateConditionalBreaks(address, flags, expression, n); + return; + } + } + } + else{ + flags = flags << 0x4; + printConditionalBreak(addConditionalBreak(address, flags), true); + return; + } +} +void deleteBreak(u32 address, u8 flags, char** expression, int howToDelete){ + bool applyOr = true; + if (howToDelete > 0){ + if (((expression[0][0] == '&') && !expression[0][1]) || + (tolower(expression[0][0]) == 'o') && (tolower(expression[0][1]) == 'n') && + (tolower(expression[0][0]) == 'l') && (tolower(expression[0][1]) == 'y')){ + applyOr = false; + howToDelete--; + expression++; + } + if (howToDelete > 0){ + u32 number = 0; + if (!dexp_eval(expression[0], &number)){ + { sprintf(monbuf, "Invalid expression for number format.\n"); monprintf(monbuf); } + return; + } + removeFlagFromConditionalBreakNo(address, (u8)number, (flags | (flags >> 4))); + { sprintf(monbuf, "Removed all specified breaks from %08x.\n", address); monprintf(monbuf); } + return; + } + removeConditionalWithAddressAndFlag(address, flags, applyOr); + removeConditionalWithAddressAndFlag(address, flags << 4, applyOr); + { sprintf(monbuf, "Removed all specified breaks from %08x.\n", address); monprintf(monbuf); } + } + else{ + removeConditionalWithAddressAndFlag(address, flags, applyOr); + removeConditionalWithAddressAndFlag(address, flags << 4, applyOr); + { sprintf(monbuf, "Removed all specified breaks from %08x.\n", address); monprintf(monbuf); } + } + return; +} +void clearBreaks(u32 address, u8 flags, char** expression, int howToClear){ + if (howToClear == 2){ + removeConditionalWithFlag(flags, true); + removeConditionalWithFlag(flags << 4, true); + } + else{ + removeConditionalWithFlag(flags, false); + removeConditionalWithFlag(flags << 4, false); + } + { sprintf(monbuf, "Cleared all requested breaks.\n", address); monprintf(monbuf); } + +} + +void listBreaks(u32 address, u8 flags, char** expression, int howToList){ + flags |= (flags << 4); + if (howToList){ + printAllFlagConditionalsWithAddress(address, flags, true); + } + else{ + printAllFlagConditionals(flags, true); + } + { sprintf(monbuf, "\n"); monprintf(monbuf); } +} + +void executeBreakCommands(int n, char** cmd){ + char* command = cmd[0]; + int len = strlen(command); + bool changed = false; + if (len <= 4){ + command = breakSymbolCombo(command, &len); + changed = (len == 5); + }if (!changed){ + command = strdup(replaceAlias(cmd[0], breakAliasTable)); + changed = (strcmp(cmd[0], command)); + } + if (!changed){ + cmd[0][0] = '!'; + return; + } + cmd++; + n--; + void(*operation)(u32, u8, char**, int) = &makeBreak; //the function to be called + + u8 flag = 0; + u32 address = 0; + //if(strlen(command) == 1){ + //Cannot happen, that would mean cmd[0] != b + //} + char target; + char ope; + + if (command[2] == '0'){ + if (n <= 0){ + { sprintf(monbuf, "Invalid break command.\n"); monprintf(monbuf); } + free(command); + return; + } + + for (int i = 0; cmd[0][i]; i++){ + cmd[0][i] = tolower(cmd[0][i]); + } + char* replaced = replaceAlias(cmd[0], breakAliasTable); + if (replaced == cmd[0]){ + target = '*'; + } + else{ + target = replaced[0]; + if ((target == 'c') || (target == 'd') || (target == 'l') || (target == 'm')){ + command[4] = target; + target = '*'; + } + cmd++; + n--; + } + command[2] = target; + } + + if (command[4] == '0'){ + if (n <= 0){ + { sprintf(monbuf, "Invalid break command.\n"); monprintf(monbuf); } + free(command); + return; + } + + for (int i = 0; cmd[0][i]; i++){ + cmd[0][i] = tolower(cmd[0][i]); + } + ope = replaceAlias(cmd[0], breakAliasTable)[0]; + if ((ope == 'c') || (ope == 'd') || (ope == 'l') || (ope == 'm')){ + command[4] = ope; + cmd++; + n--; + } + else{ + command[4] = 'm'; + } + + + } + + switch (command[4]){ + case 'l': operation = &listBreaks; break; + case 'c': operation = &clearBreaks; break; + case 'd': operation = &deleteBreak; break; + + case 'm': + default: operation = &makeBreak; + }; + + switch (command[2]){ + case 'g': switch (command[4]){ + case 'l': debuggerBreakRegisterList((n>0) && (tolower(cmd[0][0]) == 'v')); return; + case 'c': debuggerBreakRegisterClear(n, cmd); return; + case 'd': debuggerBreakRegisterDelete(n, cmd); return; + + case 'm': debuggerBreakRegister(n, cmd); + default: return; + }; + return; + case '*': flag = 0xf; break; + case 't': flag = 0x8; break; + case 'a': flag = 0x4; break; + case 'x': flag = 0xC; break; + case 'r': flag = 0x2; break; + case 'w': flag = 0x1; break; + case 'i': flag = 0x3; break; + default: free(command); return; + }; + + free(command); + bool hasAddress = false; + if ((n >= 1) && (operation != clearBreaks)){ + if (!dexp_eval(cmd[0], &address)){ + { sprintf(monbuf, "Invalid expression for address format.\n"); monprintf(monbuf); } + return; + } + hasAddress = true; + } + if (operation == listBreaks){ + operation(address, flag, NULL, hasAddress); + return; + } + else if (operation == clearBreaks){ + if (!hasAddress && (n >= 1)){ + if (((cmd[0][0] == '|' && cmd[0][1] == '|') || + ((cmd[0][0] == 'O' || cmd[0][0] == 'o') && + cmd[0][1] == 'r' || cmd[0][1] == 'r'))) { + operation(address, flag, NULL, 2); + } + else{ + operation(address, flag, NULL, 0); + } + } + else{ + operation(address, flag, NULL, 0); + } + } + else if (!hasAddress && (operation == deleteBreak)){ + { sprintf(monbuf, "Delete breakpoint operation requires at least one address;\n"); monprintf(monbuf); } + { sprintf(monbuf, "Usage: break [type] delete [address] no.[number] --> Deletes breakpoint [number] of [address].\n"); monprintf(monbuf); } + //{ sprintf(monbuf, "Usage: [delete Operand] [address] End [address] --> Deletes range between [address] and [end]\n"); monprintf(monbuf); } + { sprintf(monbuf, "Usage: break [type] delete [address]\n --> Deletes all breakpoints of [type] on [address]."); monprintf(monbuf); } + return; + } + else if (!hasAddress && (operation == makeBreak)){ + { sprintf(monbuf, "Can only create breakpoints if an address is provided"); monprintf(monbuf); } + //print usage here + return; + } + else{ + operation(address, flag, cmd + 1, n - 1); + return; + } + +brkcmd_special_register: + switch (command[4]){ + case 'l': debuggerBreakRegisterList((n>0) && (tolower(cmd[0][0]) == 'v')); return; + case 'c': debuggerBreakRegisterClear(n, cmd); return; + case 'd': debuggerBreakRegisterDelete(n, cmd); return; + + case 'm': debuggerBreakRegister(n, cmd); + default: return; + }; + return; +} + +void debuggerDisable(int n, char** args){ + if (n >= 3){ + debuggerUsage("disable"); + return; + } + while (n > 1){ + int i = 0; + while (args[3 - n][i]){ + args[3 - n][i] = tolower(args[2 - n][i]); + i++; + } + if (strcmp(args[3 - n], "breg")){ + enableRegBreak = false; + { sprintf(monbuf, "Break on register disabled.\n"); monprintf(monbuf); } + } + else if (strcmp(args[3 - n], "tbl")){ + canUseTbl = false; + useWordSymbol = false; + { sprintf(monbuf, "Symbol table disabled.\n"); monprintf(monbuf); } + } + else{ + { sprintf(monbuf, "Invalid command. Only tbl and breg are accepted as commands\n"); monprintf(monbuf); } + return; + } + n--; + } +} + +void debuggerEnable(int n, char** args){ + if (n >= 3){ + debuggerUsage("enable"); + return; + } + while (n > 1){ + int i = 0; + while (args[3 - n][i]){ + args[3 - n][i] = tolower(args[2 - n][i]); + i++; + } + if (strcmp(args[3 - n], "breg")){ + enableRegBreak = true; + { sprintf(monbuf, "Break on register enabled.\n"); monprintf(monbuf); } + } + else if (strcmp(args[3 - n], "tbl")){ + canUseTbl = true; + useWordSymbol = thereIsATable; + { sprintf(monbuf, "Symbol table enabled.\n"); monprintf(monbuf); } + } + else{ + { sprintf(monbuf, "Invalid command. Only tbl and breg are accepted as commands\n"); monprintf(monbuf); } + return; + } + n--; + } +} + +DebuggerCommand debuggerCommands[] = { + //simple commands + { "?", debuggerHelp, "Shows this help information. Type ? for command help. Alias 'help', 'h'.", "[]" }, + // { "n", debuggerNext, "Executes the next instruction.", "[]" }, + // { "c", debuggerContinue, "Continues execution", NULL }, + // // Hello command, shows Hello on the board + + //{ "br", debuggerBreakRead, "Break on read", "{address} {size}" }, + //{ "bw", debuggerBreakWrite, "Break on write", "{address} {size}" }, + //{ "bt", debuggerBreakWrite, "Break on write", "{address} {size}" }, + + //{ "ba", debuggerBreakArm, "Adds an ARM breakpoint", "{address}" }, + //{ "bd", debuggerBreakDelete, "Deletes a breakpoint", "" }, + //{ "bl", debuggerBreakList, "Lists breakpoints" }, + //{ "bpr", debuggerBreakRead, "Break on read", "{address} {size}" }, + //{ "bprc", debuggerBreakReadClear, "Clear break on read", NULL }, + //{ "bpw", debuggerBreakWrite, "Break on write", "{address} {size}" }, + //{ "bpwc", debuggerBreakWriteClear, "Clear break on write", NULL }, + { "breg", debuggerBreakRegister, "Breaks on a register specified value", " {flag} {value}" }, + { "bregc", debuggerBreakRegisterClear, "Clears all break on register", " {flag} {value}" }, + //{ "bt", debuggerBreakThumb, "Adds a THUMB breakpoint", "{address}" } + + // //diassemble commands + // { "d", debuggerDisassemble, "Disassembles instructions", "[
[]]" }, + // { "da", debuggerDisassembleArm, "Disassembles ARM instructions", "[{address} [{number}]]" }, + // { "dt", debuggerDisassembleThumb, "Disassembles Thumb instructions", "[{address} [{number}]]" }, + + { "db", debuggerDontBreak, "Don't break at the following address.", "[{address} [{number}]]" }, + { "dbc", debuggerDontBreakClear, "Clear the Don't Break list.", NULL }, + { "dload", debuggerDumpLoad, "Load raw data dump from file", " {address}" }, + { "dsave", debuggerDumpSave, "Dump raw data to file", " {address} {size}" }, + // { "dn", debuggerDisassembleNear, "Disassembles instructions near PC", "[{number}]" }, + + { "disable", debuggerDisable, "Disables operations.", "tbl|breg" }, + { "enable", debuggerEnable, "Enables operations.", "tbl|breg" }, + + { "eb", debuggerEditByte, "Modify memory location (byte)", "{address} {value}*" }, + { "eh", debuggerEditHalfWord, "Modify memory location (half-word)", "{address} {value}*" }, + { "ew", debuggerEditWord, "Modify memory location (word)", "{address} {value}*" }, + { "er", debuggerEditRegister, "Modify register", " {value}" }, + + { "eval", debuggerEval, "Evaluate expression", "{expression}" }, + + { "fillb", debuggerFillByte, "Fills memory location (byte)", "{address} {value} {number of times}" }, + { "fillh", debuggerFillHalfWord, "Fills memory location (half-word)", "{address} {value} {number of times}" }, + { "fillw", debuggerFillWord, "Fills memory location (word)", "{address} {value} {number of times}" }, + + { "copyb", debuggerCopyByte, "Copies memory content (byte)", "{address} {second address} {size} optional{repeat}" }, + { "copyh", debuggerCopyHalfWord, "Copies memory content (half-word)", "{address} {second address} {size} optional{repeat}" }, + { "copyw", debuggerCopyWord, "Copies memory content (word)", "{address} {second address} {size} optional{repeat}" }, + + { "ft", debuggerFindText, "Search memory for ASCII-string.", " [] " }, + { "fh", debuggerFindHex, "Search memory for hex-string.", " [] " }, + { "fr", debuggerFindResume, "Resume current search.", "[]" }, + + { "io", debuggerIo, "Show I/O registers status", "[video|video2|dma|timer|misc]" }, + // { "load", debuggerReadState, "Loads a Fx type savegame", "" }, + + { "mb", debuggerMemoryByte, "Shows memory contents (bytes)", "{address}" }, + { "mh", debuggerMemoryHalfWord, "Shows memory contents (half-words)", "{address}" }, + { "mw", debuggerMemoryWord, "Shows memory contents (words)", "{address}" }, + { "ms", debuggerStringRead, "Shows memory contents (table string)", "{address}" }, + + { "r", debuggerRegisters, "Shows ARM registers", NULL }, + // { "rt", debuggerRunTo, "Run to address", "{address}" }, + // { "rta", debuggerRunToArm, "Run to address (ARM)", "{address}" }, + // { "rtt", debuggerRunToThumb, "Run to address (Thumb)", "{address}" }, + + // { "reset", debuggerResetSystem, "Resets the system", NULL }, + // { "reload", debuggerReloadRom, "Reloads the ROM", "optional {rom path}" }, + { "execute", debuggerExecuteCommands, "Executes commands from a text file", "{file path}" }, + + // { "save", debuggerWriteState, "Creates a Fx type savegame", "" }, + // { "sbreak", debuggerBreak, "Adds a breakpoint on the given function", "||" }, + { "sradix", debuggerSetRadix, "Sets the print radix", "" }, + // { "sprint", debuggerPrint, "Print the value of a expression (if known)", "[/x|/o|/d] " }, + { "ssymbols", debuggerSymbols, "List symbols", "[]" }, + //#ifndef FINAL_VERSION + // { "strace", debuggerDebug, "Sets the trace level", "" }, + //#endif + //#ifdef DEV_VERSION + // { "sverbose", debuggerVerbose, "Change verbose setting", "" }, + //#endif + { "swhere", debuggerWhere, "Shows call chain", NULL }, + + { "tbl", debuggerReadCharTable, "Loads a character table", "" }, + + // { "trace", debuggerTrace, "Control tracer", "start|stop|file " }, + { "var", debuggerVar, "Define variables", " {variable}" }, + { NULL, NULL, NULL, NULL } // end marker +}; + +void printFlagHelp() +{ + monprintf("Flags are combinations of six distinct characters:\n"); + monprintf("\t\te --> Equal to;\n"); + monprintf("\t\tg --> Greater than;\n"); + monprintf("\t\tl --> Less than;\n"); + monprintf("\t\ts --> signed;\n"); + monprintf("\t\tu --> unsigned (assumed by ommision);\n"); + monprintf("\t\tn --> not;\n"); + monprintf("Ex: ge -> greater or equal; ne -> not equal; lg --> less or greater (same as not equal);\n"); + monprintf("s and u parts cannot be used in the same line, and are not negated by n;\n"); + monprintf("Special flags: always(all true), never(all false).\n"); +} + +void debuggerUsage(char *cmd) +{ + if (!strcmp(cmd, "break")){ + monprintf("Break command, composed of three parts:\n"); + monprintf("Break (b, bp or break): Indicates a break command;\n"); + monprintf("Type of break: Indicates the type of break the command applies to;\n"); + monprintf("Command: Indicates the type of command to be applied.\n"); + monprintf("Type Flags:\n\tt (thumb): The Thumb execution mode.\n"); + monprintf("\ta (ARM): The ARM execution mode.\n"); + monprintf("\tx (execution, exe, exec, e): Any execution mode.\n"); + monprintf("\tr (read): When a read occurs.\n"); + monprintf("\tw (write): When a write occurs.\n"); + monprintf("\ti (io, access,acc): When memory access (read or write) occurs.\n"); + monprintf("\tg (register, reg): Special On Register value change break.\n"); + monprintf("\t* (any): On any occasion (except register change).Omission value.\n"); + monprintf("Cmd Flags:\n\tm (make): Create a breakpoint.Default omission value.\n"); + monprintf("\tl (list,lst): Lists all existing breakpoints of the specified type.\n"); + monprintf("\td (delete,del): Deletes a specific breakpoint of the specified type.\n"); + monprintf("\tc (clear, clean, cls): Erases all breakpoints of the specified type.\n"); + monprintf("\n"); + monprintf("All those flags can be combined in order to access the several break functions\n"); + monprintf("EX: btc clears all breaks; bx, bxm creates a breakpoint on any type of execution.\n"); + monprintf("All commands can be built by using [b|bp][TypeFlag][CommandFlag];\n"); + monprintf("All commands can be built by using [b|bp|break] [TypeFlag|alias] [CommandFlag|alias];\n"); + monprintf("Each command has separate arguments from each other.\nFor more details, use help b[reg|m|d|c|l]\n"); + return; + } + if (!strcmp(cmd, "breg")){ + monprintf("Break on register command, special case of the break command.\n"); + monprintf("It allows the user to break when a certain value is inside a register.\n"); + monprintf("All register breaks are conditional.\n"); + monprintf("Usage: breg [regName] [condition] [Expression].\n"); + monprintf("regName is between r0 and r15 (PC, LR and SP included);\n"); + monprintf("expression is an evaluatable expression whose value determines when to break;\n"); + monprintf("condition is the condition to be evaluated in typeFlags.\n"); + printFlagHelp(); + monprintf("---------!!!WARNING!!!---------\n"); + monprintf("Register checking and breaking is extremely expensive for the computer.\n"); + monprintf("On one of the test machines, a maximum value of 600% for speedup collapsed\n"); + monprintf("to 350% just from having them enabled.\n"); + monprintf("If (or while) not needed, you can have a speedup by disabling them, using\n"); + monprintf("disable breg.\n"); + monprintf("Breg is disabled by default. Re-enable them using enable breg.\n"); + monprintf("Use example: breg r0 ne 0x0 --> Breaks as soon as r0 is not 0.\n"); + return; + } + if (!strcmp(cmd, "bm")){ + monprintf("Create breakpoint command. Used to place a breakpoint on a given address.\n"); + monprintf("It allows for breaks on execution(any processor mode) and on access(r/w).\n"); + monprintf("Breaks can be Conditional or Inconditional.\n\n"); + monprintf("Inconditional breaks:\nUsage: [breakTag] [address]\n"); + monprintf("Simplest of the two, the old type of breaks. Creates a breakpoint that, when\n"); + monprintf("the given type flag occurs (like a read, or a run when in thumb mode), halts;\n\n"); + monprintf("Conditional breaks:\n"); + monprintf("Usage:\n\t[breakTag] [address] if {' [expr] [cond] ' [expr] <&&,||>}\n"); + monprintf("Where <> elements are optional, {} are repeateable;\n"); + monprintf("[expression] are evaluatable expressions, in the usual VBA format\n(that is, eval acceptable);\n"); + monprintf("type is the type of that expression. Uses C-like names. Omission means integer.\n"); + monprintf("cond is the condition to be evaluated.\n"); + monprintf("If && or || are not present, the chain of evaluation stops.\n"); + monprintf("&& states the next condition must happen with the previous one, or the break\nfails.\n"); + monprintf("|| states the next condition is independant from the last one, and break\nseperately.\n\n"); + monprintf("Type can be:\n"); + monprintf(" [u8, b, byte],[u16, h, hword, halfword],[u32,w, word]\n"); + monprintf(" [s8, sb, sbyte],[s16, sh, shword, short, shalfword],[s32, int, sw, word]\n"); + monprintf("Types have to be preceded by a ' ex: 'int, 'u8\n\n"); + monprintf("Conditions may be:\n"); + monprintf("C-like:\t\t[<], [<=], [>], [>=] , [==], [!= or <>]\n"); + monprintf("ASM-like:\t[lt], [le], [gt], [ge] , [eq], [ne]\n\n"); + monprintf("EX: bw 0x03005008 if old_value == 'u32 [0x03005008]\n"); + monprintf("Breaks on write from 0x03005008, when the old_value variable, that is assigned\n"); + monprintf("as the previous memory value when a write is performed, is equal to the new\ncontents of 0x03005008.\n\n"); + monprintf("EX: bx 0x08000500 if r0 == 1 || r0 > 1 && r2 == 0 || 'u8 [r7] == 5\n"); + monprintf("Breaks in either thumb or arm execution of 0x08000500, if r0's contents are 1,\n"); + monprintf("or if r0's contents are bigger than 1 and r2 is equal to 0, or the content of\nthe address at r7(as byte) is equal to 5.\n"); + monprintf("It will not break if r0 > 1 and r2 != 0.\n"); + return; + } + if (!strcmp(cmd, "bl")){ + monprintf("List breakpoints command. Used to view breakpoints.\n"); + monprintf("Usage: [breakTag]
\n"); + monprintf("It will list all breaks on the specified type (read, write..).\n"); + monprintf("If (optional) address is included, it will try and list all breaks of that type\n"); + monprintf("for that address.\n"); + monprintf("The numbers shown on that list (No.) are the ones needed to delete it directly.\n"); + monprintf("v option lists all requested values, even if empty.\n"); + return; + } + if (!strcmp(cmd, "bc")){ + monprintf("Clear breakpoints command. Clears all specified breakpoints.\n"); + monprintf("Usage: [breakTag] \n"); + monprintf("It will delete all breaks on all addresses for the specified type.\n"); + monprintf("If (optional) or is included, it will try and delete all breaks associated with\n"); + monprintf("the flags. EX: bic or --> Deletes all breaks on read and all on write.\n"); + return; + } + if (!strcmp(cmd, "bd")){ + monprintf("Delete breakpoint command. Clears the specified breakpoint.\n"); + monprintf("Usage: [breakTag] [address] [number]\n"); + monprintf("It will delete the numbered break on that addresses for the specified type.\n"); + monprintf("If only is included, it will delete only breaks with the specified flag.\n"); + monprintf("EX: bxd 0x8000000 only -->Deletes all breaks on 0x08000000 that break on both\n"); + monprintf("arm and thumb modes. Thumb only or ARM only are unnafected.\n"); + monprintf("EX: btd 0x8000000 5 -->Deletes the thumb break from the 5th break on 0x8000000.\n"); + monprintf("---------!!!WARNING!!!---------\n"); + monprintf("Break numbers are volatile, and may change at any time. before deleting any one\n"); + monprintf("breakpoint, list them to see if the number hasn't changed. The numbers may\n"); + monprintf("change only when you add or delete a breakpoint to that address. Numbers are \n"); + monprintf("internal to each address.\n"); + return; + } + + for (int i = 0;; i++) { + if (debuggerCommands[i].name) { + if (!strcmp(debuggerCommands[i].name, cmd)) { + sprintf(monbuf, "%s %s\t%s\n", + debuggerCommands[i].name, + debuggerCommands[i].syntax ? debuggerCommands[i].syntax : "", + debuggerCommands[i].help); + monprintf(monbuf); + break; + } + } + else { + { sprintf(monbuf, "Unrecognized command '%s'.", cmd); monprintf(monbuf); } + break; + } + } +} + +void debuggerHelp(int n, char **args) +{ + if (n == 2) { + debuggerUsage(args[1]); + } + else { + for (int i = 0;; i++) { + if (debuggerCommands[i].name) { + { sprintf(monbuf, "%-10s%s\n", debuggerCommands[i].name, debuggerCommands[i].help); monprintf(monbuf); } + } + else + break; + } + { sprintf(monbuf, "%-10s%s\n", "break", "Breakpoint commands"); monprintf(monbuf); } + } +} + +char* strqtok(char* string, const char* ctrl) +{ + static char* nexttoken = NULL; + char* str; + + if (string != NULL) + str = string; + else { + if (nexttoken == NULL) + return NULL; + str = nexttoken; + }; + + char deli[32]; + memset(deli, 0, 32 * sizeof(char)); + while (*ctrl) + { + deli[*ctrl >> 3] |= (1 << (*ctrl & 7)); + ctrl++; + }; + // can't allow to be set + deli['"' >> 3] &= ~(1 << ('"' & 7)); + + // jump over leading delimiters + while ((deli[*str >> 3] & (1 << (*str & 7))) && *str) + str++; + + if (*str == '"') + { + string = ++str; + + // only break if another quote or end of string is found + while ((*str != '"') && *str) + str++; + } + else { + string = str; + + // break on delimiter + while (!(deli[*str >> 3] & (1 << (*str & 7))) && *str) + str++; + }; + + if (string == str) + { + nexttoken = NULL; + return NULL; + } + else { + if (*str) + { + *str = 0; + nexttoken = str + 1; + } + else + nexttoken = NULL; + + return string; + }; +}; + +void dbgExecute(char* toRun){ + char *commands[40]; + int commandCount = 0; + commands[0] = strqtok(toRun, " \t\n"); + if (commands[0] == NULL) + return; + commandCount++; + while ((commands[commandCount] = strqtok(NULL, " \t\n"))) { + commandCount++; + if (commandCount == 40) + break; + } + + //from here on, new algorithm. + // due to the division of functions, some steps have to be made + + //first, convert the command name to a standart lowercase form + //if more lowercasing needed, do it on the caller. + for (int i = 0; commands[0][i]; i++){ + commands[0][i] = tolower(commands[0][i]); + } + + // checks if it is a quit command, if so quits. + //if (isQuitCommand(commands[0])){ + // if (quitConfirm()){ + // debugger = false; + // emulating = false; + // } + // return; + //} + + commands[0] = replaceAlias(commands[0], cmdAliasTable); + + if (commands[0][0] == 'b'){ + executeBreakCommands(commandCount, commands); + if (commands[0][0] == '!') + commands[0][0] = 'b'; + else + return; + } + + //although it mights seem wierd, the old step is the last one to be executed. + for (int j = 0;; j++) { + bool notFound = false; + if (debuggerCommands[j].name == NULL) { + { sprintf(monbuf, "Unrecognized command %s. Type h for help.\n", commands[0]); monprintf(monbuf); } + return; + } + if (!strcmp(commands[0], debuggerCommands[j].name)) { + debuggerCommands[j].function(commandCount, commands); + return; + } + } +} + +void dbgExecute(std::string &cmd) +{ + char* dbgCmd = new char[cmd.length() + 1]; + strcpy(dbgCmd, cmd.c_str()); + dbgExecute(dbgCmd); + delete[] dbgCmd; +} + int remoteTcpSend(char *data, int len) { return send(remoteSocket, data, len, 0); @@ -230,7 +2839,7 @@ void remotePutPacket(const char *packet) *p++ = hex[csum>>4]; *p++ = hex[csum & 15]; *p++ = 0; - // printf("Sending %s\n", buffer); + //log("send: %s\n", buffer); char c = 0; while(c != '+'){ @@ -241,24 +2850,6 @@ void remotePutPacket(const char *packet) } } -#define debuggerReadMemory(addr) \ - (*(u32*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]) - -#define debuggerReadHalfWord(addr) \ - (*(u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]) - -#define debuggerReadByte(addr) \ - map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] - -#define debuggerWriteMemory(addr, value) \ - *(u32*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] = (value) - -#define debuggerWriteHalfWord(addr, value) \ - *(u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] = (value) - -#define debuggerWriteByte(addr, value) \ - map[(addr)>>24].address[(addr) & map[(addr)>>24].mask] = (value) - void remoteOutput(const char *s, u32 addr) { char buffer[16384]; @@ -323,7 +2914,7 @@ void remoteSendStatus() (v >> 24) & 255); s += 12; *s = 0; - // printf("Sending %s\n", buffer); + //log("Sending %s\n", buffer); remotePutPacket(buffer); } @@ -332,7 +2923,7 @@ void remoteBinaryWrite(char *p) u32 address; int count; sscanf(p,"%x,%x:", &address, &count); - // printf("Binary write for %08x %d\n", address, count); + // monprintf("Binary write for %08x %d\n", address, count); p = strchr(p, ':'); p++; @@ -350,7 +2941,7 @@ void remoteBinaryWrite(char *p) break; } } - // printf("ROM is %08x\n", debuggerReadMemory(0x8000254)); + // monprintf("ROM is %08x\n", debuggerReadMemory(0x8000254)); remotePutPacket("OK"); } @@ -359,7 +2950,7 @@ void remoteMemoryWrite(char *p) u32 address; int count; sscanf(p,"%x,%x:", &address, &count); - // printf("Memory write for %08x %d\n", address, count); + // monprintf("Memory write for %08x %d\n", address, count); p = strchr(p, ':'); p++; @@ -378,7 +2969,7 @@ void remoteMemoryWrite(char *p) debuggerWriteByte(address, v); address++; } - // printf("ROM is %08x\n", debuggerReadMemory(0x8000254)); + // monprintf("ROM is %08x\n", debuggerReadMemory(0x8000254)); remotePutPacket("OK"); } @@ -387,7 +2978,7 @@ void remoteMemoryRead(char *p) u32 address; int count; sscanf(p,"%x,%x:", &address, &count); - // printf("Memory read for %08x %d\n", address, count); + // monprintf("Memory read for %08x %d\n", address, count); char buffer[1024]; @@ -402,6 +2993,33 @@ void remoteMemoryRead(char *p) remotePutPacket(buffer); } +void remoteQuery(char *p) +{ + if (!strncmp(p, "fThreadInfo", 11)) + { + remotePutPacket("m-1"); + } + else if (!strncmp(p, "sThreadInfo", 11)) + { + remotePutPacket("l"); + } + else if (!strncmp(p, "Supported", 9)) + { + remotePutPacket("PacketSize=1000"); + } + else if (!strncmp(p, "Rcmd,", 5)) + { + p += 5; + std::string cmd = HexToString(p); + dbgExecute(cmd); + remotePutPacket("OK"); + } + else + { + remotePutPacket(""); + } +} + void remoteStepOverRange(char *p) { u32 address; @@ -422,33 +3040,202 @@ void remoteStepOverRange(char *p) remoteSendStatus(); } +void remoteSetBreakPoint(char *p) +{ + u32 address; + int count; + sscanf(p, ",%x,%x#", &address, &count); + + for (int n = 0; n < count; n+=4) + addConditionalBreak(address + n, armState ? 0x04 : 0x08); + + // Out of bounds memory checks + //if (address < 0x2000000 || address > 0x3007fff) { + // remotePutPacket("E01"); + // return; + //} + + //if (address > 0x203ffff && address < 0x3000000) { + // remotePutPacket("E01"); + // return; + //} + + //u32 final = address + count; + + //if (address < 0x2040000 && final > 0x2040000) { + // remotePutPacket("E01"); + // return; + //} + //else if (address < 0x3008000 && final > 0x3008000) { + // remotePutPacket("E01"); + // return; + //} + remotePutPacket("OK"); +} + +void remoteClearBreakPoint(char *p) +{ + int result; + u32 address; + int count; + sscanf(p, ",%x,%x#", &address, &count); + + for (int n = 0; n < count; n+=4) + result = removeConditionalWithAddressAndFlag(address + n, armState ? 0x04 : 0x08, true); + + if (result != -2) + remotePutPacket("OK"); + else + remotePutPacket(""); +} + +void remoteSetMemoryReadBreakPoint(char *p) +{ + u32 address; + int count; + sscanf(p, ",%x,%x#", &address, &count); + + for (int n = 0; n < count; n++) + addConditionalBreak(address + n, 0x02); + + // Out of bounds memory checks + //if (address < 0x2000000 || address > 0x3007fff) { + // remotePutPacket("E01"); + // return; + //} + + //if (address > 0x203ffff && address < 0x3000000) { + // remotePutPacket("E01"); + // return; + //} + + //u32 final = address + count; + + //if (address < 0x2040000 && final > 0x2040000) { + // remotePutPacket("E01"); + // return; + //} + //else if (address < 0x3008000 && final > 0x3008000) { + // remotePutPacket("E01"); + // return; + //} + remotePutPacket("OK"); +} + +void remoteClearMemoryReadBreakPoint(char *p) +{ + bool error = false; + int result; + u32 address; + int count; + sscanf(p, ",%x,%x#", &address, &count); + + for (int n = 0; n < count; n++) + { + result = removeConditionalWithAddressAndFlag(address + n, 0x02, true); + if (result == -2) + error = true; + } + + if (!error) + remotePutPacket("OK"); + else + remotePutPacket(""); +} + +void remoteSetMemoryAccessBreakPoint(char *p) +{ + u32 address; + int count; + sscanf(p, ",%x,%x#", &address, &count); + + for (int n = 0; n < count; n++) + addConditionalBreak(address + n, 0x03); + + // Out of bounds memory checks + //if (address < 0x2000000 || address > 0x3007fff) { + // remotePutPacket("E01"); + // return; + //} + + //if (address > 0x203ffff && address < 0x3000000) { + // remotePutPacket("E01"); + // return; + //} + + //u32 final = address + count; + + //if (address < 0x2040000 && final > 0x2040000) { + // remotePutPacket("E01"); + // return; + //} + //else if (address < 0x3008000 && final > 0x3008000) { + // remotePutPacket("E01"); + // return; + //} + remotePutPacket("OK"); +} + +void remoteClearMemoryAccessBreakPoint(char *p) +{ + bool error = false; + int result; + u32 address; + int count; + sscanf(p, ",%x,%x#", &address, &count); + + for (int n = 0; n < count; n++) + { + result = removeConditionalWithAddressAndFlag(address + n, 0x03, true); + if (result == -2) + error = true; + } + + if (!error) + remotePutPacket("OK"); + else + remotePutPacket(""); +} + void remoteWriteWatch(char *p, bool active) { u32 address; int count; sscanf(p, ",%x,%x#", &address, &count); - fprintf(stderr, "Write watch for %08x %d\n", address, count); - - if(address < 0x2000000 || address > 0x3007fff) { - remotePutPacket("E01"); - return; + if (active) + { + for (int n = 0; n < count; n++) + addConditionalBreak(address + n, 0x01); + } + else + { + for (int n = 0; n < count; n++) + removeConditionalWithAddressAndFlag(address + n, 0x01, true); } - if(address > 0x203ffff && address < 0x3000000) { - remotePutPacket("E01"); - return; - } + // Out of bounds memory check + //fprintf(stderr, "Write watch for %08x %d\n", address, count); + + //if(address < 0x2000000 || address > 0x3007fff) { + // remotePutPacket("E01"); + // return; + //} + + //if(address > 0x203ffff && address < 0x3000000) { + // remotePutPacket("E01"); + // return; + //} u32 final = address + count; - if(address < 0x2040000 && final > 0x2040000) { - remotePutPacket("E01"); - return; - } else if(address < 0x3008000 && final > 0x3008000) { - remotePutPacket("E01"); - return; - } + //if(address < 0x2040000 && final > 0x2040000) { + // remotePutPacket("E01"); + // return; + //} else if(address < 0x3008000 && final > 0x3008000) { + // remotePutPacket("E01"); + // return; + //} #ifdef BKPT_SUPPORT for(int i = 0; i < count; i++) { @@ -463,6 +3250,18 @@ void remoteWriteWatch(char *p, bool active) remotePutPacket("OK"); } +void remoteReadRegister(char *p) +{ + int r; + sscanf(p, "%x", &r); + char buffer[1024]; + char *s = buffer; + u32 v = reg[r].I; + sprintf(s, "%02x%02x%02x%02x", v & 255, (v >> 8) & 255, + (v >> 16) & 255, (v >> 24) & 255); + remotePutPacket(buffer); +} + void remoteReadRegisters(char *p) { char buffer[1024]; @@ -535,7 +3334,7 @@ void remoteWriteRegister(char *p) v = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); - // printf("Write register %d=%08x\n", r, v); + // monprintf("Write register %d=%08x\n", r, v); reg[r].I = v; if(r == 15) { armNextPC = v; @@ -547,8 +3346,6 @@ void remoteWriteRegister(char *p) remotePutPacket("OK"); } -extern int emulating; - void remoteStubMain() { if(!debugger) @@ -567,10 +3364,6 @@ void remoteStubMain() if(res == -1) { fprintf(stderr, "GDB connection lost\n"); -#ifdef SDL - dbgMain = debuggerMain; - dbgSignal = debuggerSignal; -#endif debugger = false; break; } else if(res == -2) @@ -604,16 +3397,13 @@ void remoteStubMain() remoteSendFnc(&ack, 1); //fprintf(stderr, "SentACK c=%c\n",c); //process message... + char type; switch(c) { case '?': remoteSendSignal(); break; case 'D': remotePutPacket("OK"); -#ifdef SDL - dbgMain = debuggerMain; - dbgSignal = debuggerSignal; -#endif remoteResumed = true; debugger = false; return; @@ -622,10 +3412,6 @@ void remoteStubMain() break; case 'k': remotePutPacket("OK"); -#ifdef SDL - dbgMain = debuggerMain; - dbgSignal = debuggerSignal; -#endif debugger = false; emulating = false; return; @@ -649,6 +3435,9 @@ void remoteStubMain() case 'g': remoteReadRegisters(p); break; + case 'p': + remoteReadRegister(p); + break; case 'P': remoteWriteRegister(p); break; @@ -665,19 +3454,49 @@ void remoteStubMain() remotePutPacket("OK"); break; case 'q': - remotePutPacket(""); + remoteQuery(p); break; case 'Z': - if(*p++ == '2') { - remoteWriteWatch(p, true); - } else - remotePutPacket(""); + type = *p++; + if (type == '0') { + remoteSetBreakPoint(p); + } + else if (type == '1') { + remoteSetBreakPoint(p); + } + else if (type == '2') { + remoteWriteWatch(p, true); + } + else if (type == '3') { + remoteSetMemoryReadBreakPoint(p); + } + else if (type == '4') { + remoteSetMemoryAccessBreakPoint(p); + } + else { + remotePutPacket(""); + } break; case 'z': - if(*p++ == '2') { - remoteWriteWatch(p, false); - } else - remotePutPacket(""); + type = *p++; + if (type == '0') { + remoteClearBreakPoint(p); + } + else if (type == '1') { + remoteClearBreakPoint(p); + } + else if (type == '2') { + remoteWriteWatch(p, false); + } + else if (type == '3') { + remoteClearMemoryReadBreakPoint(p); + } + else if (type == '4') { + remoteClearMemoryAccessBreakPoint(p); + } + else { + remotePutPacket(""); + } break; default: { @@ -720,4 +3539,45 @@ void remoteCleanUp() if(remoteCleanUpFnc) remoteCleanUpFnc(); } + +std::string HexToString(char * p) +{ + std::string hex(p); + std::string cmd; + std::stringstream ss; + int offset = 0; + while (offset < hex.length()) { + unsigned int buffer = 0; + ss.clear(); + ss << std::hex << hex.substr(offset, 2); + ss >> std::hex >> buffer; + cmd.push_back(static_cast(buffer)); + offset += 2; + } + return cmd; +} + +std::string StringToHex(std::string &cmd) +{ + std::stringstream ss; + ss << std::hex; + for (int i = 0; i < cmd.length(); ++i) + ss << std::setw(2) << std::setfill('0') << (int)cmd.c_str()[i]; + return ss.str(); +} + +void monprintf(std::string line) +{ + std::string output = "O"; + line = StringToHex(line); + output += line; + + if (output.length() <= 1000) + { + char dbgReply[1000]; + strcpy(dbgReply, output.c_str()); + remotePutPacket(dbgReply); + } +} + #endif diff --git a/src/gba/remote.h b/src/gba/remote.h new file mode 100644 index 00000000..951e42cb --- /dev/null +++ b/src/gba/remote.h @@ -0,0 +1,79 @@ +#ifndef REMOTE_H +#define REMOTE_H + +#include "../common/Types.h" +#include "GBA.h" + +#define BitSet(array, bit) \ + ((u8 *)(array))[(bit) >> 3] |= (1 << ((bit) & 7)) + +#define BitClear(array, bit) \ + ((u8 *)(array))[(bit) >> 3] &= ~(1 << ((bit) & 7)) + +#define BitGet(array, bit) \ + ((u8)((array)[(bit) >> 3]) & (u8)(1 <<((bit) & 7))) + +#define BreakSet(array, addr, flag) \ + ((u8 *)(array))[(addr)>>1] |= ((addr&1) ? (flag<<4) : (flag&0xf)) + +#define BreakClear(array, addr, flag) \ + ((u8 *)(array))[(addr)>>1] &= ~((addr&1) ? (flag<<4) : (flag&0xf)) + +//check +#define BreakThumbCheck(array, addr) \ + ((u8 *)(array))[(addr)>>1] &((addr&1) ? 0x80 : 0x8 ) + +#define BreakARMCheck(array, addr) \ + ((u8 *)(array))[(addr)>>1] & ((addr&1) ? 0x40 : 0x4 ) + +#define BreakReadCheck(array, addr) \ + ((u8 *)(array))[(addr)>>1] & ((addr&1) ? 0x20 : 0x2 ) + +#define BreakWriteCheck(array, addr) \ + ((u8 *)(array))[(addr)>>1] & ((addr&1) ? 0x10 : 0x1 ) + +#define BreakCheck(array, addr, flag) \ + ((u8 *)(array))[(addr)>>1] & ((addr&1) ? (flag<<4) : (flag&0xf)) + +extern bool debugger; + +extern bool dexp_eval(char *, u32*); +extern void dexp_setVar(char *, u32); +extern void dexp_listVars(); +extern void dexp_saveVars(char *); +extern void dexp_loadVars(char *); + +bool debuggerBreakOnExecution(u32 address, u8 state); +bool debuggerBreakOnWrite(u32 address, u32 value, int size); +void debuggerBreakOnWrite(u32 address, u32 oldvalue, u32 value, int size, int t); +bool debuggerBreakOnRead(u32 address, int size); + +struct regBreak{ + //u8 regNum; /No longer needed + // bit 0 = equal + // bit 1 = greater + // bit 2 = smaller + // bit 3 = signed + u8 flags; + u32 intVal; + struct regBreak* next; +}; +extern u8 lowRegBreakCounter[4]; //(r0-r3) +extern u8 medRegBreakCounter[4]; //(r4-r7) +extern u8 highRegBreakCounter[4]; //(r8-r11) +extern u8 statusRegBreakCounter[4]; //(r12-r15) + +extern bool enableRegBreak; +extern regBreak* breakRegList[16]; +extern void breakReg_check(int i); + +struct regBreak* getFromBreakRegList(u8 regnum, int location); + +void clearBreakRegList(); +void clearParticularRegListBreaks(int reg); +void deleteFromBreakRegList(u8 regnum, int location); + +void addBreakRegToList(u8 regnum, u8 flags, u32 value); +void printBreakRegList(bool verbose); + +#endif // REMOTE_H diff --git a/src/gtk/system.cpp b/src/gtk/system.cpp index 20507f2d..b9b715a9 100644 --- a/src/gtk/system.cpp +++ b/src/gtk/system.cpp @@ -181,10 +181,6 @@ void debuggerOutput(const char *, u32) { } -void debuggerBreakOnWrite(u32 address, u32 oldvalue, u32 value, int size, int t) -{ -} - void (*dbgMain)() = debuggerMain; void (*dbgSignal)(int, int) = debuggerSignal; void (*dbgOutput)(const char *, u32) = debuggerOutput; diff --git a/src/sdl/SDL.cpp b/src/sdl/SDL.cpp index 8c203472..0786d095 100644 --- a/src/sdl/SDL.cpp +++ b/src/sdl/SDL.cpp @@ -50,7 +50,6 @@ #include "../gb/gbSound.h" #include "../Util.h" -#include "debugger.h" #include "filters.h" #include "text.h" #include "inputSDL.h" @@ -211,7 +210,6 @@ int showSpeedTransparent = 1; bool disableStatusMessages = false; bool paused = false; bool pauseNextFrame = false; -bool debugger = false; bool debuggerStub = false; int fullscreen = 0; int sdlFlashSize = 0; @@ -225,9 +223,9 @@ static int ignore_first_resize_event = 0; /* forward */ void systemConsoleMessage(const char*); -void (*dbgMain)() = debuggerMain; -void (*dbgSignal)(int,int) = debuggerSignal; -void (*dbgOutput)(const char *, u32) = debuggerOutput; +void (*dbgMain)(); +void (*dbgSignal)(int,int); +void (*dbgOutput)(const char *, u32); int mouseCounter = 0; @@ -1555,7 +1553,7 @@ void sdlPollEvents() } break; case SDLK_F11: - if(dbgMain != debuggerMain) { + if(dbgMain == remoteStubMain) { if(armState) { armNextPC -= 4; reg[15].I -= 4; diff --git a/src/sdl/debugger.cpp b/src/sdl/debugger.cpp index 8b771111..afc9b1b1 100644 --- a/src/sdl/debugger.cpp +++ b/src/sdl/debugger.cpp @@ -1058,25 +1058,6 @@ static void debuggerBreakArm(int n, char **args) debuggerUsage("ba"); } -/*extern*/ void debuggerBreakOnWrite(u32 address, u32 oldvalue, u32 value, - int size, int t) -{ - const char *type = "write"; - if(t == 2) - type = "change"; - - if(size == 2) - printf("Breakpoint (on %s) address %08x old:%08x new:%08x\n", - type, address, oldvalue, value); - else if(size == 1) - printf("Breakpoint (on %s) address %08x old:%04x new:%04x\n", - type, address, (u16)oldvalue,(u16)value); - else - printf("Breakpoint (on %s) address %08x old:%02x new:%02x\n", - type, address, (u8)oldvalue, (u8)value); - debugger = true; -} - static void debuggerBreakWriteClear(int n, char **args) { if(n == 3) { diff --git a/src/win32/Commands.cpp b/src/win32/Commands.cpp index 54e2042f..e7dc93a2 100644 --- a/src/win32/Commands.cpp +++ b/src/win32/Commands.cpp @@ -176,7 +176,8 @@ struct { { "CheatsSave", ID_CHEATS_SAVECHEATLIST }, { "CheatsDisable", ID_CHEATS_DISABLECHEATS }, { "ToolsDebugGDB", ID_TOOLS_DEBUG_GDB }, - { "ToolsDebugGDBLoad", ID_TOOLS_DEBUG_LOADANDWAIT }, + { "ToolsDebugGDBConfigurePort", ID_TOOLS_DEBUG_CONFIGUREPORT }, + { "ToolsDebugGDBBreakOnLoad", ID_TOOLS_DEBUG_BREAKONLOAD }, { "ToolsDebugGDBBreak", ID_TOOLS_DEBUG_BREAK }, { "ToolsDebugGDBDisconnect", ID_TOOLS_DEBUG_DISCONNECT }, { "ToolsDisassemble", ID_TOOLS_DISASSEMBLE }, diff --git a/src/win32/GDBConnection.cpp b/src/win32/GDBConnection.cpp index 837317ae..673539d2 100644 --- a/src/win32/GDBConnection.cpp +++ b/src/win32/GDBConnection.cpp @@ -24,7 +24,10 @@ GDBPortDlg::GDBPortDlg(CWnd* pParent /*=NULL*/) //{{AFX_DATA_INIT(GDBPortDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT - port = 55555; + if (theApp.gdbPort == 0) + port = 55555; + else + port = theApp.gdbPort; sock = INVALID_SOCKET; if(!initialized) { @@ -97,30 +100,8 @@ void GDBPortDlg::OnOk() address.sin_port = htons(atoi(buffer)); port = ntohs(address.sin_port); - SOCKET s = socket(AF_INET, SOCK_STREAM, 0); - - if(s != INVALID_SOCKET) { - int error = bind(s, (sockaddr *)&address, sizeof(address)); - - if(error) { - systemMessage(IDS_ERROR_BINDING, "Error binding socket. Port probably in use."); - error = closesocket(s); - EndDialog(FALSE); - } else { - error = listen(s, 1); - if(!error) { - sock = s; - EndDialog(TRUE); - } else { - systemMessage(IDS_ERROR_LISTENING, "Error listening on socket."); - closesocket(s); - EndDialog(FALSE); - } - } - } else { - systemMessage(IDS_ERROR_CREATING_SOCKET, "Error creating socket."); - EndDialog(FALSE); - } + theApp.gdbPort = port; + EndDialog(TRUE); } void GDBPortDlg::OnCancel() @@ -136,11 +117,45 @@ void GDBPortDlg::OnClose() // GDBWaitingDlg dialog -GDBWaitingDlg::GDBWaitingDlg(SOCKET s, int p, CWnd* pParent /*=NULL*/) +GDBWaitingDlg::GDBWaitingDlg(int p, CWnd* pParent /*=NULL*/) : CDialog(GDBWaitingDlg::IDD, pParent) { //{{AFX_DATA_INIT(GDBWaitingDlg) //}}AFX_DATA_INIT + sockaddr_in address; + address.sin_family = AF_INET; + address.sin_addr.s_addr = inet_addr("0.0.0.0"); + address.sin_port = htons(p); + port = ntohs(address.sin_port); + + SOCKET s = socket(AF_INET, SOCK_STREAM, 0); + + if (s != INVALID_SOCKET) { + int error = bind(s, (sockaddr *)&address, sizeof(address)); + + if (error) { + systemMessage(IDS_ERROR_BINDING, "Error binding socket. Port probably in use."); + error = closesocket(s); + //EndDialog(FALSE); + } + else { + error = listen(s, 1); + if (!error) { + sock = s; + //EndDialog(TRUE); + } + else { + systemMessage(IDS_ERROR_LISTENING, "Error listening on socket."); + closesocket(s); + //EndDialog(FALSE); + } + } + } + else { + systemMessage(IDS_ERROR_CREATING_SOCKET, "Error creating socket."); + //EndDialog(FALSE); + } + port = p & 65535; listenSocket = s; } @@ -199,13 +214,13 @@ LRESULT GDBWaitingDlg::OnSocketAccept(WPARAM wParam, LPARAM lParam) if(s != INVALID_SOCKET) { char dummy; recv(s, &dummy, 1, 0); - if(dummy != '+') { - systemMessage(IDS_ACK_NOT_RECEIVED, "ACK not received from GDB."); - OnClose(); // calls EndDialog - } else { + //if(dummy != '+') { + // systemMessage(IDS_ACK_NOT_RECEIVED, "ACK not received from GDB."); + // OnClose(); // calls EndDialog + //} else { sock = s; EndDialog(TRUE); - } + //} } } diff --git a/src/win32/GDBConnection.h b/src/win32/GDBConnection.h index d2fa805d..723804f3 100644 --- a/src/win32/GDBConnection.h +++ b/src/win32/GDBConnection.h @@ -62,7 +62,7 @@ class GDBWaitingDlg : public CDialog SOCKET getSocket(); SOCKET getListenSocket(); afx_msg LRESULT OnSocketAccept(WPARAM wParam, LPARAM lParam); - GDBWaitingDlg(SOCKET s,int p, CWnd* pParent = NULL); // standard constructor + GDBWaitingDlg(int p, CWnd* pParent = NULL); // standard constructor // Dialog Data //{{AFX_DATA(GDBWaitingDlg) diff --git a/src/win32/MainWnd.cpp b/src/win32/MainWnd.cpp index 379516d1..5eb51135 100644 --- a/src/win32/MainWnd.cpp +++ b/src/win32/MainWnd.cpp @@ -279,10 +279,10 @@ BEGIN_MESSAGE_MAP(MainWnd, CWnd) ON_UPDATE_COMMAND_UI(ID_TOOLS_TILEVIEWER, OnUpdateToolsTileviewer) ON_COMMAND(ID_DEBUG_NEXTFRAME, OnDebugNextframe) ON_UPDATE_COMMAND_UI(ID_CHEATS_AUTOMATICSAVELOADCHEATS, OnUpdateCheatsAutomaticsaveloadcheats) - ON_COMMAND(ID_TOOLS_DEBUG_GDB, OnToolsDebugGdb) - ON_UPDATE_COMMAND_UI(ID_TOOLS_DEBUG_GDB, OnUpdateToolsDebugGdb) - ON_COMMAND(ID_TOOLS_DEBUG_LOADANDWAIT, OnToolsDebugLoadandwait) - ON_UPDATE_COMMAND_UI(ID_TOOLS_DEBUG_LOADANDWAIT, OnUpdateToolsDebugLoadandwait) + ON_COMMAND(ID_TOOLS_DEBUG_CONFIGUREPORT, OnToolsDebugConfigurePort) + ON_UPDATE_COMMAND_UI(ID_TOOLS_DEBUG_CONFIGUREPORT, OnUpdateToolsDebugConfigurePort) + ON_COMMAND(ID_TOOLS_DEBUG_BREAKONLOAD, OnToolsDebugBreakOnLoad) + ON_UPDATE_COMMAND_UI(ID_TOOLS_DEBUG_BREAKONLOAD, OnUpdateToolsDebugBreakOnLoad) ON_COMMAND(ID_TOOLS_DEBUG_BREAK, OnToolsDebugBreak) ON_UPDATE_COMMAND_UI(ID_TOOLS_DEBUG_BREAK, OnUpdateToolsDebugBreak) ON_COMMAND(ID_TOOLS_DEBUG_DISCONNECT, OnToolsDebugDisconnect) @@ -632,6 +632,10 @@ bool MainWnd::FileRun() if (theApp.linkAuto) BootLink(theApp.linkMode, theApp.linkHostAddr, theApp.linkTimeout, theApp.linkHacks, theApp.linkNumPlayers); #endif + + if (theApp.gdbBreakOnLoad) + OnToolsDebugBreak(); + return true; } diff --git a/src/win32/MainWnd.h b/src/win32/MainWnd.h index bfa0ce2b..643c7a3e 100644 --- a/src/win32/MainWnd.h +++ b/src/win32/MainWnd.h @@ -281,10 +281,10 @@ protected: afx_msg void OnUpdateToolsTileviewer(CCmdUI* pCmdUI); afx_msg void OnDebugNextframe(); afx_msg void OnUpdateCheatsAutomaticsaveloadcheats(CCmdUI* pCmdUI); - afx_msg void OnToolsDebugGdb(); - afx_msg void OnUpdateToolsDebugGdb(CCmdUI* pCmdUI); - afx_msg void OnToolsDebugLoadandwait(); - afx_msg void OnUpdateToolsDebugLoadandwait(CCmdUI* pCmdUI); + afx_msg void OnToolsDebugConfigurePort(); + afx_msg void OnUpdateToolsDebugConfigurePort(CCmdUI* pCmdUI); + afx_msg void OnToolsDebugBreakOnLoad(); + afx_msg void OnUpdateToolsDebugBreakOnLoad(CCmdUI* pCmdUI); afx_msg void OnToolsDebugBreak(); afx_msg void OnUpdateToolsDebugBreak(CCmdUI* pCmdUI); afx_msg void OnToolsDebugDisconnect(); diff --git a/src/win32/MainWndTools.cpp b/src/win32/MainWndTools.cpp index 579191b9..a38e8e06 100644 --- a/src/win32/MainWndTools.cpp +++ b/src/win32/MainWndTools.cpp @@ -177,84 +177,68 @@ void MainWnd::OnDebugNextframe() theApp.winPauseNextFrame = true; } -void MainWnd::OnToolsDebugGdb() +void MainWnd::OnToolsDebugConfigurePort() { - GDBPortDlg dlg; + GDBPortDlg dlg; - if(dlg.DoModal()) { - GDBWaitingDlg wait(dlg.getSocket(), dlg.getPort()); - if(wait.DoModal()) { - remoteSetSockets(wait.getListenSocket(), wait.getSocket()); - debugger = true; - emulating = 1; - theApp.cartridgeType = IMAGE_GBA; - theApp.filename = "\\gnu_stub"; - rom = (u8 *)malloc(0x2000000); - workRAM = (u8 *)calloc(1, 0x40000); - bios = (u8 *)calloc(1,0x4000); - internalRAM = (u8 *)calloc(1,0x8000); - paletteRAM = (u8 *)calloc(1,0x400); - vram = (u8 *)calloc(1, 0x20000); - oam = (u8 *)calloc(1, 0x400); - pix = (u8 *)calloc(1, 4 * 241 * 162); - ioMem = (u8 *)calloc(1, 0x400); - - theApp.emulator = GBASystem; - - CPUInit(theApp.biosFileNameGBA, theApp.useBiosFileGBA); - CPUReset(); + if(dlg.DoModal()) { } - } } -void MainWnd::OnUpdateToolsDebugGdb(CCmdUI* pCmdUI) +void MainWnd::OnUpdateToolsDebugConfigurePort(CCmdUI* pCmdUI) { - pCmdUI->Enable(theApp.videoOption <= VIDEO_6X && remoteSocket == -1); } -void MainWnd::OnToolsDebugLoadandwait() +void MainWnd::OnToolsDebugBreakOnLoad() { - if(fileOpenSelect(0)) { - if(FileRun()) { - if(theApp.cartridgeType != 0) { - systemMessage(IDS_ERROR_NOT_GBA_IMAGE, "Error: not a GBA image"); - OnFileClose(); - return; - } - GDBPortDlg dlg; - - if(dlg.DoModal()) { - GDBWaitingDlg wait(dlg.getSocket(), dlg.getPort()); - if(wait.DoModal()) { - remoteSetSockets(wait.getListenSocket(), wait.getSocket()); - debugger = true; - emulating = 1; - } - } - } - } + theApp.gdbBreakOnLoad = !theApp.gdbBreakOnLoad; } -void MainWnd::OnUpdateToolsDebugLoadandwait(CCmdUI* pCmdUI) +void MainWnd::OnUpdateToolsDebugBreakOnLoad(CCmdUI* pCmdUI) { - pCmdUI->Enable(theApp.videoOption <= VIDEO_6X && remoteSocket == -1); + pCmdUI->SetCheck(theApp.gdbBreakOnLoad); } void MainWnd::OnToolsDebugBreak() { - if(armState) { - armNextPC -= 4; - reg[15].I -= 4; - } else { - armNextPC -= 2; - reg[15].I -= 2; - } - debugger = true; + GDBPortDlg dlg; + + int port = theApp.gdbPort; + if (port == 0) + { + if (dlg.DoModal()) { + port = dlg.getPort(); + } + } + + if (port != 0) { + if (remoteSocket == -1) + { + GDBWaitingDlg wait(port); + if (wait.DoModal()) { + remoteSetSockets(wait.getListenSocket(), wait.getSocket()); + debugger = true; + emulating = 1; + } + } + else + { + if (armState) { + armNextPC -= 4; + reg[15].I -= 4; + } + else { + armNextPC -= 2; + reg[15].I -= 2; + } + debugger = true; + } + } } void MainWnd::OnUpdateToolsDebugBreak(CCmdUI* pCmdUI) { - pCmdUI->Enable(theApp.videoOption <= VIDEO_6X && remoteSocket != -1); + pCmdUI->Enable(theApp.videoOption <= VIDEO_6X && emulating != 0); } void MainWnd::OnToolsDebugDisconnect() diff --git a/src/win32/VBA.cpp b/src/win32/VBA.cpp index 179df3ed..770e806b 100644 --- a/src/win32/VBA.cpp +++ b/src/win32/VBA.cpp @@ -129,7 +129,6 @@ static char THIS_FILE[] = __FILE__; #endif int emulating = 0; -bool debugger = false; int RGB_LOW_BITS_MASK = 0; bool b16to32Video = false; int systemFrameSkip = 0; @@ -290,6 +289,7 @@ VBA::VBA() pauseWhenInactive = true; speedupToggle = false; winGbPrinterEnabled = false; + gdbBreakOnLoad = false; threadPriority = 2; disableMMX = false; languageOption = 0; @@ -1339,7 +1339,8 @@ BOOL VBA::OnIdle(LONG lCount) return TRUE; // continue loop return !::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE); } else if(emulating && active && !paused) { - for(int i = 0; i < 2; i++) { + for(int i = 0; i < 2; i++) { // Why is this loop here? + if (!debugger) emulator.emuMain(emulator.emuCount); #ifndef NO_LINK @@ -1731,6 +1732,9 @@ void VBA::loadSettings() linkNumPlayers = regQueryDwordValue("LinkNumPlayers", 2); #endif + gdbPort = regQueryDwordValue("gdbPort", 55555); + gdbBreakOnLoad = regQueryDwordValue("gdbBreakOnLoad", false) ? true : false; + Sm60FPS::bSaveMoreCPU = regQueryDwordValue("saveMoreCPU", 0); #ifndef NO_OAL @@ -2665,6 +2669,9 @@ void VBA::saveSettings() regSetDwordValue("LinkNumPlayers", linkNumPlayers); #endif + regSetDwordValue("gdbPort", gdbPort); + regSetDwordValue("gdbBreakOnLoad", gdbBreakOnLoad); + regSetDwordValue("lastFullscreen", lastFullscreen); regSetDwordValue("pauseWhenInactive", pauseWhenInactive); diff --git a/src/win32/VBA.h b/src/win32/VBA.h index fb6d1fe9..e0ba4d54 100644 --- a/src/win32/VBA.h +++ b/src/win32/VBA.h @@ -124,6 +124,7 @@ class VBA : public CWinApp int rewindCount; bool rewindSaveNeeded; int rewindTimer; + bool gdbBreakOnLoad; int captureFormat; bool tripleBuffering; unsigned short throttle; @@ -218,6 +219,8 @@ class VBA : public CWinApp BOOL linkHacks; int linkNumPlayers; + int gdbPort; + public: VBA(); ~VBA(); diff --git a/src/win32/VBA.rc b/src/win32/VBA.rc index be520a08..fbcfda50 100644 --- a/src/win32/VBA.rc +++ b/src/win32/VBA.rc @@ -795,7 +795,7 @@ CAPTION "Waiting..." FONT 8, "MS Sans Serif" BEGIN PUSHBUTTON "Cancel",ID_CANCEL,67,23,50,14 - LTEXT "Waiting for connection on port:",IDC_STATIC,7,7,117,8 + LTEXT "Waiting for GDB on port:",IDC_STATIC,7,7,117,8 LTEXT "",IDC_PORT,143,7,36,8,SS_NOPREFIX END @@ -1957,10 +1957,10 @@ BEGIN MENUITEM "&Next frame", ID_DEBUG_NEXTFRAME POPUP "GDB" BEGIN - MENUITEM "Wait for connection...", ID_TOOLS_DEBUG_GDB - MENUITEM "Load and wait...", ID_TOOLS_DEBUG_LOADANDWAIT MENUITEM "Break into GDB", ID_TOOLS_DEBUG_BREAK MENUITEM "Disconnect", ID_TOOLS_DEBUG_DISCONNECT + MENUITEM "Break on load", ID_TOOLS_DEBUG_BREAKONLOAD + MENUITEM "Configure port...", ID_TOOLS_DEBUG_CONFIGUREPORT END MENUITEM SEPARATOR POPUP "Record" diff --git a/src/win32/resource.h b/src/win32/resource.h index 74bd2097..99287c40 100644 --- a/src/win32/resource.h +++ b/src/win32/resource.h @@ -711,7 +711,8 @@ #define ID_OPTIONS_GAMEBOY_COLORS 40147 #define ID_TOOLS_DISASSEMBLE 40151 #define ID_TOOLS_DEBUG_GDB 40152 -#define ID_TOOLS_DEBUG_LOADANDWAIT 40153 +#define ID_TOOLS_DEBUG_CONFIGUREPORT 40153 +#define ID_TOOLS_DEBUG_BREAKONLOAD 40159 #define ID_TOOLS_DEBUG_DISCONNECT 40154 #define ID_TOOLS_DEBUG_BREAK 40155 #define ID_TOOLS_LOGGING 40156 diff --git a/src/wx/sys.cpp b/src/wx/sys.cpp index dad98979..ab815894 100644 --- a/src/wx/sys.cpp +++ b/src/wx/sys.cpp @@ -1125,15 +1125,11 @@ void debuggerMain() { } -bool debugger; +//bool debugger; void (*dbgOutput)(const char *s, u32 addr) = debuggerOutput; void (*dbgSignal)(int sig,int number) = debuggerSignal; -void debuggerBreakOnWrite(u32 address, u32 oldvalue, u32 value, int size, int t) -{ -} - void log(const char *defaultMsg, ...) { static FILE *out = NULL;