Visual Studio Debugging - Inspect Variables Fast and In Place

All programmers know how to do basic debugging. I won’t cover that in this series of techniques. I’ll talk about some relatively advanced debugging method which you may not know but will make you powerful once you learn them. I will use C++ and Visual Studio 2015 for the whole demo. ?

In this article, I’ll use this piece of code for all demos.

Even if the program is not running yet, when you put the mouse on a variable, it will show the type of this variable. So you don’t have to page up to find the declaration of it

When the program is under debug, if the mouse is moving over a variable, the value of the variable is evaluated and displayed. It is allowed to expand the variable to inspect members if it is of a complicate type. The following demonstrates how to inspect vectors. Same for class or structure variables.


The little pin in red rectangle allow you pin a variable on the screen so you can monitor it. Once it is pinned, you can move it to a blank area so it does not hide any code. This floating window lets you monitor variables during debugging without occupying spaces in Watch window, as it is not easy to find variables in different functions if there are many in the watch list. In this floating window, you can even add a comment for it to remind yourself.

You can change the value of a variable by clicking on the value and change it, and it is changed immediately.

If you are inspecting the value but you want to read the code behind the display window, you can move the mouse away to cancel the display to read the code and then display the variable again, but this is not convenient, especially when you are checking a very complicated variable, for example, an instance of a class with hundred of member variables. The trick here is to press the Ctrl key, the variable display window is pretty much transparent so you can read the code behind. When you release Ctrl key after the checking of code, the variable display comes back and you can continue inspecting the variable.

During the inspection, if you want to add a variable or a member in a variable to the watch window, you can right click on the variable or a member of it and choose to add it to Watch.

Before we have this, all of these is done in watch window, which make the window kind of messy. From Microsoft, this is supported form Visual Studio 2010. If you don’t know it yet, this is the time to master it and perform debugging like a professional, like me!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末辟灰,一起剝皮案震驚了整個(gè)濱河市捧弃,隨后出現(xiàn)的幾起案子菠净,更是在濱河造成了極大的恐慌呛凶,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,406評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件灭抑,死亡現(xiàn)場離奇詭異十艾,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)腾节,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評論 3 393
  • 文/潘曉璐 我一進(jìn)店門忘嫉,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人禀倔,你說我怎么就攤上這事榄融〔我” “怎么了救湖?”我有些...
    開封第一講書人閱讀 163,711評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長涎才。 經(jīng)常有香客問我鞋既,道長力九,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,380評論 1 293
  • 正文 為了忘掉前任邑闺,我火速辦了婚禮跌前,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘陡舅。我一直安慰自己抵乓,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,432評論 6 392
  • 文/花漫 我一把揭開白布靶衍。 她就那樣靜靜地躺著灾炭,像睡著了一般。 火紅的嫁衣襯著肌膚如雪颅眶。 梳的紋絲不亂的頭發(fā)上蜈出,一...
    開封第一講書人閱讀 51,301評論 1 301
  • 那天,我揣著相機(jī)與錄音涛酗,去河邊找鬼铡原。 笑死,一個(gè)胖子當(dāng)著我的面吹牛商叹,可吹牛的內(nèi)容都是我干的燕刻。 我是一名探鬼主播,決...
    沈念sama閱讀 40,145評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼剖笙,長吁一口氣:“原來是場噩夢啊……” “哼酌儒!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起枯途,我...
    開封第一講書人閱讀 39,008評論 0 276
  • 序言:老撾萬榮一對情侶失蹤忌怎,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后酪夷,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體榴啸,經(jīng)...
    沈念sama閱讀 45,443評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,649評論 3 334
  • 正文 我和宋清朗相戀三年晚岭,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了鸥印。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,795評論 1 347
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡坦报,死狀恐怖库说,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情片择,我是刑警寧澤潜的,帶...
    沈念sama閱讀 35,501評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站字管,受9級特大地震影響啰挪,放射性物質(zhì)發(fā)生泄漏信不。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,119評論 3 328
  • 文/蒙蒙 一亡呵、第九天 我趴在偏房一處隱蔽的房頂上張望抽活。 院中可真熱鬧,春花似錦锰什、人聲如沸下硕。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,731評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽卵牍。三九已至,卻和暖如春沦泌,著一層夾襖步出監(jiān)牢的瞬間糊昙,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,865評論 1 269
  • 我被黑心中介騙來泰國打工谢谦, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留释牺,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,899評論 2 370
  • 正文 我出身青樓回挽,卻偏偏與公主長得像没咙,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子千劈,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,724評論 2 354

推薦閱讀更多精彩內(nèi)容