This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug gdb/18436] New: Can't print dynamically allocated global array


https://sourceware.org/bugzilla/show_bug.cgi?id=18436

            Bug ID: 18436
           Summary: Can't print dynamically allocated global array
           Product: gdb
           Version: 7.9
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: stanton at haas dot berkeley.edu
  Target Milestone: ---

If I dynamically allocate memory for an array using malloc, if the pointer is
defined globally, when I ask gdb to print an element of the array I get the
error message

cannot subscript something of type `<data variable, no debug info>'

Here's a very short program that demonstrates the problem. Compile with 

gcc -g -c -o main.o main.c
gcc -o main main.o 

then, using gdb, step into the middle of the loop and try "print vec[0]". It
works fine if the "double *vec;" line is inside main().

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

double *vec;

int main(int argc, char *argv[])
{
    int i;

    vec = (double *) malloc((unsigned) 10*sizeof(double));

    for (i=0; i<10; i++) {
        vec[i] = i;
        printf("Item %d = %15.6g\n", i, vec[i]);
    }

    free((char*) vec);

    return(0);
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]