Segmentation fault - Debug assembly gdb

I am debugging a segmentation fault. Here is a piece of code that causes errors when calling ff_printf.

for (p = &v[QUEUE], i = 0; i < p->used; i++) {
        queue_t *q = p->data[i];
        ff_printf(F_DB, "  %02u %s\n",
            p->cp, q->tq->queue_name);
    }

      

Seg error on ff_printf line. When I debug gdb I can resolve p-> cp and q-> tq-> queue_name. F_DB is also allowed, since it is an enumeration. Hence, it did not generate invalid respect error.

After disassembling the code, I get the following assembly of the above code snippet for the ff_printf line.

   0x0000000000449b88 <+360>:   mov    -0x14(%r13),%rax
   0x0000000000449b8c <+364>:   movzwl %r10w,%edx

   0x0000000000449b90 <+368>:   movzwl (%rbx),%r9d
   0x0000000000449b94 <+372>:   mov    $0x56a4d9,%r8d
   0x0000000000449b9a <+378>:   mov    $0x5,%ecx
   0x0000000000449b9f <+383>:   mov    $0x5bb,%esi
   0x0000000000449ba4 <+388>:   mov    $0x56a27b,%edi
   0x0000000000449ba9 <+393>:   mov    (%rax,%rdx,8),%rax
   0x0000000000449bad <+397>:   mov    $0x56aec0,%edx
=> 0x0000000000449bb2 <+402>:   mov    0x88(%rax),%rax
   0x0000000000449bb9 <+409>:   mov    %r10d,-0x48(%rbp)
   0x0000000000449bbd <+413>:   mov    %rax,(%rsp)
   0x0000000000449bc1 <+417>:   xor    %eax,%eax
   0x0000000000449bc3 <+419>:   callq  0x4423c0 <ff_printf>

      

Now I debugged registers and tested the code snippet. I was able to get F_DB, p-> cp, q-> tq-> queue_name via build debug (namely via registers). I noticed that the% rax value is 0x0. I observe that the seg error occurs before the ff_printf library call.

I have two questions:

1: How to match this

"    => 0x0000000000449bb2 <+402>:  mov    0x88(%rax),%rax" 

      

for a piece of code?

I noticed that% rax fills up after

0x0000000000449b88 <+360>:  mov    -0x14(%r13),%rax

      

which I think is mov (address $ r13 - 0x14) in% rax.

and

0x0000000000449ba9 <+393>:  mov    (%rax,%rdx,8),%rax

      

which i think is mov (address $ rax + address $ rdx + 8) in% rax. I'm right?

2: I'm not sure if there was any stack damage. This segregation is very rare, I cannot reproduce it. How to retreat further from here?

+3


source to share


1 answer


p = & v [QUEUE]

it is not correct if QUEUE is the size v, since its index ranges from zero to QUEUE-1.

So use



p = & v [QUEUE-1]

Or, if you want to start at the beginning of v, use

p = v

0


source







All Articles