How to debug Custom Action DLL
在MSI工程中,經(jīng)常會(huì)遇到這樣的情況:
MSI 工程需要調(diào)用DLL(C++)中的一個(gè)函數(shù)實(shí)現(xiàn)某些特殊或者復(fù)雜的功能,通常的做法是在Custom Action 中調(diào)用該DLL 。
那么在安裝過(guò)程中,該Custom Action 被調(diào)用的時(shí)候,如何使用Visual Studio 逐行Debug DLL 的源代碼呢?
答案是:使用VS2010 中的Attach to Process 就可以實(shí)現(xiàn)。
?
步驟如下:
1> VS 工程設(shè)置為Debug 模式,并設(shè)置斷點(diǎn)。
在斷點(diǎn)前,彈出一個(gè) dialog ,用來(lái)標(biāo)識(shí)debug的 開(kāi)始位置。以?C++ DLL 獲取 MSI Property?中的工程為例。
2> 以?Custom Action : dynamic link library?中的 MSI 工程為例。 編譯MSI 工程,運(yùn)行安裝包。
?
3> 彈出設(shè)定的 dialog 時(shí),在VS 工程中選擇,Debug / Attach to Process…
Msiexec.exe 是windows installer 服務(wù),選擇運(yùn)行MessageBox 的windows installer服務(wù),點(diǎn)擊 ”Attach” 。
?
在VS 工程中,將鼠標(biāo)移到斷點(diǎn)處,可以看到工程和 msiexec.exe 已經(jīng)關(guān)聯(lián)了起來(lái)。
??
?
4> 繼續(xù)安裝,在彈出的dialog 中 點(diǎn)擊“OK”。
再看VS 工程,程序就停在了斷點(diǎn)處,之后就可以逐行debug代碼了。
?
5> 按下 F10,進(jìn)入下一行代碼,彈出如下對(duì)話框,會(huì)發(fā)現(xiàn)是亂碼,原因待續(xù)。
補(bǔ)充一下:productName 參數(shù)接收的是 MSI 中 Property 表中的 ProductName 屬性值。
詳情請(qǐng)參見(jiàn):Custom Action : dynamic link library???
?
---------------------------------------------------------------------------------------
Debug 過(guò)程中,可能會(huì)發(fā)現(xiàn) Debug 斷點(diǎn)沒(méi)有被執(zhí)行到,紅色斷點(diǎn)變成了空心的黃色圓圈,將鼠標(biāo)停放到斷點(diǎn)上,相關(guān)的提示信息就會(huì)顯示出來(lái)。
可能會(huì)遇到的問(wèn)題:
1> The breakpoint will not currently be hit. No symbols have been loaded for this document.
?
解決方案:
1)工程右鍵 Property -> Configuration Properties -> Linker / Debugging / Generate Debug Info?
設(shè)置為 : Yes (/DEBUG)
?
2)如果還不好用的話,試試下面的方法:
Tools -> Options... ->Debugging / Symbols?
a>手動(dòng)添加 .pdb 文件的路徑
b>勾選 “Microsoft Symbol Servers”
?
2>
The breakpoint will not currently be hit. The source code is different from the original version.
To allow the breakpoint to be hit when the source code is different, right-click on the breakpoint, choose 'Location...', and turn on 'Allow the source code to be different from the original version.'
To allow this for all breakpoint, disable the option 'Require source files to exactly match the original version' under Tools, Options, Debugging, General.
這種情況原因很明顯,就是你修改了源代碼,但是沒(méi)有重新編譯,MSI 工程中引用的 DLL 的源代碼和工程里的不一致,就出現(xiàn)了斷點(diǎn)沒(méi)有被執(zhí)行到的情況。
按照提示的信息照做就可以了。
?
相關(guān)鏈接參考:
Debug a custom action dll
How to: Attach to a Running Process
Attach to Process in Visual Studio
?
轉(zhuǎn)載于:https://www.cnblogs.com/cindy-hu-23/p/3726998.html
總結(jié)
以上是生活随笔為你收集整理的How to debug Custom Action DLL的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: WMS
- 下一篇: Linux常用监控命令简介 – vmst