Make the debugger a global object.

This commit is contained in:
Maxim Poliakovski 2024-11-30 12:04:23 +01:00
parent 04899d6528
commit f1e56cd353
3 changed files with 27 additions and 6 deletions

View File

@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cpu/ppc/ppcdisasm.h> #include <cpu/ppc/ppcdisasm.h>
#include <cpu/ppc/ppcemu.h> #include <cpu/ppc/ppcemu.h>
#include <cpu/ppc/ppcmmu.h> #include <cpu/ppc/ppcmmu.h>
#include <debugger/debugger.h>
#include <devices/common/hwinterrupt.h> #include <devices/common/hwinterrupt.h>
#include <devices/common/ofnvram.h> #include <devices/common/ofnvram.h>
#include "memaccess.h" #include "memaccess.h"
@ -445,7 +446,11 @@ static void delete_prompt() {
#endif #endif
} }
void enter_debugger() { DppcDebugger::DppcDebugger() {
}
void DppcDebugger::enter_debugger() {
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str, string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str,
inst_string, inst_num_str, profile_name, sub_cmd; inst_string, inst_num_str, profile_name, sub_cmd;
uint32_t addr, inst_grab; uint32_t addr, inst_grab;

View File

@ -22,6 +22,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef DEBUGGER_H_ #ifndef DEBUGGER_H_
#define DEBUGGER_H_ #define DEBUGGER_H_
void enter_debugger(); #include <memory>
class DppcDebugger {
public:
static DppcDebugger* get_instance() {
if (!debugger_obj) {
debugger_obj = std::unique_ptr<DppcDebugger>(new DppcDebugger());
}
return debugger_obj.get();
};
void enter_debugger();
private:
inline static std::unique_ptr<DppcDebugger> debugger_obj{nullptr};
explicit DppcDebugger(); // private constructor to implement a singleton
};
#endif // DEBUGGER_H_ #endif // DEBUGGER_H_

View File

@ -208,7 +208,7 @@ int main(int argc, char** argv) {
// sent to the logfile only). // sent to the logfile only).
cerr << message.preamble << message.indentation << message.prefix << message.message << endl; cerr << message.preamble << message.indentation << message.prefix << message.message << endl;
power_off_reason = po_enter_debugger; power_off_reason = po_enter_debugger;
enter_debugger(); DppcDebugger::get_instance()->enter_debugger();
// Ensure that NVRAM and other state is persisted before we terminate. // Ensure that NVRAM and other state is persisted before we terminate.
delete gMachineObj.release(); delete gMachineObj.release();
@ -282,15 +282,15 @@ void run_machine(std::string machine_str, std::string bootrom_path, uint32_t exe
switch (execution_mode) { switch (execution_mode) {
case interpreter: case interpreter:
power_off_reason = po_starting_up; power_off_reason = po_starting_up;
enter_debugger(); DppcDebugger::get_instance()->enter_debugger();
break; break;
case threaded_int: case threaded_int:
power_off_reason = po_starting_up; power_off_reason = po_starting_up;
enter_debugger(); DppcDebugger::get_instance()->enter_debugger();
break; break;
case debugger: case debugger:
power_off_reason = po_enter_debugger; power_off_reason = po_enter_debugger;
enter_debugger(); DppcDebugger::get_instance()->enter_debugger();
break; break;
default: default:
LOG_F(ERROR, "Invalid EXECUTION MODE"); LOG_F(ERROR, "Invalid EXECUTION MODE");