The shl_symbol Structure
The members of the shl_symbol structure are defined as follows:
name | Contains the name of a symbol. |
|
|
type | Contains the symbol's type: TYPE_PROCEDURE or TYPE_DATA is a data symbol used for C |
| uninitialized global variables or Fortran common blocks. |
|
|
value | Contains the symbol's address. It is valid only if EXPORT_SYMBOLS is specified without the NO_VALUES |
| modifier. |
|
|
handle | Contains the handle of the shared library in which the symbol is found, or NULL in the case of symbols |
| defined by shl_definesym. It is valid only if EXPORT_SYMBOLS or INITIALIZERS are requested |
| without the NO_VALUES modifier. It is especially useful when used with the GLOBAL_VALUES modifier, |
| allowing you to determine the library in which the |
|
|
Example 17 shl_getsymbols Example
“show_symbols - Display Shared Library Symbols” (page 180) shows the source for a function named show_symbols that displays shared library symbols. The syntax of this routine is defined as:
int show_symbols(shl_t hndl, short type,
int flags)
hndl | The handle of the shared library whose symbols you want to display. |
|
|
type | The type of symbol you want to display. This is the same as the type parameter to shl_getsymbols |
| and can have these values: TYPE_PROCEDURE, TYPE_DATA, or TYPE_UNDEFINED. If it is |
| TYPE_UNDEFINED, show_symbols displays the type of each symbol. |
|
|
flags | This is the same as the flags parameter. It can have the value EXPORT_SYMBOLS or |
| IMPORT_SYMBOLS. In addition, it can be ORed with NO_VALUES or GLOBAL_VALUES. If |
| EXPORT_SYMBOLS is specified without being ORed with NO_VALUES, show_symbols displays |
| the address of each symbol. |
|
|
|
|
show_symbols - Display Shared Library Symbols
#include <dl.h> |
|
#include <stdio.h> |
|
#include <stdlib.h> |
|
int show_symbols(shl_t | hndl, |
short | type, |
int | flags) |
{
int num_symbols, sym_idx;
struct shl_symbol *symbols, *orig_symbols;
num_symbols = shl_getsymbols(hndl, type, flags, malloc, &symbols); if (num_symbols < 0) {
printf("shl_getsymbols failed\n"); exit(1);
}
orig_symbols = symbols;
for (sym_idx = 0; sym_idx < num_symbols; sym_idx++)
{
printf("
switch
case TYPE_PROCEDURE: |
| |
printf(" | PROCEDURE"); | |
break; |
|
|
case TYPE_DATA: |
| |
printf(" | DATA | "); |
break; |
|
|
case TYPE_STORAGE:
180 Shared Library Management Routines