I am trying to debug my hypervisor using GDB server (via VMware). Unfortunately, GDB prints wrong values for non-pointer type variables.
For example, I have 2 variables declared as follows:
WORD fileType;
WORD_PTR pfileType = &fileType;
fileType = 5;
I have put a breakpoint right after the assignment to fileType (using the "native debug" VS Code plugin), and on GDB I ran the following:
print fileType
0
print *pfileType
5
So, I printed the addresses, and it is obvious that GDB is using the wrong address for the fileType
variable:
print &fileType
(WORD *) 0x64013dc07d66
print pfileType
(WORD_PTR) 0x64013dc07e6e
I have tried to add the -fvar-tracking
flag (according to this post), but I still get the exact same output.
Here is the full list of flags that I am using to compile my code:
-nostdlib \
-c \
-fPIC \
-w \
-fno-stack-protector \
-mno-red-zone \
-nostdinc \
-g3 \
-ggdb \
-fshort-wchar \
-fvar-tracking \
-fno-omit-frame-pointer
Any ideas why this is happening? Perhaps I am doing something wrong?