Compare commits

...

2 Commits

Author SHA1 Message Date
Dr-Carlos b494a30404 _is: add sort option 2022-12-23 07:11:16 +11:00
Dr-Carlos f16ecc370c _e: print large demical representations correctly 2022-12-22 09:58:52 +11:00
3 changed files with 22 additions and 8 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

@ -49,14 +49,15 @@ static _e_args parse_e(Session &session, Parser &parser)
void _e(Session &, std::string, std::vector<long> const &values)
{
for(long value: values) {
long print_val = labs(value);
/* Hexa format */
int length = (labs(value) <= (1ll << 32) ? 8 : 16) + 2 + (value < 0);
int length = (print_val <= (1ll << 32) ? 8 : 16) + 2 + (value < 0);
std::string format = fmt::format("{{:#0{}x}}", length);
fmt::print(format, value);
long a = abs(value);
if(a <= 100 || a % 100 <= 1 || a % 100 >= 99)
fmt::print(" = {}", a);
if(print_val <= 100 || print_val % 100 <= 1 || print_val % 100 >= 99)
fmt::print(" = {}", print_val);
fmt::print("\n");
}

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.
)");