Kenwood HP 9000 Personal Computer User Manual


 
Chapter 6 229
Shared Library Management Routines
The shl_load Shared Library Management Routines
Description
To obtain information on currently loaded libraries, use the shl_get
function. If you are programming in a threaded environment, use the
thread-safe version shl_get_r which is the same as shl_get in all
other respects. (See Programming with Threads on HP-UX for more
information about threads.)
Other than obtaining interesting information, this routine is of little use
to most programmers. A typical use might be to display the names and
starting/ending address of all shared libraries in a process's virtual
memory address space.
Example
The function show_loaded_libs shown below displays the name and
start and end address of the text and data/bss segments the library
occupies in a process's virtual address space.
show_loaded_libs — Display Library Information
#include <stdio.h> /* contains standard I/O defs */
#include <dl.h> /* contains shared library type defs */
void show_loaded_libs(void)
{
int idx;
struct shl_descriptor *desc;
printf(“SUMMARY of currently loaded libraries:\n”);
printf(“%-25s %10s %10s %10s %10s\n”,
“___library___”, “_tstart_”, “__tend__”, “_dstart_”, “__dend__”);
idx = 0;
for (idx = 0; shl_get(idx, &desc) != -1; idx++)
printf(“%-25s %#10lx %#10lx %#10lx %#10lx\n”,
desc->filename, desc->tstart, desc->tend, desc->dstart, desc->dend);
}
Calling this function from a C program compiled with shared libc and
libdld produced the following output:
SUMMARY of currently loaded libraries:
___library___ _tstart_ __tend__ _dstart_ __dend__
./a.out 0x1000 0x1918 0x40000000 0x40000200
/usr/lib/libdld.sl 0x800ac800 0x800ad000 0x6df62800 0x6df63000
/usr/lib/libc.sl 0x80003800 0x80091000 0x6df63000 0x6df85000