MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / FixTraceFlags

Function FixTraceFlags

dbug/dbug.c:805–875  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

803#define fflags(cs) cs->stack->out_file ? ListFlags(cs->stack->functions) : TRACE_ON;
804
805void FixTraceFlags(uint old_fflags, CODE_STATE *cs)
806{
807 const char *func;
808 uint new_fflags, traceon, level;
809 struct _db_stack_frame_ *framep;
810
811 /*
812 first (a.k.a. safety) check:
813 if we haven't started tracing yet, no call stack at all - we're safe.
814 */
815 framep=cs->framep;
816 if (framep == 0)
817 return;
818
819 /*
820 Ok, the tracing has started, call stack isn't empty.
821
822 second check: does the new list have a SUBDIR rule ?
823 */
824 new_fflags=fflags(cs);
825 if (new_fflags & SUBDIR)
826 goto yuck;
827
828 /*
829 Ok, new list doesn't use SUBDIR.
830
831 third check: we do NOT need to re-scan if
832 neither old nor new lists used SUBDIR flag and if a default behavior
833 (whether an unlisted function is traced) hasn't changed.
834 Default behavior depends on whether there're INCLUDE elements in the list.
835 */
836 if (!(old_fflags & SUBDIR) && !((new_fflags^old_fflags) & INCLUDE))
837 return;
838
839 /*
840 Ok, old list may've used SUBDIR, or defaults could've changed.
841
842 fourth check: are we inside a currently active SUBDIR rule ?
843 go up the call stack, if TRACE_ON flag ever changes its value - we are.
844 */
845 for (traceon=framep->level; framep; framep=framep->prev)
846 if ((traceon ^ framep->level) & TRACE_ON)
847 goto yuck;
848
849 /*
850 Ok, TRACE_ON flag doesn't change in the call stack.
851
852 fifth check: but is the top-most value equal to a default one ?
853 */
854 if (((traceon & TRACE_ON) != 0) == ((new_fflags & INCLUDE) == 0))
855 return;
856
857yuck:
858 /*
859 Yuck! function list was changed, and one of the currently active rules
860 was possibly affected. For example, a tracing could've been enabled or
861 disabled for a function somewhere up the call stack.
862 To react correctly, we must go up the call stack all the way to

Callers 3

_db_set_Function · 0.85
_db_push_Function · 0.85
_db_pop_Function · 0.85

Calls 1

FixTraceFlags_helperFunction · 0.85

Tested by

no test coverage detected