我想調試用戶定義的函數(在C/C++中實現的prepareTheOutputRecord
,它是postgres中用戶定義函數的一部分。我用gdb實現這一目標:使用kdbg(KDE調試器在Lilnux中)調試postgres(和外部.so庫)
- 功能
prepareTheOutputRecord
位於libMyExtenstion.so
文件中PostgreSQL服務器的lib目錄 我開始psql的外殼,獲取進程的PID
postgres=# SELECT pg_backend_pid(); pg_backend_pid - - - - - - - - - - - - - - 4120 (1 row)
運行帶有附加的PID GDB:
gdb -p 4120
搜索現在.so文件,功能如何精確地叫:
nm -as libMyExtenstion.so | grep prepareTheOputRecord 00000000002633fe t _ZN6libafd6LIBAFD22prepareTheOutputRecordEP20FunctionCallInfoData
在gdb設置斷點,然後運行程序:
(gdb) b _ZN6libafd6LIBAFD22prepareTheOutputRecordEP20FunctionCallInfoData Function "_ZN6libafd6LIBAFD22prepareTheOutputRecordEP20FunctionCallInfoData" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (_ZN6libafd6LIBAFD22prepareTheOutputRecordEP20FunctionCallInfoData) pending. (gdb) c
在psql中執行SQL。在某個點上,斷點在gdb中:
Breakpoint 1, prepareTheOutputRecord (this=0x1116410, fcinfo=0x7fff3a41e150) at ../Dir/file.cpp:1736 1736 funcctx = SRF_PERCALL_SETUP(); (gdb)
繼續調試代碼。
我想在kdbg中完全一樣。爲此,我加載了postgres可執行文件,連接到進程,加載cpp文件,在函數中用鼠標設置斷點,繼續執行postgres進程,但斷點從未被擊中:(我重複了同樣的操作。所以沒有任何成功文件(而不是Postgres的可執行文件)。我甚至試圖設置斷點_ZN6libafd6LIBAFD22prepareTheOutputRecordEP20FunctionCallInfoData
(不用鼠標點擊),但程序不會在工具KDbg :(