--- nono/debugger/debugger_private.h 2026/04/29 17:04:30 1.1.1.1 +++ nono/debugger/debugger_private.h 2026/04/29 17:04:33 1.1.1.2 @@ -1,14 +1,18 @@ // // nono -// Copyright (C) 2020 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #pragma once -#include "header.h" #include "bus.h" #include "cvprompt.h" #include "textscreen.h" +#include + +using ConstStringPair = std::pair; +using HelpMessages = std::vector; // 諸情報付きのアドレス struct saddr_t @@ -31,17 +35,6 @@ struct saddr_t // addr がデータアクセスなら true。 bool data = false; - // コンストラクタ - saddr_t() {} - // コピーコンストラクタ - saddr_t(const saddr_t& lhs) { - addr = lhs.addr; - logical = lhs.logical; - search = lhs.search; - super = lhs.super; - data = lhs.super; - } - bool IsLogical() const { return logical; } bool IsSearch() const { return search; } bool IsSuper() const { return super; } @@ -68,16 +61,22 @@ class Console; class DebuggerMD; class Disasm; -class Debugger +class Debugger final { friend class DebuggerMD_m680x0; friend class DebuggerMD_m88xx0; private: // 型 - typedef void (Debugger::*cmdfunc_t)(); + enum CommandAction { + Stay, // デバッガプロンプトに留まる + Leave, // デバッガプロンプトを抜けて VM を実行する + Quit, // デバッガとの接続を終了する + }; + using cmdfunc_t = void (Debugger::*)(); typedef struct { const char *name; cmdfunc_t func; + CommandAction action; } cmddef_t; // ブレークポイント @@ -91,15 +90,17 @@ class Debugger public: Debugger(); - virtual ~Debugger() { } + ~Debugger() { } void Init(); void ThreadRun(); bool Check(); private: - bool MainLoop(); - cmddef_t *ParseCmd(); + bool Accept(); + bool AcquirePrompt(); + CommandAction MainLoop(); + void ParseCmdbuf(); // コマンド名は大文字小文字を区別する関係でスネークスタイル。 void cmd_b(); void cmd_b_list(); @@ -117,29 +118,26 @@ class Debugger void cmd_minus(); void cmd_n(); void cmd_q(); - void cmd_r(); - void cmd_ra(); - void cmd_rc(); - void cmd_rf(); - void cmd_rm(); - void cmd_ro(); void cmd_s(); void cmd_so(); void cmd_show(); void cmd_t(); - void cmd_unknown(); int AddBreakpoint(uint32 addr, bool ismemory); - void Continue(); bool GetAddr(uint32& addr, uint32& lastaddr); void cmd_d_common(MemdumpMode mode); void cmd_m_common(MemdumpMode mode); bool ParseAddr(const char *arg, uint32_t *addrp); bool SetNBreakpoint(); - void HelpMain(); + static const HelpMessages HelpMsgMain; + void Help(const HelpMessages msgs); + + // モニターを更新して表示 + void ShowMonitor(Object& obj); + // テキストスクリーンを表示 + void ShowTextScreen(TextScreen& screen); - void ShowMonitor(TextScreen& monitor); // アドレスをダンプ表示用に整形して返す bool FormatDumpAddr(saddr_t addr, std::string& addrstr); @@ -149,14 +147,12 @@ class Debugger const char *prompt; // プロンプト文字列 std::string cmdbuf {}; // 現在のコマンドライン std::string last_cmdbuf {}; // 直前のコマンドライン - int ac = 0; - std::string strav[10] { {}, }; - const char *av[10] {}; + std::vector args {}; uint32 pc = 0; uint32 nextpc = 0; std::vector ir {}; // この後実行する命令のバイナリ列 - breakpoint_t bpoint[MAX_BREAKPOINTS] {}; + std::array bpoint {}; bool bc_enable = false; uint32 bc_addr = 0; uint32 d_last_addr = 0; @@ -174,8 +170,7 @@ class Debugger // 一度VMを実行して再びプロンプトに来たら true bool is_continued = false; - static cmddef_t cmdtable[]; - static cmddef_t cmdtable_unknown; + static std::vector cmdtable; }; // デバッガの CPU 依存部分 @@ -184,9 +179,6 @@ class DebuggerMD public: DebuggerMD(Debugger *arg) { parent = arg; - - // 奇数にしておくことで初回に必ずアドレス変換を起こさせる。 - last_lpage.addr = 0xffffffff; } virtual ~DebuggerMD() { } @@ -223,13 +215,14 @@ class DebuggerMD // 現在のレジスタセットを内部にバックアップする virtual void BackupRegs() = 0; - // レジスタの一覧を cons に出力 - virtual void ShowRegMain(Console *cons) = 0; - virtual void ShowRegCtrl(Console *cons) = 0; - virtual void ShowRegFPU(Console *cons) = 0; - virtual void ShowRegMMU(Console *cons) = 0; - virtual void ShowRegATC(Console *cons) = 0; - virtual void ShowRegOther(Console *cons) = 0; + // レジスタ表示系のコマンドを実行。処理すれば true を返す。 + virtual bool ShowRegister(Console *cons, + const std::vector& args) = 0; + // レジスタ表示系コマンドのヘルプメッセージを取得 + virtual const HelpMessages& GetRegisterHelp() const = 0; + + // ブランチ履歴(オブジェクト)を取得 + virtual Object& GetBrHist() const = 0; // 直近の命令でアクセスした laddr が一致したら true を返す // 1 命令で複数にアクセスする場合を考慮して、md 側で判断する @@ -255,10 +248,6 @@ class DebuggerMD protected: Debugger *parent; // 親クラス - - // 前回アクセス時の論理ページ。.addr == 0xffffffff なら無効。 - saddr_t last_lpage; - uint32 last_ppage; }; #define NORM "\x1b[0m"