diff --git a/.vscode/launch.json b/.vscode/launch.json index cc49c1d..a7a3679 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -19,6 +19,22 @@ "osx": { "MIMode": "lldb" } + }, + { + "name": "orig nm read", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/debug_bld/ft_nm", + "args": ["/usr/bin/nm"], + "preLaunchTask": "build", + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "osx": { + "MIMode": "lldb" + } } ] } \ No newline at end of file diff --git a/meson.build b/meson.build index 7abcc1c..c221fb0 100644 --- a/meson.build +++ b/meson.build @@ -3,6 +3,7 @@ project( 'c', default_options: [ 'buildtype=plain', + 'strip=true', ], ) diff --git a/src/main.c b/src/main.c index 3648f55..fd0c8a1 100644 --- a/src/main.c +++ b/src/main.c @@ -90,20 +90,37 @@ int main(int argc, char **argv) (file + symtab_cmd->symoff); struct nlist_64 symbol; char *str_table = file + symtab_cmd->stroff; + printf("# symbols: %d\n", symtab_cmd->nsyms); while(j < symtab_cmd->nsyms) { symbol = symbol_table[j]; + int type = symbol.n_type & N_TYPE; + int external = symbol.n_type & N_EXT; + int offset = external ? 0 : 32; + + if ( + type != N_UNDF && + type != N_ABS && + type != N_SECT && + type != N_PBUD && + type != N_INDR) + { + j++; + continue; + } + if (symbol.n_value) print_addr((void *)symbol.n_value); else ft_putstr(" "); - int type = symbol.n_type & N_TYPE; + ft_putchar(' '); if (type == N_UNDF) - ft_putstr(" U "); + ft_putchar('U' + offset); if (type == N_ABS) - ft_putstr(" A "); + ft_putchar('A' + offset); if (type == N_SECT) - ft_putstr(" T "); + ft_putchar('T' + offset); + ft_putchar(' '); ft_putstr(str_table + symbol.n_un.n_strx); ft_putstr("\n"); j++;