--- nono/debugger/debugger_private.h 2026/04/29 17:04:33 1.1.1.2 +++ nono/debugger/debugger_private.h 2026/04/29 17:04:37 1.1.1.3 @@ -6,6 +6,7 @@ #pragma once +#include "branchhistory.h" #include "bus.h" #include "cvprompt.h" #include "textscreen.h" @@ -79,12 +80,39 @@ class Debugger final CommandAction action; } cmddef_t; + // ブレークポイント種別 + enum BreakpointType { + Unused = 0, + Address, // このアドレスに来る直前 + Memory, // このアドレスをアクセスした直後 + Exception, // この例外を検出した直後 + Instruction, // この命令を実行する直前 + }; + // ブレークポイント typedef struct { - bool enable; - bool ismemory; - uint32 addr; - uint32 count; + BreakpointType type {}; // 種別 + // 種別ごとのパラメータ + union { + uint32 addr {}; // ターゲットアドレス (Address/Memory) + struct { + int vec1; // ベクタ番号 (開始) + int vec2; // ベクタ番号 (終了) + }; + struct { + uint32 inst; // 命令ワード + uint32 mask; // マスク + }; + }; + + uint32 matched {}; // 成立回数 (積算) + + // skip はユーザ指定値。ただし + // -1 なら常にスキップ、つまりブレークせずカウントのみ行う、 + // 0 ならスキップなし、つまり成立ごとにブレーク(これがデフォルト)、 + // n(>0) なら n 回の成立をスキップし、(n+1) 回目でブレークの意。 + int32 skip {}; // スキップ回数 (ユーザ指定値) + int32 skipremain {}; // 残りスキップ回数 (0 で成立) } breakpoint_t; static const int MAX_BREAKPOINTS = 8; @@ -95,21 +123,32 @@ class Debugger final void Init(); void ThreadRun(); bool Check(); + void NotifyException(int vector); + + // ブレークポイントモニタを更新 + void MonitorBreakpoint(TextScreen& monitor); private: bool Accept(); bool AcquirePrompt(); CommandAction MainLoop(); + bool CheckAllBreakpoints(); + bool CheckBreakpointInst(breakpoint_t&); void ParseCmdbuf(); // コマンド名は大文字小文字を区別する関係でスネークスタイル。 void cmd_b(); + void cmd_bi(); + void cmd_bm(); + void cmd_bv(); void cmd_b_list(); + void cmd_b_set(BreakpointType); void cmd_brhist(); void cmd_bx(); void cmd_c(); void cmd_d(); void cmd_dt(); void cmd_D(); + void cmd_exhist(); void cmd_h(); void cmd_L(); void cmd_m(); @@ -123,10 +162,13 @@ class Debugger final void cmd_show(); void cmd_t(); - int AddBreakpoint(uint32 addr, bool ismemory); + int AddBreakpoint(const breakpoint_t&); + void RecalcInstMask(); bool GetAddr(uint32& addr, uint32& lastaddr); void cmd_d_common(MemdumpMode mode); + void cmd_hist_common(BranchHistory& hist, uint64 flag); void cmd_m_common(MemdumpMode mode); + bool ParseVerbHex(const char *arg, uint32 *valp); bool ParseAddr(const char *arg, uint32_t *addrp); bool SetNBreakpoint(); @@ -134,7 +176,7 @@ class Debugger final void Help(const HelpMessages msgs); // モニターを更新して表示 - void ShowMonitor(Object& obj); + void ShowMonitor(IMonitor& monitor); // テキストスクリーンを表示 void ShowTextScreen(TextScreen& screen); @@ -155,6 +197,10 @@ class Debugger final std::array bpoint {}; bool bc_enable = false; uint32 bc_addr = 0; + uint32 bi_inst = 0; + int bi_inst_bytes = 0; + int bi_need_bytes = 0; + int bv_vector = -1; uint32 d_last_addr = 0; uint32 m_last_addr = 0; bool n_enable = false; @@ -221,8 +267,9 @@ class DebuggerMD // レジスタ表示系コマンドのヘルプメッセージを取得 virtual const HelpMessages& GetRegisterHelp() const = 0; - // ブランチ履歴(オブジェクト)を取得 - virtual Object& GetBrHist() const = 0; + // ブランチ履歴・例外履歴(オブジェクト)を取得 + virtual BranchHistory& GetBrHist() const = 0; + virtual BranchHistory& GetExHist() const = 0; // 直近の命令でアクセスした laddr が一致したら true を返す // 1 命令で複数にアクセスする場合を考慮して、md 側で判断する @@ -246,6 +293,11 @@ class DebuggerMD virtual std::string FormatDisasmLive(const std::string& mnemonic, const std::vector& bin) = 0; + // ベクタ番号の最大値 (+1) + int vector_max = 0; + // 1命令の最小ビット数 + uint inst_bits = 0; + protected: Debugger *parent; // 親クラス };