8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 09:23:03 +01:00

CORE-5216: Provide location context (line/column numbers) for runtime

errors raised inside EXECUTE BLOCK.
This commit is contained in:
Dmitry Yemanov 2016-04-28 15:36:36 +03:00
parent 224070ca8c
commit 25313daa11

View File

@ -1174,49 +1174,52 @@ void EXE_execute_triggers(thread_db* tdbb,
static void stuff_stack_trace(const jrd_req* request) static void stuff_stack_trace(const jrd_req* request)
{ {
Firebird::string sTrace; string sTrace;
bool isEmpty = true;
for (const jrd_req* req = request; req; req = req->req_caller) for (const jrd_req* req = request; req; req = req->req_caller)
{ {
const JrdStatement* statement = req->getStatement(); const JrdStatement* const statement = req->getStatement();
Firebird::string name;
string context, name;
if (statement->triggerName.length()) if (statement->triggerName.length())
{ {
name = "At trigger '"; context = "At trigger";
name += statement->triggerName.c_str(); name = statement->triggerName.c_str();
} }
else if (statement->procedure) else if (statement->procedure)
{ {
name = statement->parentStatement ? "At sub procedure '" : "At procedure '"; context = statement->parentStatement ? "At sub procedure" : "At procedure";
name += statement->procedure->getName().toString().c_str(); name = statement->procedure->getName().toString();
} }
else if (statement->function) else if (statement->function)
{ {
name = statement->parentStatement ? "At sub function '" : "At function '"; context = statement->parentStatement ? "At sub function" : "At function";
name += statement->function->getName().toString().c_str(); name = statement->function->getName().toString();
}
else if (req->req_src_line)
{
context = "At anonymous block";
} }
if (! name.isEmpty()) if (context.hasData())
{ {
name.trim(); name.trim();
if (sTrace.length() + name.length() + 2 > MAX_STACK_TRACE) if (name.hasData())
context += string(" '") + name + string("'");
if (sTrace.length() + context.length() > MAX_STACK_TRACE)
break; break;
if (isEmpty) if (sTrace.hasData())
{ sTrace += "\n";
isEmpty = false;
sTrace += name + "'"; sTrace += context;
}
else {
sTrace += "\n" + name + "'";
}
if (req->req_src_line) if (req->req_src_line)
{ {
Firebird::string src_info; string src_info;
src_info.printf(" line: %" ULONGFORMAT", col: %" ULONGFORMAT, src_info.printf(" line: %" ULONGFORMAT", col: %" ULONGFORMAT,
req->req_src_line, req->req_src_column); req->req_src_line, req->req_src_column);
@ -1228,7 +1231,7 @@ static void stuff_stack_trace(const jrd_req* request)
} }
} }
if (!isEmpty) if (sTrace.hasData())
ERR_post_nothrow(Arg::Gds(isc_stack_trace) << Arg::Str(sTrace)); ERR_post_nothrow(Arg::Gds(isc_stack_trace) << Arg::Str(sTrace));
} }