OSDev.org https://forum.osdev.org/ |
|
Error in debugging code https://forum.osdev.org/viewtopic.php?f=13&t=37058 |
Page 1 of 1 |
Author: | pranavappu007 [ Thu Jul 30, 2020 9:52 am ] |
Post subject: | Error in debugging code |
IN the middle of implementing a low level BASIC like "Thing"(not sure what to call it, for now I call it executer), when I encountered this error. I was trying to implement negative number support in the code. In the "source code" it executes(not the source of the executer itself) negative numbers are simply number prefixed by a negative sign. My "executer" should convert this into actual negative numbers and store in arrays. There was some problem with that, so I wrote a bunch of debug-print code to check the issue. In this code I am just printing an integer array to check if it contains the value it should contain..(array should not contain any negative value at this point) Code: int test=0;char val[5]={}; int l=0; for(int k=0;exp[k]!=0;k++) { test=exp[k]; //taking in value int_to_ascii(test, val); //converting to ASCII print(val,2*l,0xd); //my print function-takes a pointer, an offset, and a color value for(int m=0;val[m]!='\0';m++) //clearing out val for next iteration val[m]='\0'; l=k*0xA0; //next line } I tried to debug using this code, tried changing lot of stuff, but nothing. Soon I realized that I already fixed the main code but the debug print was actually buggy! It doesn't print exp[0], no matter what I try.For example, when I expect the output to be: Quote:
20530 5 but it always do Quote: 20530 ;omits the first value 5 If I try to force some other value into exp[0], then Quote: 20530P\. ;invalid values, there is no way this can happen 5 This is my int_to_ascii code: Code: if(src==0) { stack[i++]='\0'; //pushing NULL and 0 to stack stack[i++]='0'; } else { while(src!=0) //converting last digit and pushing to stack { stack[i]=(0x30+src%10); src/=10; i++; } } i--; len=i; while(i>=0) { dest[len-i]=stack[i]; //popping and placing from left to right i--; //inorder not to get reversed. } I don't see a way from these code snippets that it should omit exp[0] or effect exp[1] when value of exp[0] is changed, when actually exp contains all desired values and my main code works. As it's just a debug-prints it's not super important, but still I would like to know the cause of this behavior. |
Author: | Octocontrabass [ Thu Jul 30, 2020 11:05 am ] |
Post subject: | Re: Error in debugging code |
Code: char val[5]={}; If the numbers you're printing have five digits, where is your null terminator? Code: l=k*0xA0; //next line That sets it to the current line, not the next line. So if you print entry 0, then you move the cursor to line 0... where will entry 1 be printed? |
Author: | pranavappu007 [ Thu Jul 30, 2020 11:17 am ] |
Post subject: | Re: Error in debugging code |
Octocontrabass wrote: That sets it to the current line, not the next line. So if you print entry 0, then you move the cursor to line 0... where will entry 1 be printed? hey that makes sense! I think the second entry overwrites the first entry, has to check that next day... I mainly use while loops and in that I increment before setting values... maybe habit got me |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |