melt日記

.NETすらまともに扱えないへたれのページ

ホーム 連絡をする 同期する ( RSS 2.0 ) Login
投稿数  111  : 記事  3  : コメント  8228  : トラックバック  41

ニュース

わんくま同盟

わんくま同盟

C# と VB.NET の質問掲示板

iKnow!


Dictation



書庫

自分は普段、自作のスマート配列クラスを使ってプログラミングしているわけですが、デバッグをするときにいつも苦労をしてます。

なぜかというと、動的配列というのはデバッガから見ると単なるポインタなので、中身を見ようと思っても1番目の値しか表示できないからです。

例えば、自分の作っているスマート配列は、

namespace MyLib
{
    template<class T>
    class SharedPtr
    {
    public:
        // スマートポインタとしての機能を実装する
        ...
 
    private:
        //! オブジェクトの実体へのポインタ
        T*                      _object;
        //! 参照数を管理するためのマネージャ
        ObjectManagerBase*      _manager;
    };
 
    // 生の配列のラッパクラス
    template<class T>
    class Array_
    {
    public:
        // 配列としての機能を実装する
        ...
 
    private:
        //! 配列の実体へのポインタ
        T*              _object;
        //! 配列の長さ
        int             _length;
    };
 
    // 参照カウント付き配列クラス。
    // このクラスは SharedPtr<Array_<T>> を継承しているので、
    // メンバとして Array_<T>* 型の _object と
    // ObjectManagerBase* 型の _manager を持っている
    template<class T>
    class Array : public SharedPtr<Array_<T>>
    {
        ...
    };
}

こんな感じになっていて、これを例えば、

MyLib::Array<int> n;
// 10 個の int 型を持った配列を n にセット
...
// 代入
for (int i = 0; i < n.Length; i++)
{
    n[i] = i;
}

こういうプログラムを書いてデバッガで除いてみると、こんな風になります。

autoexp.dat 適用前

カーソルの当たっている部分が自分の表示したい int の配列なわけですが、最初の値しか見えません。配列なのだから全ての値が見えないとデバッグになりません。

また、いろいろなオブジェクトを経由しているため、何度も + を選択しないと目的の値までたどり着けません。

それから、_manager という参照数を管理するためのクラスが存在しています。このクラスは配列として表現したいので、こういった余分な情報はいらないのです。


何とかデバッガの表示を変えられないかなぁと調べてみたら、ありました。

<PROGRAM FILES>\Microsoft Visual Studio 8\Common7\Packages\Debugger のフォルダ(WindowsXP の場合)に autoexp.dat というファイルがあるので、これを編集すれば表示を変更することが出来るようです。


autoexp.dat に記述する構文は独特なので分かりづらかったのですが、Writing custom visualizers for Visual Studio 2005 や他の記述を見ながら頑張ってみました。


こんな感じになりました。

MyLib::Array<*>{
    children
    (
        #array
        (
            expr : ($c._object->_object)[$i],
            size :  $c._object->_length
        )
    )
    preview
    ( 
        #( 
            "[", $c._object->_length, "](",
            #array
            (
                expr :  ($c._object->_object)[$i],
                size :  $c._object->_length
            ), 
            ")"
        )
    )
}

この設定を [Visualizer] の下に書いて再度実行してみると、

autoexp.dat 適用後

ちゃんと全ての配列が表示されています。

今まで苦労していた配列のデバッグとか、これをうまく使えばいい感じになりそうです。




あと、↑のクラスは、元々は組み込みのプラットフォーム向けに作ったクラスなのです。

組み込みの場合、template を書きまくると実行サイズが増えすぎてやばいので、作った当時はこんな感じになっていました。

namespace MyLib
{
    class SharedPtrBase
    {
    public:
        // void* になっていても出来ることはここでやらせる
 
    protected:
        void*                   _object;
        ObjectManagerBase*      _manager;
    };
 
    template<class T>
    class SharedPtr : public SharedPtrBase
    {
    public:
        // void* だと実装できない機能を実装する
        ...
    };
 
    class ArrayBase
    {
    public:
        // void* になっていても出来ることはここでやらせる
        ...
 
    protected:
        void*           _object;
        int             _length;
    };
 
    // 生の配列のラッパクラス
    template<class T>
    class Array_ : public ArrayBase
    {
    public:
        // void* だと実装できない機能を実装する
        ...
 
    private:
    };
 
    template<class T>
    class Array : public SharedPtr<Array_<T>>
    {
        ...
    };
}

配列の実体が void* なんですね。

こいつの配列の中身を表示するとか無理なんじゃね?とか思ったんですが、$T1 と書けば template の第1引数が取れるので、

MyLib::Array<*>{
    children
    (
        #array
        (
            expr : (($T1*)(((MyLib::Array_<$T1>*)$c._object)->_object))[$i],
            size :  ((MyLib::Array_<$T1>*)$c._object)->_length
        )
    )
    preview
    ( 
        #( 
            "[", ((MyLib::Array_<$T1>*)$c._object)->_length, "](",
            #array
            (
                expr :  (($T1*)(((MyLib::Array_<$T1>*)$c._object)->_object))[$i],
                size :  ((MyLib::Array_<$T1>*)$c._object)->_length
            ), 
            ")"
        )
    )
}

こうやって書いてみたところ、正常に中身まで表示されました。


恐るべし autoexp.dat!

投稿日時 : 2007年10月1日 15:23

コメント

# re: [C++]autoexp.dat 2007/10/02 14:37 GPGA
早速使ってみたよ。
これ、超便利だな^^

# [C++]Boost デバッグ手法 2008/03/27 13:27 melt日記
[C++]Boost デバッグ手法

# [C++]Boost デバッグ手法 2008/03/27 13:34 melt日記
[C++]Boost デバッグ手法

# wwFlNupYPR 2011/12/27 19:17 http://www.greetingbee.com/
Very amusing thoughts, well told, everything is in its place:D

Well, actually, a lot of what you write is not quite true !... well, okay, it does not matter:D

# ARkTjqKItIDsciy 2012/01/07 9:01 http://www.luckyvitamin.com/m-1679-keurig
Good day! I do not see the conditions of using the information. May I copy the text from here on my site if you leave a link to this page?!...

# jianbin0301 2018/03/01 14:35 165464@qq.com
http://www.kobe9elites.us.com
http://www.nbajerseysstore.us.com
http://www.michaelkors.de.com
http://www.ferragamoshoes.org.uk
http://www.lacostepoloshirts.us.com
http://www.airforce1.us.com
http://www.canadagoose-jackets.org.uk
http://www.canadagoosejackets.me.uk
http://www.michaelkorsoutletclearance-online.us.com
http://www.fitflopssale.in.net
http://www.canadagoosejacketscg.ca
http://www.jordanshoesshop.us.com
http://www.pandoracharmss.us.com
http://www.pandoraoutlet-store.us.com
http://www.cheapjerseyswholesale.org
http://www.newbalanceshoes.in.net
http://www.coachfactoryoutlet-clearance.us.com
http://www.swarovskicrystalco.org.uk
http://www.montblancpenssale.us.com
http://www.fredperrypolo-shirts.com
http://www.rayban--sunglasses.co.uk
http://www.toryburchoutletofficials.us.com
http://www.christianlouboutins.org.uk
http://www.mulberrybagsuk.co.uk
http://www.raybansunglassesonsales.us.com
http://www.poloralphlaurenoutlet-online.us.com
http://www.uggoutlet.ca
http://www.reebokoutletstores.us.com
http://www.airhuaracheuk.org.uk
http://www.outlettruereligion.in.net
http://www.coachfactoryoutletstore.com.co
http://www.mulberryhandbagss.org.uk
http://www.ralphlauren-polo.us.org
http://www.raybansunglasses2.us.com
http://www.nfljerseysfactorystore.us.com
http://www.raybansunglassesonlines.us.com
http://www.cheapsoccerjersey.net
http://www.longchamphandbagssale.co.uk
http://www.canadagooseoutletclearance.us.com
http://www.michaelkorsoutletfriday.us.com
http://www.oakleysunglasseswear.us.com
http://www.nikeoutlets.us.org
http://www.poloralphlaurendiscount.us.com
http://www.canadagooseoutletcom.us.com
http://www.coachoutletclearance.us.org
http://www.canadagooseoutletcoats.us.com
http://www.jordanshoesstore.us.com
http://www.christianlouboutin-shoes.me.uk
http://www.ralph-laurenpoloshirts.us.com
http://www.uggsoutletshop.us.com
http://www.coachoutletclearanceonline.us.com
http://www.michaelkorsoutletme.us.com
http://www.raybanssunglassesoutlets.us.com
http://www.oakleysunglassesformens.us.com
http://www.coach-factoryoutlets.us.org
http://www.suprashoes.us.com
http://www.oakleysunglasseswholesaleus.us.com
http://www.fitflopsshoes.in.net
http://www.katespadeoutletsales.us.com
http://www.mcmoutletstore.us.org
http://www.michaelkorsoutletcoupons.us.com
http://www.oakleysunglassessites.us.com
http://www.jordanshoesfactory.us.com
http://www.nikerosheone.us
http://www.coachoutletcoupons.us.com
http://www.canadagooseoutletsalestore.us.com
http://www.uggsoutletco.us.com
http://www.yeezyboost350sale.us.com
http://www.clevelandcavaliers.us.com
http://www.poloralphlaurenofficial.us.com
http://www.raybansunglassesforwomens.us.com
http://www.coachoutletstore.com.co
http://www.adidasnmdad.us.com
http://www.katespadeoutletofficial.us.org
http://www.uggoutletstoresofficial.us.com
http://www.raybanssunglassessale.us.com
http://www.canadagoosejacketsusa.us.com
http://www.pandora-charmssaleclearance.org.uk
http://www.michaelkors.eu.com
http://www.raybansunglassesoutlets.com.co
http://www.swarovski-outlets.us.com

# re: Ruby で数値を 0 埋めする 2019/01/24 13:56 zzyytt
http://www.airmax90.us.org
http://www.goyard-handbags.us.com
http://www.michaeljordanshoes.us.com
http://www.adidasnmds.com
http://www.vans-outlet.us.com
http://www.adidasshoesonline.com
http://www.russellwestbrookshoes.us.com
http://www.adidasnmds.us.com
http://www.nike-hyperdunk.us.com
http://www.goldengoose-outlet.us.com
http://www.jordan11retro.us.com
http://www.nikehuaracheshoes.us.com
http://www.bape-hoodie.us.com
http://www.curry5shoes.net
http://www.hermesbelts.co.uk
http://www.fila-shoes.us.com
http://www.jordanshoes.org.uk
http://www.guccibelt.us.com
http://www.adidaseqts.com
http://www.yeezy-shoes.org.uk


# Vapor Max 2019/04/08 7:01 azezkeic@hotmaill.com
Game Killer Apk Download Latest Version for Android (No Ad) ... Guess not because Game killer full version app is not available on Play store.

# Yeezys 2019/04/19 5:36 qlnxzbxwq@hotmaill.com
They were doled out exclusively to employees and were never sold to the public, which explains why very few photographs of the shoe actually exist. In fact, the last time they surfaced was when they hit auction two summers ago.

# Pandora Sale 2019/04/20 11:34 nxmbqah@hotmaill.com
Boeing will cut production of its 737 MAX by one-fifth and has appointed a special board committee to review the development of its new aircraft. The airline giant said on Friday that it will cut its maximum monthly production by 10 to 42 by mid-April. Boeing plans to produce 57 737 MAXs a month this summer.

# Nike Outlet Store Online Shopping 2019/04/22 22:14 joamctqq@hotmaill.com
Game Killer Apk Download Latest Version for Android (No Ad) ... Guess not because Game killer full version app is not available on Play store.

# Balenciaga 2019/04/25 8:33 bjmfgpc@hotmaill.com
O'Neill expressed optimism about the economic outlook and stressed that according to the latest data released by Goldman Sachs Group, the global economic situation may soon stop falling.

# Pandora 2019/04/28 16:26 ovypybslu@hotmaill.com
A former Florida police officer was sentenced to 25 years in prison on Thursday for fatally shooting a black motorist who was awaiting a tow truck in October 2015.

# Nike 2019/05/05 8:33 tcgjwuiqp@hotmaill.com
He was doing that on jump shots, Lillard told Yahoo Sports. That’s not when you’re supposed to rock the baby. You rock the baby after overpowering someone in the post. He had one layup in the post on me. Look it up. I’ll live with his jump shots. He wasn’t rocking no baby on me.

# Jordan 11 Concord 2018 2019/05/07 1:26 dyttlkc@hotmaill.com
"We also issued a blanket order that asked anyone who had been in the library, on 4/11 between 11 and 3 to self-quarantine, notify health services and establish that they were immune before they exposed themselves to the public," said Barbara Ferrer, Los Angeles County's public health director.

# Yeezy 500 2019/05/12 19:12 gfscfeo@hotmaill.com
If George really wanted to get Lillard back, his best option is to just wait until next season and hope he can get revenge on the Trail Blazers. It takes time to come back after losing like that.

# NFL Jerseys 2019/05/21 11:34 vpcpqnkwtul@hotmaill.com
http://www.nikeshoes.us.org/ Nike Shoes

# Nike Pegasus 35 2019/06/04 5:11 xhrwaixkbe@hotmaill.com
http://www.nikeoutletonlineshopping.us/ Nike Outlet

# cheap custom nfl jerseys 2019/06/04 18:03 jbyrvs@hotmaill.com
http://www.nike--outlet.us/ Nike Outlet

# Travis Scott Jordan 1 2019/06/05 1:25 vpwifcvg@hotmaill.com
They're still talented and skilled. They're generally smart. The unity has become uneven. That ruthless thing,Jordan however,Jordan has never been more elusive than this season ? and it has carried over into the first five games of these playoffs.

# Adidas Yeezys 2019/06/17 2:23 akbthvzyhki@hotmaill.com
http://www.nikefactoryoutletstoreonline.com/ Nike Outlet store

# NFL Jerseys 2019/06/21 2:12 rbaiik@hotmaill.com
http://www.redjordan12.us/ Jordan 12 Gym Red

# Nike Outlet store 2019/06/22 6:58 xtsguyk@hotmaill.com
http://www.nikeshoxoutlet.us/ Nike Shox

# jordan 11 concord 2018 2019/07/06 19:41 ishias@hotmaill.com
http://www.redjordan12.us/ Red Jordan 12

# Yeezy 2019/07/29 6:00 xyckzshj@hotmaill.com
http://www.nikeoutletstoreonlineshopping.us/ Nike Outlet Store

# Yeezy Shoes 2019/08/04 15:15 ohtwtl@hotmaill.com
http://www.yeezy350.us.com/ Yeezy

# Yeezy 2019/08/17 2:47 xljnovqc@hotmaill.com
http://www.yeezy700.org.uk/ Yeezy

# Yeezy 350 2019/08/22 3:00 nihjabnuwep@hotmaill.com
http://www.yeezy-shoes.in.net/ Yeezy Shoes

# Adidas Yeezy 2019/08/22 15:55 hzysfifvd@hotmaill.com
http://www.adidasyeezy.us.com/ Adidas Yeezy

Post Feedback

タイトル
名前
Url:
コメント