Exemple #1
0
END_TEST

START_TEST(test_debug) {
    const char *errstr = NULL;
    int ostdout, spair[2];
    ssize_t len;
    struct pcap_file_header pcap_fhdr = {};
    struct parent_msg msg = {};
    char buf[2048];

    mark_point();
    if (isatty(STDOUT_FILENO)) { 
	errstr = "please redirect stdout to tcpdump or a file";
	my_log(CRIT, "check");
	WRAP_FATAL_START();
	debug_header();
	WRAP_FATAL_END();
	fail_unless (strncmp(check_wrap_errstr, errstr, strlen(errstr)) == 0,
	    "incorrect message logged: %s", check_wrap_errstr);
    }

    ostdout = dup(STDOUT_FILENO);
    my_socketpair(spair);
    dup2(spair[0], STDOUT_FILENO);
    close(ostdout);
    errstr = "check";
    my_log(CRIT, errstr);

    mark_point();
    debug_header();
    fflush(stdout);
    fail_unless (strncmp(check_wrap_errstr, errstr, strlen(errstr)) == 0,
        "incorrect message logged: %s", check_wrap_errstr);
    len = read(spair[1], &pcap_fhdr, sizeof(pcap_fhdr));
    fail_unless(len == sizeof(pcap_fhdr),
                "failed to read pcap header");
    fail_unless(pcap_fhdr.magic == PCAP_MAGIC,
                "invalid pcap header returned");
    fail_unless(pcap_fhdr.snaplen == ETHER_MAX_LEN,
                "invalid pcap header returned");
    fail_unless(pcap_fhdr.linktype == DLT_EN10MB,
                "invalid pcap header returned");

    mark_point();
    msg.len = ETHER_MIN_LEN;
    debug_write(&msg, 0);
    fflush(stdout);
    fail_unless (strncmp(check_wrap_errstr, errstr, strlen(errstr)) == 0,
        "incorrect message logged: %s", check_wrap_errstr);
    len = read(spair[1], buf, sizeof(buf));
    fail_unless(len == (PCAP_PKTHDR_SIZ + msg.len),
                "failed to read pcap record"); 

    close(spair[0]);
    close(spair[1]);
    dup2(ostdout, STDOUT_FILENO);
    close(ostdout);
}
static void debug_chain()
{
    memory_header *cur = heap.first;

    mbedtls_fprintf( stderr, "\nBlock list\n" );
    while( cur != NULL )
    {
        debug_header( cur );
        cur = cur->next;
    }

    mbedtls_fprintf( stderr, "Free list\n" );
    cur = heap.first_free;

    while( cur != NULL )
    {
        debug_header( cur );
        cur = cur->next_free;
    }
}
/**
 * Scan packet buffer
 */
int scan(JNIEnv *env, jobject obj, jobject jpacket, scanner_t *scanner,
		packet_state_t *p_packet, int first_id, char *buf, int buf_len,
		uint32_t wirelen) {

	scan_t scan; // Our current in progress scan's state information
	scan_t *pscan = &scan;
	scan.env = env;
	scan.jscanner = obj;
	scan.jpacket = jpacket;
	scan.scanner = scanner;
	scan.packet = p_packet;
	scan.header = &p_packet->pkt_headers[0];
	scan.buf = buf;
	scan.buf_len = buf_len; // Changing buffer length, reduced by 'postfix'
	scan.mem_len = buf_len; // Constant in memory buffer length
	scan.wire_len = wirelen;
	scan.offset = 0;
	scan.length = 0;
	scan.id = first_id;
	scan.next_id = PAYLOAD_ID;
	scan.flags = 0;
	scan.stack_index = 0;

	scan.hdr_count = 0;
	scan.hdr_flags = 0;
	scan.hdr_prefix = 0;
	scan.hdr_gap = 0;
	scan.hdr_payload = 0;
	scan.hdr_postfix = 0;

	memset(scan.header, 0, sizeof(header_t));

	// Point jscan 
	setJMemoryPhysical(env, scanner->sc_jscan, toLong(&scan));

	// Local temp variables
	register uint64_t mask;

#ifdef DEBUG
	debug_enter("scan");
	debug_trace("processing packet", "#%d", p_packet->pkt_frame_num);
#endif

	/*
	 * Main scanner loop, 1st scans for builtin header types then
	 * reverts to calling on JBinding objects to provide the binding chain
	 */
	while (scan.id != END_OF_HEADERS) {
#ifdef DEBUG
		debug_trace("", "");
		debug_trace("processing header", id2str(scan.id));
		debug_scan("loop-top", &scan);
#endif

		/* A flag that keeps track of header recording. Set in record_header()*/
		scan.is_recorded = 0;

		/*
		 * If debugging is compiled in, we can also call on each protocols
		 * debug_* function to print out details about the protocol header
		 * structure. 
		 */
#ifdef DEBUG
		if (native_debug[scan.id]) {
			native_debug[scan.id](scan.buf + scan.offset);
		}
#endif

		/* 
		 * Scan of each protocol is done through a dispatch function table.
		 * Each protocol that has a protocol header scanner attached, a scanner
		 * designed specifically for that protocol. The protocol id is also the
		 * index into the table. There are 2 types of scanners both have exactly
		 * the same signature and thus both are set in this table. The first is
		 * the native scanner that only performs a direct scan of the header.
		 * The second scanner is a java header scanner. It is based on 
		 * JHeaderScanner class. A single dispatch method callJavaHeaderScanner
		 * uses the protocol ID to to dispatch to the appropriate java scanner.
		 * Uses a separate java specific table: sc_java_header_scanners[]. The
		 * java scanner is capable of calling the native scan method from java
		 * but also adds the ability to check all the attached JBinding[] for
		 * any additional registered bindings. Interesting fact is that if the
		 * java scanner doesn't have any bindings nor does it override the 
		 * default scan method to perform a scan in java and is also setup to 
		 * dispatch to native scanner, it is exactly same thing as if the 
		 * native scanner was dispatched directly from here, but round 
		 * about way through java land.
		 */
		if (scanner->sc_scan_table[scan.id] != NULL) {
			scanner->sc_scan_table[scan.id](&scan); // Dispatch to scanner
		}

#ifdef DEBUG
		debug_scan("loop-middle", &scan);
#endif

		if (scan.length == 0) {
#ifdef DEBUG
			debug_scan("loop-length==0", &scan);
#endif
			if (scan.id == PAYLOAD_ID) {
				if (scan.stack_index == 0) {
					scan.next_id = END_OF_HEADERS;
				} else {
					scan.stack_index --;
					scan.next_id = scan.stack[scan.stack_index].next_id;
					scan.offset = scan.stack[scan.stack_index].offset;
				}
			} else {
				scan.next_id = PAYLOAD_ID;
			}

		} else { // length != 0

#ifdef DEBUG
			debug_scan("loop-length > 0", &scan);
#endif

			/******************************************************
			 * ****************************************************
			 * * If override flag is set, then we reset the
			 * * discovered next protocol. If that is what the user 
			 * * wants then that is what he gets.
			 * ****************************************************
			 ******************************************************/
			if (scanner->sc_flags[scan.id] & FLAG_OVERRIDE_BINDING) {
#ifdef DEBUG
				debug_scan("TCP OVERRIDE", &scan);
#endif
				scan.next_id = PAYLOAD_ID;
			}

			/******************************************************
			 * ****************************************************
			 * * Now do HEURISTIC discovery scans if the appropriate
			 * * flags are set. Heuristics allow us to provide nxt
			 * * protocol binding, using discovery (an educated 
			 * * guess). 
			 * ****************************************************
			 ******************************************************/
			if (scanner->sc_flags[scan.id] & FLAG_HEURISTIC_BINDING) {

				/* 
				 * Save these critical properties, in case heuristic changes them
				 * for this current header, not the next one its supposed to
				 * check for.
				 */
				int saved_offset = scan.offset;
				int saved_length = scan.length;

				/* Advance offset to next header, so that heuristics can get a 
				 * peek. It will be restored at the end of heuristics block.
				 */
				scan.offset += scan.length + scan.hdr_gap;

				/*
				 * 2 types of heuristic bindings. Pre and post.
				 * Pre - heuristics are run before the direct discovery method
				 *       in scanner. Only after the pre-heuristic fail do we
				 *       utilize the directly discovered binding.
				 * 
				 * Post - heuristics are run after the direct discovery method
				 *        didn't produce a binding.
				 *
				 * ------------------------------------------------------------
				 * 
				 * In our case, since we have already ran the direct discovery
				 * in the header scanner, we save scan.next_id value, reset it,
				 * call the heuristic function, check its scan.next_id if it
				 * was set, if it was, then use that instead. Otherwise if it
				 * wasn't restore the original next_id and continue on normally.
				 */
				if (scanner->sc_flags[scan.id] & FLAG_HEURISTIC_PRE_BINDING) {
#ifdef DEBUG
					debug_scan("heurists_pre", &scan);
#endif

					int saved_next_id = scan.next_id;
					scan.next_id = PAYLOAD_ID;

					for (int i = 0; i < MAX_ID_COUNT; i++) {
						native_validate_func_t validate_func;
						validate_func
								= scanner->sc_heuristics_table[scan.id][i];

						if (validate_func == NULL) {
							break;
						}

						if ((scan.next_id = validate_func(&scan)) != INVALID) {
							break;
						}
					}

					if (scan.next_id == PAYLOAD_ID) {
						scan.next_id = saved_next_id;
					}

				} else if (scan.next_id == PAYLOAD_ID) {
#ifdef DEBUG
					debug_scan("heurists_post", &scan);
#endif
					for (int i = 0; i < MAX_ID_COUNT; i++) {
						native_validate_func_t validate_func;
						validate_func
								= scanner->sc_heuristics_table[scan.id][i];

						if (validate_func == NULL) {
							break;
						}

#ifdef DEBUG
						debug_trace("heurists_post", "[%d]", i);
#endif
						if ((scan.next_id = validate_func(&scan)) != INVALID) {

#ifdef DEBUG
							debug_scan("heurists_post::found", &scan);
#endif

							break;
						}
					}
				}

				/* Restore these 2 critical properties */
				scan.offset = saved_offset;
				scan.length = saved_length;
			}

			/******************************************************
			 * ****************************************************
			 * * Now record discovered information in structures
			 * ****************************************************
			 ******************************************************/
			record_header(&scan);

#ifdef DEBUG
			debug_header("header_t", scan.header - 1);
#endif
		} // End if len != 0

#ifdef DEBUG
		debug_scan("loop-bottom", &scan);
#endif

		scan.id = scan.next_id;
		scan.offset += scan.length + scan.hdr_gap;
		scan.length = 0;
		scan.next_id = PAYLOAD_ID;

		if (scan.offset >= scan.buf_len) {
			scan.id = END_OF_HEADERS;
		}

	} // End for loop

	/* record number of header entries found */
	//	scan.packet->pkt_header_count = count;

	process_flow_key(&scan);

#ifdef DEBUG
	debug_trace("loop-finished",
			"header_count=%d offset=%d header_map=0x%X",
			scan.packet->pkt_header_count, scan.offset,
			scan.packet->pkt_header_map);
	debug_exit("scan()");
#endif

	return scan.offset;
} // End scan()
Exemple #4
0
void debug_dump(void)
{
	int					i,idx,cnt,mem_sz;
	obj_type			*obj;
	effect_type			*effect;
	proj_type			*proj;
	weapon_type			*weap;
	proj_setup_type		*proj_setup;
	model_type			*mdl;
	script_type			*script;
	timer_type			*timer;
	SDL_version			*sdl_ver;
	
	console_add_system("Debugging info dumped to stdout");
	
	fprintf(stdout,"\n\n");
	fprintf(stdout,"#########################################################################\n");
	fprintf(stdout,"Dump: dim3 Debugging Info\n");
	fprintf(stdout,"Engine v%s\n",dim3_version);
	fprintf(stdout,"(c) 2000-2007 Klink! Software\n");
	fprintf(stdout,"#########################################################################\n\n");

		// game info
		
	fprintf(stdout,"**************************************\n");
	fprintf(stdout,"Game\n");
	fprintf(stdout,"**************************************\n\n");
	fprintf(stdout,"Project:  %s\n",net_setup.host.proj_name);
	fprintf(stdout,"Tick: %d\n",game_time_get());
	
	debug_return();
	
		// system info
		
	fprintf(stdout,"**************************************\n");
	fprintf(stdout,"System\n");
	fprintf(stdout,"**************************************\n\n");
	fprintf(stdout,"Arch Type: %s\n",arch_type);

#ifdef D3_OS_MAC
	fprintf(stdout,"OS Version: %d.%d.%d\n",os_vers_major,os_vers_minor_1,os_vers_minor_2);
#endif
	
	sdl_ver=(SDL_version*)SDL_Linked_Version();
	fprintf(stdout,"SDL Version: %d.%d.%d\n",sdl_ver->major,sdl_ver->minor,sdl_ver->patch);
	fprintf(stdout,"JavaScript Version: %.2f\n",((float)JS_VERSION/100.0f));
	fprintf(stdout,"PNG Version: %s\n",PNG_LIBPNG_VER_STRING);
	
	debug_return();
	
		// video info
		
	fprintf(stdout,"**************************************\n");
	fprintf(stdout,"Video\n");
	fprintf(stdout,"**************************************\n\n");
	fprintf(stdout,"Engine: %s\n",render_info.name);
	fprintf(stdout,"Screen: %d,%d at %d\n",render_info.monitor_x_sz,render_info.monitor_y_sz,render_info.monitor_refresh_rate);
	fprintf(stdout,"Max Texture Units: %d\n",render_info.texture_unit_count);
	fprintf(stdout,"Max Texture Size: %d\n",render_info.texture_max_size);
	
	if (!gl_check_frame_buffer_ok()) fprintf(stdout,"Shadow support disabled; Unsupported on this video card.\n");
	if (!gl_check_fsaa_ok()) fprintf(stdout,"FSAA support disabled; Unsupported on this video card.\n");
	if (!gl_check_texture_compress_ok()) fprintf(stdout,"Compression disabled; Unsupported on this video card.\n");
	if (!gl_check_point_sprite_ok()) fprintf(stdout,"Point sprite support disabled; Unsupported on this video card.\n");
	if (!gl_check_shader_ok()) fprintf(stdout,"GLSL support disabled; Unsupported on this video card.\n");

	fprintf(stdout,"Extensions:\n%s\n",render_info.ext_string);

#ifdef D3_OS_WINDOWS
	fprintf(stdout,"WGL Extensions:\n%s\n",wglGetExtensionsStringARB(wglGetCurrentDC()));
#endif
	
	debug_return();

		// map info
		
	fprintf(stdout,"**************************************\n");
	fprintf(stdout,"Map\n");
	fprintf(stdout,"**************************************\n\n");
	fprintf(stdout,"Map:  %s\n",map.info.name);
	fprintf(stdout,"Author:  %s\n",map.info.author);
	fprintf(stdout,"Mesh Count:  %d\n",map.mesh.nmesh);
	fprintf(stdout,"Liquid Count:  %d\n",map.liquid.nliquid);
	fprintf(stdout,"Spot Count:  %d\n",map.nspot);
	fprintf(stdout,"Scenery Count:  %d\n",map.nscenery);
	fprintf(stdout,"Node Count:  %d\n",map.nnode);
	
	debug_return();
	
		// objects

	debug_header("Objects",server.count.obj,(sizeof(obj_type)*server.count.obj));
	
	debug_space("Name",25);
	debug_space("Type",15);
	debug_space("Script",25);
	debug_space("Binding",10);
	debug_return();
	debug_space("------------------------",25);
	debug_space("------------------------",15);
	debug_space("------------------------",25);
	debug_space("---------",10);
	debug_return();
	
	obj=server.objs;
	
	for ((i=0);(i!=server.count.obj);i++) {
		debug_space(obj->name,25);
		debug_space(obj->type,15);
		if (!obj->scenery.on) {
			idx=scripts_find_uid(obj->attach.script_uid);
			debug_space(js.scripts[idx].name,25);
		}
		else {
			debug_space("*",25);
		}
		debug_space(bind_type_str[obj->bind],10);
		debug_return();
		obj++;
	}
	
	debug_return();
	
		// weapons

	debug_header("Weapons",server.count.weapon,(sizeof(weapon_type)*server.count.weapon));
	
	debug_space("Name",20);
	debug_space("Object",20);
	debug_return();
	debug_space("-------------------",20);
	debug_space("-------------------",20);
	debug_return();
	
	weap=server.weapons;
	
	for ((i=0);(i!=server.count.weapon);i++) {
		obj=object_find_uid(weap->obj_uid);
		
		debug_space(weap->name,20);
		debug_space(obj->name,20);
		debug_return();
		weap++;
	}
	
	debug_return();
	
		// projectile setups

	debug_header("Projectile Setups",server.count.proj_setup,(sizeof(proj_setup_type)*server.count.proj_setup));
	
	debug_space("Name",20);
	debug_space("Object",20);
	debug_space("Weapon",20);
	debug_return();
	debug_space("-------------------",20);
	debug_space("-------------------",20);
	debug_space("-------------------",20);
	debug_return();
	
	proj_setup=server.proj_setups;
	
	for ((i=0);(i!=server.count.proj_setup);i++) {
		obj=object_find_uid(proj_setup->obj_uid);
		weap=weapon_find_uid(proj_setup->weap_uid);
		
		debug_space(proj_setup->name,20);
		debug_space(obj->name,20);
		debug_space(weap->name,20);
		debug_return();
		proj_setup++;
	}
	
	debug_return();
	
		// models

	mem_sz=sizeof(model_type)*server.count.model;

	mdl=server.models;
	
	for (i=0;i!=server.count.model;i++) {
		mem_sz+=model_memory_size(mdl);
		mdl++;
	}
		
	debug_header("Models",server.count.model,mem_sz);
	
	debug_space("Name",32);
	debug_space("Vertexes",10);
	debug_space("Trigs",10);
	debug_space("Ref Count",10);
	debug_return();
	debug_space("------------------------------",32);
	debug_space("---------",10);
	debug_space("---------",10);
	debug_space("---------",10);
	debug_return();

	mdl=server.models;
	
	for (i=0;i!=server.count.model;i++) {
		debug_space(mdl->name,32);
		debug_int_space(mdl->meshes[0].nvertex,10);
		debug_int_space(mdl->meshes[0].ntrig,10);
		debug_int_space(mdl->reference_count,10);
		debug_return();
		mdl++;
	}
	
	debug_return();
	
		// projectiles
		
	debug_header("Projectiles",server.count.proj,(sizeof(proj_type)*max_projectile));
	
	debug_space("Name",20);
	debug_space("Object",20);
	debug_space("Weapon",20);
	debug_return();
	debug_space("-------------------",20);
	debug_space("-------------------",20);
	debug_space("-------------------",20);
	debug_return();
	
	proj=server.projs;
	
	for ((i=0);(i!=server.count.proj);i++) {
		obj=object_find_uid(proj->obj_uid);
		weap=weapon_find_uid(proj->weap_uid);
		proj_setup=proj_setups_find_uid(proj->proj_setup_uid);
		
		debug_space(proj_setup->name,20);
		debug_space(obj->name,20);
		debug_space(weap->name,20);
		debug_return();
		proj++;
	}
	
	debug_return();
	
		// effects
		
	debug_header("Effects",server.count.effect,(sizeof(effect_type)*max_effect));
	
	debug_space("Type",10);
	debug_space("Life Tick",10);
	debug_return();
	debug_space("---------",10);
	debug_space("---------",10);
	debug_return();
	
	effect=server.effects;
	
	for ((i=0);(i!=server.count.effect);i++) {
		debug_space(effect_type_str[effect->effecttype],10);
		debug_int_space(effect->life_tick,10);
		debug_return();
		effect++;
	}
	
	debug_return();
	
		// scripts
		
	script=js.scripts;
	
	cnt=0;
	for ((i=0);(i!=max_scripts);i++) {
		if (script->used) cnt++;
		script++;
	}
		
	debug_header("Scripts",cnt,-1);
	
	debug_space("Name",32);
	debug_return();
	debug_space("-------------------------------",32);
	debug_return();
	
	script=js.scripts;
	
	for ((i=0);(i!=max_scripts);i++) {
		if (script->used) {
			debug_space(script->name,32);
			debug_return();
		}
		script++;
	}
	
	debug_return();
	
		// timers
		
	debug_header("Timers",js.count.timer,-1);
	
	debug_space("Script",32);
	debug_space("Count",10);
	debug_space("Type",10);
	debug_return();
	debug_space("-------------------------------",32);
	debug_space("---------",10);
	debug_space("---------",10);
	debug_return();
	
	timer=js.timers;
	
	for ((i=0);(i!=js.count.timer);i++) {
		script=&js.scripts[scripts_find_uid(timer->attach.script_uid)];
		debug_space(script->name,32);
		debug_int_space(timer->count,10);
		debug_space((timer->mode==timer_mode_repeat)?"Timer":"Wait",10);
		debug_return();
		timer++;
	}
	
	debug_return();

	fflush(stdout);
}