!4189 修复无attach可进入调试流程&报错信息修改

Merge pull request !4189 from 李秦朗/client_id
This commit is contained in:
opengauss_bot
2023-09-21 12:26:26 +00:00
committed by Gitee
7 changed files with 87 additions and 25 deletions

View File

@ -743,11 +743,11 @@ void clean_up_debug_client(bool hasError)
DebugClientInfo* client = u_sess->plsql_cxt.debug_client;
/* clean comm idx*/
if (client->comm_idx < PG_MAX_DEBUG_CONN && client->comm_idx >= 0) {
uint64 clientSessionId = ENABLE_THREAD_POOL ? u_sess->session_id : t_thrd.proc_cxt.MyProcPid;
PlDebuggerComm* debug_comm = &g_instance.pldebug_cxt.debug_comm[client->comm_idx];
AutoMutexLock debuglock(&debug_comm->mutex);
debuglock.lock();
if (debug_comm->hasClient() &&
(debug_comm->clientId == u_sess->session_id || debug_comm->clientId == t_thrd.proc_cxt.MyProcPid)) {
if (debug_comm->hasClient() && debug_comm->clientId == clientSessionId) {
/* only wake up server for error when it's not recevied server error */
if (hasError && debug_comm->IsServerWaited && !debug_comm->hasServerErrorOccured) {
debug_comm->hasClientErrorOccured = true;

View File

@ -331,8 +331,14 @@ static Datum get_info_local_data(const char* var_name, const int frameno, Functi
*/
Datum debug_client_info_code(PG_FUNCTION_ARGS)
{
InterfaceCheck("info_code", false);
Oid funcid = PG_GETARG_OID(0);
/*
* Anonymous block debugging call info_code() needs to get
* information from the server, so set needAttach to TRUE
* Procedure and function get information from system table,
* info_code() can be called at any time, so set needAttach to FALSE.
*/
InterfaceCheck("info_code", !OidIsValid(funcid));
const int DEBUG_LOCAL_VAR_TUPLE_ATTR_NUM = 3;
@ -493,7 +499,7 @@ Datum debug_client_add_breakpoint(PG_FUNCTION_ARGS)
lines = debug_show_code_worker(funcOid, &nLine, &headerlines);
if (lineno < 1 || (uint32)lineno > nLine - headerlines) {
ereport(WARNING, (errcode(ERRCODE_WARNING),
errmsg("lineno must be within the range of [1, MaxLineNumber]"
errmsg("lineno must be within the range of [1, MaxLineNumber]."
" Please use dbe_pldebugger.info_code for valid breakpoint candidates")));
PG_RETURN_INT32(-1);
}
@ -523,7 +529,7 @@ Datum debug_client_add_breakpoint(PG_FUNCTION_ARGS)
PG_RETURN_INT32(-1);
} else if (ans == ADD_BP_ERR_OUT_OF_RANGE) {
ereport(WARNING, (errcode(ERRCODE_WARNING),
errmsg("lineno must be within the range of [1, MaxLineNumber]"
errmsg("lineno must be within the range of [1, MaxLineNumber]."
" Please use dbe_pldebugger.info_code for valid breakpoint candidates")));
PG_RETURN_INT32(-1);
} else if (ans == ADD_BP_ERR_INVALID_BP_POS) {
@ -564,7 +570,7 @@ Datum debug_client_delete_breakpoint(PG_FUNCTION_ARGS)
error:
ereport(ERROR,
(errmodule(MOD_PLDEBUGGER), errcode(ERRCODE_AMBIGUOUS_PARAMETER),
errmsg("invalid break point index"),
errmsg("invalid breakpoint index"),
errdetail("the given index is either outside the range or already deleted"),
errcause("try to delete a breakpoint that's never added"),
erraction("use dbe_pldebugger.info_breakpoints() to show all valid breakpoints")));
@ -600,7 +606,7 @@ Datum debug_client_enable_breakpoint(PG_FUNCTION_ARGS)
error:
ereport(ERROR,
(errmodule(MOD_PLDEBUGGER), errcode(ERRCODE_AMBIGUOUS_PARAMETER),
errmsg("invalid break point index"),
errmsg("invalid breakpoint index"),
errdetail("the given index is either outside the range or already enabled"),
errcause("try to enable a breakpoint that's already enabled"),
erraction("use dbe_pldebugger.info_breakpoints() to show all breakpoints")));
@ -636,7 +642,7 @@ Datum debug_client_disable_breakpoint(PG_FUNCTION_ARGS)
error:
ereport(ERROR,
(errmodule(MOD_PLDEBUGGER), errcode(ERRCODE_AMBIGUOUS_PARAMETER),
errmsg("invalid break point index"),
errmsg("invalid breakpoint index"),
errdetail("the given index is either outside the range or already disabled"),
errcause("try to disabled a breakpoint that's already disabled"),
erraction("use dbe_pldebugger.info_breakpoints() to show all breakpoints")));
@ -951,7 +957,7 @@ Datum debug_server_turn_off(PG_FUNCTION_ARGS)
PlDebugEntry* entry = has_debug_func(funcOid, &found);
if (!found) {
ereport(WARNING, (errmodule(MOD_PLDEBUGGER),
errmsg("function %d has not be turned on", funcOid)));
errmsg("function %d has not been turned on", funcOid)));
} else {
if (entry->func && entry->func->debug) {
clean_up_debug_server(entry->func->debug, false, false);
@ -1018,12 +1024,12 @@ static void InterfaceCheck(const char* funcname, bool needAttach)
int commIdx = u_sess->plsql_cxt.debug_client->comm_idx;
CHECK_DEBUG_COMM_VALID(commIdx);
/* if current debug index is not myself during debug, clean up my self */
uint64 clientSessionId = ENABLE_THREAD_POOL ? u_sess->session_id : t_thrd.proc_cxt.MyProcPid;
PlDebuggerComm* debug_comm = &g_instance.pldebug_cxt.debug_comm[commIdx];
DebugClientInfo* client = u_sess->plsql_cxt.debug_client;
AutoMutexLock debuglock(&debug_comm->mutex);
debuglock.lock();
if ((debug_comm->clientId != u_sess->session_id && debug_comm->clientId != t_thrd.proc_cxt.MyProcPid) ||
!debug_comm->isRunning()) {
if (debug_comm->clientId != clientSessionId || !debug_comm->isRunning()) {
client->comm_idx = -1;
MemoryContextDelete(client->context);
u_sess->plsql_cxt.debug_client = NULL;
@ -1088,7 +1094,7 @@ static PlDebugEntry* add_debug_func(Oid key)
} else {
ReleaseDebugCommIdx(commIdx);
ereport(ERROR, (errmodule(MOD_PLDEBUGGER),
errmsg("function %d has already be turned on", key)));
errmsg("function %d has already been turned on", key)));
}
return entry;
}

View File

@ -1576,7 +1576,7 @@ const int DEBUG_SERVER_PRINT_VAR_FRAMENO_EXCEED = 1;
if (!g_instance.pldebug_cxt.debug_comm[idx].Used()) \
ereport(ERROR, \
(errmodule(MOD_PLDEBUGGER), errcode(ERRCODE_PLDEBUGGER_ERROR), \
errmsg("Debug Comm %d has been released or not turn on yet.", idx))); \
errmsg("Debug Comm %d has been released or not turned on yet.", idx))); \
} while (0)
static const char *stringFromCompileStatus(int strindex)

View File

@ -75,7 +75,7 @@ begin
insert into tmp_holder select breakpointno || ':' || lineno || ':' || query || ':' || enable from dbe_pldebugger.info_breakpoints();
end;
$$;
WARNING: lineno must be within the range of [1, MaxLineNumber] Please use dbe_pldebugger.info_code for valid breakpoint candidates
WARNING: lineno must be within the range of [1, MaxLineNumber]. Please use dbe_pldebugger.info_code for valid breakpoint candidates
CONTEXT: SQL statement "insert into tmp_holder select * from dbe_pldebugger.add_breakpoint(funcoid, 0)"
PL/pgSQL function inline_code_block line 6 at SQL statement
WARNING: the given line number does not name a valid breakpoint. Please use dbe_pldebugger.info_code for valid breakpoint candidates
@ -87,7 +87,7 @@ PL/pgSQL function inline_code_block line 9 at SQL statement
WARNING: the given line number already contains a valid breakpoint. Please se dbe_pldebugger.info_breakpoints for detail.
CONTEXT: SQL statement "insert into tmp_holder select * from dbe_pldebugger.add_breakpoint(funcoid, 15)"
PL/pgSQL function inline_code_block line 11 at SQL statement
WARNING: lineno must be within the range of [1, MaxLineNumber] Please use dbe_pldebugger.info_code for valid breakpoint candidates
WARNING: lineno must be within the range of [1, MaxLineNumber]. Please use dbe_pldebugger.info_code for valid breakpoint candidates
CONTEXT: SQL statement "insert into tmp_holder select * from dbe_pldebugger.add_breakpoint(funcoid, 50)"
PL/pgSQL function inline_code_block line 19 at SQL statement
select * from tmp_holder;
@ -1475,13 +1475,13 @@ select dbe_pldebugger.info_code(0);
(7 rows)
insert into tmp_holder select * from dbe_pldebugger.add_breakpoint(0, 0); -- negative
WARNING: lineno must be within the range of [1, MaxLineNumber] Please use dbe_pldebugger.info_code for valid breakpoint candidates
WARNING: lineno must be within the range of [1, MaxLineNumber]. Please use dbe_pldebugger.info_code for valid breakpoint candidates
insert into tmp_holder select * from dbe_pldebugger.add_breakpoint(0, 6); -- headerline
insert into tmp_holder select * from dbe_pldebugger.add_breakpoint(0, 6); -- already
WARNING: the given line number already contains a valid breakpoint. Please se dbe_pldebugger.info_breakpoints for detail.
insert into tmp_holder select * from dbe_pldebugger.add_breakpoint(0, 8); -- ok
insert into tmp_holder select * from dbe_pldebugger.add_breakpoint(0, 13); -- negative
WARNING: lineno must be within the range of [1, MaxLineNumber] Please use dbe_pldebugger.info_code for valid breakpoint candidates
WARNING: lineno must be within the range of [1, MaxLineNumber]. Please use dbe_pldebugger.info_code for valid breakpoint candidates
insert into tmp_holder select * from dbe_pldebugger.disable_breakpoint(1); -- ok
insert into tmp_holder select * from dbe_pldebugger.enable_breakpoint(1); -- ok
insert into tmp_holder select * from dbe_pldebugger.delete_breakpoint(0); -- ok
@ -1536,10 +1536,31 @@ select * from dbe_pldebugger.print_var('k');
k | int4 | 0 | | f
(1 row)
select * from dbe_pldebugger.abort();
abort
-------
t
select * from dbe_pldebugger.continue();
funcoid | funcname | lineno | query
---------+-------------------+--------+----------------------
0 | "anonymous block" | 0 | [EXECUTION FINISHED]
(1 row)
select pg_sleep(1);
pg_sleep
----------
(1 row)
select * from dbe_pldebugger.continue();
ERROR: must attach a execute func before execute dbe_pldebugger.continue
DETAIL: execute func not attached before execute dbe_pldebugger.continue
select dbe_pldebugger.attach(nodename, port) from debug_info;
attach
------------------------------------------------------------------------------------------------------------------
(0,"""anonymous block""",6," select oid from pg_proc into funcoid where proname='abs' and prosrc='int8abs';")
(1 row)
select * from dbe_pldebugger.continue();
funcoid | funcname | lineno | query
---------+-------------------+--------+----------------------
0 | "anonymous block" | 0 | [EXECUTION FINISHED]
(1 row)
select * from tmp_holder;

View File

@ -161,7 +161,7 @@ ERROR: must attach a execute func before execute dbe_pldebugger.abort
DETAIL: execute func not attached before execute dbe_pldebugger.abort
-- turn off without turn on
select * from dbe_pldebugger.turn_off(1);
WARNING: function 1 has not be turned on
WARNING: function 1 has not been turned on
turn_off
----------
f
@ -683,8 +683,21 @@ begin
insert into test_anonymous values(k, 'test2');
end;
$$;
ERROR: receive abort message
CONTEXT: PL/pgSQL function inline_code_block line 9 at SQL statement
delete from debug_info;
insert into debug_info select * from dbe_pldebugger.turn_on(0);
do $$
declare
funcoid oid;
k int;
begin
select oid from pg_proc into funcoid where proname='abs' and prosrc='int8abs';
perform * from pg_proc where oid = funcoid;
k = test_increment(3);
insert into test_anonymous values(k, 'test');
k = abs(-k);
insert into test_anonymous values(k, 'test2');
end;
$$;
drop schema pl_debugger cascade;
NOTICE: drop cascades to 20 other objects
DETAIL: drop cascades to table test

View File

@ -478,6 +478,11 @@ select frameno, funcname, lineno, query from dbe_pldebugger.backtrace();
select * from dbe_pldebugger.info_locals();
select funcname, lineno, query from dbe_pldebugger.finish();
select * from dbe_pldebugger.print_var('k');
select * from dbe_pldebugger.abort();
select * from dbe_pldebugger.continue();
select pg_sleep(1);
select * from dbe_pldebugger.continue();
select dbe_pldebugger.attach(nodename, port) from debug_info;
select * from dbe_pldebugger.continue();
select * from tmp_holder;

View File

@ -444,4 +444,21 @@ begin
end;
$$;
delete from debug_info;
insert into debug_info select * from dbe_pldebugger.turn_on(0);
do $$
declare
funcoid oid;
k int;
begin
select oid from pg_proc into funcoid where proname='abs' and prosrc='int8abs';
perform * from pg_proc where oid = funcoid;
k = test_increment(3);
insert into test_anonymous values(k, 'test');
k = abs(-k);
insert into test_anonymous values(k, 'test2');
end;
$$;
drop schema pl_debugger cascade;