DebugCommand* ExamineCommand::Build(std::vector<Token*> args) { if (args.size() < 2) { return new InvalidCommand(args, -1, "too few arguments"); } Token* target = args[1]; if (!target->CanAddressMemory()) { return new InvalidCommand(args, 1, "expects address"); } FormatToken* format = NULL; IntegerToken* count = NULL; switch (args.size()) { case 2: { // mem addr[.x64] [10] format = new Format<uint64_t>("%016" PRIx64, 'x'); count = new IntegerToken(10); break; } case 3: { // mem addr.format [10] // mem addr[.x64] n Token* second = args[2]; if (second->IsFormat()) { format = FormatToken::Cast(second); count = new IntegerToken(10); break; } else if (second->IsInteger()) { format = new Format<uint64_t>("%016" PRIx64, 'x'); count = IntegerToken::Cast(second); } else { return new InvalidCommand(args, 2, "expects format or integer"); } VIXL_UNREACHABLE(); break; } case 4: { // mem addr.format n Token* second = args[2]; Token* third = args[3]; if (!second->IsFormat() || !third->IsInteger()) { return new InvalidCommand(args, -1, "expects addr[.format] [n]"); } format = FormatToken::Cast(second); count = IntegerToken::Cast(third); break; } default: return new InvalidCommand(args, -1, "too many arguments"); } return new ExamineCommand(args[0], target, format, count); }
DebugCommand* StepCommand::Build(std::vector<Token*> args) { IntegerToken* count = NULL; switch (args.size()) { case 1: { // step [1] count = new IntegerToken(1); break; } case 2: { // step n Token* first = args[1]; if (!first->IsInteger()) { return new InvalidCommand(args, 1, "expects int"); } count = IntegerToken::Cast(first); break; } default: return new InvalidCommand(args, -1, "too many arguments"); } return new StepCommand(args[0], count); }
DebugCommand* DisasmCommand::Build(std::vector<Token*> args) { IntegerToken* count = NULL; switch (args.size()) { case 1: { // disasm [10] count = new IntegerToken(10); break; } case 2: { // disasm n Token* first = args[1]; if (!first->IsInteger()) { return new InvalidCommand(args, 1, "expects int"); } count = IntegerToken::Cast(first); break; } default: return new InvalidCommand(args, -1, "too many arguments"); } Token* target = new IdentifierToken("pc"); FormatToken* format = new Format<uint32_t>("%08" PRIx32, 'i'); return new ExamineCommand(args[0], target, format, count); }