summaryrefslogtreecommitdiff
path: root/sql/sp_pcontext.cc
diff options
context:
space:
mode:
authorunknown <pem@mysql.com>2005-11-17 11:11:48 +0100
committerunknown <pem@mysql.com>2005-11-17 11:11:48 +0100
commit91ab707678870966b9410cd3bdd783eb2a7c19e4 (patch)
tree56f597a525587468da328317b4cb9b936d5a2d3f /sql/sp_pcontext.cc
parent14637f97cdd7ff4a7d60c09052e2e280ee57c957 (diff)
downloadmariadb-git-91ab707678870966b9410cd3bdd783eb2a7c19e4.tar.gz
Background:
Since long, the compiled code of stored routines has been printed in the trace file when starting mysqld with the "--debug" flag. (At creation time only, and only in debug builds of course.) This has been helpful when debugging stored procedure execution, but it's a bit awkward to use. Also, the printing of some of the instructions is a bit terse, in particular for sp_instr_stmt where only the command code was printed. This improves the printout of several of the instructions, and adds the debugging- only commands "show procedure code <name>" and "show function code <name>". (In non-debug builds they are not available.) sql/lex.h: New symbol for debug-only command (e.g. show procedure code). sql/sp_head.cc: Fixed some minor debug-mode bugs in show_create_*(). New method for debugging: sp_head::show_routine_code() - returns the "assembly code" for a stored routine as a result set. Improved the print() methods for many sp_instr* classes, particularly for sp_instr_stmt where the query string is printed as well (up to a max length, just to give a hint of which statement it is). Also print the names of variables and cursors in some instruction. sql/sp_head.h: New debugging-only method in sp_head: show_routine_code(). Added offset member to sp_instr_cpush for improved debug printing. sql/sp_pcontext.cc: Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all frames, not just the first one. (For debugging purposes) Added a similar find_cursor(uint i, ...) method, for debugging. sql/sp_pcontext.h: Moved find_pvar(uint i) method to sp_pcontext.cc. Added a similar find_cursor(uint i, ...) method, for debugging. sql/sql_lex.h: Added new sql_command codes for debugging. sql/sql_parse.cc: Added new commands for debugging, e.g. "show procedure code". sql/sql_yacc.yy: Added new commands for debugging purposes: "show procedure code ..." and "show function code ...". These are only enabled in debug builds, otherwise they result in a syntax error. (I.e. they don't exist)
Diffstat (limited to 'sql/sp_pcontext.cc')
-rw-r--r--sql/sp_pcontext.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/sql/sp_pcontext.cc b/sql/sp_pcontext.cc
index f873b676925..32824b75847 100644
--- a/sql/sp_pcontext.cc
+++ b/sql/sp_pcontext.cc
@@ -169,6 +169,29 @@ sp_pcontext::find_pvar(LEX_STRING *name, my_bool scoped)
return NULL;
}
+/*
+ Find a variable by offset from the top.
+ This used for two things:
+ - When evaluating parameters at the beginning, and setting out parameters
+ at the end, of invokation. (Top frame only, so no recursion then.)
+ - For printing of sp_instr_set. (Debug mode only.)
+ */
+sp_pvar_t *
+sp_pcontext::find_pvar(uint i)
+{
+ if (m_poffset <= i && i < m_poffset + m_pvar.elements)
+ { // This frame
+ sp_pvar_t *p;
+
+ get_dynamic(&m_pvar, (gptr)&p, i - m_poffset);
+ return p;
+ }
+ else if (m_parent)
+ return m_parent->find_pvar(i); // Some previous frame
+ else
+ return NULL; // index out of bounds
+}
+
void
sp_pcontext::push_pvar(LEX_STRING *name, enum enum_field_types type,
sp_param_mode_t mode)
@@ -331,3 +354,22 @@ sp_pcontext::find_cursor(LEX_STRING *name, uint *poff, my_bool scoped)
return m_parent->find_cursor(name, poff, scoped);
return FALSE;
}
+
+/*
+ Find a cursor by offset from the top.
+ This is only used for debugging.
+ */
+my_bool
+sp_pcontext::find_cursor(uint i, LEX_STRING *n)
+{
+ if (m_coffset <= i && i < m_coffset + m_cursor.elements)
+ { // This frame
+ get_dynamic(&m_cursor, (gptr)n, i - m_poffset);
+ return TRUE;
+ }
+ else if (m_parent)
+ return m_parent->find_cursor(i, n); // Some previous frame
+ else
+ return FALSE; // index out of bounds
+}
+