Debug a C shared library using Eclipse or Visual C++ 6.0

Поиск
Список
Период
Сортировка
От Aurora Sánchez
Тема Debug a C shared library using Eclipse or Visual C++ 6.0
Дата
Msg-id 000401c7cd42$f8012a30$ef0210ac@gtd.es
обсуждение исходный текст
Список pgsql-hackers
<div class="Section1"><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial">Hi,</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB" style="font-size:
10.0pt;font-family:Arial">I have a problem when trying to debug a shared library developed in C. I’m following the
stepsincluded in the docs, in chapter 33 (extending SQL), section 33.9 (C-Language functions) <a
href="http://www.postgresql.org/docs/8.2/interactive/xfunc-c.html">http://www.postgresql.org/docs/8.2/interactive/xfunc-c.html</a></span></font><p
class="MsoNormal"><fontface="Arial" size="2"><span lang="EN-GB" style="font-size: 
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial">I’ve successfully compiled the example <b><span
style="font-weight:bold">tablefunc.c</span></b>which is included in <a
href="http://developer.postgresql.org/cvsweb.cgi/pgsql/contrib/tablefunc/">http://developer.postgresql.org/cvsweb.cgi/pgsql/contrib/tablefunc/</a></span></font><p
class="MsoNormal"><fontface="Arial" size="2"><span lang="EN-GB" style="font-size: 
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial">I’m using <b><span style="font-weight:bold">Eclipse 3.2</span></b> and have installed
<b><spanstyle="font-weight:bold">mingw</span></b>. The problem I have is that I cannot debug the functions. When trying
todebug, I choose the option “C/C++ attach to local application”. Then a list of processes to select appears. The only
optionI can choose is pgAdmin3.exe. When I choose it and open a SQL script in the pgadmin and execute the function I’m
tryingto debug, the function works properly but in doesn’t’ enter the debug. </span></font><p class="MsoNormal"><font
face="Arial"size="2"><span lang="EN-GB" style="font-size: 
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial">This is the code I use to create the function. It’s linked to the dll compiled with Eclipse.
</span></font><pclass="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB" style="font-size: 
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal" style="margin-left:35.4pt"><font face="Courier New"
size="1"><spanlang="EN-GB" style="font-size:9.0pt;font-family:"Courier New"">CREATE OR REPLACE FUNCTION
mi_crosstab(text)</span></font><pclass="MsoNormal" style="margin-left:35.4pt"><font face="Courier New" size="1"><span
lang="EN-GB"style="font-size:9.0pt;font-family:"Courier New"">  RETURNS SETOF record AS</span></font><p
class="MsoNormal"style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:9.0pt;font-family:"Courier
New"">E'D:\\\\eclipse\\\\workspace\\\\tablefunc_lib\\\\Debug\\\\tablefunc_lib','mi_crosstab'</span></font><p
class="MsoNormal"style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:9.0pt;font-family:"CourierNew"">  LANGUAGE 'c' VOLATILE STRICT;</span></font><p class="MsoNormal"
style="margin-left:35.4pt"><fontface="Courier New" size="1"><span lang="EN-GB"
style="font-size:9.0pt;font-family:"CourierNew"">ALTER FUNCTION mi_crosstab(text) OWNER TO postgres;</span></font><p
class="MsoNormal"><fontface="Arial" size="2"><span lang="EN-GB" style="font-size: 
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial">I have seen that there are several processes called postgres.exe in the system administrator
window.I have managed to make them appear in the list I mentioned, but when I select them in the debug option, I get
thefollowing error message: “Attach to process failed”.</span></font><p class="MsoNormal"><font face="Arial"
size="2"><spanlang="EN-GB" style="font-size: 
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial">I’m also trying to debug using Microsoft Visual C++ 6.0. With this option I cannot even
compileany library. </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB" style="font-size: 
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial">This is the simple code I’m trying to compile:</span></font><p class="MsoNormal"><font
face="Arial"size="2"><span lang="EN-GB" style="font-size: 
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal" style="margin-left:35.4pt"><font face="Courier New"
size="1"><spanlang="EN-GB" style="font-size:8.0pt;font-family:"Courier New"">extern "C"{</span></font><p
class="MsoNormal"style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">#include <postgres.h></span></font><p class="MsoNormal"
style="margin-left:35.4pt"><fontface="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">#include <string.h></span></font><p class="MsoNormal"
style="margin-left:35.4pt"><fontface="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">#include <fmgr.h></span></font><p class="MsoNormal"
style="margin-left:35.4pt"><fontface="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">};</span></font><p class="MsoNormal" style="margin-left:35.4pt"><font
face="CourierNew" size="1"><span lang="EN-GB" style="font-size:8.0pt;font-family:"Courier New""> </span></font><p
class="MsoNormal"style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">PG_MODULE_MAGIC;</span></font><p class="MsoNormal"
style="margin-left:35.4pt"><fontface="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew""> </span></font><p class="MsoNormal" style="margin-left:35.4pt"><font
face="CourierNew" size="1"><span lang="EN-GB" style="font-size:8.0pt;font-family:"Courier
New"">PG_FUNCTION_INFO_V1(add_one_float8);</span></font><pclass="MsoNormal" style="margin-left:35.4pt"><font
face="CourierNew" size="1"><span lang="EN-GB" style="font-size:8.0pt;font-family:"Courier New""> </span></font><p
class="MsoNormal"style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">__stdcall DllMain( HANDLE hModule, </span></font><p class="MsoNormal"
style="margin-left:35.4pt"><fontface="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">                       DWORD  ul_reason_for_call, </span></font><p
class="MsoNormal"style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">                       LPVOID lpReserved</span></font><p
class="MsoNormal"style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">                                   )</span></font><p class="MsoNormal"
style="margin-left:35.4pt"><fontface="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">{</span></font><p class="MsoNormal" style="margin-left:35.4pt"><font
face="CourierNew" size="1"><span lang="EN-GB" style="font-size:8.0pt;font-family:"Courier New"">    return
TRUE;</span></font><pclass="MsoNormal" style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">}</span></font><p class="MsoNormal" style="margin-left:35.4pt"><font
face="CourierNew" size="1"><span lang="EN-GB" style="font-size:8.0pt;font-family:"Courier New""> </span></font><p
class="MsoNormal"style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew""> </span></font><p class="MsoNormal" style="margin-left:35.4pt"><font
face="CourierNew" size="1"><span lang="EN-GB" style="font-size:8.0pt;font-family:"Courier New"">extern "C"
{</span></font><pclass="MsoNormal" style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">__declspec(dllexport) Datum
add_one_float8(PG_FUNCTION_ARGS)</span></font><pclass="MsoNormal" style="margin-left:35.4pt"><font face="Courier New"
size="1"><spanlang="EN-GB" style="font-size:8.0pt;font-family:"Courier New"">{</span></font><p class="MsoNormal"
style="margin-left:35.4pt"><fontface="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">    /* The macros for FLOAT8 hide its pass-by-reference nature.
*/</span></font><pclass="MsoNormal" style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew"">    float8   arg = PG_GETARG_FLOAT8(0);</span></font><p
class="MsoNormal"style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew""> </span></font><p class="MsoNormal" style="margin-left:35.4pt"><font
face="CourierNew" size="1"><span lang="EN-GB" style="font-size:8.0pt;font-family:"Courier New"">   
PG_RETURN_FLOAT8(arg+ 1.0);</span></font><p class="MsoNormal" style="margin-left:35.4pt"><font face="Courier New"
size="1"><spanlang="EN-GB" style="font-size:8.0pt;font-family:"Courier New"">}</span></font><p class="MsoNormal"
style="margin-left:35.4pt"><fontface="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew""> </span></font><p class="MsoNormal" style="margin-left:35.4pt"><font
face="CourierNew" size="1"><span lang="EN-GB" style="font-size:8.0pt;font-family:"Courier New"">};</span></font><p
class="MsoNormal"style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew""> </span></font><p class="MsoNormal" style="margin-left:35.4pt"><font
face="CourierNew" size="1"><span lang="EN-GB" style="font-size:8.0pt;font-family:"Courier New""> </span></font><p
class="MsoNormal"><fontface="Arial" size="2"><span lang="EN-GB" style="font-size: 
10.0pt;font-family:Arial">When doing so I get 3 warnings referred to the MAGIC FUNCTION declaration, and the function
doesn’twork.</span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB" style="font-size: 
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal" style="margin-left:35.4pt"><font face="Courier New"
size="1"><spanlang="EN-GB" style="font-size:9.0pt;font-family:"Courier New"">warning C4273: 'Pg_magic_func' :
inconsistentdll linkage.  dllexport assumed.</span></font><p class="MsoNormal" style="margin-left:35.4pt"><font
face="CourierNew" size="1"><span lang="EN-GB" style="font-size:9.0pt;font-family:"Courier New"">warning C4273:
'pg_finfo_add_one_float8': inconsistent dll linkage.  dllexport assumed.</span></font><p class="MsoNormal"
style="margin-left:35.4pt"><fontface="Courier New" size="1"><span lang="EN-GB"
style="font-size:9.0pt;font-family:"CourierNew"">Linking...</span></font><p class="MsoNormal"
style="margin-left:35.4pt"><fontface="Courier New" size="1"><span lang="EN-GB"
style="font-size:9.0pt;font-family:"CourierNew"">LINK : warning LNK4075: ignoring /INCREMENTAL due to /FORCE
specification</span></font><pclass="MsoNormal" style="margin-left:35.4pt"><font face="Courier New" size="1"><span
lang="EN-GB"style="font-size:9.0pt;font-family:"Courier New"">   Creating library Debug/Postgres_dll.lib and object
Debug/Postgres_dll.exp</span></font><pclass="MsoNormal" style="margin-left:35.4pt"><font face="Courier New"
size="1"><spanlang="EN-GB" style="font-size:9.0pt;font-family:"Courier New""> </span></font><p class="MsoNormal"
style="margin-left:35.4pt"><fontface="Courier New" size="1"><span lang="EN-GB"
style="font-size:9.0pt;font-family:"CourierNew"">Postgres_dll.dll - 0 error(s), 3 warning(s)</span></font><p
class="MsoNormal"style="margin-left:35.4pt"><font face="Courier New" size="1"><span lang="EN-GB"
style="font-size:8.0pt;font-family:"CourierNew""> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span
lang="EN-GB"style="font-size: 
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial">The Pg_magic_func is declared in the header file <b><span
style="font-weight:bold">fmgr.h</span></b>,I have checked it but I don’t see any error there. </span></font><p
class="MsoNormal"><fontface="Arial" size="2"><span lang="EN-GB" style="font-size: 
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial">Please, if you could provide me some feedback, I’d be really grateful!!</span></font><p
class="MsoNormal"><fontface="Arial" size="2"><span lang="EN-GB" style="font-size: 
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial">Thanks,</span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:
10.0pt;font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span lang="EN-GB"
style="font-size:10.0pt;font-family:Arial">Aurora</span></font><fontface="Arial" size="2"><span lang="EN-GB"
style="font-size:10.0pt;font-family:Arial"></span></font></div>

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: 8.2 is 30% better in pgbench than 8.3
Следующее
От: "Simon Riggs"
Дата:
Сообщение: Re: 8.2 is 30% better in pgbench than 8.3