07-29-2013 07:57 AM - last edited on 07-29-2013 07:35 PM by JinJing1
If I do this C++ code in a 64-bit program on HP-UX 11.31 and new is successful:
char *p = new char;
p points to somewhere in the heap. But what is possible min and max values for p?
I understand that p is always bigger than 0x6000000000000000. But what are actual min and max values on HP-UX 11.31 for a valid pointer?
P.S. This thread has been moved from HP-UX >General > to HP-UX > languages.-Hp forum moderator
Solved! Go to Solution.
07-29-2013 09:51 AM - edited 07-29-2013 07:43 PM
Take a look at end(3C).
The heap range is from _end to the current brk value.
(gdb) p /x &_end
$8 = 0x6000000000000038
(gdb) p /x sbrk(0)
$9 = 0x38
Unfortunately since there is no debug info for sbrk, it only prints at the low order 32 bits. :-(
07-29-2013 10:24 PM - edited 07-29-2013 10:49 PM
Dennis, thank for a reply.
Unfortunatelly I still don't quite understand how to get min and max values.
Take this program as an example (I build it: aCC +DD64 -g main2.cpp -o main2)
char *p = new char;
So my question in what range can be p after "new char"? MIN_VALUE < p < MAX_VALUE ?
I run gdb and did what you suggested:
(gdb) r Starting program: /import/home/sergey.kurenkov/src/ia64.11-31/tests/
test.analyze_core/./main2 Breakpoint 1, main () at main2.cpp:4 4 char *p = new char; (gdb) n 5 printf("%p\n", p); (gdb) p/x p $1 = 0x6000000000004790 (gdb) p/x &_end $2 = 0x6000000000000070 (gdb) p/x &_edata $3 = 0x6000000000000050 (gdb)
Looking at this I can guess that I can use &_end as MIN_VALUE, but how to get MAX_VALUE?
Is it p/x &_end + sbrk(0)? If it is so it is useless in case one analyzes a core file. I mean one can't execute p/x sbrk(0) while analyzing a core file:
(gdb) p/x sbrk(0)
You can't do that without a process to debug.
07-29-2013 11:43 PM - edited 07-29-2013 11:44 PM
>how to get MAX_VALUE?
>Is it p/x &_end + sbrk(0)?
No, it's at least: p /x ((long long)&_end >> 32 << 32) + sbrk(0)
>If it is so it is useless in case one analyzes a core file.
You'll need to compute this outside of gdb:
$ elfdump -o -S core.10472
*** Program Header ***
Type Offset Vaddr FSize Memsz
CoreVer 00000000000004d8 0000000000000000 0000000000000004 0000000000000004
CoreLoad 000000000000caf8 6000000000000000 0000000000001000 0000000000001000
It's CoreLoad.Vaddr + CoreLoad.Memsz: 0x6000000000000000 + 0x0000000000001000
Or use gdb's "info file":
(gdb) info file
Operating System Information:
sysname : B.11.31
Symbols from "./a.out".
Local core dump file:
`./core.10472', file type elf64-big.
0x6000000000000000 - 0x6000000000001000 is segment5 (PT_HP_CORE_LOADABLE)