[英]Deferred breakpoints: when are classes loaded
在使用 mvnDebug 之后,我正在嘗試使用jdb -attach 8000
調試mvnDebug
。
我嘗試放置斷點,但得到:
main[1] stop in DeployMojo.DeployMojo
Deferring breakpoint DeployMojo.DeployMojo.
It will be set after the class is loaded.
main[1] stop at Dependency:66
Deferring breakpoint Dependency:66.
It will be set after the class is loaded.
當我運行時,不會調用斷點。 我有源代碼(使用 maven 命令生成),但我怎樣才能讓調試器可以使用它們?
是否有 class 加載程序可以放置斷點?
這可能是因為您的類名錯誤或因為您省略了包。 如果類Dependency
在com.my.package
包中,則在類com.my.package.Dependency
中斷,而不是在Dependency
。
我正在使用jdb -attach -sourcepath ~/path/to/project/main/java
。 結果 jdb 不喜歡~
並且需要jdb -attach -sourcepath $HOME/path/to/project/main/java
或絕對路徑。
對我來說,tibtof 的回答只是我需要的一半。 在我明確添加 package 名稱后,jdb 將在我的這個 gradle 項目上產生“嘗試編譯並調試”:
> Unable to set deferred breakpoint package.ClassName:LineNumber : No linenumber information for package.ClassName. Try compiling with debugging on.
在這種情況下,如果您使用的是 gradle,則需要確保compileJava
任務中的options.debug=true
,您可以使用下面的println
進行檢查。
在我的例子中,我是在調試的情況下編譯的——或者我是這么想的。 我的build.gradle
是這樣的(基於這個答案和這篇文章):
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:all' << '-Werror' << '-g'
options.debug = project.hasProperty('debug')
options.debugOptions.debugLevel = 'source,lines,vars'
options.debugOptions.debugLevel = 'source,lines,vars'
doLast {
println "Args for for $name are $options.allCompilerArgs"
println "debug=$options.debug"
}
}
當我運行./gradlew build -Pdebug
時,它按預期打印:
Args for for compileJava are [-Xlint:all, -Werror, -g]
debug=true
事實證明,當我稍后運行./gradlew runMyTask --debug-jvm
時,它重新運行了compileJava
任務,因為我沒有再次通過-Pdebug
。 使用--info
運行 gradle 確認:
Task ':compileJava' is not up-to-date because:
Value of input property 'options.debug' has changed for task ':compileJava'
當我添加上述println
幾個小時后,這個事實才變得明顯:
afarah@gentoopc $ ./gradlew runMyTask --debug-jvm
> Task :compileJava
Args for for compileJava are [-Xlint:all, -Werror, -g]
debug=false
> Task :runMyTask
Listening for transport dt_socket at address: 5005
所以解決方案是運行./gradlew runMyTask --debug-jvm -Pdebug
,即再次傳遞-Pdebug
:
afarah@gentoopc $ ./gradlew runMyTask --debug-jvm -Pdebug
> Task :compileJava
Args for for compileJava are [-Xlint:all, -Werror, -g]
debug=true
> Task :runMyTask
Listening for transport dt_socket at address: 5005
現在注意debug=true
,最后 jdb 沒有報錯,停在了我的 LineNumber 斷點處。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.