Mode déboguage depuis des arguments de la ligne de commande

This commit is contained in:
Horde Nicolas 2021-07-16 19:42:49 +02:00
parent 9cb767d1ec
commit 0b3d5eef47
3 changed files with 49 additions and 28 deletions

View File

@ -4,7 +4,7 @@ OPTIONS=-std=c++17
DOCKER=docker run --name maker --rm -v $$(pwd):/data maker
START=./start.sh
all: dockerfile files run
all: dockerfile run
clean: dockerclean
@ -21,7 +21,7 @@ dockerfile:
dockerfile_force: dockerclean dockerfile
files: ./ia86
compile: ./ia86
ia86: ./ia86.cpp
$(DOCKER) $(CC) $(OPTIONS) -o $@ $^ $(LFLAGS)
@ -29,7 +29,12 @@ ia86: ./ia86.cpp
rerun:
$(START)
run: clear delete files rerun
redebug:
$(START) debug
run: clear delete compile rerun
debug: clear delete compile redebug
stop:
docker stop maker

View File

@ -67,7 +67,7 @@ Scenario scenario;
Level level;
Unasm unasm;
int marker;
bool debug=true;
bool debugnow;
uc_hook uh_mem;
uc_hook uh_code;
uc_hook uh_call;
@ -323,6 +323,7 @@ Desassembler::Desassembler(Menu *widget) : widget(widget)
err = cs_open(CS_ARCH_X86, CS_MODE_16, &handle);
if (err != CS_ERR_OK)
throw Error("Désassembleur - initialisation....................[ERREUR]");
if (debugnow)
widget->tolog("Désassembleur - initialisation....................[ OK ]");
}
catch(exception const& e)
@ -346,7 +347,7 @@ void Desassembler::Desassemble(uint8_t *content, uint32_t address,uint32_t size,
throw Error("Désassembleur - désassemblage.....................[ERREUR]");
else
{
if (debug) widget->tolog("Désassemblage - désassemblage.....................[ "+to_string(srcsize)+"l ]");
if (debugnow) widget->tolog("Désassemblage - désassemblage.....................[ "+to_string(srcsize)+"l ]");
unasm->src.clear();
unasm->pos.clear();
for (size_t j = 0; j < srcsize; j++)
@ -384,6 +385,7 @@ Assembler::Assembler(Menu *widget) : widget(widget)
err = ks_open(KS_ARCH_X86, KS_MODE_16, &ks);
if (err != KS_ERR_OK)
throw Error("Assembleur - initialisation.......................[ERREUR]");
if (debugnow)
widget->tolog("Assembleur - initialisation.......................[ OK ]");
}
catch(exception const& e)
@ -675,6 +677,7 @@ void VMEngine::Init()
err = uc_open(UC_ARCH_X86, UC_MODE_16, &uc);
if (err != UC_ERR_OK)
throw Error("VM IA86 - initilisation...........................[ERREUR]");
if (debugnow)
widget->tolog("VM IA86 - initilisation...........................[ OK ]");
}
catch(exception const& e)
@ -959,7 +962,7 @@ void VMEngine::Configure(State *init, std::string code)
SetMem(&mcode[i]);
else
throw Error("VM IA86 - code non assemblé...................[ERREUR]");
if (debug) widget->tolog("Section N°"+std::to_string(i)+" : "+intToHexString(mcode[i].address,8)+" -> "+to_string(mcode[i].size)+" octets");
if (debugnow) widget->tolog("Section N°"+std::to_string(i)+" : "+intToHexString(mcode[i].address,8)+" -> "+to_string(mcode[i].size)+" octets");
}
status=verify();
if (status==0)
@ -1184,6 +1187,7 @@ void VMEngine::SetRegs(State *init)
out << " AX=" << std::uppercase << std::setfill('0') << std::setw(4) << std::hex << init->dump.regs.ax << " ";
else
out << "EAX=" << std::uppercase << std::setfill('0') << std::setw(8) << std::hex << init->dump.regs.eax << " ";
if (debugnow)
widget->tolog(out.str());
}
@ -1233,6 +1237,8 @@ Menu::Menu (finalcut::FWidget* parent)
initMenusCallBack();
loadScenario("./scenarios.json");
addTimer(50);
if (debugnow)
tolog("DEBOGUAGE ACTIVE !");
}
void Menu::initWindows()
@ -1557,6 +1563,7 @@ void Menu::loadScenario(std::string file)
{
scenar.Load(scenario.levels);
scenario.loaded=true;
if (debugnow)
tolog("Application - charge scénarios....................[ OK ]");
tolog("-={ "+ scenario.title+" }=-");
loadLevel(0);
@ -1571,8 +1578,11 @@ void Menu::loadScenario(std::string file)
void Menu::loadLevel(int alevel)
{
if (scenario.levels[alevel].title!=level.title)
{
vm.Unconfigure();
level=scenario.levels[alevel];
if (debugnow)
tolog("Application - charge niveau.......................[ INFO ]");
view.setText("Objectif: "+level.title);
view.clear();
@ -1584,6 +1594,7 @@ void Menu::loadLevel(int alevel)
vm.setRights(level.rights);
AdjustWindows();
showInstr();
}
}
void Menu::end()
@ -1738,6 +1749,7 @@ void Menu::addbp()
if (vm.isInitialized())
{
std::string address=debug.getaddress();
if (debugnow)
tolog("VM IA86 - ajout breakpoint.....................["+address+"]");
vm.addbreakpoint(vm.getCS(),stoi(address,nullptr,16));
showInstr();
@ -1750,6 +1762,10 @@ void Menu::addbp()
int main (int argc, char* argv[])
{
mapping();
std::vector<std::string> args(argv, argv+argc);
for (size_t i = 1; i < args.size(); ++i) {
debugnow=(args[i] == "debug");
}
finalcut::FApplication app {argc, argv};
Menu main_dlg {&app};
finalcut::FWidget::setMainWidget (&main_dlg);

View File

@ -5,7 +5,7 @@ KITTY=$(kitty -v|grep created)
if [ "${KITTY}" != "" ]; then
echo "Kitty installé"
if [ ${X} -ge 1920 ]; then
kitty --start-as fullscreen ./ia86
kitty --start-as fullscreen ./ia86 $1
exit
fi
fi
@ -22,4 +22,4 @@ elif [ ${X} -ge 1280 ]; then
else
SIZE=6
fi
xterm -fullscreen -fa monaco -fs ${SIZE} -bg black -fg green -e ./ia86
xterm -fullscreen -fa monaco -fs ${SIZE} -bg black -fg green -e "sleep 0.4;./ia86 $1"