Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to view variables with the RECORD type #9

Open
wants to merge 56 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d83fa7a
Print vars
ng-galien Feb 1, 2022
3d60064
Add missing macros
ng-galien Feb 1, 2022
87b09aa
Install instructions
ng-galien Feb 2, 2022
7a6579b
Install formatting
ng-galien Feb 2, 2022
fe84731
Update INSTALL.md
ng-galien Apr 17, 2022
b9f94a6
Update plpgsql_debugger.c
cvas71 Sep 29, 2022
620da21
Merge pull request #1 from cvas71/print-vars
ng-galien Sep 29, 2022
43e6a9b
Merge pull request #2 from ng-galien/print-vars
ng-galien Sep 29, 2022
631d30f
Move files
Sep 29, 2022
f49f85f
Merge branch 'EnterpriseDB:master' into print-vars-dev
ng-galien Sep 29, 2022
977db8a
handle version for var output
Sep 29, 2022
40f24a5
v11 support
Sep 29, 2022
159fc40
Disable RECORD for pg 12
Sep 29, 2022
57333dd
Merge pull request #3 from ng-galien/print-vars-dev
ng-galien Sep 30, 2022
9a49b3b
Update plpgsql_debugger.c
cvas71 Sep 30, 2022
4cce124
print json on record types
Oct 2, 2022
ccecddc
missing include
Oct 2, 2022
65fc4ca
Merge pull request #5 from ng-galien/stringify-records
ng-galien Oct 2, 2022
904f889
Merge pull request #4 from cvas71/print-vars
ng-galien Oct 3, 2022
cf0720f
Merge branch 'stringify-records' into print-vars-dev
Oct 3, 2022
697879b
print recfield name
Oct 3, 2022
8e3122f
Merge pull request #6 from ng-galien/print-vars-dev
ng-galien Oct 4, 2022
6fba139
Add Action to build images
ng-galien Aug 27, 2023
6f2f92b
Checkout print-vars
ng-galien Aug 27, 2023
4f2d55c
Remove inputs
ng-galien Aug 27, 2023
8170d8d
Use of buildx
ng-galien Aug 27, 2023
0c92a19
Fix TAG
ng-galien Aug 27, 2023
b4868c8
Add setup step
ng-galien Aug 27, 2023
9f020ba
Puts version in inputs
ng-galien Aug 27, 2023
8001192
Change action title
ng-galien Aug 27, 2023
560b1a9
Fix platform name
ng-galien Aug 27, 2023
350adb6
Merge pull request #7 from EnterpriseDB/master
ng-galien Aug 27, 2023
a5881a9
Simplified conditions
ng-galien Aug 27, 2023
a4337e9
README
ng-galien Aug 27, 2023
2a877e2
Fix typo
ng-galien Aug 27, 2023
701e6a4
Don't care about manifest
ng-galien Aug 27, 2023
1d0cf98
exlude pg 11
ng-galien Aug 27, 2023
0de7992
Fix multiplatform name
ng-galien Aug 27, 2023
dbbe31f
Fix multi platform
ng-galien Aug 28, 2023
1f75f8a
Fix exclusion
ng-galien Aug 28, 2023
af48347
Step nane
ng-galien Aug 28, 2023
ac00852
Use debian 12
ng-galien Aug 28, 2023
6717cd3
Typo
ng-galien Aug 28, 2023
679a828
Use buildx
ng-galien Aug 28, 2023
92b35b6
Multi image build & Cron
ng-galien Aug 28, 2023
4c053d3
Tags handling
ng-galien Aug 28, 2023
984f01a
Tags
ng-galien Aug 28, 2023
0e332ff
Image tags
ng-galien Aug 28, 2023
f111467
typo
ng-galien Aug 28, 2023
db4a6a8
Github actions
ng-galien Aug 27, 2023
903d858
Merge remote-tracking branch 'origin/print-vars' into print-vars
ng-galien Aug 28, 2023
13326e0
Fix PG 16 compilation
ng-galien Nov 18, 2023
313cf73
Decompose build
ng-galien Nov 18, 2023
f300b46
Fix Debugger install
ng-galien Nov 18, 2023
262482f
Fix missing package
ng-galien Nov 18, 2023
e51c717
Fix image cleaning
ng-galien Nov 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Docker image for multi-arch

on:
workflow_dispatch:
schedule:
#every month the 23rd at 6:23am
- cron: '23 6 23 * *'

env:
PG_IMAGE: postgres-debugger

jobs:
build-and-push:
runs-on: ubuntu-latest
strategy:
matrix:
image:
- bullseye
- bookworm
platform:
- linux/amd64
- linux/amd64,linux/arm64
version:
- 11
- 12
- 13
- 14
- 15
- 16
exclude:
- platform: linux/amd64,linux/arm64
version: 11
- platform: linux/amd64,linux/arm64
version: 12
- platform: linux/amd64,linux/arm64
version: 13
- platform: linux/amd64
version: 14
- platform: linux/amd64
version: 15
- platform: linux/amd64
version: 16

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: print-vars

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push bullseye
if: matrix.image == 'bullseye'
uses: docker/build-push-action@v4
with:
context: docker
platforms: ${{ matrix.platform }}
build-args: |
TAG=${{ matrix.version }}
BASE_IMAGE=${{ matrix.version }}-${{ matrix.image }}
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.PG_IMAGE }}:${{ matrix.version }}-${{ matrix.image }}

- name: Build and push bookworm
if: matrix.image == 'bookworm'
uses: docker/build-push-action@v4
with:
context: docker
platforms: ${{ matrix.platform }}
build-args: |
TAG=${{ matrix.version }}
BASE_IMAGE=${{ matrix.version }}-${{ matrix.image }}
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.PG_IMAGE }}:${{ matrix.version }}-${{ matrix.image }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.PG_IMAGE }}:${{ matrix.version }}


5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.o
*.bc
*.so
.vscode
vcpkg
36 changes: 36 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Install with docker container

Tested with succes with PG 13 & 14
Replace X with your version

## Run docker container
> docker run --name postgres-14-idea-debugger -p 5442:5432 -e POSTGRES_PASSWORD=postgres -d postgres:1X

## Install Postgres and debugger sources

> apt update && apt upgrade

> apt install git build-essential libreadline-dev zlib1g-dev bison libkrb5-dev flex postgresql-server-dev-1X

> cd /usr/src/

> git clone https://github.com/postgres/postgres.git

> cd postgres

> git checkout REL_1X_STABLE

> ./configure

> cd contrib

> git clone https://github.com/ng-galien/pldebugger.git

> cd pldebugger/

> git checkout print-vars

## Install debugger

> make clean && make USE_PGXS=1 && make USE_PGXS=1 install

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
EXTENSION = pldbgapi
MODULE_big = plugin_debugger

OBJS = plpgsql_debugger.o plugin_debugger.o dbgcomm.o pldbgapi.o
OBJS = plpgsql_var.o plpgsql_debugger.o plugin_debugger.o dbgcomm.o pldbgapi.o
ifdef INCLUDE_PACKAGE_SUPPORT
OBJS += spl_debugger.o
endif
Expand Down
33 changes: 33 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Filename: Dockerfile

#POSTGRES IMAGE
ARG BASE_IMAGE=latest
FROM postgres:${BASE_IMAGE}

# SET ENV
ARG TAG
ENV PG_LIB=postgresql-server-dev-${TAG}
ENV PG_BRANCH=REL_${TAG}_STABLE
ENV PLUGIN_BRANCH=print-vars

# APT
RUN apt --yes update \
&& apt --yes upgrade \
&& apt --yes install git build-essential libreadline-dev zlib1g-dev bison libkrb5-dev flex libicu-dev pkg-config $PG_LIB \
&& cd /usr/src/ \
&& git clone --progress -b $PG_BRANCH --single-branch https://github.com/postgres/postgres.git \
&& cd postgres \
&& ./configure \
&& cd /usr/src/postgres/contrib \
&& git clone -b $PLUGIN_BRANCH --single-branch https://github.com/ng-galien/pldebugger.git \
&& cd pldebugger \
&& make clean && make USE_PGXS=1 && make USE_PGXS=1 install \
&& rm -r /usr/src/postgres \
&& apt --yes remove --purge git build-essential libreadline-dev zlib1g-dev bison libkrb5-dev flex libicu-dev pkg-config $PG_LIB \
&& apt --yes autoremove \
&& apt --yes clean

# CONFIG
COPY *.sql /docker-entrypoint-initdb.d/
COPY *.sh /docker-entrypoint-initdb.d/
RUN chmod a+r /docker-entrypoint-initdb.d/*
25 changes: 25 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Docker Image

## Build the image

### Environment variables


* PG_VERSION: PostgreSQL version (from 11 to 16)
* PG_PLATFORM: Target platform, tested on linux/amd64 and linux/arm64 (arm64 is supported from PostgreSQL 14)
* BASE_IMAGE: Image name (11-bookworm, ...)


```bash
export PG_PLATFORM=linux/arm64 \
&& PG_VERSION=16 \
&& export PG_IMAGE=postgres-debugger \
&& export DOCKER_USER=galien0xffffff \
&& export BASE_IMAGE="16-bookworm"
```

### With buildx

```bash
docker buildx build --platform $PG_PLATFORM --build-arg "TAG=$PG_VERSION" --build-arg "BASE_IMAGE=$BASE_IMAGE" -t "$DOCKER_USER/$PG_IMAGE:$PG_VERSION" .
```
3 changes: 3 additions & 0 deletions docker/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

sed -i "s/#shared_preload_libraries = ''/shared_preload_libraries = 'plugin_debugger'/g" /var/lib/postgresql/data/postgresql.conf
132 changes: 77 additions & 55 deletions plpgsql_debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/syscache.h"
#include "utils/lsyscache.h"
#include "utils/datum.h"
#include "utils/rel.h"
#include "miscadmin.h"
#include "funcapi.h"
#include "parser/parse_type.h"

#if INCLUDE_PACKAGE_SUPPORT
#include "spl.h"
Expand All @@ -35,6 +40,7 @@
#endif

#include "pldebugger.h"
#include "plpgsql_var.h"

/* Include header for GETSTRUCT */
#if (PG_VERSION_NUM >= 90300)
Expand Down Expand Up @@ -77,6 +83,8 @@ typedef struct
#endif
} dbg_ctx;

#define NULL_DATUM "NULL"

static void dbg_startup( PLpgSQL_execstate * estate, PLpgSQL_function * func );
static void dbg_newstmt( PLpgSQL_execstate * estate, PLpgSQL_stmt * stmt );
static void initialize_plugin_info( PLpgSQL_execstate * estate, PLpgSQL_function * func );
Expand Down Expand Up @@ -298,82 +306,95 @@ varIsArgument(const PLpgSQL_execstate *estate, PLpgSQL_function *func,
static void
plpgsql_send_vars(ErrorContextCallback *frame)
{
PLpgSQL_execstate *estate = (PLpgSQL_execstate *) frame->arg;
dbg_ctx * dbg_info = (dbg_ctx *) estate->plugin_info;
int i;

PLpgSQL_datum *datum;
PLpgSQL_variable *variable;

Datum datum_value;
Oid typeid;
int32 typetypmod;
bool isNull;
bool isArg;
int i;
StringInfo nameString;
StringInfo valueString;
PLpgSQL_datum_type datumType;

PLpgSQL_execstate *estate = (PLpgSQL_execstate *) frame->arg;
dbg_ctx *dbg_info = (dbg_ctx *) estate->plugin_info;

for( i = 0; i < estate->ndatums; i++ )
{
if( is_var_visible( estate, i ))
{
switch( estate->datums[i]->dtype )
isNull = true;
datum = (PLpgSQL_datum*) estate->datums[i];
variable = (PLpgSQL_variable*) estate->datums[i];
isArg = dbg_info->func->fn_nargs > 0 && i < dbg_info->func->fn_nargs;
datumType = estate->datums[i]->dtype;
switch( datumType )
{
#if (PG_VERSION_NUM >= 110000)
case PLPGSQL_DTYPE_PROMISE:
#endif
case PLPGSQL_DTYPE_VAR:
{
PLpgSQL_var * var = (PLpgSQL_var *) estate->datums[i];
char * val;
char * name = var->refname;
bool isArg;

isArg = varIsArgument(estate, dbg_info->func, i, &name);

if( datumIsNull((PLpgSQL_datum *)var ))
val = "NULL";
else
val = get_text_val( var, NULL, NULL );

dbg_send( "%s:%c:%d:%c:%c:%c:%d:%s",
name,
isArg ? 'A' : 'L',
var->lineno,
dbg_info->symbols[i].duplicate_name ? 'f' : 't',
var->isconst ? 't':'f',
var->notnull ? 't':'f',
var->datatype ? var->datatype->typoid : InvalidOid,
val );

break;
}
#if 0
FIXME: implement other types

case PLPGSQL_DTYPE_REC:
{
PLpgSQL_rec * rec = (PLpgSQL_rec *) estate->datums[i];
int att;
char * typeName;

if (rec->tupdesc != NULL)
{
for( att = 0; att < rec->tupdesc->natts; ++att )
{
typeName = SPI_gettype( rec->tupdesc, att + 1 );

dbg_send( "o:%s.%s:%d:%d:%d:%d:%s\n",
rec->refname, NameStr( rec->tupdesc->attrs[att]->attname ),
0, rec->lineno, 0, rec->tupdesc->attrs[att]->attnotnull, typeName ? typeName : "" );

if( typeName )
pfree( typeName );
}
}
break;
}
#endif
case PLPGSQL_DTYPE_ROW:
#endif
#if (PG_VERSION_NUM >= 130000)
case PLPGSQL_DTYPE_REC:
case PLPGSQL_DTYPE_RECFIELD:
#endif

#if (PG_VERSION_NUM < 140000)
case PLPGSQL_DTYPE_ARRAYELEM:
#endif
#if (PG_VERSION_NUM < 110000)
case PLPGSQL_DTYPE_EXPR:
#endif
{
/* FIXME: implement other types */

exec_eval_datum(estate, datum, &typeid, &typetypmod, &datum_value, &isNull);

valueString = makeStringInfo();
nameString = makeStringInfo();

if (isNull)
{
appendStringInfoString(valueString, NULL_DATUM);
}
else
{
print_datum(valueString, estate, datum_value, typeid);
}

if (datumType == PLPGSQL_DTYPE_RECFIELD)
{
appendStringInfo(nameString, "%s.%s",
((PLpgSQL_rec *) (estate->datums[((PLpgSQL_recfield *) datum)->recparentno]))->refname,
variable->refname);
}
else
{
appendStringInfoString(nameString, variable->refname);
}

dbg_send("%s:%c:%d:%c:%c:%c:%d:%s",
nameString->data,
isArg ? 'A' : 'L',
variable->lineno,
dbg_info->symbols[i].duplicate_name ? 'f' : 't',
variable->isconst ? 't':'f',
variable->notnull ? 't':'f',
typeid,
valueString->data);

pfree(valueString);
pfree(nameString);

break;
}
default: {
break;
}
}
Expand Down Expand Up @@ -1531,3 +1552,4 @@ datumIsNull(PLpgSQL_datum *datum)

return false;
}

Loading