我想调试一个用户定义的函数(在C / C ++中实现的prepareTheOutputRecord
,它是postgres中用户定义函数的一部分。这里是我用gdb实现这个的方法:
prepareTheOutputRecord
驻留在postgresql server的lib目录中的libMyExtenstion.so
文件中我启动psql shell,检索进程的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中:(
答案 0 :(得分:0)
我认为问题是kdb
没有作为根(或postgres)运行。由于权限错误,未加载符号,因此未显示断点(也不允许放置在函数中)