Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmds] Add 'disasm -' option to read from stdin #2118

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions elkscmd/debug/dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

char f_ksyms;
char f_syms;
char f_fdinput;
unsigned short textseg, ftextseg, dataseg;

char * noinstrument getsymbol(int seg, int offset)
Expand Down Expand Up @@ -134,9 +135,26 @@ int disasm_file(char *filename)
return 0;
}

int disasm_fd(int fd)
{
int ip = 0;
int nextip;

infp = fdopen(fd, "r");
if (!infp)
return 1;

while (!feof(infp)) {
if (!f_asmout) printf("%04hx ", ip);
nextip = disasm(textseg, ip, nextbyte_file, dataseg);
ip = nextip;
}
return 0;
}

void usage(void)
{
printf("Usage: disasm [-k] [-a] [-s symfile] [[seg:off[#size] | filename]\n");
printf("Usage: disasm [-k][-a][-s symfile] [[seg:off[#size] | filename | -]\n");
exit(1);
}

Expand Down Expand Up @@ -166,7 +184,9 @@ int main(int ac, char **av)
}
ac -= optind;
av += optind;
if (ac < 1)
if (ac == 1 && **av == '-')
f_fdinput = 1;
else if (ac < 1)
usage();

if (symfile && !sym_read_symbols(symfile)) {
Expand All @@ -188,6 +208,8 @@ int main(int ac, char **av)
}
#endif

if (f_fdinput)
return disasm_fd(0);
if (strchr(*av, ':')) {
sscanf(*av, "%lx:%lx#%ld", &seg, &off, &count);

Expand Down
Loading