GDB cannot access struct member whose offset is larger than 256MB

Solution Verified - Updated -

Issue

  • GDB cannot access struct member whose offset is larger than 256MB
  • The following is the sample program to reproduce it.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BSIZE (0x10000000)

struct s {
     char buf1[BSIZE];
     char buf2[8];
     char buf3[8];
     char buf4[8];
};

int main()
{
     struct s *p = malloc(sizeof(struct s));
     memset(p,0,sizeof(struct s));
     printf("%p %x\n", &p->buf2[0], p->buf2[0]);
     return(0);
}

  • Compile the program:

[root@localhost test]# gcc -Wall -g test.c

  • Run in GDB as follows:

[root@localhost test]# gdb ./a.out
(gdb) b 18
Breakpoint 1 at 0x400554: file test.c, line 18.
(gdb) run
Starting program: /root/gdb/a.out
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x2aaaaaac7000

Breakpoint 1, main () at test.c:18
18              printf("%p %x\n", &p->buf2[0], p->buf2[0]);
(gdb) p p->buf2[0]
Cannot access memory at address 0x2aaa9b022010
(gdb)

  • This works correctly for any value less than 0x10000000 for BSIZE

Environment

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • gdb-7.0.1-37.el5_7.1

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content