local symbols partially working

This commit is contained in:
Dmytro Voroshylov 2019-06-19 22:07:27 +03:00
parent 33627101f9
commit 6ad69a276b
3 changed files with 38 additions and 4 deletions

16
.vscode/launch.json vendored
View file

@ -19,6 +19,22 @@
"osx": { "osx": {
"MIMode": "lldb" "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"
}
} }
] ]
} }

View file

@ -3,6 +3,7 @@ project(
'c', 'c',
default_options: [ default_options: [
'buildtype=plain', 'buildtype=plain',
'strip=true',
], ],
) )

View file

@ -90,20 +90,37 @@ int main(int argc, char **argv)
(file + symtab_cmd->symoff); (file + symtab_cmd->symoff);
struct nlist_64 symbol; struct nlist_64 symbol;
char *str_table = file + symtab_cmd->stroff; char *str_table = file + symtab_cmd->stroff;
printf("# symbols: %d\n", symtab_cmd->nsyms);
while(j < symtab_cmd->nsyms) while(j < symtab_cmd->nsyms)
{ {
symbol = symbol_table[j]; 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) if (symbol.n_value)
print_addr((void *)symbol.n_value); print_addr((void *)symbol.n_value);
else else
ft_putstr(" "); ft_putstr(" ");
int type = symbol.n_type & N_TYPE; ft_putchar(' ');
if (type == N_UNDF) if (type == N_UNDF)
ft_putstr(" U "); ft_putchar('U' + offset);
if (type == N_ABS) if (type == N_ABS)
ft_putstr(" A "); ft_putchar('A' + offset);
if (type == N_SECT) if (type == N_SECT)
ft_putstr(" T "); ft_putchar('T' + offset);
ft_putchar(' ');
ft_putstr(str_table + symbol.n_un.n_strx); ft_putstr(str_table + symbol.n_un.n_strx);
ft_putstr("\n"); ft_putstr("\n");
j++; j++;