How do I type cast an array of strings in GDB?
Roger Cruz
rogerc@ignitus.com
Mon Jul 26 13:01:00 GMT 1999
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)
More information about the Gdb
mailing list