1

There's something weird going on I don't understand.

I have a data variable:

variable_a dq 0

I check it's 0:

(gdb) x variable_a 
0x0:    Cannot access memory at address 0x0

So far so good.

I have rax:

(gdb) i r
rax            0x7fffffffe9e2   140737488349666

I MOV rax into variable.

mov [variable_a], rax

I print variable.

(gdb) x variable_a 
0xffffffffffffe9e2:     <error: Cannot access memory at address 0xffffffffffffe9e2>

Why is this happening? It looks like 1/4 of the variable is getting set to 1s when it should be 0s.

I changed to using a BSS variable and it works just fine. I'm using YASM.

Rafael
  • 7,605
  • 13
  • 31
  • 46
nemasu
  • 426
  • 2
  • 10
  • What version of yasm are you using? Only half of rax's value is being moved to variable_a... – Rafael Jan 24 '19 at 05:54
  • @Rafael yasm 1.3.0 – nemasu Jan 24 '19 at 06:15
  • 2
    `x` expects an address. Use `x &variable_a` or `p variable_a`. – Margaret Bloom Jan 24 '19 at 07:55
  • 3
    as for the sign extension, probably GDB is making a pointer from the lower 32 bits of `variable_a`. I don't think GDB has a way of knowing how actually big the variable is, so it's guessing/defaulting to 4-bytes. – Margaret Bloom Jan 24 '19 at 08:07
  • @MargaretBloom x &directory_path gives 0xffffe9e2. But x/1g &directory_path gives the right value (140737488349666). Something else must be messing with variable_a then, cause the value is wrong later on. Comes out as 0x00007fffffff0000. – nemasu Jan 24 '19 at 08:23
  • 1
    @nemasu Possibly, just make sure to use the correct GDB commands in order to avoid the common pitfalls. `mov [variable_a], rax` will move 64 bits, so that's not the problem. Luckily GDB is a debugger, so you can easily pinpoint what's wrong :) – Margaret Bloom Jan 24 '19 at 08:49

0 Answers0