infoCodeList = infos.stream().filter(item -> item.lineno != null).collect(Collectors.toList());
+ StringBuffer buffer = new StringBuffer();
+ infoCodeList.forEach(infoItem -> {
+ if (!infoItem.query.endsWith("\n")) {
+ infoItem.query = infoItem.query + "\n";
+ }
+ buffer.append(infoItem.query);
+ });
+ SourceCodeVo sourceCodeVo = new SourceCodeVo();
+ sourceCodeVo.setCodes(infoCodeList);
+ sourceCodeVo.setSourceCode(buffer.toString());
+ return (T) sourceCodeVo;
+ }
+
+ private static boolean getConvert(String version) {
+ return DebugConstants.DBE_DEBUGGER.equalsIgnoreCase(version);
+ }
+}
diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/VersionHelper.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/VersionHelper.java
new file mode 100644
index 0000000000000000000000000000000000000000..3daaa6c4069e850f9430e44bf9804cac241b2630
--- /dev/null
+++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/VersionHelper.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2022 Huawei Technologies Co.,Ltd.
+ *
+ * openGauss is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ *
+ * http://license.coscl.org.cn/MulanPSL2
+ *
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+package org.opengauss.mppdbide.common;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.opengauss.mppdbide.debuger.debug.DebugConstants;
+import org.opengauss.mppdbide.debuger.debug.DebugConstants.DebugOpt;
+import org.opengauss.mppdbide.debuger.vo.VersionVo;
+import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility;
+
+/**
+ * Title: class
+ *
+ * Description: check version.
+ *
+ * @since 3.0.0
+ */
+public class VersionHelper {
+ /**
+ * Description: get openGauss debugger version
+ *
+ * @param serverConn database connection
+ * @return pl_debugger or dbe_debugger
+ * @throws SQLException the exception
+ */
+ public static VersionVo getDebuggerVersion(IConnection serverConn) throws SQLException {
+ if (serverConn == null) {
+ throw new SQLException("serverConn is null!");
+ }
+ String sql = DebugConstants.getDbVersionSql();
+ VersionVo versionVo = new VersionVo();
+ try (PreparedStatement ps = serverConn.getStatement(sql)) {
+ try (ResultSet rs = ps.executeQuery()) {
+ if (rs.next()) {
+ // (openGauss 2.1.0 build 590b0f8e) openGauss version info
+ String version = rs.getObject(1).toString();
+ MPPDBIDELoggerUtility.debug("openGauss db info version:" + version);
+ versionVo.version = version;
+ }
+ MPPDBIDELoggerUtility.debug("openGauss db info is empty!");
+ return versionVo;
+ }
+ }
+ }
+
+ /**
+ * Description: get getDebugOptByDebuggerVersion
+ *
+ * @param serverConn database connection
+ * @param debugOpt param
+ * @return the return value
+ * @throws SQLException the exception
+ */
+ public static DebugOpt getDebugOptByDebuggerVersion(IConnection serverConn, DebugOpt debugOpt) throws SQLException {
+ if (serverConn == null) {
+ return debugOpt;
+ }
+ VersionVo versionVo = getDebuggerVersion(serverConn);
+ DebugOpt res = DebugConstants.getDebugOptByDebuggerVersion(debugOpt, versionVo.getDebuggerVersion());
+ if (res == null) {
+ return debugOpt;
+ }
+ return res;
+ }
+}
diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/debug/DebugConstants.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/debug/DebugConstants.java
index 8e28d5218d2c168aee52829c67bb63d46389b188..632036efdfc11fd47bed27a25357792201dcbfdd 100644
--- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/debug/DebugConstants.java
+++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/debug/DebugConstants.java
@@ -15,7 +15,10 @@
package org.opengauss.mppdbide.debuger.debug;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Locale;
+import java.util.Map;
import java.util.stream.Stream;
/**
@@ -29,13 +32,99 @@ public class DebugConstants {
*/
public static final int DEFAULT_STRING_BUILD_LEN = 128;
+ /**
+ * default PL_DEBUGGER name
+ */
+ public static final String PL_DEBUGGER = "pl_debugger";
+
+ /**
+ * default DBE_DEBUGGER name
+ */
+ public static final String DBE_DEBUGGER = "dbe_debugger";
+
+ /**
+ * default version
+ */
+ public static final Integer DBE_DEBUGGER_MIN_VERSION = 300;
+
+ /**
+ * enumMap
+ */
+ public static final LinkedHashMap ENUM_MAP = getEnumMap(DebugOpt.class);
+
+ /**
+ * store dataType
+ */
+ private static final Map DATA_TYPE = new HashMap<>();
+
+ /**
+ * dataTypes
+ */
+ static {
+ DATA_TYPE.put("bpchar", "char");
+ DATA_TYPE.put("bool", "boolean");
+ DATA_TYPE.put("float", "binary double");
+ DATA_TYPE.put("int2", "smallint");
+ DATA_TYPE.put("int4", "integer");
+ DATA_TYPE.put("int8", "bigint");
+ DATA_TYPE.put("float8", "double precision");
+ DATA_TYPE.put("float4", "real");
+ DATA_TYPE.put("timetz", "time with time zone");
+ DATA_TYPE.put("timestamptz", "timestamp with time zone");
+ DATA_TYPE.put("time", "time without time zone");
+ DATA_TYPE.put("bpchar", "timestamp");
+ }
+
+ /**
+ * getDataType
+ *
+ * @param data dataType
+ * @return the data type string
+ */
+ public static String getDataType(String data) {
+ return DATA_TYPE.get(data);
+ }
+
+ /**
+ * get DebugOpt by different debugger
+ *
+ * @param debugOpt the debugOpt
+ * @param debuggerVersion the version
+ * @return DebugOpt the return value
+ */
+ public static DebugOpt getDebugOptByDebuggerVersion(DebugOpt debugOpt, String debuggerVersion) {
+ if (PL_DEBUGGER.equalsIgnoreCase(debuggerVersion)) {
+ return debugOpt;
+ } else {
+ String optName = debugOpt.name();
+ optName = "DBE_" + optName;
+ return ENUM_MAP.get(optName);
+ }
+ }
+
+ /**
+ * get name and all enum map
+ *
+ * @param
+ * @param enumClass the enumclass
+ * @return LinkedHashMap
+ */
+ public static > LinkedHashMap getEnumMap(final Class enumClass) {
+ final LinkedHashMap map = new LinkedHashMap<>();
+ for (final E e : enumClass.getEnumConstants()) {
+ map.put(e.name(), e);
+ }
+ return map;
+ }
+
/**
* Title: the DebugOpt enum use to descript debuger interface
*/
public static enum DebugOpt {
+ // pldebugger command
DEBUG_ON("pldbg_on", 0),
DEBUG_OFF("pldbg_off", 0),
- DEBUG_VERSION("pldbg_get_proxy_info", 0),
+ DEBUG_VERSION("version", 0),
GET_SOURCE_CODE("pldbg_get_source", 1),
GET_TOTAL_SOURCE_CODE("pg_get_functiondef", 1),
START_SESSION("plpgsql_oid_debug", 1),
@@ -49,7 +138,29 @@ public class DebugConstants {
GET_STACKS("pldbg_get_stack", 1),
GET_BREAKPOINTS("pldbg_get_breakpoints", 1),
DROP_BREAKPOINT("pldbg_drop_breakpoint", 3),
- SET_BREAKPOINT("pldbg_set_breakpoint", 3);
+ SET_BREAKPOINT("pldbg_set_breakpoint", 3),
+ // dbe_debugger command
+ DBE_DEBUG_ON("DBE_PLDEBUGGER.turn_on", 1),
+ DBE_DEBUG_OFF("DBE_PLDEBUGGER.turn_off", 1),
+ DBE_DEBUG_VERSION("version", 0),
+ DBE_GET_SOURCE_CODE("DBE_PLDEBUGGER.info_code", 1),
+ DBE_GET_TOTAL_SOURCE_CODE("pg_get_functiondef", 1),
+ DBE_START_SESSION("DBE_PLDEBUGGER.turn_on", 1),
+ DBE_ATTACH_SESSION("DBE_PLDEBUGGER.attach", 2),
+ DBE_STEP_INTO("DBE_PLDEBUGGER.step", 1),
+ DBE_STEP_OVER("DBE_PLDEBUGGER.next", 0),
+ DBE_STEP_OUT("pldbg_step_out", 1),
+ DBE_CONTINUE_EXEC("DBE_PLDEBUGGER.continue", 0),
+ DBE_ABORT_TARGET("DBE_PLDEBUGGER.abort", 0),
+ DBE_GET_VARIABLES("DBE_PLDEBUGGER.print_var", 1),
+ DBE_GET_STACKS("DBE_PLDEBUGGER.backtrace", 0),
+ DBE_GET_BREAKPOINTS("DBE_PLDEBUGGER.info_breakpoints", 0),
+ DBE_DROP_BREAKPOINT("DBE_PLDEBUGGER.delete_breakpoint", 1),
+ DBE_SET_BREAKPOINT("DBE_PLDEBUGGER.add_breakpoint", 2),
+ DBE_REMARK_INFO_SET("DBE_PLDEBUGGER.remark_info_set", 2),
+ DBE_REMARK_INFO_GET("DBE_PLDEBUGGER.remark_info_get", 1),
+ DBE_COVERAGE_INFO_GET("DBE_PLDEBUGGER.coverage_info_get", 1),
+ DBE_COVERAGE_INFO_DEL("DBE_PLDEBUGGER.coverage_info_del", 2);
/**
* opt of interface
@@ -95,4 +206,13 @@ public class DebugConstants {
paramReplace
);
}
+
+ /**
+ * get openGauss db version sql
+ *
+ * @return String query sql
+ */
+ public static String getDbVersionSql() {
+ return "select version()";
+ }
}
diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/BreakPointHandle.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/BreakPointHandle.java
new file mode 100644
index 0000000000000000000000000000000000000000..c78df5292452d4edc2c56fb63504b960d2319136
--- /dev/null
+++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/BreakPointHandle.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2022 Huawei Technologies Co.,Ltd.
+ *
+ * openGauss is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ *
+ * http://license.coscl.org.cn/MulanPSL2
+ *
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+package org.opengauss.mppdbide.debuger.service;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opengauss.mppdbide.debuger.annotation.ParseVo;
+import org.opengauss.mppdbide.debuger.vo.PositionVo;
+import org.opengauss.mppdbide.debuger.vo.dbe.InfoBreakPointsVo;
+
+/**
+ * Description: BreakPointHandle
+ *
+ * @since 3.0.0
+ */
+public class BreakPointHandle implements IQueryResConvertService {
+ /**
+ * covertList
+ *
+ * @param rs the rs
+ * @param
+ * @return the return value
+ * @throws SQLException the SQL exception
+ */
+ @Override
+ public List covertList(ResultSet rs) throws SQLException {
+ List list = new ArrayList();
+ List infos = ParseVo.parseList(rs, InfoBreakPointsVo.class);
+ infos.forEach(item -> {
+ PositionVo vo = new PositionVo();
+ vo.func = item.funcoid;
+ vo.linenumber = item.lineno;
+ vo.breakpointno = item.breakpointno;
+ list.add((T) vo);
+ });
+ return list;
+ }
+}
diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/BreakPointListHandle.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/BreakPointListHandle.java
new file mode 100644
index 0000000000000000000000000000000000000000..fac81825b58a9c2db4e6715fdc7fbfaa69baf64d
--- /dev/null
+++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/BreakPointListHandle.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2022 Huawei Technologies Co.,Ltd.
+ *
+ * openGauss is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ *
+ * http://license.coscl.org.cn/MulanPSL2
+ *
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+package org.opengauss.mppdbide.debuger.service;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opengauss.mppdbide.debuger.annotation.ParseVo;
+import org.opengauss.mppdbide.debuger.vo.BreakPointListVo;
+
+/**
+ * Description: BreakPointListHandle
+ *
+ * @since 3.0.0
+ */
+public class BreakPointListHandle implements IQueryResConvertService {
+ /**
+ * covertList
+ *
+ * @param rs the rs
+ * @param
+ * @return the return value
+ * @throws SQLException the SQL exception
+ */
+ @Override
+ public List covertList(ResultSet rs) throws SQLException {
+ List list = new ArrayList();
+ List pointList = ParseVo.parseList(rs, BreakPointListVo.class);
+ pointList.forEach(item -> {
+ BreakPointListVo breakPointListVo = new BreakPointListVo();
+ breakPointListVo.breakpointno = item.breakpointno;
+ breakPointListVo.enable = item.enable;
+ breakPointListVo.funcoid = item.funcoid;
+ breakPointListVo.lineno = item.lineno;
+ breakPointListVo.query = item.query;
+ list.add((T) breakPointListVo);
+ });
+ return list;
+ }
+}
diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DbeDebugService.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DbeDebugService.java
new file mode 100644
index 0000000000000000000000000000000000000000..9dda765b60336ffa9ee728f18cd267ee5dd82efd
--- /dev/null
+++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DbeDebugService.java
@@ -0,0 +1,413 @@
+/*
+ * Copyright (c) 2022 Huawei Technologies Co.,Ltd.
+ *
+ * openGauss is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ *
+ * http://license.coscl.org.cn/MulanPSL2
+ *
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ */
+
+package org.opengauss.mppdbide.debuger.service;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.opengauss.mppdbide.common.QueryResVoConvertHelper;
+import org.opengauss.mppdbide.common.VersionHelper;
+import org.opengauss.mppdbide.debuger.annotation.ParseVo;
+import org.opengauss.mppdbide.debuger.debug.DebugConstants;
+import org.opengauss.mppdbide.debuger.debug.DebugConstants.DebugOpt;
+import org.opengauss.mppdbide.debuger.exception.DebugExitException;
+import org.opengauss.mppdbide.debuger.vo.BreakPointListVo;
+import org.opengauss.mppdbide.debuger.vo.PositionVo;
+import org.opengauss.mppdbide.debuger.vo.StackVo;
+import org.opengauss.mppdbide.debuger.vo.VariableVo;
+import org.opengauss.mppdbide.debuger.vo.dbe.AttachVo;
+import org.opengauss.mppdbide.debuger.vo.dbe.TurnOnVo;
+import org.opengauss.mppdbide.utils.DebuggerStartVariable;
+import org.opengauss.mppdbide.utils.VariableRunLine;
+import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility;
+import org.opengauss.mppdbide.utils.vo.DebuggerStartInfoVo;
+
+/**
+ * Title: the DbeDebugService class
+ *
+ * @since 3.0.0
+ */
+public class DbeDebugService extends DebugService {
+ /**
+ * save parameters
+ */
+ public static final Map> map = new ConcurrentHashMap<>();
+
+ private TurnOnVo turnOnVo = null;
+ private DebuggerReportService reportService = DebuggerReportService.getInstance();
+
+ /**
+ * prepare to debug
+ *
+ * @return void
+ * @throws SQLException the exp
+ */
+ @Override
+ public void prepareDebug() throws SQLException {
+ List