我正在用gdb調試「Veracrypt」,因爲我想知道使用Veracrypt掛載卷時調用的函數的順序。由於Veracrypt使用多線程,我通過編寫gdb選項「-g」修改了MakeFile,並使用了一些命令,如thread apply all bt full
,set follow-fork-mode child
等。此外,我嘗試使用線程ID(例如sudo gdb -p [process ID]
)附加線程。如何使用GDB調試多線程?
所以我可以調試Veracrypt的代碼,但我無法調試一些代碼。
使用GDB,我已驗證時Veracrypt正在運行(卷裝入和卸除過程)中使用的多線程的線程ID和gdb顯示創建的線程的線程ID,如下所示。
[New Thread 0x7fffedf3e700 (LWP 5071)]
[New Thread 0x7fffed73d700 (LWP 5072)]
[New Thread 0x7fffecf3c700 (LWP 5073)]
[New Thread 0x7fffe7fff700 (LWP 5074)]
[New Thread 0x7fffe522f700 (LWP 5075)]
[New Thread 0x7fffe4a2e700 (LWP 5076)]
[New Thread 0x7fffdf568700 (LWP 5077)]
[New Thread 0x7fffded67700 (LWP 5078)]
[New Thread 0x7fffde566700 (LWP 5079)]
[Thread 0x7fffded67700 (LWP 5078) exited]
[New Thread 0x7fffded67700 (LWP 5081)]
[New Thread 0x7fffc9798700 (LWP 5082)]
[New Thread 0x7fffc8f97700 (LWP 5083)]
[New Thread 0x7fffc3fff700 (LWP 5084)]
[New Thread 0x7fffc37fe700 (LWP 5085)]
[New Thread 0x7fffc2ffd700 (LWP 5086)]
[Thread 0x7fffc3fff700 (LWP 5084) exited]
[Thread 0x7fffc2ffd700 (LWP 5086) exited]
[Thread 0x7fffc37fe700 (LWP 5085) exited]
[Thread 0x7fffded67700 (LWP 5081) exited]
[Thread 0x7fffc8f97700 (LWP 5083) exited]
[Thread 0x7fffc9798700 (LWP 5082) exited]
[New Thread 0x7fffc9798700 (LWP 5087)]
[New Thread 0x7fffc8f97700 (LWP 5088)]
[New Thread 0x7fffded67700 (LWP 5089)]
[New Thread 0x7fffc37fe700 (LWP 5090)]
[New Thread 0x7fffc3fff700 (LWP 5091)]
[Thread 0x7fffc9798700 (LWP 5087) exited]
[Thread 0x7fffc8f97700 (LWP 5088) exited]
[Thread 0x7fffc37fe700 (LWP 5090) exited]
[Thread 0x7fffc3fff700 (LWP 5091) exited]
[Thread 0x7fffde566700 (LWP 5079) exited]
[New Thread 0x7fffde566700 (LWP 5092)]
[New Thread 0x7fffc3fff700 (LWP 5093)]
[Thread 0x7fffc3fff700 (LWP 5093) exited]
[Thread 0x7fffded67700 (LWP 5089) exited]
[New Thread 0x7fffded67700 (LWP 5094)]
[Thread 0x7fffded67700 (LWP 5094) exited]
[New Thread 0x7fffded67700 (LWP 5095)]
[Thread 0x7fffded67700 (LWP 5095) exited]
[Thread 0x7fffedf3e700 (LWP 5071) exited]
[Thread 0x7fffed73d700 (LWP 5072) exited]
[Thread 0x7fffe7fff700 (LWP 5074) exited]
[Thread 0x7fffecf3c700 (LWP 5073) exited]
[Thread 0x7fffe522f700 (LWP 5075) exited]
[Thread 0x7ffff7fc4a40 (LWP 5066) exited]
[Thread 0x7fffdf568700 (LWP 5077) exited]
[Thread 0x7fffe4a2e700 (LWP 5076) exited]
[Inferior 1 (process 5066) exited normally]
我使用的「fprintf中(..)」和「GETPID()」編寫時Veracrypt在文件中運行(卷裝入和卸除過程)執行每個功能的線程ID。 (我在這部分也有一個問題,因爲在不能用gdb調試的函數代碼中,「printf(...)」函數不會將值輸出到終端,但是在函數代碼中可以調試後,該值被打印到終端上。)
當我檢查執行函數的線程標識時,我想在使用「fprintf」函數生成的文件中進行調試,它不在線程標識列表中gdb(上面的代碼)生成的值大於列表中的線程ID。 (在這種情況下(上面的代碼),執行我想要調試的函數的線程ID是5098)。
我想調試一些函數,如CoreUnix.cpp::MountVolume
和CoreLinux::MountVolumeNative
。我怎樣才能用gdb調試這些函數?
我也使用「gettid()」,但它的值與getpid()的值相同。 「無法調試的函數」的確切含義在於,它是Veracrypt的函數代碼,它不會在斷點處停止,而是使用用於調試多線程但在Veracrypt的裝載過程中運行的選項。 –