I get a strange problem here, and ask for help.
(gdb)
28 set_file_bit( file, bytePos, bitPos, argv[1] );
(gdb) p argv[1]
$3 = 0xbfffef5c "00"
(gdb) s
set_file_bit (file=0x804b008, bytePos=2, bitPos=2, binary=0x80490e5 "11") at util/file.c:112
112 long int pos = ftell(file);
We can see the value of binary is 0x80490e5, not 0xbfffef5c , why?
argv is the parameter of function main.
some part of function main is
int main( int argc, char** argv ){
FILE* file = 0;
file = fopen( "t.txt", "r+" );
unsigned int bytePos = 2;
unsigned int bitPos = 2;
char buff[2] = { 0, 0 };
get_byte( file, bytePos, 1, buff);
set_file_bit( file, bytePos, bitPos, argv[1] );
Thanks
The most likely reason is that
set_file_bitwas compiled with optimization, and the parameters have not been completely set up when GDB stepped into it.Try printing
binaryinsideset_file_bit, it will likely be0xbfffef5c. When debugging optimized code, one frequently sees such artifacts. Rebuild with-O0to make your debugging easier.