You just need to go "up" in the stack to bring ptr back in scope.
Code:
jdeckard@bender ~/test $ cat gdbfun.c
void myfunc( void )
{
int x;
x = 1 + 1;
}
int main( void )
{
char *ptr = "Greetings from the text segment!";
myfunc();
return 0;
}
jdeckard@bender ~/test $ gcc -g -o gdbfun gdbfun.c -std=c99
jdeckard@bender ~/test $ gdb gdbfun
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) b myfunc
Breakpoint 1 at 0x40046c: file gdbfun.c, line 5.
(gdb) r
Starting program: /home/jdeckard/test/gdbfun
Breakpoint 1, myfunc () at gdbfun.c:5
5 x = 1 + 1;
(gdb) up
#1 0x000000000040048a in main () at gdbfun.c:12
12 myfunc();
(gdb) p ptr
$1 = 0x400590 "Greetings from the text segment!"
(gdb)