Port-sparc64 archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
GDB bug or something else?
I have a small test program which stores 0x12345 into %i6 register save
area on the stack, then reads it back and prints it. The test is done
on NetBSD-11 sun4u sparc64 machine.
The test program is attached. Can anyone think of reasons why single
stepping through the program with GDB results in incorrect value read
from the stack, instead of 0x12345? Using GDB x/xg command to examine
the value at the specified address also gives the same incorrect value.
Running the program normally produces a correct value.
I think I calculated the offset for %i6 correctly for the current
stack frame and I'm not corrupting any GDB structures. This looks like
a potential GDB bug.
/*
1) Build and run test program. All looks good:
$ gcc -O0 -g3 -Wall -pedantic test.c
$ ./a.out
sp_value = 0xffffffffffffcd41
i6_stack_value = 0x0000000000012345
2) Run via gdb. All looks good:
$ gdb --args a.out
(gdb) run
sp_value = 0xffffffffffffcd01
i6_stack_value = 0x0000000000012345
[Inferior 1 (process 845) exited normally]
3) Step via gdb. We get completely wrong i6 value:
$ gdb --arg a.out
(gdb) break main
Breakpoint 1 at 0x100b64: file test.c, line 67.
(gdb) run
Breakpoint 1, main () at test.c:67
67 __asm__ __volatile__ ("mov %%sp, %0" : "=r"(sp_value) : : "memory");
(gdb) n
68 printf("sp_value = 0x%016" PRIx64 "\n", sp_value);
(gdb)
sp_value = 0xffffffffffffcd01
71 i6_stack_addr = sp_value + i6_stack_offset;
(gdb)
74 *((uint64_t *)i6_stack_addr) = 0x12345;
(gdb)
77 i6_stack_value = *((uint64_t *)i6_stack_addr);
(gdb)
80 printf("i6_stack_value = 0x%016" PRIx64 "\n", i6_stack_value);
(gdb)
i6_stack_value = 0xffffffffffffcdb1
82 return 0;
(gdb)
83 }
(gdb)
[Inferior 1 (process 855) exited normally]
*/
#include <assert.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
/* Current %sp register value */
static uint64_t sp_value;
/* Stack offset for %i6 register save area */
static uint64_t i6_stack_offset = 2047 + 112;
/* Stack address for %i6 register save area */
static uint64_t i6_stack_addr; /* %sp + 2047 bias + 112 */
static uint64_t i6_stack_value;
int main(void)
{
/* Get current value of %sp register */
__asm__ __volatile__ ("mov %%sp, %0" : "=r"(sp_value) : : "memory");
printf("sp_value = 0x%016" PRIx64 "\n", sp_value);
/* Calculate stack address for %i6 register save area */
i6_stack_addr = sp_value + i6_stack_offset;
/* Store some random value in %i6 save area */
*((uint64_t *)i6_stack_addr) = 0x12345;
/* Read value in %i6 save area */
i6_stack_value = *((uint64_t *)i6_stack_addr);
/* Print stored value */
printf("i6_stack_value = 0x%016" PRIx64 "\n", i6_stack_value);
return 0;
}
Home |
Main Index |
Thread Index |
Old Index