CC-RL/CC-RX/CC-RHでVisual Studioの__debugbreak()機能のようなものを作って試してみようと思います

こんにちは。NoMaYです。

昔、Windowsアプリケーションを作っていた頃、WindowsのDebugBreak()というAPIでブレークポイントを(諸般の事情で)手作業でソースに書いていたことがありました。別スレッドの案件でちょっとそのことを思い出しましたので試してみることにしました。

Google検索: Windows OR VisualStudio DebugBreak OR __debugbreak
www.google.com/search?q=Windows+OR+VisualStudio+DebugBreak+OR+__debugbreak&num=50
 

Parents
  • こんにちは。NoMaYです。

    次はCC-RXで試してみました。RL78のブレークポイントの命令コードが0xffだったのに対して、RXのブレークポイントの命令コードは0x01ですので、CC-RLとCC-RXでインラインアセンブラの仕様が同じだったのであれば、それに置き換えるだけのことだったのですけれども、CC-RLでは使えた.byte擬似命令がCC-RXでは使えませんでしたので、苦肉の策を取ることにしました。今回は以下のインラインアセンブラ関数で実現してみました。

    実は、数年前にがじぇルネのブログ投稿欄にGR-CITRUSについて投稿したものが幾つかあって、そこに一度作ったものがあったのですけれども、その時のインラインアセンブラ関数ではCC-RXがワーニングを表示してしまっていましたので、それとは違うインラインアセンブラ関数にしてみました。ただ、.byte擬似命令がCC-RXで使えないことに対する小細工としてのインラインアセンブラコードが、当時のものでは2バイトだったのに対して、今回のものでは6バイトになっていますので、#if 1/0で切り替えられるようにしてあります。ちなみに、そのワーニングは-nomessageや-no_warningの抑止対象範囲外のものとなっていますので、残念ながら当時のものに対してワーニングを抑止することは出来ません。

    なお、CS+とVSCode、実機とルネサスRXシミュレータで試してみましたが、RXシミュレータでは命令コードの0x01は不正命令として扱われることになっているようで、プログラムの不正命令例外ハンドラが実行されるようになっています。もしかすると、実機でもデバッガを繋いでいない場合には、そういう動作になっているかも知れません。

    #pragma inline_asm __debugbreak
    static void __debugbreak(void)
    {
    #if 1 // 1 or 0

    // This code is longer than the latter but the code does not cause any warnings.
    mov.l #3, r1
    bra.l r1
    add #0,r1 // .byte 0x62, 0x01
    // 0x62 is 1st code of add #0,r1
    // 0x01 is 2nd code of add #0,r1 and is the debug exception code of RX such as 0xCC (int 03h) of x86
    // If you want to start from the next instruction, you need to change PC by yourself or to make a CS+'s Python script.

    #else

    // This code is shorter than the former but the code causes `W0551001:Destination address may be changed` warning.
    ?: bra.b ?- + 1 // .byte 0x2E, 0x01
    // 0x2E is 1st code of bra.b PC + 1
    // 0x01 is 2nd code of bra.b PC + 1 and is the debug exception code of RX such as 0xCC (int 03h) of x86
    // If you want to start from the next instruction, you need to change PC by yourself or to make a CS+'s Python script.

    #endif
    }

     
    GR-CITRUSでCS+のRXシリアルデバッガを使えるようにしてみた(IDE for GR編)
    community-ja.renesas.com/gr_user_forum_japanese/b/weblog2/posts/gr_2d00_citrus_5f00_rx_2d00_serial_2d00_debugger_2d00_ide4gr

    GR-CITRUSでCS+のRXシリアルデバッガを使えるようにしてみた(CC-RX&CS+編)
    community-ja.renesas.com/gr_user_forum_japanese/b/weblog2/posts/gr_2d00_citrus_5f00_rx_2d00_serial_2d00_debugger_2d00_cc-rx

    GR-CITRUSでCS+のRXシリアルデバッガを使えるようにしてみた(実装編)
    community-ja.renesas.com/gr_user_forum_japanese/b/weblog2/posts/gr_2d00_citrus_5f00_rx_2d00_serial_2d00_debugger_2d00_impl

    (5-5) r_usb_PMSC_apl.cの先頭のbebugbreak()というインラインアセンブラ関数

    #if defined(RXSDBG) // for RX Serial Debugger
    #pragma inline_asm debugbreak
    static void debugbreak(void) { ?: bra.b ?- + 01h ; .byte 0x2E, 0x01 }
    // 0x2E is 1st code of bra.b PC + 01h
    // 0x01 is 2nd code of bra.b PC + 01h and is the debug exception code of RX such as 0xCC (int 03h) of x86
    // If you want to start from PC + 02h, you need to change PC by yourself or to make a CS+'s Python script
    #endif



    top コンパイラ編 コンパイラ言語仕様 拡張言語仕様 拡張仕様の使用方法
    4.2.4 拡張仕様の使用方法
    (5) アセンブラ記述関数インライン展開
    tool-support.renesas.com/autoupdate/support/onlinehelp/ja-JP/csp/V8.09.00/CS+.chm/Compiler-CCRX.chm/Output/ccrx04c0204y.html#96980

    以下、CS+とVSCodeの画面コピーです。

    実機+CS+


    実機+VSCode


    ルネサスRXシミュレータ+CS+ (プログラムの不正命令例外ハンドラへ飛ぶ)


    ルネサスRXシミュレータ+VSCode (プログラムの不正命令例外ハンドラへ飛ぶ)

     

Reply
  • こんにちは。NoMaYです。

    次はCC-RXで試してみました。RL78のブレークポイントの命令コードが0xffだったのに対して、RXのブレークポイントの命令コードは0x01ですので、CC-RLとCC-RXでインラインアセンブラの仕様が同じだったのであれば、それに置き換えるだけのことだったのですけれども、CC-RLでは使えた.byte擬似命令がCC-RXでは使えませんでしたので、苦肉の策を取ることにしました。今回は以下のインラインアセンブラ関数で実現してみました。

    実は、数年前にがじぇルネのブログ投稿欄にGR-CITRUSについて投稿したものが幾つかあって、そこに一度作ったものがあったのですけれども、その時のインラインアセンブラ関数ではCC-RXがワーニングを表示してしまっていましたので、それとは違うインラインアセンブラ関数にしてみました。ただ、.byte擬似命令がCC-RXで使えないことに対する小細工としてのインラインアセンブラコードが、当時のものでは2バイトだったのに対して、今回のものでは6バイトになっていますので、#if 1/0で切り替えられるようにしてあります。ちなみに、そのワーニングは-nomessageや-no_warningの抑止対象範囲外のものとなっていますので、残念ながら当時のものに対してワーニングを抑止することは出来ません。

    なお、CS+とVSCode、実機とルネサスRXシミュレータで試してみましたが、RXシミュレータでは命令コードの0x01は不正命令として扱われることになっているようで、プログラムの不正命令例外ハンドラが実行されるようになっています。もしかすると、実機でもデバッガを繋いでいない場合には、そういう動作になっているかも知れません。

    #pragma inline_asm __debugbreak
    static void __debugbreak(void)
    {
    #if 1 // 1 or 0

    // This code is longer than the latter but the code does not cause any warnings.
    mov.l #3, r1
    bra.l r1
    add #0,r1 // .byte 0x62, 0x01
    // 0x62 is 1st code of add #0,r1
    // 0x01 is 2nd code of add #0,r1 and is the debug exception code of RX such as 0xCC (int 03h) of x86
    // If you want to start from the next instruction, you need to change PC by yourself or to make a CS+'s Python script.

    #else

    // This code is shorter than the former but the code causes `W0551001:Destination address may be changed` warning.
    ?: bra.b ?- + 1 // .byte 0x2E, 0x01
    // 0x2E is 1st code of bra.b PC + 1
    // 0x01 is 2nd code of bra.b PC + 1 and is the debug exception code of RX such as 0xCC (int 03h) of x86
    // If you want to start from the next instruction, you need to change PC by yourself or to make a CS+'s Python script.

    #endif
    }

     
    GR-CITRUSでCS+のRXシリアルデバッガを使えるようにしてみた(IDE for GR編)
    community-ja.renesas.com/gr_user_forum_japanese/b/weblog2/posts/gr_2d00_citrus_5f00_rx_2d00_serial_2d00_debugger_2d00_ide4gr

    GR-CITRUSでCS+のRXシリアルデバッガを使えるようにしてみた(CC-RX&CS+編)
    community-ja.renesas.com/gr_user_forum_japanese/b/weblog2/posts/gr_2d00_citrus_5f00_rx_2d00_serial_2d00_debugger_2d00_cc-rx

    GR-CITRUSでCS+のRXシリアルデバッガを使えるようにしてみた(実装編)
    community-ja.renesas.com/gr_user_forum_japanese/b/weblog2/posts/gr_2d00_citrus_5f00_rx_2d00_serial_2d00_debugger_2d00_impl

    (5-5) r_usb_PMSC_apl.cの先頭のbebugbreak()というインラインアセンブラ関数

    #if defined(RXSDBG) // for RX Serial Debugger
    #pragma inline_asm debugbreak
    static void debugbreak(void) { ?: bra.b ?- + 01h ; .byte 0x2E, 0x01 }
    // 0x2E is 1st code of bra.b PC + 01h
    // 0x01 is 2nd code of bra.b PC + 01h and is the debug exception code of RX such as 0xCC (int 03h) of x86
    // If you want to start from PC + 02h, you need to change PC by yourself or to make a CS+'s Python script
    #endif



    top コンパイラ編 コンパイラ言語仕様 拡張言語仕様 拡張仕様の使用方法
    4.2.4 拡張仕様の使用方法
    (5) アセンブラ記述関数インライン展開
    tool-support.renesas.com/autoupdate/support/onlinehelp/ja-JP/csp/V8.09.00/CS+.chm/Compiler-CCRX.chm/Output/ccrx04c0204y.html#96980

    以下、CS+とVSCodeの画面コピーです。

    実機+CS+


    実機+VSCode


    ルネサスRXシミュレータ+CS+ (プログラムの不正命令例外ハンドラへ飛ぶ)


    ルネサスRXシミュレータ+VSCode (プログラムの不正命令例外ハンドラへ飛ぶ)

     

Children
No Data