| 1 | /* nm.c - a feeble shared-lib library parser
|
|---|
| 2 | * Copyright 1997, 1998 Tom Spindler
|
|---|
| 3 | * This software is covered under perl's Artistic license.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /* $Id: nm.c,v 1.1 1998/02/16 03:51:26 dogcow Exp $ */
|
|---|
| 7 |
|
|---|
| 8 | #include <be/kernel/image.h>
|
|---|
| 9 | #include <malloc.h>
|
|---|
| 10 | #include <string.h>
|
|---|
| 11 | #include <unistd.h>
|
|---|
| 12 | #include <stdio.h>
|
|---|
| 13 | #include <stdlib.h>
|
|---|
| 14 |
|
|---|
| 15 | main(int argc, char **argv) {
|
|---|
| 16 | char *path, *symname;
|
|---|
| 17 | image_id img;
|
|---|
| 18 | int32 n = 0;
|
|---|
| 19 | volatile int32 symnamelen, symtype;
|
|---|
| 20 | void *symloc;
|
|---|
| 21 |
|
|---|
| 22 | if (argc != 2) { printf("more args, bozo\n"); exit(1); }
|
|---|
| 23 |
|
|---|
| 24 | path = (void *) malloc((size_t) 2048);
|
|---|
| 25 | symname = (void *) malloc((size_t) 2048);
|
|---|
| 26 |
|
|---|
| 27 | if (!getcwd(path, 2048)) { printf("aiee!\n"); exit(1); }
|
|---|
| 28 | if (!strcat(path, "/")) {printf("naah.\n"); exit (1); }
|
|---|
| 29 | /*printf("%s\n",path);*/
|
|---|
| 30 |
|
|---|
| 31 | if ('/' != argv[1][0]) {
|
|---|
| 32 | if (!strcat(path, argv[1])) { printf("feh1\n"); exit(1); }
|
|---|
| 33 | } else {
|
|---|
| 34 | if (!strcpy(path, argv[1])) { printf("gah!\n"); exit(1); }
|
|---|
| 35 | }
|
|---|
| 36 | /*printf("%s\n",path);*/
|
|---|
| 37 |
|
|---|
| 38 | img = load_add_on(path);
|
|---|
| 39 | if (B_ERROR == img) {printf("Couldn't load_add_on() %s.\n", path); exit(2); }
|
|---|
| 40 |
|
|---|
| 41 | symnamelen=2047;
|
|---|
| 42 |
|
|---|
| 43 | while (B_BAD_INDEX != get_nth_image_symbol(img, n++, symname, &symnamelen,
|
|---|
| 44 | &symtype, &symloc)) {
|
|---|
| 45 | printf("%s |%s |GLOB %Lx | \n", symname,
|
|---|
| 46 | ((B_SYMBOL_TYPE_ANY == symtype) || (B_SYMBOL_TYPE_TEXT == symtype)) ? "FUNC" : "VAR ", symloc);
|
|---|
| 47 | symnamelen=2047;
|
|---|
| 48 | }
|
|---|
| 49 | printf("number of symbols: %d\n", n);
|
|---|
| 50 | if (B_ERROR == unload_add_on(img)) {printf("err while closing.\n"); exit(3); }
|
|---|
| 51 | free(path);
|
|---|
| 52 | return(0);
|
|---|
| 53 | }
|
|---|