_d: use expr_or_range to allow addresses or ranges
This commit is contained in:
parent
2f2e4bb1d5
commit
c66ae1d5c6
43
shell/d.cpp
43
shell/d.cpp
|
@ -77,25 +77,25 @@ struct _d_args
|
|||
|
||||
static _d_args parse_d(Session &session, Parser &parser)
|
||||
{
|
||||
_d_args args;
|
||||
|
||||
if(!session.current_space)
|
||||
return {};
|
||||
|
||||
uint32_t address = session.current_space->cursor;
|
||||
args.address = session.current_space->cursor;
|
||||
args.range = {};
|
||||
|
||||
if(!parser.at_end()) {
|
||||
auto v = parser.expr_or_range(session.current_space);
|
||||
|
||||
if(std::holds_alternative<long>(v)) {
|
||||
address = std::get<long>(v);
|
||||
}
|
||||
else {
|
||||
// TODO: Use an args struct etc. This is placeholder.
|
||||
address = std::get<Range>(v).start;
|
||||
}
|
||||
if(std::holds_alternative<long>(v))
|
||||
args.address = std::get<long>(v);
|
||||
else
|
||||
args.range = std::get<Range>(v);
|
||||
}
|
||||
|
||||
parser.end();
|
||||
return {address, {}};
|
||||
return args;
|
||||
}
|
||||
|
||||
void _d(Session &session, std::optional<uint32_t> address_opt,
|
||||
|
@ -105,19 +105,8 @@ void _d(Session &session, std::optional<uint32_t> address_opt,
|
|||
return;
|
||||
FxOS::Disassembly disasm(*session.current_space);
|
||||
|
||||
if(address_opt.has_value()) {
|
||||
uint32_t address = address_opt.value();
|
||||
|
||||
if(address & 1) {
|
||||
fmt::print("address 0x{:08x} is odd, starting at 0x{:08x}\n",
|
||||
address, address + 1);
|
||||
address++;
|
||||
}
|
||||
|
||||
disassemble(session, disasm,
|
||||
{"cfg", "pcrel", /*"constprop",*/ "syscall", "print"}, address);
|
||||
}
|
||||
else if(range_opt.has_value()) {
|
||||
if(range_opt.has_value()) {
|
||||
Range range = range_opt.value();
|
||||
if(range.start & 1) {
|
||||
fmt::print("address 0x{:08x} is odd, starting at 0x{:08x}\n",
|
||||
|
@ -140,6 +129,18 @@ void _d(Session &session, std::optional<uint32_t> address_opt,
|
|||
disassemble(session, disasm,
|
||||
{"pcrel", /*"constprop",*/ "syscall", "print"}, -1);
|
||||
}
|
||||
else if(address_opt.has_value()) {
|
||||
uint32_t address = address_opt.value();
|
||||
|
||||
if(address & 1) {
|
||||
fmt::print("address 0x{:08x} is odd, starting at 0x{:08x}\n",
|
||||
address, address + 1);
|
||||
address++;
|
||||
}
|
||||
|
||||
disassemble(session, disasm,
|
||||
{"cfg", "pcrel", /*"constprop",*/ "syscall", "print"}, address);
|
||||
}
|
||||
}
|
||||
|
||||
//---
|
||||
|
|
|
@ -306,14 +306,9 @@ void Parser::accept_options()
|
|||
// Parsing rules for expressions
|
||||
//---
|
||||
|
||||
long Parser::atom(std::optional<Token> token)
|
||||
long Parser::atom()
|
||||
{
|
||||
Token t;
|
||||
|
||||
if(token.has_value())
|
||||
t = token.value();
|
||||
else
|
||||
t = expect({'$', '(', '-', T::SYMBOL, T::NUM, T::SYSCALL});
|
||||
Token t = expect({'$', '(', '-', T::SYMBOL, T::NUM, T::SYSCALL});
|
||||
|
||||
if(t.type == T::SYMBOL) {
|
||||
/* TODO: Specify the space that symbols are taken from */
|
||||
|
@ -397,10 +392,10 @@ long Parser::term()
|
|||
return v;
|
||||
}
|
||||
|
||||
long Parser::expr(VirtualSpace *space, std::optional<Token> token)
|
||||
long Parser::expr(VirtualSpace *space)
|
||||
{
|
||||
m_expr_space = space;
|
||||
long val = atom(token);
|
||||
long val = atom();
|
||||
m_expr_space = nullptr;
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ public:
|
|||
/* Read a numerical constant, or an expression. Expression uses the space
|
||||
to access the program counter and query symbol values */
|
||||
long num();
|
||||
long expr(VirtualSpace *space, std::optional<Token> token={});
|
||||
long expr(VirtualSpace *space);
|
||||
/* Read a range; again $ and symbols are interpreted. If (before) and
|
||||
(after) are both specified, a single value will also be accepted, and
|
||||
the range [value-before, value+after) will be returned. */
|
||||
|
@ -194,7 +194,7 @@ private:
|
|||
/* Parsing rules for expressions */
|
||||
long term();
|
||||
long factor();
|
||||
long atom(std::optional<Token> token={});
|
||||
long atom();
|
||||
|
||||
/* true if we're completing a partial command, false if we're parsing a
|
||||
finished one */
|
||||
|
|
Loading…
Reference in New Issue