Files
hakorune/docs/debug_reports/chatgpt5_debug_request.md
Selfhosting Dev 40489a3c97 feat(debug): Add debug logging to console.log_handle for plugin investigation
- Added eprintln! debug messages to trace handle values
- Helps investigate why plugin return values display as blank
- Part of ongoing LLVM backend plugin return value investigation

Related to issue where print(c.get()) shows blank output

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-11 06:03:21 +09:00

2.1 KiB
Raw Blame History

ChatGPT5さんへプラグイン戻り値表示バグ詳細調査レポート

🎯 根本原因特定完了

問題の流れ

  1. プラグイン戻り値取得 正常

    • CounterBox.get() → 整数2が返される
    • L1016でvmapに生のi64値として格納
  2. LLVM console.log呼び出し 正常

    • L1270でnyash.console.log_handle(生のi64値)呼び出し
  3. nyrt処理 ここに問題

    // crates/nyrt/src/lib.rs:2391-2401
    pub extern "C" fn nyash_console_log_handle(handle: i64) -> i64 {
        if let Some(obj) = handles::get(handle as u64) {  // ← 生の値2でハンドル検索→失敗
            let s = obj.to_string_box().value;
            println!("{}", s);
        } else {
            println!("{}", handle);  // ← なぜか空白表示される
        }
    }
    

疑問点

なぜprintln!("{}", handle)が空白になるのか?

  • handleには実際の値2が入っているはず
  • なぜprintln!が何も出力しない?

🔍 必要な修正案

提案1: デバッグ出力追加

pub extern "C" fn nyash_console_log_handle(handle: i64) -> i64 {
    eprintln!("DEBUG: handle={}", handle);  // デバッグ出力
    if let Some(obj) = handles::get(handle as u64) {
        let s = obj.to_string_box().value;
        println!("{}", s);
    } else {
        eprintln!("DEBUG: handle {} not found in registry", handle);
        println!("{}", handle);  // 元のコード
    }
    0
}

提案2: 生の整数値対応

pub extern "C" fn nyash_console_log_handle(handle: i64) -> i64 {
    if let Some(obj) = handles::get(handle as u64) {
        let s = obj.to_string_box().value;
        println!("{}", s);
    } else {
        // プラグイン戻り値の生の整数を直接表示
        println!("{}", handle);
        eprintln!("DEBUG: Printed raw value {}", handle);
    }
    0
}

🐛 追加問題: 文字列連結

MIRで"result is: " + 2String + Integer → Integerと間違った型推論

お手数ですが、調査をお願いします!