_is: add sort option

This commit is contained in:
Dr-Carlos 2022-12-23 07:11:16 +11:00
parent f16ecc370c
commit b494a30404
2 changed files with 17 additions and 4 deletions

View File

@ -34,6 +34,11 @@ struct Symbol
/* Symbol name, no particular conventions */
std::string name;
bool operator<(const FxOS::Symbol &right) const
{
return (type < right.type) || (value < right.value);
}
};
/* A symbol table, usually the set of symbols of a virtual space */

View File

@ -249,6 +249,7 @@ struct _is_args
{
std::string vspace_name;
std::optional<FxOS::Symbol> symbol;
bool sort;
};
static struct _is_args parse_is(Session &session, Parser &parser)
@ -258,6 +259,9 @@ static struct _is_args parse_is(Session &session, Parser &parser)
parser.option("vspace",
[&args](std::string const &value) { args.vspace_name = value; });
parser.option("sort",
[&args](std::string const &value) { args.sort = (value == "true"); });
parser.accept_options();
FxOS::Symbol s;
@ -296,7 +300,7 @@ static struct _is_args parse_is(Session &session, Parser &parser)
}
void _is(Session &session, std::string vspace_name,
std::optional<FxOS::Symbol> symbol)
std::optional<FxOS::Symbol> symbol, bool sort)
{
VirtualSpace *space = session.current_space;
if(!space) {
@ -351,6 +355,9 @@ void _is(Session &session, std::string vspace_name,
symbols = {s};
}
if(sort)
std::sort(&symbols[0], &symbols[symbols.size()]);
for(auto const &s: symbols) {
if(s.type == FxOS::Symbol::Syscall) {
fmt::print(theme(10), " %{:04x}", s.value);
@ -404,12 +411,13 @@ static ShellCommand _is_cmd(
"is",
[](Session &s, Parser &p) {
auto args = parse_is(s, p);
_is(s, args.vspace_name, args.symbol);
_is(s, args.vspace_name, args.symbol, args.sort);
},
[](Session &s, Parser &p) { parse_is(s, p); }, "Info Symbols", R"(
is [vspace=<virtual_space>] [<address|syscall>]
is [sort=true] [vspace=<virtual_space>] [<address|syscall>]
Lists symbols in the specified virtual space (defaults to the current
one). By default, all symbols are listed, but if an address or syscall is
provided, the symbol associated with it will be printed instead.
provided, the symbol associated with it will be printed instead. If sort=true,
symbols will be sorted by syscall number and then address.
)");