rdebug_compile_routine

NAME

rdebug_compile_routine(): Rebuild a routine with/without debugging info.

TYPE

Procedure

DESCRIPTION

This procedure is part of the rdebug API.

rdebug_compile_routine() modifies a routine code to include/exclude debug info.

rdebug works by injecting debug code into stored routines. In order to debug a routine, one must first make sure it is "compiled with debug mode" (though technically the routine is never compiled).

rdebug_compile_routine() works on the very code of one's routine, and injects variables & statements to manage the debugging process. These variables and statements do not modify the behavior of the routine: executed outside a debugging session, it should act exactly the same way as a "normal" routine with no debug info.

This also makes for a routine's code bloat and possible slow down to to the fact it is interpreted by MySQL (therefore more code to interpret).

Once the debugging session is complete, one wishes to remove the injected debug code from the routine. rdebug_compile_routine() will strip down the debug code and restore the routine to the exact same original code.

Compiling a routine twice with debug info is valid, though the 2nd call makes no difference. Likewise, Compiling the routine twice without debug info is fine, and the second call makes no changes to the code.

Execution of this routine should take place outside a debugging session (typically compiling with debug info beforehand, and compiling without debug info afterwards).

SYNOPSIS

rdebug_compile_routine(
    in rdebug_routine_schema varchar(128) charset utf8,
    in rdebug_routine_name   varchar(128) charset utf8,
    in debug_info     bool
  )
  MODIFIES SQL DATA

Input:

  • rdebug_routine_schema: schema where routine is located.
  • rdebug_routine_name: name of routine to compile.
  • debug_info: TRUE or 1 to inject debug code into the routine, FALSE or 0 to remove debug code from the routine and return to original code.

EXAMPLES

Compile routine with debug info. Show routine before/after:

mysql> call rdebug_show_routine('test','analyze_continents');
+------------------------------------------------------------+
| `test`.`analyze_continents` breakpoints                    |
+------------------------------------------------------------+
| main_body: begin                                           |
|   declare done bool default false;                         |
|   declare current_continent varchar(32) default null;      |
|   declare continents_cursor cursor for                     |
|             select distinct continent from world.Country;  |
|   declare continue handler for not found set done := true; |
|                                                            |
|   open continents_cursor;                                  |
|   cursor_loop: while not done do                           |
|     fetch continents_cursor into current_continent;        |
|     if done then                                           |
|       leave cursor_loop;                                   |
|     end if;                                                |
|     call analyze_continent_cities(current_continent);      |
|   end while;                                               |
|   close continents_cursor;                                 |
| end                                                        |
+------------------------------------------------------------+

mysql> call rdebug_compile_routine('test','analyze_continents', true);

mysql> call rdebug_show_routine('test','analyze_continents');
+-------------------------------------------------------------+
| `test`.`analyze_continents` breakpoints                     |
+-------------------------------------------------------------+
| main_body: begin                                            |
|   declare done bool default false;                          |
|   declare current_continent varchar(32) default null;       |
|   declare continents_cursor cursor for                      |
|             select distinct continent from world.Country;   |
|   declare continue handler for not found set done := true;  |
|                                                             |
|   [:80]open continents_cursor;                              |
|   [:86]cursor_loop: while not done do                       |
|     [:98]fetch continents_cursor into current_continent;    |
|     [:108]if done then                                      |
|       [:115]leave cursor_loop;                              |
|     [:121]end if;                                           |
|     [:127]call analyze_continent_cities(current_continent); |
|   [:136]end while;                                          |
|   [:142]close continents_cursor;                            |
| [:147]end                                                   |
+-------------------------------------------------------------+
The actual injected routine code is far more complex and is not presented here.

ENVIRONMENT

MySQL 5.1 or newer

SEE ALSO

rdebug_show_routine(), rdebug_show_routine_statements()

AUTHOR

Shlomi Noach
 
common_schema documentation