How to debug Custom Action DLL
在MSI工程中,經常會遇到這樣的情況:
MSI 工程需要調用DLL(C++)中的一個函數實現某些特殊或者復雜的功能,通常的做法是在Custom Action 中調用該DLL 。
那么在安裝過程中,該Custom Action 被調用的時候,如何使用Visual Studio 逐行Debug DLL 的源代碼呢?
答案是:使用VS2010 中的Attach to Process 就可以實現。
?
步驟如下:
1> VS 工程設置為Debug 模式,并設置斷點。
在斷點前,彈出一個 dialog ,用來標識debug的 開始位置。以?C++ DLL 獲取 MSI Property?中的工程為例。
2> 以?Custom Action : dynamic link library?中的 MSI 工程為例。 編譯MSI 工程,運行安裝包。
?
3> 彈出設定的 dialog 時,在VS 工程中選擇,Debug / Attach to Process…
Msiexec.exe 是windows installer 服務,選擇運行MessageBox 的windows installer服務,點擊 ”Attach” 。
?
在VS 工程中,將鼠標移到斷點處,可以看到工程和 msiexec.exe 已經關聯了起來。
??
?
4> 繼續安裝,在彈出的dialog 中 點擊“OK”。
再看VS 工程,程序就停在了斷點處,之后就可以逐行debug代碼了。
?
5> 按下 F10,進入下一行代碼,彈出如下對話框,會發現是亂碼,原因待續。
補充一下:productName 參數接收的是 MSI 中 Property 表中的 ProductName 屬性值。
詳情請參見:Custom Action : dynamic link library???
?
---------------------------------------------------------------------------------------
Debug 過程中,可能會發現 Debug 斷點沒有被執行到,紅色斷點變成了空心的黃色圓圈,將鼠標停放到斷點上,相關的提示信息就會顯示出來。
可能會遇到的問題:
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?
設置為 : Yes (/DEBUG)
?
2)如果還不好用的話,試試下面的方法:
Tools -> Options... ->Debugging / Symbols?
a>手動添加 .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.
這種情況原因很明顯,就是你修改了源代碼,但是沒有重新編譯,MSI 工程中引用的 DLL 的源代碼和工程里的不一致,就出現了斷點沒有被執行到的情況。
按照提示的信息照做就可以了。
?
相關鏈接參考:
Debug a custom action dll
How to: Attach to a Running Process
Attach to Process in Visual Studio
?
轉載于:https://www.cnblogs.com/cindy-hu-23/p/3726998.html
總結
以上是生活随笔為你收集整理的How to debug Custom Action DLL的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WMS
- 下一篇: Linux常用监控命令简介 – vmst