BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

What are valid heap addresses for 64 bit application on HP-UX 11.31?

SOLVED
Go to Solution
Highlighted
Regular Advisor

What are valid heap addresses for 64 bit application on HP-UX 11.31?

[ Edited ]

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

3 REPLIES
Acclaimed Contributor

Re: What are valid heap addresses for 64 bit application on HP-UX 11.31?

[ Edited ]

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.  :-(

Regular Advisor

Re: What are valid heap addresses for 64 bit application on HP-UX 11.31?

[ Edited ]

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)

 

#include <stdio.h>
int main()
{
  char *p = new char;
  printf("%p\n", p);
  delete p;
  return 0;
}

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.

 

 

Acclaimed Contributor

Re: What are valid heap addresses for 64 bit application on HP-UX 11.31?

[ Edited ]

>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
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)