Added <print-disassembly> tool to dtools
This commit is contained in:
parent
5d47b73298
commit
119da0bb1e
4 changed files with 101 additions and 6 deletions
|
|
@ -94,6 +94,8 @@ list(APPEND TOOLS_SOURCE_FILES
|
|||
${CMAKE_CURRENT_LIST_DIR}/src/tools/Tools.cpp
|
||||
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/hardware/VirtualHardDrive.cpp
|
||||
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/debugger/DisassemblyLoader.cpp
|
||||
)
|
||||
#-----------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
1638
|
||||
1639
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
#include "Tools.hpp"
|
||||
|
||||
#include <ostd/Color.hpp>
|
||||
#include <ostd/IOHandlers.hpp>
|
||||
#include <ostd/Utils.hpp>
|
||||
#include <fstream>
|
||||
#include "../hardware/VirtualHardDrive.hpp"
|
||||
#include "GlobalData.hpp"
|
||||
#include "debugger/DisassemblyLoader.hpp"
|
||||
#include <ostd/Serial.hpp>
|
||||
|
||||
namespace dragon
|
||||
|
|
@ -51,6 +54,12 @@ namespace dragon
|
|||
if (rValue != ErrorNoError)
|
||||
return rValue;
|
||||
}
|
||||
else if (tool == "print-disassembly")
|
||||
{
|
||||
rValue = tool_print_disassembly(argc, argv);
|
||||
if (rValue != ErrorNoError)
|
||||
return rValue;
|
||||
}
|
||||
else if (tool == "--help")
|
||||
{
|
||||
print_application_help();
|
||||
|
|
@ -442,6 +451,79 @@ namespace dragon
|
|||
return ErrorNoError;
|
||||
}
|
||||
|
||||
int32_t Tools::tool_print_disassembly(int argc, char** argv)
|
||||
{
|
||||
using TableList = std::vector<code::Assembler::tDisassemblyLine>;
|
||||
if (argc < 3)
|
||||
{
|
||||
out.fg(ostd::ConsoleColors::Red).p("Error: too few arguments.").nl();
|
||||
out.fg(ostd::ConsoleColors::Red).p(" Usage: ./dtools print-disassembly <disassembly_file>").reset().nl();
|
||||
return ErrorPrintDisassemblyTooFewArgs;
|
||||
}
|
||||
ostd::String arg1 = argv[2];
|
||||
arg1.trim();
|
||||
TableList codeTable;
|
||||
TableList labelTable;
|
||||
TableList dataTable;
|
||||
if (arg1 == "-d")
|
||||
{
|
||||
if (argc < 4)
|
||||
{
|
||||
out.fg(ostd::ConsoleColors::Red).p("Error: too few arguments.").nl();
|
||||
out.fg(ostd::ConsoleColors::Red).p(" Usage: ./dtools print-disassembly -d <disassembly_directory>").reset().nl();
|
||||
return ErrorPrintDisassemblyTooFewArgs;
|
||||
}
|
||||
dragon::DisassemblyLoader::loadDirectory(argv[3]);
|
||||
codeTable = dragon::DisassemblyLoader::getCodeTable();
|
||||
labelTable = dragon::DisassemblyLoader::getLabelTable();
|
||||
dataTable = dragon::DisassemblyLoader::getDataTable();
|
||||
}
|
||||
else if (arg1 == "-f")
|
||||
{
|
||||
const auto& table = dragon::DisassemblyLoader::loadFile(argv[3]);
|
||||
if (!table.isInitialized())
|
||||
{
|
||||
out.fg(ostd::ConsoleColors::Red).p("Error: Invalid disassembly file.").reset().nl();
|
||||
return ErrorPrintDisassemblyInvalidFile;
|
||||
}
|
||||
codeTable = table.getCodeTable();
|
||||
labelTable = table.getLabelTable();
|
||||
dataTable = table.getDataTable();
|
||||
}
|
||||
else
|
||||
{
|
||||
out.fg(ostd::ConsoleColors::Red).p("Error: invalid argument.").nl();
|
||||
out.fg(ostd::ConsoleColors::Red).p(" Usage: ./dtools print-disassembly -d <disassembly_directory>").reset().nl();
|
||||
return ErrorPrintDisassemblyInvalidArg;
|
||||
}
|
||||
out.bg(ostd::ConsoleColors::White).fg(ostd::ConsoleColors::Black).p("DATA:").reset().nl();
|
||||
for (const auto& line : dataTable)
|
||||
{
|
||||
out.fg(ostd::ConsoleColors::BrightGray).p(ostd::Utils::getHexStr(line.addr, true, 2)).p("\t\t");
|
||||
out.fg(ostd::ConsoleColors::Green).p(line.code).p("\t\t");
|
||||
out.fg(ostd::ConsoleColors::Blue).p(line.size).p(" bytes\t\t");
|
||||
out.reset().nl();
|
||||
}
|
||||
out.nl();
|
||||
out.bg(ostd::ConsoleColors::White).fg(ostd::ConsoleColors::Black).p("LABELS:").reset().nl();
|
||||
for (const auto& line : labelTable)
|
||||
{
|
||||
out.fg(ostd::ConsoleColors::BrightGray).p(ostd::Utils::getHexStr(line.addr, true, 2)).p("\t\t");
|
||||
out.fg(ostd::ConsoleColors::Green).p(line.code).p("\t\t");
|
||||
out.reset().nl();
|
||||
}
|
||||
out.nl();
|
||||
out.bg(ostd::ConsoleColors::White).fg(ostd::ConsoleColors::Black).p("CODE:").reset().nl();
|
||||
for (const auto& line : codeTable)
|
||||
{
|
||||
out.fg(ostd::ConsoleColors::BrightGray).p(ostd::Utils::getHexStr(line.addr, true, 2)).p("\t\t");
|
||||
out.fg(ostd::ConsoleColors::Green).p(line.code).p("\t\t");
|
||||
out.reset().nl();
|
||||
}
|
||||
out.nl();
|
||||
return ErrorNoError;
|
||||
}
|
||||
|
||||
void Tools::print_application_help(void)
|
||||
{
|
||||
out.nl().fg(ostd::ConsoleColors::Yellow).p("List of available tools:").nl().nl();
|
||||
|
|
@ -469,6 +551,13 @@ namespace dragon
|
|||
out.p(" -l (optional) Used to specify the partition's label.").nl();
|
||||
out.p(" -f (optional) Used to specify one single flag for the partition. Use multiple -f parameters for multiple flags.").nl().nl();
|
||||
|
||||
out.fg(ostd::ConsoleColors::Blue).p("print-disassembly [-d <disassembly_directory>] | [-f <disassembly_file>]").nl();
|
||||
out.fg(ostd::ConsoleColors::Green).p("The <print-disassembly> tool is used to parse and print disassembly tables.").nl();
|
||||
out.p(" <disassembly_directory> Path to the directory containing the disassembly files to parse. (Used only for -d option)").nl();
|
||||
out.p(" <disassembly_file> Path to the disassembly file to parse. (Used only for -f option)").nl();
|
||||
out.p(" -d Used to specify a directory path (mutually exclusive with -f).").nl();
|
||||
out.p(" -f Used to specify a file path (mutually exclusive with -d).").nl().nl();
|
||||
|
||||
out.fg(ostd::ConsoleColors::Magenta).p("Usage: ./dtools <tool_name> [...arguments...]").nl().nl().reset();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ namespace dragon
|
|||
static int32_t tool_load_binary(int argc, char** argv);
|
||||
static int32_t tool_read_dpt(int argc, char** argv);
|
||||
static int32_t tool_new_dpt(int argc, char** argv);
|
||||
static int32_t tool_print_disassembly(int argc, char** argv);
|
||||
static void print_application_help(void);
|
||||
static int32_t get_tool(int argc, char** argv, ostd::String& outTool);
|
||||
|
||||
|
|
@ -51,6 +52,9 @@ namespace dragon
|
|||
inline static constexpr int32_t ErrorNewDPTDiskOverflow = 19;
|
||||
inline static constexpr int32_t ErrorNewDPTUnknownFlag = 20;
|
||||
inline static constexpr int32_t ErrorNewDPTTooManyPartitions = 21;
|
||||
inline static constexpr int32_t ErrorPrintDisassemblyTooFewArgs = 22;
|
||||
inline static constexpr int32_t ErrorPrintDisassemblyInvalidFile = 23;
|
||||
inline static constexpr int32_t ErrorPrintDisassemblyInvalidArg = 24;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue