/* not the proper way. like macro taking automatically telling you the __LINE__ and __FILE__ but i couldn't get it to work the register just kept getting screwy and mov no work. odd. so i opped to use a function */ #ifdef _WIN32 #include #endif #include void ASSERT(short option, char *msg, int _line, char *_file) { char buff[512], print_buff[512]; unsigned long _eax, _ebx, _ecx, _edx, _esi, _edi, _eip; FILE *fp; int rt = 0; #ifdef _DEBUG /* obviuosly no asserts in release build.. */ memset(buff, 0, 512); memset(print_buff, 0, 512); /* no idea why i unraveled this from normal __asm { instrc.. }*/ #ifdef _WIN32 /* gcc not work this.. */ __asm mov _eax, eax; __asm mov _ebx, ebx; __asm mov _ecx, ecx; __asm mov _edx, edx; __asm mov _esi, esi; __asm mov _edi, edi; #endif if (option == 0) { sprintf(buff, "%s\n\nassert in file %s on line %d\n\n\tregister dump\n\neax = %x\t\tebx = %x\necx = %x\t\t\tedx = %x\nesi = %x\t\tedi = %x\neip = %x\n\nwould you like the dump logged to dump.txt?", msg, _file, _line, _eax, _ebx, _ecx, _edx, _esi, _edi, _eip); sprintf(print_buff, "assert occured in file %s on line %d\n\nregister values follow\n\neax = %x\t\tebx = %x\necx = %x\t\t\tedx = %x\nesi = %x\t\tedi = %x\neip = %x\n\n", __FILE__, __LINE__, _eax, _ebx, _ecx, _edx, _esi, _edi, _eip); #ifdef _WIN32 rt = MessageBox(NULL, TEXT(buff), TEXT("test_assert"), MB_YESNO | MB_ICONEXCLAMATION); #endif switch (rt) { case 6: printf("DUMP\n"); fp = fopen("dump.txt", "w"); if (fp == NULL) printf("ERROR"); fprintf(fp, print_buff); fclose(fp); #ifdef _WIN32 __asm INT 3; /* start debugger */ #endif break; } } else ; #endif } /* { #ifdef _DEBUG char buff[512]; char print_buff[512]; FILE *fp; ulong _eax, _ebx, _ecx, _edx, _esi, _edi, _eip, _ebp, _efl; short esp; int rt = 0; memset(buff, 0, 512); memset(print_buff, 0, 512); __asm { mov _eax, eax; mov _ebx, ebx; mov _ecx, ecx; mov _edx, edx; mov _esi, esi; mov _edi, edi; } if (option == 0) { sprintf(buff, "%s\n\nassert in file %s on line %d\n\n\tregister dump\n\neax = %x\t\tebx = %x\necx = %x\t\t\tedx = %x\nesi = %x\t\tedi = %x\neip = %x\n\nwould you like the dump logged to dump.txt?", msg, __FILE__, __LINE__, _eax, _ebx, _ecx, _edx, _esi, _edi, _eip); sprintf(print_buff, "assert occured in file %s on line %d\n\nregister values follow\n\neax = %x\t\tebx = %x\necx = %x\t\t\tedx = %x\nesi = %x\t\tedi = %x\neip = %x\n\n", __FILE__, __LINE__, _eax, _ebx, _ecx, _edx, _esi, _edi, _eip); rt = MessageBox(NULL, TEXT(buff), TEXT("test_assert"), MB_YESNO | MB_ICONEXCLAMATION); printf("RT = %d\n", rt); switch (rt) { case 6: // 6 is ok printf("DUMP\n"); fp = fopen("dump.txt", "w"); if (fp == NULL) printf("ERROR"); //fprintf(fp, buff); fprintf(fp, print_buff); fclose(fp); break; } printf("rt = %d\n", rt); printf("%s\n", buff); __asm { int 3; } } #endif } */ /* void ASSERT(int option, char *msg) { #ifdef _DEBUG char buff[512]; char print_buff[512]; FILE *fp; ulong _eax, _ebx, _ecx, _edx, _esi, _edi, _eip, _ebp, _efl; short esp; int rt = 0; memset(buff, 0, 512); memset(print_buff, 0, 512); __asm { mov _eax, eax; mov _ebx, ebx; mov _ecx, ecx; mov _edx, edx; mov _esi, esi; mov _edi, edi; } if (option == 0) { sprintf(buff, "%s\n\nassert in file %s on line %d\n\n\tregister dump\n\neax = %x\t\tebx = %x\necx = %x\t\t\tedx = %x\nesi = %x\t\tedi = %x\neip = %x\n\nwould you like the dump logged to dump.txt?", msg, __FILE__, __LINE__, _eax, _ebx, _ecx, _edx, _esi, _edi, _eip); sprintf(print_buff, "assert occured in file %s on line %d\n\nregister values follow\n\neax = %x\t\tebx = %x\necx = %x\t\t\tedx = %x\nesi = %x\t\tedi = %x\neip = %x\n\n", __FILE__, __LINE__, _eax, _ebx, _ecx, _edx, _esi, _edi, _eip); rt = MessageBox(NULL, TEXT(buff), TEXT("test_assert"), MB_YESNO | MB_ICONEXCLAMATION); printf("RT = %d\n", rt); switch (rt) { case 6: // 6 is ok printf("DUMP\n"); fp = fopen("dump.txt", "w"); if (fp == NULL) printf("ERROR"); //fprintf(fp, buff); fprintf(fp, print_buff); fclose(fp); break; } printf("rt = %d\n", rt); printf("%s\n", buff); __asm { int 3; } } #endif } */ static unsigned char *mem_block; static int block_size; /* void alloc_block(int block_amount) { mem_block = (char *)malloc(sizeof(char)*block_amount*1000); test_assert (mem_block!= NULL, "something happen"); } void main() { alloc_block(5000); test_assert(0, "crashed it on purpose"); } */