# questions about nlist



## fluca1978 (Apr 18, 2013)

Hello,
I'm trying to understand how to extract all available symbols from an executable, and therefore I've written the following simple function that should dump a nlist structure:


```
void
dump_nlist( struct nlist *nlist ){

  if( nlist == NULL || nlist->n_name == NULL )
    printf( "\n\t---<null>---" );
  else
    printf( "\n\t---\n\tType [%c]\tName [%s]\n\tShort Desc [%d]\n\tAddress/value [%d]\n\tOther \
[%c]\n\t---",
            nlist->n_type,
            nlist->n_name,
            nlist->n_desc,
            nlist->n_value,
            nlist->n_other );
}
```

and in my program I do the following:


```
struct nlist nlist_array[ 300 ];
  struct nlist *nlistp = NULL;
...
nsymbols = nlist( boot_file_name, nlist_array );
for ( nlistp = nlist_array; nlistp; nlistp++ )
    dump_nlist( nlistp );
```

The first question is on how to know how many nlist structures have been extracted, since the nlist(3) function returns only the number of invalid entries. Second, the above loop does not work and stops in the middle with a signal 11, and I suspect it is something wrong with an element in the list, but inspecting it with the debugger does not show me any evident error. Does anybody has a clue?


----------



## trasz@ (Apr 20, 2013)

From the manual page, this seems to be used for a.out executables, which are long gone; current executable format is ELF.  Perhaps you should try libelf instead?


----------



## fluca1978 (Apr 21, 2013)

trasz@ said:
			
		

> From the manual page, this seems to be used for a.out executables, which are long gone; current executable format is ELF.  Perhaps you should try libelf instead?



Thanks, but it seems to work, simply I was misunderstanding the meaning of the second argument: the nlist pointer must be to a list where each element is initialized with the name of the symbol to find out, and then the nlist(3) function fills each entry witht the other data (type, address, ..). However, is there anything kernel-specific to get out a list of kernel symbols or do I have to use libelf?


----------

