_isc: add positional arg to specify printed info

This commit is contained in:
Dr-Carlos 2022-04-17 12:58:52 +09:30
parent 631482e4f5
commit 86300fc1c7
1 changed files with 23 additions and 8 deletions

View File

@ -135,10 +135,11 @@ void _io(Session &session, std::string name)
struct _isc_args
{
std::string vspace_name;
bool sort;
bool sort = false;
std::vector<uint32_t> addresses;
};
static struct _isc_args parse_isc(Session &, Parser &parser)
static struct _isc_args parse_isc(Session &session, Parser &parser)
{
_isc_args args;
@ -149,6 +150,9 @@ static struct _isc_args parse_isc(Session &, Parser &parser)
parser.accept_options();
while(!parser.at_end())
args.addresses.push_back(parser.expr(session.current_space));
parser.end();
return args;
}
@ -164,7 +168,8 @@ bool operator<(const SyscallInfo &left, const SyscallInfo &right)
return (left.address < right.address) || (left.id < right.id);
}
void _isc(Session &session, std::string vspace_name, bool sort)
void _isc(Session &session, std::string vspace_name, bool sort,
std::vector<uint32_t> addresses)
{
VirtualSpace *space = session.current_space;
if(!vspace_name.empty())
@ -175,7 +180,7 @@ void _isc(Session &session, std::string vspace_name, bool sort)
OS *os = space->os_analysis();
if(!os) {
if (!vspace_name.empty())
if(!vspace_name.empty())
throw CommandError("OS analysis on '{}' failed", vspace_name);
throw CommandError("OS analysis failed");
}
@ -183,9 +188,19 @@ void _isc(Session &session, std::string vspace_name, bool sort)
int total = os->syscall_count();
auto info = std::make_unique<SyscallInfo[]>(total);
for(int i = 0; i < total; i++) {
for(int i = 0; i < total; i++)
info[i] = (SyscallInfo) {.address = os->syscall(i), .id = i};
}
if(!addresses.empty())
std::remove_if(&info[0], &info[total],
[addresses, &total](const SyscallInfo &item) {
if(std::find(addresses.begin(), addresses.end(), item.address)
== addresses.end()) {
total--;
return true;
}
return false;
});
if(sort)
std::sort(&info[0], &info[total]);
@ -254,10 +269,10 @@ static ShellCommand _isc_cmd(
"isc",
[](Session &s, Parser &p) {
auto args = parse_isc(s, p);
_isc(s, args.vspace_name, args.sort);
_isc(s, args.vspace_name, args.sort, args.addresses);
},
[](Session &s, Parser &p) { parse_isc(s, p); }, "Info Syscalls", R"(
isc [sort=true] [vspace=<virtual_name>]
isc [sort=true] [vspace=<virtual_space>] [<address>...]
Prints the syscall table for the specified virtual space (defaults to the
current one). By default, syscalls are enumerated by syscall number. If