Add vspace and syscall/address option to 'is' command #7

Merged
Lephenixnoir merged 3 commits from Dr-Carlos/fxos:master into master 2022-12-04 11:37:49 +01:00
2 changed files with 107 additions and 8 deletions

View File

@ -23,6 +23,7 @@
#include <memory>
#include <variant>
#include <algorithm>
#include <vector>
namespace FxOS {

View File

@ -246,17 +246,113 @@ void _isc(Session &session, std::string vspace_name, bool sort,
// is
//---
static void parse_is(Session &, Parser &parser)
struct _is_args
{
std::string vspace_name;
std::optional<FxOS::Symbol> symbol;
};
static struct _is_args parse_is(Session &session, Parser &parser)
{
_is_args args;
parser.option("vspace",
[&args](std::string const &value) { args.vspace_name = value; });
parser.accept_options();
FxOS::Symbol s;
if(!parser.at_end()) {
if(parser.lookahead().type == T::SYSCALL) {
s.type = FxOS::Symbol::Syscall;
s.value = parser.expect(T::SYSCALL).value.NUM;
}
else {
s.type = FxOS::Symbol::Address;
s.value = parser.expr(session.current_space);
}
args.symbol = s;
}
else {
args.symbol = {};
}
VirtualSpace *space = session.current_space;
if(!args.vspace_name.empty()) {
space = session.get_space(args.vspace_name);
if(!space) {
std::string msg
= format("virtual space '%s' does not exist", args.vspace_name);
if(parser.completing())
throw Parser::CompletionRequest("_error", msg);
else
FxOS_log(ERR, "%s", msg);
}
}
parser.end();
return args;
}
void _is(Session &session)
void _is(Session &session, std::string vspace_name,
std::optional<FxOS::Symbol> symbol)
{
if(!session.current_space)
VirtualSpace *space = session.current_space;
if(!space) {
FxOS_log(ERR, "no virtual space selected");
return;
}
for(auto const &s: session.current_space->symbols.symbols) {
if(!vspace_name.empty())
space = session.get_space(vspace_name);
if(!space) {
FxOS_log(ERR, "virtual space '%s' does not exist", vspace_name);
return;
}
std::vector<FxOS::Symbol> symbols;
if(!symbol.has_value())
symbols = space->symbols.symbols;
else {
FxOS::Symbol s = symbol.value();
std::optional<std::string> name = space->symbols.query(s.type, s.value);
if(name.has_value())
s.name = name.value();
else if(s.type == FxOS::Symbol::Address) {
if(vspace_name.empty())
FxOS_log(ERR,
"no symbol exists for address 0x%08x in current virtual space",
s.value);
else
FxOS_log(ERR,
"no symbol exists for syscall 0x%08x in virtual space '%s'",
s.value, vspace_name);
return;
}
else if(s.type == FxOS::Symbol::Syscall) {
if(vspace_name.empty())
FxOS_log(ERR,
"no symbol exists for syscall %%%04x in current virtual space",
s.value);
else
FxOS_log(ERR,
"no symbol exists for syscall %%%04x in virtual space '%s'",
s.value, vspace_name);
return;
Dr-Carlos marked this conversation as resolved
Review

You don't need to distinguish formats here. This is because printf will never ever lie to you; if you ask for %03x but the value has 4 digits it will still display all 4. So in general for syscalls we just do %03x and leave it.

I haven't disassembled enough fx-CG code to be annoyed at alignment issues due to syscalls above 0x1000, but if you do feel free to use %04x or %4.3x everywhere.

You don't need to distinguish formats here. This is because printf will never ever lie to you; if you ask for `%03x` but the value has 4 digits it will still display all 4. So in general for syscalls we just do `%03x` and leave it. I haven't disassembled enough fx-CG code to be annoyed at alignment issues due to syscalls above 0x1000, but if you do feel free to use `%04x` or `%4.3x` everywhere.
Review

I did not realise that, thanks (again just copied the fmt::print use). I wasn't bothered by the %03x/%04x until writing a script that uses this new functionality, where it started bothering me.

I have used %04x and will probably make a PR to use %04x everywhere, or maybe make it an option - what do you think?

I did not realise that, thanks (again just copied the fmt::print use). I wasn't bothered by the %03x/%04x until writing a script that uses this new functionality, where it started bothering me. I have used %04x and will probably make a PR to use %04x everywhere, or maybe make it an option - what do you think?
Review

Feel free to make it %04x everywhere. Consistency is simple, and no one really minds an extra 0.

Feel free to make it `%04x` everywhere. Consistency is simple, and no one really minds an extra 0.
}
symbols = {s};
}
for(auto const &s: symbols) {
if(s.type == FxOS::Symbol::Syscall && s.value < 0x1000) {
fmt::print(theme(10), " %{:03x}", s.value);
}
@ -311,11 +407,13 @@ sort=true is specified, they are instead sorted by address.
static ShellCommand _is_cmd(
"is",
[](Session &s, Parser &p) {
parse_is(s, p);
_is(s);
auto args = parse_is(s, p);
_is(s, args.vspace_name, args.symbol);
},
[](Session &s, Parser &p) { parse_is(s, p); }, "Info Symbols", R"(
is
is [vspace=<virtual_space>] [<address|syscall>]
Lists all symbols in the current virtual space.
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.
)");