This is the mail archive of the gdb@sourceware.cygnus.com 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]

How do I type cast an array of strings in GDB?


I have the following definition in a file, compiled without the -g switch:

LOCAL char *  semTypeMsg [MAX_SEM_TYPE] =
    {
    "BINARY", "MUTEX", "COUNTING", "OLD", "\0", "\0", "\0", "\0"
    };

I want to index this array to get to the different strings:

(gdb) p semTypeMsg[0]
cannot subscript something of type `<data variable, no debug info>'
(gdb) whatis semTypeMsg
type = <data variable, no debug info>

But because it was compiled without the -g switch, I can't do this
directly.  How do I cast this variable name to allow me access to the
strings?  I've tried a bunch of compinations and they are all unsuccessful

(gdb) p ((char *)semTypeMsg)
$19 = 0xfdd8c "BINARY"
(gdb) p ((char *)semTypeMsg)[0]
$20 = 66 'B'
(gdb) p ((char **)semTypeMsg)[0]
$21 = 0x42494e41Requested target address (0x42494e41) is outside
the valid memory range: 0x0-0x1000000

(gdb) p ((char **)semTypeMsg)+1
$22 = (char **) 0xfdd90
(gdb) p *(((char **)semTypeMsg)+1)
$23 = 0x52590000Requested target address (0x52590000) is outside
the valid memory range: 0x0-0x1000000

(gdb) p (char *)(((char **)semTypeMsg)+1)
$24 = 0xfdd90 "RY"
(gdb) p (char *)(((char **)semTypeMsg)+1)



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