public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/18436] New: Can't print dynamically allocated global array
@ 2015-05-20  4:54 stanton at haas dot berkeley.edu
  2015-05-20 16:34 ` [Bug gdb/18436] " keiths at redhat dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: stanton at haas dot berkeley.edu @ 2015-05-20  4:54 UTC (permalink / raw)
  To: gdb-prs

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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-08-03 15:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-20  4:54 [Bug gdb/18436] New: Can't print dynamically allocated global array stanton at haas dot berkeley.edu
2015-05-20 16:34 ` [Bug gdb/18436] " keiths at redhat dot com
2015-05-20 17:15 ` stanton at haas dot berkeley.edu
2015-05-20 17:48 ` keiths at redhat dot com
2015-05-20 18:13 ` stanton at haas dot berkeley.edu
2015-05-21 17:26 ` stanton at haas dot berkeley.edu
2023-08-03 15:53 ` tromey at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).