Re: debugging C functions - Mailing list pgsql-general

From Islam Hegazy
Subject Re: debugging C functions
Date
Msg-id 063501c7a6eb$42f1d9a0$0d0e9f88@pc.cpsc.ucalgary.ca
Whole thread Raw
In response to debugging C functions  ("Islam Hegazy" <islheg@gawab.com>)
List pgsql-general
It worked today with me and I discovered what is the problem. The problem is
that I have 2 structures that contain pointers. I inistiate variables from
these structures as static. I can't declare the pointers inside the struct
as static. Now the problem is that when the function is called a second
time, it returns set of records, it finds the static pointers in the
function but the pointers inside the struct are deleted. Here is a portion
of the code:

typedef struct

{

int value;

struct TuplesList *next;

}TuplesList;

typedef struct

{

TuplesList *tuplesHead;

TuplesList *tuplesTail;

struct AggrQuery *nextQuery;

}AggrQuery;



Datum AggrFn(PG_FUNCTION_ARGS)

{

    static AggrQuery *queriesHead;

    static AggrQuery *queriesTail;

}

First call to AggrFn is correct, in the second call queriesHead and
queriesTail are preserved but queriesHead->tuplesHead, for example, is
rubbish from memory. I read in the PostgreSQL documentation 'However, if you
want to allocate any data structures to live across calls, you need to put
them somewhere else. The memory context referenced by multi_call_memory_ctx
is a suitable location for any data that needs to survive until the SRF is
finished running'. I don't understand this statement so I created the
variables as static but it is not working with struct....

Regards

Islam Hegazy



----- Original Message -----
From: "Gregory Stark" <stark@enterprisedb.com>
To: "Islam Hegazy" <islheg@gawab.com>
Cc: "Tom Lane" <tgl@sss.pgh.pa.us>; "Joe Conway" <mail@joeconway.com>;
<pgsql-general@postgresql.org>
Sent: Monday, June 04, 2007 5:50 AM
Subject: Re: [GENERAL] debugging C functions


> "Islam Hegazy" <islheg@gawab.com> writes:
>
>> I do the same but I use the ddd debugger
>> 1) Load the shared library from the SQL
>> 2) Open the .c file of my function
>> 3) Place the break points
>> 4) Execute the sql statement 'Select * from Myfn(...);'
>>
>> The result is displayed and the debugger doesn't stop at the breakpoints.
>
> Are you sure you're attaching to the right process?
>
> One way to do it is to run select pg_backend_pid() from psql and attach to
> that pid.
>
> --
>  Gregory Stark
>  EnterpriseDB          http://www.enterprisedb.com
>


pgsql-general by date:

Previous
From: Jeff Davis
Date:
Subject: Re: Partitioning (was Re: Slightly OT.)
Next
From: "Simon Riggs"
Date:
Subject: Re: PITR Base Backup on an idle 8.1 server