From 751f9ea3a601eff7707e2cc35ada8f58d712f384 Mon Sep 17 00:00:00 2001 From: Horde Nicolas Date: Wed, 14 Jul 2021 01:15:38 +0200 Subject: [PATCH] =?UTF-8?q?Segfault=20stabilis=C3=A9,=20ajout=20de=20break?= =?UTF-8?q?points?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ia86.cpp | 86 ++++++++++++++++++++++++++++++++++++++++---------------- ia86.h | 22 ++++++++++----- 2 files changed, 77 insertions(+), 31 deletions(-) diff --git a/ia86.cpp b/ia86.cpp index 0694fc6..e1d30eb 100644 --- a/ia86.cpp +++ b/ia86.cpp @@ -158,11 +158,26 @@ void InstructionWindow::clear() listview.redraw(); } +string InstructionWindow::getaddress() +{ + return listview.getCurrentItem()->getText(0).c_str(); +} + void InstructionWindow::setmark(int index) { listview.setmark(index); } +int InstructionWindow::getindex() +{ + return listview.getindex(); +} + +void InstructionWindow::setmultimark(std::vector mark) +{ + listview.setmultimark(mark); +} + int InstructionWindow::getsize() { return listview.getCount(); @@ -643,6 +658,7 @@ void VMEngine::Halt() void VMEngine::Unconfigure() { + this->clearbreakpoints(); this->Halt(); if (initialized) widget->tolog("VM IA86 - déconfiguration.........................[ INFO ]"); @@ -735,17 +751,17 @@ void VMEngine::clearbreakpoints() breakpoints.clear(); } -void VMEngine::addbreakpoint(int address) +void VMEngine::addbreakpoint(std::string address) { - for(int item: breakpoints) + for(std::string item: breakpoints) if (item==address) return; breakpoints.push_back(address); } -void VMEngine::removebreakpoint(int address) +void VMEngine::removebreakpoint(std::string address) { int i=0; - for(int item: breakpoints) + for(std::string item: breakpoints) if (item==address) { breakpoints.erase(breakpoints.begin()+i); @@ -756,8 +772,21 @@ void VMEngine::removebreakpoint(int address) std::vector VMEngine::getBreapoints() { std::vector list; - for(int item: breakpoints) - widget->tolog(to_string(item)); + std::vector> items=((Menu*)widget)->getsrc(); + for(std::string bpaddress: breakpoints) + { + int line=0; + for(std::array item: items) + { + if (item[0]==bpaddress) + { + ((Menu*)widget)->tolog(to_string(line)); + list.push_back(line++); + break; + } + + } + } return list; } @@ -1124,7 +1153,7 @@ void Menu::initWindows() void Menu::AdjustWindows() { - this->setGeometry ( FPoint { 63, 45 }, FSize{60, 11} ); + //this->setGeometry ( FPoint { 63, 45 }, FSize{60, 11} ); edit.setGeometry ( FPoint { 01, 17 }, FSize{39, 27} ); view.setGeometry ( FPoint { 01, 45 }, FSize{60, 11} ); regs.setGeometry ( FPoint { 01, 01 }, FSize{40, 15} ); @@ -1136,7 +1165,7 @@ void Menu::AdjustWindows() debug.setGeometry ( FPoint { 42, 17 }, FSize{60, 27} ); scenar.setGeometry ( FPoint { 187, 01 }, FSize{25, 55} ); info.setGeometry (FPoint { 55, 25 }, FSize{50, 14}); - this->show(); + //this->show(); info.hide(); flags.hide(); stack.hide(); @@ -1159,11 +1188,11 @@ void Menu::AdjustWindows() mem.show(); if (level.rights > 6) screen.show(); - Options.setEnable(); + /*Options.setEnable(); Tools.setEnable(); Window.setEnable(); Debug.setEnable(); - Breakpoint.setEnable(); + Breakpoint.setEnable();*/ } else { @@ -1173,11 +1202,11 @@ void Menu::AdjustWindows() tuto.hide(); debug.hide(); scenar.hide(); - Options.setDisable(); + /*Options.setDisable(); Tools.setDisable(); Window.setDisable(); Debug.setDisable(); - Breakpoint.setDisable(); + Breakpoint.setDisable();*/ } } @@ -1281,11 +1310,11 @@ void Menu::initMenusCallBack() this, &Menu::end ); - About.addCallback + AddBp.addCallback ( "clicked", this, - &Menu::about + &Menu::addbreakpoint ); } @@ -1308,16 +1337,15 @@ Episode 1 : Apprendre l'assembleur X86"); void Menu::initLayout() { - Log.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); + this->setGeometry ( FPoint { 63, 45 }, FSize{60, 11}, false); + this->setTopPadding(1); + this->setLeftPadding(0); + this->setRightPadding(0); + this->setBottomPadding(0); + Log.setGeometry (FPoint{0, 0}, FSize{getWidth(), getHeight()},false); FDialog::initLayout(); } -void Menu::adjustSize() -{ - finalcut::FDialog::adjustSize(); - Log.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1)); -} - void Menu::onClose (finalcut::FCloseEvent* ev) { finalcut::FApplication::closeConfirmationDialog (this, ev); @@ -1386,6 +1414,7 @@ void Menu::compile() void Menu::tolog(std::string str) { this->Log.append(str); + this->Log.scrollBy (0, 10); } void Menu::about() @@ -1408,6 +1437,11 @@ void Menu::about() AdjustWindows(); } +std::vector> Menu::getsrc() +{ + return debug.get(); +} + void Menu::showInstr() { try @@ -1416,6 +1450,7 @@ void Menu::showInstr() { debug.set(vm.getInstr(vm.getCS(),vm.getEIP(),debug.getHeight()-3)); debug.setmark(vm.getLine()); + debug.setmultimark(vm.getBreapoints()); mem.set(vm.getRam(vm.getDS(), 0x0000, mem.getHeight(),mem.getWidth())); } } @@ -1487,6 +1522,12 @@ void Menu::step() showInstr(); } +void Menu::addbreakpoint() +{ + vm.addbreakpoint(debug.getaddress()); + showInstr(); +} + //---------------------------------------------------------------------- // Fonction Main //---------------------------------------------------------------------- @@ -1495,9 +1536,6 @@ int main (int argc, char* argv[]) mapping(); finalcut::FApplication app {argc, argv}; Menu main_dlg {&app}; - /*main_dlg.setText ("Journaux"); - main_dlg.setGeometry ( FPoint { 63, 45 }, FSize{60, 11} ); - main_dlg.show();*/ finalcut::FWidget::setMainWidget (&main_dlg); return app.exec(); } diff --git a/ia86.h b/ia86.h index 41fb9d8..fa7ca30 100644 --- a/ia86.h +++ b/ia86.h @@ -201,8 +201,11 @@ class InstructionWindow final : public finalcut::FDialog std::vector> get(); void set(std::vector> src); void clear(); + int getindex(); + void setmultimark(std::vector mark); void setmark(int index); int getsize(); + string getaddress(); private: // Method std::vector> content; @@ -315,8 +318,8 @@ class VMEngine bool isInitialized(); void setRights(int rights); void clearbreakpoints(); - void addbreakpoint(int address); - void removebreakpoint(int address); + void addbreakpoint(std::string address); + void removebreakpoint(std::string address); std::vector getBreapoints(); int getLine(); uint32_t getEIP(); @@ -325,7 +328,7 @@ class VMEngine uint16_t getES(); uint16_t getSS(); private: - std::vector breakpoints; + std::vector breakpoints; int rights; void Init(); void Close(); @@ -356,6 +359,7 @@ class Menu final : public finalcut::FDialog void loadLevel(int alevel); void closeLevel(); void tolog(std::string str); + std::vector> getsrc(); void SetScreen(uint16_t x, uint16_t y, char value); private: void onTimer (finalcut::FTimerEvent*) override; @@ -368,6 +372,7 @@ class Menu final : public finalcut::FDialog void end(); void loadScenario(std::string file); void showInstr(); + void addbreakpoint(); void exec(); void trace(); void step(); @@ -376,13 +381,12 @@ class Menu final : public finalcut::FDialog void AdjustWindows(); void initWindows(); void initLayout() override; - void adjustSize() override; // Event handler void onClose (finalcut::FCloseEvent*) override; // Callback method void cb_message (const finalcut::FMenuItem*); // Data members - finalcut::FString line{13, finalcut::UniChar::BoxDrawingsHorizontal}; + //finalcut::FString line{13, finalcut::UniChar::BoxDrawingsHorizontal}; finalcut::FMenuBar Menubar{this}; finalcut::FMenu Game{"&Partie", &Menubar}; finalcut::FMenuItem New{"&Nouvelle partie", &Game}; @@ -394,8 +398,13 @@ class Menu final : public finalcut::FDialog finalcut::FRadioMenuItem Es_edi{"ES:EDI", &Memory}; finalcut::FRadioMenuItem Cs_eip{"CS:EIP", &Memory}; finalcut::FRadioMenuItem Ss_sp{"SS:SP", &Memory}; + finalcut::FRadioMenuItem Value{"Valeur...", &Memory}; + finalcut::FMenu Code{"&Code", &Options}; + finalcut::FRadioMenuItem Cs_eip2{"CS:EIP", &Code}; + finalcut::FRadioMenuItem Value2{"Valeur...", &Code}; + finalcut::FRadioMenuItem Att{"Syntaxe AT&T", &Code}; finalcut::FMenu Tools{"&Outils", &Menubar}; - finalcut::FMenuItem Assemble{"&Compilation", &Tools}; + finalcut::FMenuItem Assemble{"&Assembler", &Tools}; finalcut::FMenuItem Rearange{"&Ordonne les fenêtres", &Tools}; finalcut::FMenu Debug{"&Déboguage", &Menubar}; finalcut::FMenuItem Run{"&Exécuter", &Debug}; @@ -404,7 +413,6 @@ class Menu final : public finalcut::FDialog finalcut::FMenuItem StepOver{"&Pas à pas", &Debug}; finalcut::FMenu Breakpoint{"&Point d'arrêt", &Menubar}; finalcut::FMenuItem AddBp{"&Ajouter", &Breakpoint}; - finalcut::FMenuItem DelBp{"&Supprimer", &Breakpoint}; finalcut::FMenuItem ClearBp{"&Tout supprimer", &Breakpoint}; finalcut::FDialogListMenu Window{"&Fenêtres", &Menubar}; finalcut::FMenu Help{"&Aide", &Menubar};