diff --git a/include/fxos/symbols.h b/include/fxos/symbols.h index 6c38da3..756f7d6 100644 --- a/include/fxos/symbols.h +++ b/include/fxos/symbols.h @@ -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 */ diff --git a/shell/i.cpp b/shell/i.cpp index b6ac39d..2bda554 100644 --- a/shell/i.cpp +++ b/shell/i.cpp @@ -249,6 +249,7 @@ struct _is_args { std::string vspace_name; std::optional 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 symbol) + std::optional 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=] [] +is [sort=true] [vspace=] [] 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. )");