سؤال

I would like to debug a user defined function (called prepareTheOutputRecord implemented in C/C++ that is a part of user defined function in postgres. Here's how I achieve this with gdb:

  1. The function prepareTheOutputRecord resides in libMyExtenstion.so file in the lib directory of postgresql server
  2. I start the psql shell, retrieve the pid of the process

    postgres=# SELECT pg_backend_pid();
    pg_backend_pid
    - - - - - - - - - - - - - - 
        4120
    (1 row)
    
  3. Run the gdb with the attached pid:

    gdb -p 4120
    
  4. Search now the .so file, how the function is exactly called:

    nm -as libMyExtenstion.so | grep prepareTheOputRecord 
    00000000002633fe t _ZN6libafd6LIBAFD22prepareTheOutputRecordEP20FunctionCallInfoData
    
  5. Set a breakpoint in gdb and run the program:

    (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
    
  6. Execute the SQL in psql. At a certain point the breakpoint is hit in gdb:

    Breakpoint 1, prepareTheOutputRecord (this=0x1116410, fcinfo=0x7fff3a41e150)
    at ../Dir/file.cpp:1736
    1736        funcctx = SRF_PERCALL_SETUP();
    (gdb) 
    
  7. Continue debugging the code.

I want to do exactly the same in kdbg. For that I loaded the postgres executable, attached to the process, loaded the cpp file, set the breakpoint with the mouse at the function, continued the execution of the postgres process, but the breakpoint was never hit :( I repeated the same with .so file (instead of postgres executable) without any success. I even tried to set the breakpoint to _ZN6libafd6LIBAFD22prepareTheOutputRecordEP20FunctionCallInfoData (without the mouse clicks) but the program does not stop in kdbg :(

هل كانت مفيدة؟

المحلول

I believe the problem was that the kdb was not run as the root (or postgres). Due to wrong permissions the symbols were not loaded and therefore no breakpoint was shown (nor allowed to be placed at a function)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top