Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 53ef6c4

Browse files
committed
Expose a few more PL/pgSQL functions to debugger plugins.
Add exec_assign_value, exec_eval_datum, and exec_cast_value to the set of functions a PL/pgSQL debugger plugin can conveniently call. This allows more convenient manipulation of the values of PL/pgSQL function variables. Pavel Stehule, reviewed by Aleksander Alekseev and myself Discussion: https://postgr.es/m/CAFj8pRD+dBPU0T-KrkP7ef6QNPDEsjYCejEsBe07NDq8TybOkA@mail.gmail.com
1 parent 9f91344 commit 53ef6c4

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/pl/plpgsql/src/pl_exec.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4077,15 +4077,18 @@ plpgsql_estate_setup(PLpgSQL_execstate *estate,
40774077
plpgsql_create_econtext(estate);
40784078

40794079
/*
4080-
* Let the plugin see this function before we initialize any local
4081-
* PL/pgSQL variables - note that we also give the plugin a few function
4082-
* pointers so it can call back into PL/pgSQL for doing things like
4083-
* variable assignments and stack traces
4080+
* Let the plugin, if any, see this function before we initialize local
4081+
* PL/pgSQL variables. Note that we also give the plugin a few function
4082+
* pointers, so it can call back into PL/pgSQL for doing things like
4083+
* variable assignments and stack traces.
40844084
*/
40854085
if (*plpgsql_plugin_ptr)
40864086
{
40874087
(*plpgsql_plugin_ptr)->error_callback = plpgsql_exec_error_callback;
40884088
(*plpgsql_plugin_ptr)->assign_expr = exec_assign_expr;
4089+
(*plpgsql_plugin_ptr)->assign_value = exec_assign_value;
4090+
(*plpgsql_plugin_ptr)->eval_datum = exec_eval_datum;
4091+
(*plpgsql_plugin_ptr)->cast_value = exec_cast_value;
40894092

40904093
if ((*plpgsql_plugin_ptr)->func_setup)
40914094
((*plpgsql_plugin_ptr)->func_setup) (estate, func);

src/pl/plpgsql/src/plpgsql.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,9 +1120,17 @@ typedef struct PLpgSQL_execstate
11201120
* statement.
11211121
*
11221122
* Also, immediately before any call to func_setup, PL/pgSQL fills in the
1123-
* error_callback and assign_expr fields with pointers to its own
1124-
* plpgsql_exec_error_callback and exec_assign_expr functions. This is
1125-
* a somewhat ad-hoc expedient to simplify life for debugger plugins.
1123+
* remaining fields with pointers to some of its own functions, allowing the
1124+
* plugin to invoke those functions conveniently. The exposed functions are:
1125+
* plpgsql_exec_error_callback
1126+
* exec_assign_expr
1127+
* exec_assign_value
1128+
* exec_eval_datum
1129+
* exec_cast_value
1130+
* (plpgsql_exec_error_callback is not actually meant to be called by the
1131+
* plugin, but rather to allow it to identify PL/pgSQL error context stack
1132+
* frames. The others are useful for debugger-like plugins to examine and
1133+
* set variables.)
11261134
*/
11271135
typedef struct PLpgSQL_plugin
11281136
{
@@ -1135,8 +1143,20 @@ typedef struct PLpgSQL_plugin
11351143

11361144
/* Function pointers set by PL/pgSQL itself */
11371145
void (*error_callback) (void *arg);
1138-
void (*assign_expr) (PLpgSQL_execstate *estate, PLpgSQL_datum *target,
1146+
void (*assign_expr) (PLpgSQL_execstate *estate,
1147+
PLpgSQL_datum *target,
11391148
PLpgSQL_expr *expr);
1149+
void (*assign_value) (PLpgSQL_execstate *estate,
1150+
PLpgSQL_datum *target,
1151+
Datum value, bool isNull,
1152+
Oid valtype, int32 valtypmod);
1153+
void (*eval_datum) (PLpgSQL_execstate *estate, PLpgSQL_datum *datum,
1154+
Oid *typeid, int32 *typetypmod,
1155+
Datum *value, bool *isnull);
1156+
Datum (*cast_value) (PLpgSQL_execstate *estate,
1157+
Datum value, bool *isnull,
1158+
Oid valtype, int32 valtypmod,
1159+
Oid reqtype, int32 reqtypmod);
11401160
} PLpgSQL_plugin;
11411161

11421162
/*

0 commit comments

Comments
 (0)