#GDB keeps thinking that x and y remain the same no matter what i do

1 messages · Page 1 of 1 (latest)

manic summit
#
#include <stdio.h>

int rotateRight(int x, int n) {
    int rotation = x >> n;
    int bits = x << (32 - n);
    int mask = rotation | bits;
    return mask;
}

void main() {
    int xi = 0x80000000;
    int ni = 1;
    int rotate = rotateRight(xi, ni);
    printf("%d", rotate);
}```
fluid raptorBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

manic summit
#

the debugger thinks it's these two values

#

when i deleted that, like, a long time ago

#

i changed the variable names, even.

molten hemlock
#

probably you are debugging wrong executable

#

exit gdb, remove file, recompile

manic summit
#

What does that mean? Like using gcc?

#

I exited gdb and recompiled it, and got the same result

urban sparrow
#

Did you forget to save the file?

molten hemlock
#

and yes, save the file

#

there's usually no magic, if I got a penny each time someone didn't save file or used different path when testing than the target path for building, I would be soooo rich :)

manic summit
#

have legit no idea what you mean

manic summit
molten hemlock
#

is that windows or linux?

#

if windows, is that mingw or wsl?

#

are you running gdb yourself from terminal or is it done via some gui?

manic summit
#

i'm running it from windows, but running it on a linux machine virtually (through a secure connection)

molten hemlock
#

how many questions have you seen?

#

(because I see answer missing)

#

well, either focused and fast and interactive or I won't be able to help you

manic summit
#

it's mainly because i don't know the answer to some of your questions, mainly whether its mingw or wsl

#

i assume wsl is a linux compiler

molten hemlock
#

it isn't windows

#

it is linux

manic summit
#

and mingw is a windows compiler

molten hemlock
#

if this is a virtual machine

manic summit
#

it is

molten hemlock
#

so that one is irrelevant

#

do you run gdb from console, typing a command?

manic summit
#

the console on my actual computer (not the linux one) or within the virtual machine?

#

because the answer is within the virtual machine

molten hemlock
#

that's what I would normally guess (even though technicaly it would be possible to do it otherwise)

#

what exact command do you use to run gdb?

manic summit
#

gdb -tui (once i'm within the directory of the c file)

#

after using gcc of course

#

gcc -g test.c (what i use to compile)

molten hemlock
#

so how do you then choose executable to debug?

manic summit
#

file test

molten hemlock
#

then it won't work, because above gcc produced file a.out

#

and not test

manic summit
#

ah

#

so i have to choose the output file?

molten hemlock
#

yes, the default name is a.out, so either you debug that, or you wite gcc -g test.c -o test

manic summit
#

ah

molten hemlock
#

generally it is convenient to know commands like ls -l or stat to be able to see what's the file date, or even ls -lt to see files sorted by date, and I was going into direction of telling you to remove test like rm test, but as you have shown already you are not recompiling that, that's no longer important

manic summit
#

i should've remembered this

#

i've done this before.

#

shit memory.

molten hemlock
#

you see, as always, program not recompiled

manic summit
#

that includes human memories, apparently

#

anyways, thanks.

#

!solved

fluid raptorBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

manic summit
#

i'm also literally going to put this in my class notes so i don't forget again (the literal screenshot of this convo)