9944b02015-03-08Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. */ #include "global.h" #include "module.h" #include "pike_error.h" #include "interpret.h" #include "pike_embed.h" #include "module_support.h"
34a6792015-03-08Martin Nilsson #include "pike_security.h" /*! @decl int(0..) map_all_objects(function(object:void) cb) *! @belongs Debug *! *! Call cb for all objects that currently exist. The callback will *! not be called with destructed objects as it's argument. *! *! Objects might be missed if @[cb] creates new objects or destroys *! old ones. *! *! This function is only intended to be used for debug purposes. *! *! @returns *! The total number of objects *! *! @seealso *! @[next_object()] */ static void f_map_all_objects( INT32 args ) { struct object *o = first_object; INT32 total = 0; ASSERT_SECURITY_ROOT("map_all_objects"); if( args!=1 ) SIMPLE_WRONG_NUM_ARGS_ERROR("map_all_objects", 1); while( o ) { struct object *next = o->next; if( o->prog ) { ref_push_object( o ); safe_apply_svalue( Pike_sp-2, 1, 1 ); pop_stack(); } total++; o = next; } pop_stack(); push_int(total); }
9944b02015-03-08Martin Nilsson  #ifdef PIKE_DEBUG /* This function is for debugging *ONLY* * do not document please. /Hubbe */ PMOD_EXPORT void f__leak(INT32 args) { INT32 i; if(!args) SIMPLE_TOO_FEW_ARGS_ERROR("_leak", 1); if(!REFCOUNTED_TYPE(TYPEOF(Pike_sp[-args]))) SIMPLE_BAD_ARG_ERROR("_leak", 1, "array|mapping|multiset|object|" "function|program|string"); add_ref(Pike_sp[-args].u.dummy); i=Pike_sp[-args].u.refs[0]; pop_n_elems(args); push_int(i); } /*! @decl int(0..) debug(int(0..) level) *! @belongs Debug *! *! Set the run-time debug level. *! *! @returns *! The old debug level will be returned. *! *! @note *! This function is only available if the Pike runtime has been compiled *! with RTL debug. */ PMOD_EXPORT void f_debug(INT32 args) { INT_TYPE d; get_all_args("debug", args, "%+", &d); pop_n_elems(args); push_int(d_flag); d_flag = d; } /*! @decl int(0..) optimizer_debug(int(0..) level) *! @belongs Debug *! *! Set the optimizer debug level. *! *! @returns *! The old optimizer debug level will be returned. *! *! @note *! This function is only available if the Pike runtime has been compiled *! with RTL debug. */ PMOD_EXPORT void f_optimizer_debug(INT32 args) { INT_TYPE l; get_all_args("optimizer_debug", args, "%+", &l); pop_n_elems(args); push_int(l_flag); l_flag = l; } /*! @decl int(0..) assembler_debug(int(0..) level) *! @belongs Debug *! *! Set the assembler debug level. *! *! @returns *! The old assembler debug level will be returned. *! *! @note *! This function is only available if the Pike runtime has been compiled *! with RTL debug. */ PMOD_EXPORT void f_assembler_debug(INT32 args) { INT_TYPE l; get_all_args("assembler_debug", args, "%+", &l); pop_n_elems(args); push_int(a_flag); a_flag = l; } /*! @decl void dump_program_tables(program p, int(0..)|void indent) *! @belongs Debug *! *! Dumps the internal tables for the program @[p] on stderr. *! *! @param p *! Program to dump. *! *! @param indent *! Number of spaces to indent the output. */ void f_dump_program_tables(INT32 args) { struct program *p; INT_TYPE indent = 0; get_all_args("dump_program_tables", args, "%p.%+", &p, &indent); dump_program_tables(p, indent); pop_n_elems(args); } #ifdef YYDEBUG /*! @decl int(0..) compiler_trace(int(0..) level) *! @belongs Debug *! *! Set the compiler trace level. *! *! @returns *! The old compiler trace level will be returned. *! *! @note *! This function is only available if the Pike runtime has been compiled *! with RTL debug. */ PMOD_EXPORT void f_compiler_trace(INT32 args) { extern int yydebug; INT_TYPE yyd;
60d03c2015-03-08Martin Nilsson  get_all_args("compiler_trace", args, "%i", &yyd);
9944b02015-03-08Martin Nilsson  pop_n_elems(args); push_int(yydebug); yydebug = yyd; } #endif /* YYDEBUG */ #endif /* PIKE_DEBUG */ PIKE_MODULE_INIT {
34a6792015-03-08Martin Nilsson  ADD_FUNCTION("map_all_objects", f_map_all_objects, tFunc(tFunction,tIntPos), OPT_EXTERNAL_DEPEND);
9944b02015-03-08Martin Nilsson #ifdef PIKE_DEBUG ADD_INT_CONSTANT("HAVE_DEBUG", 1, 0); ADD_FUNCTION("_leak", f__leak, tFunc(tRef,tInt), OPT_EXTERNAL_DEPEND); ADD_FUNCTION("debug", f_debug, tFunc(tIntPos,tIntPos), OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND); ADD_FUNCTION("optimizer_debug", f_optimizer_debug, tFunc(tIntPos,tIntPos), OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND); ADD_FUNCTION("assembler_debug", f_assembler_debug, tFunc(tInt,tIntPos), OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND); ADD_FUNCTION("dump_program_tables", f_dump_program_tables, tFunc(tPrg(tObj) tIntPos,tVoid), OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND); #ifdef YYDEBUG ADD_FUNCTION("compiler_trace", f_compiler_trace, tFunc(tIntPos,tIntPos), OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND); #endif /* YYDEBUG */ #endif /* PIKE_DEBUG */ } PIKE_MODULE_EXIT { }