HP-UX HB v13.00 Ch-11 - Software Development

HP-UX Handbook Rev 13.00 Page 86 (of 101)
Chapter 11 Software Development
October 29, 2013
smaller than the primordial thread, that’s why stack overflows are much more likely in
multithreaded programs.
These default sizes are hardcoded into the POSIX threads library libpthread[.sl|.so].
Programs can specify the stacksize for each new thread before it is created with
pthread_attr_setstacksize(3T). Alternatively they can also change the default stacksize
with pthread_default_stacksize_np(3T) before they start creating threads.
The default thread stacksize can also be defined before starting a program, with the environment
variable PTHREAD_THREAD_STACK_SIZE. This feature is natively implemented in HP-UX 11.31.
HP-UX 11.11 needs at least phtread patch PHCO_36229, and on HP-UX 11.23 pthread patch
PHCO_34718 or later is required.
Checking for thread stack overflows means looking up stack pointer addresses with the
debugger, and comparing them with the thread stack boundaries. Select the thread and frame that
received the signal, and print the stack pointer:
$ gdb <program> core
:
(gdb) info threads
* 224 system thread 509883 0xc020c718 in kill+0x10 () from
/usr/lib/libc.2
223 system thread 555147 0xc020b540 in __ksleep+0x10 () from
/usr/lib/libc.2
:
$ thread 224
(gdb) thr 224
[Switching to thread 224 (system thread 509883)]
#0 0xc020c718 in kill+0x10 () from lib/libc.2
(gdb) bt
:
#8 <signal handler called>
#9 0xcaac2d34 in alloc_object+0xc () from
/opt/java1.4/jre/lib/PA_RISC2.0/hotspot/libjvm.sl
:
(gdb) frame 9 ### the “original” problem frame
#9 0xcaac2d34 in alloc_object+0xc () from
/opt/java1.4/jre/lib/PA_RISC2.0/hotspot/libjvm.sl
(gdb) p/x $sp
$6 = 0x7360d300
Then check e.g. with adb how this address fits into the memory mapped thread stacks:
$ echo $m | adb <program> core
:
MMF: b = 73509000 e = 7358A000 f = 9A780A4
MMF: b = 7358A000 e = 7360B000 f = 9AF90B4