Skip to content

Commit

Permalink
Add some support for multiple PL languages in the same plugin
Browse files Browse the repository at this point in the history
Right now this only benefits EnterpriseDB's SPL support, as it can now be
built into the same .so file, and you can see SPL and PL/pgSQL stack frames
simultaneously in the debugger. But this could be expanded to support e.g
plperl or plpython. Even if you wouldn't allow setting breakpoints and
stepping perl or python code, you could at least display functions written
in those languages in the call stack.
  • Loading branch information
hlinnaka committed Apr 19, 2012
1 parent bfa77b3 commit 323cffa
Show file tree
Hide file tree
Showing 4 changed files with 732 additions and 560 deletions.
21 changes: 10 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ include $(top_srcdir)/src/Makefile.shlib
all: all-lib
endif # PLUGIN_big


ifeq ($(PORTNAME), win32)
SHLIB_LINK += -lwsock32
SYMLINKCMD = cp
else
SYMLINKCMD = ln -s
endif

ifeq ($(PORTNAME), win32)
override CFLAGS += $(CFLAGS_SL) -I$(top_builddir)/src/pl/plpgsql/src
else
Expand All @@ -88,7 +80,7 @@ install-plugins: installdir-plugins $(addsuffix $(DLSUFFIX), $(PLUGIN_big))
$(INSTALL_SHLIB) $(addsuffix $(DLSUFFIX), $(PLUGIN_big)) '$(DESTDIR)$(pkglibdir)/plugins/'

clean-plugins:
rm -f $(addsuffix $(DLSUFFIX), $(PLUGIN_big)) $(PLUGIN_OBJS)
rm -f $(addsuffix $(DLSUFFIX), $(PLUGIN_big)) $(PLUGIN_OBJS) spl_debugger.c

uninstall-plugins:
rm -f $(addprefix '$(DESTDIR)$(pkglibdir)'/plugins/, $(addsuffix $(DLSUFFIX), $(PLUGIN_big)))
Expand All @@ -110,15 +102,22 @@ plpgsql_debugger.o: CFLAGS += -I$(top_builddir)/src/pl/plpgsql/src
## debugger module for the SPL language. It's pretty much the same as the
## PL/pgSQL one, but the structs have some extra fields and are thus not
## binary-compatible. We make a copy of the .c file, and pass the
## INCLUDE_PACKAGE_SUPPORT=1 flag to compile it against SPL instead of PL/pgSQL
## INCLUDE_PACKAGE_SUPPORT=1 flag to compile it against SPL instead of PL/pgSQL.
##
## To make debugging the debugger itself simpler, all the functions are
## mechanically renamed from plpgsql_* to spl_*.
##
## To enable this, you need to run make as "make INCLUDE_PACKAGE_SUPPORT=1"
##
ifdef INCLUDE_PACKAGE_SUPPORT
spl_debugger.c: plpgsql_debugger.c
$(SYMLINKCMD) $(module_srcdir)plpgsql_debugger.c spl_debugger.c
sed -e 's/plpgsql_/spl_/g' $(module_srcdir)plpgsql_debugger.c > spl_debugger.c

spl_debugger.o: CFLAGS += -DINCLUDE_PACKAGE_SUPPORT=1 -I$(top_builddir)/src/pl/edb-spl/src

# There's some tiny differences in plugin_debugger.c, if we're including SPL
# language. Pass the INCLUDE_PACKAGE_SUPPORT flag to plugin_debugger.c too.
plugin_debugger.o: CFLAGS += -DINCLUDE_PACKAGE_SUPPORT=1
endif

################################################################################
Expand Down
22 changes: 21 additions & 1 deletion pldebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,23 @@ extern errorHandlerCtx client_lost;
#define PLDBG_RESTART 'r'
#define PLDBG_STOP 'x'

typedef struct
{
void (* initialize)(void);
bool (* frame_belongs_to_me)(ErrorContextCallback *frame);
void (* send_stack_frame)(ErrorContextCallback *frame);
void (* send_vars)(ErrorContextCallback *frame);
void (* select_frame)(ErrorContextCallback *frame);
void (* print_var)(ErrorContextCallback *frame, const char *var_name, int lineno);
bool (* do_deposit)(ErrorContextCallback *frame, const char *var_name,
int line_number, const char *value);
Oid (* get_func_oid)(ErrorContextCallback *frame);
void (* send_cur_line)(ErrorContextCallback *frame);
} debugger_language_t;

/* in plugin_debugger.c */
extern bool plugin_debugger_main_loop(void);

extern bool breakAtThisLine( Breakpoint ** dst, eBreakpointScope * scope, Oid funcOid, int lineNumber );
extern bool attach_to_proxy( Breakpoint * breakpoint );
extern char * findSource( Oid oid, HeapTuple * tup );
Expand All @@ -71,7 +87,11 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)))
extern char * dbg_read_str(void);

/* in plpgsql_debugger.c */
extern void plpgsql_debugger_init(void);
extern void plpgsql_debugger_fini(void);

extern debugger_language_t plpgsql_debugger_lang;
#ifdef INCLUDE_PACKAGE_SUPPORT
extern debugger_language_t spl_debugger_lang;
#endif

#endif
Loading

0 comments on commit 323cffa

Please sign in to comment.