LoginSignup
26
24

More than 5 years have passed since last update.

Visual Studio のデバッガで文字列を UTF-8 で表示させる

Last updated at Posted at 2015-02-10

Visual Studio のデバッガでウォッチ式のカスタマイズができることはよく知られています。
例えば、次のサイトなどに詳しく書かれています。

ウォッチをより便利に使う10の書式

しかし、クラスメンバとして含まれているもののような場合、いちいち指定するのは面倒です。
例えば、デフォルトでローカルエンコーディング(CP932)で表示されてしまう非Unicode文字列をすべてUTF-8で表示させたいということがあると思います。
このような場合、Natvis ファイルによってカスタマイズが可能です。

Create custom views of native objects in the debugger

例えば、文字列を UTF-8 で表示させたい場合、%VSINSTALLDIR%\Common7\Packages\Debugger\Visualizers\stl.natvis の以下の部分で、"_Bx._Buf,s" を "_Bx._Buf,s8" に変更します。

<Type Name="std::basic_string&lt;char,*&gt;">  
    <DisplayString Condition="_Myres &lt; _BUF_SIZE">{_Bx._Buf,s}</DisplayString>  
    <DisplayString Condition="_Myres &gt;= _BUF_SIZE">{_Bx._Ptr,s}</DisplayString>  
    <StringView Condition="_Myres &lt; _BUF_SIZE">_Bx._Buf,s</StringView>  
    <StringView Condition="_Myres &gt;= _BUF_SIZE">_Bx._Ptr,s</StringView>  

Visual Studio を再起動すると適用されます。

この記事は、以下の記事を参考にしました。

Visual Studio 2010/2013 string对UTF8的支持总结

26
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
24