⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 u.c

📁 一个很不错的程序切片工具,希望大家来讨论以下,对测试人员很有帮助
💻 C
📖 第 1 页 / 共 3 页
字号:
# include <stdio.h># include <string.h># include <sys/file.h># include <sys/stat.h># include <sys/time.h># include <X11/Xlib.h># include <X11/Intrinsic.h># include <X11/StringDefs.h># include <X11/Shell.h># include <X11/Xaw/Form.h># include <X11/Xaw/SimpleMenu.h># include <X11/Xaw/SmeBSB.h># include <X11/Xaw/SmeLine.h># include <X11/Xaw/MenuButton.h># include <X11/Xaw/Command.h># include <X11/Xaw/Label.h># include <X11/Xaw/Paned.h># include <X11/Xaw/List.h># include <X11/Xaw/Box.h># include <X11/Xaw/Form.h># include <X11/Xaw/Viewport.h># include "sets.h"# include "MultiSlice.h"# include "slice.h"# include "config.h"	static  char    sccsid[] = "@(#)u.c	1.12  7/26/96";# define WIDTH 450# define XtNrunningFG "runningFG"# define XtNrunningBG "runningBG"typedef enum {select_action,show,tree} proc_action;Widget	QQQ;Widget	top;Widget	help_label;Widget	progress;typedef struct {	char	*proc;	char	*var;	Widget	*state_label;	Widget	slice_label;	Widget	display_label;	Widget	var_list;	Widget	slicewin;	Widget	history_list;	Widget	var_popup,proc_popup;	char	*ptext,*stext;	char	*root_file;	int		slice_var_index,pid,header;	int		is_primary;	proc_action reason;	int		is_running;	Pixel	active_fg,active_bg;} proc_state_rec,*proc_state_ptr;extern	char version[];long		addr,start_addr;int		current_proc;static char	home[] = HOME;	Widget		slicewin;	static		char srcfile[1000] = " ";int SliceTrace;	int			slice_on_var = 0;	int			dice_on_var = 0;	bit_set		*slice_set,*dice_set,*alt_slice_set,				*primary_set,*secondary_set;char	**proc_name_list,**file_name_list;char	***local_vars,***global_vars;int		*proc_ids,n_proc_list,**global_ids;int		*line_map;	bit_set	active;int update_progress (old)	int	old;{	int		n,at,f;	char	label[1000];	n = 0;	for (f = 0 ; f < n_files; f++){		at = -1;		while ((at = get_next_member(slice_set[f],at)) >= 0)			n++;	}	if (old != n){		sprintf (label,"%5d nodes",n);		XtVaSetValues (progress,XtNlabel,label,NULL);	}	return n;}button_help (w,mess,e,ok)	Widget	w;	char	*mess;	XEvent	*e;	Boolean	*ok;{	/* printf ("%s\n",mess); */	XtVaSetValues (help_label,		XtNlabel, (XtArgVal) mess,		NULL);}set_button_help (w,mess)	Widget	w;	char	*mess;{	static char buff[] = "Describe object under mouse pointer";	XtAddEventHandler (w,EnterWindowMask,False,button_help,mess);	XtAddEventHandler (w,LeaveWindowMask,False,button_help,buff);}update_label(state)	proc_state_ptr		state;{	char	buff[1000];	char	*at,*name;	if (state->pid){		name = files[procs[state->pid].file_id].name;		at = strrchr (name,'/');		if (at) at++;		else at = name;		sprintf (buff,"File: %sc %s %s %s %s",			at,			"Proc:",state->proc,"Var:",			state->slice_var_index?				procs[state->pid].locals[state->slice_var_index].name:			"<none>");		XtVaSetValues (*(state->state_label),			XtNlabel,			(XtArgVal) buff,		NULL);	}	else {		name = file_name_list[state->header];		at = strrchr (name,'/');		if (at) at++;		else at = name;		sprintf (buff,"File: %s %s %s %s %s",			at,			"Proc:","<global var>","Var:",			state->slice_var_index?globals[state->slice_var_index].name:			"<none>");		XtVaSetValues (*(state->state_label),			XtNlabel,			(XtArgVal) buff,		NULL);	}	/*		printf ("proc %s local %s\n",procs[state->pid].proc_name,			procs[state->pid].locals[list->list_index].name);		state->slice_var_index = ix;		printf ("%s\n",globals[ix].name);		files[procs[state->pid].file_id].name,	XawListChange (state->var_list,local_vars[list->list_index],	XawListChange (state->var_list,list,0,0,True);	*/}make_line_map(){	int		i,sum;	line_map = (int *) malloc (n_files*sizeof(int));	if (!line_map) {		fprintf (stderr,"out of memory\n");		exit(1);	}	sum = 0;	for (i = 0; i < n_files; i++){		line_map[i] = sum;		sum += files[i].n_lines;	}}disp_to_file_and_line (disp_line,filex,line)	int		disp_line,*filex,*line;{	int		f,lx;	lx = disp_line;	for (f = 0; f < n_files; f++){		if (lx > files[f].n_lines){			lx -= files[f].n_lines;		}		else {			*filex = f;			*line = lx;			return;		}	}	*filex = 0;	*line = 0;}make_head_list(){	int		k,i,n;	n = n_heads;	file_name_list = (char **) malloc ((n_heads+2)*sizeof(char *));	global_vars = (char ***) malloc ((n+2)*sizeof(char **));	global_ids = (int **) malloc ((n+2)*sizeof(int *));	file_name_list[0] = "No Selection";	for (i = 0; i < n_heads; i++){		file_name_list[i+1] = headers[i].header_file;		global_vars[i+1] = (char **)			malloc (sizeof(char *)*(headers[i].n+2));		global_vars[i+1][0] = "No Selection";		global_ids[i+1] = headers[i].ids;		for (k = 0; k < headers[i].n; k++){			global_vars[i+1][k+1] = headers[i].names[k];		}		global_vars[i+1][headers[i].n+1] = NULL;	}	file_name_list[n_heads+1] = NULL;}make_proc_list(){	int		k,i,n;	n = 0;	for (i = 1; i <= n_procs; i++)		if (procs[i].entry != -1) n++;	proc_ids = (int *) malloc((n+1)*sizeof(int));	proc_name_list = (char **) malloc ((n+2)*sizeof(char *));	local_vars = (char ***) malloc ((n+1)*sizeof(char **));	n_proc_list = n;	n = 1;	proc_name_list[0] = "No Selection";	for (i = 1; i <= n_procs; i++)		if (procs[i].entry != -1){			proc_name_list[n] = procs[i].proc_name;			proc_ids[n] = i;			local_vars[n] = (char **)				malloc (sizeof(char *)*(procs[i].n_locals+2));			local_vars[n][0] = "No Selection";			for (k = 1; k <= procs[i].n_locals; k++)				local_vars[n][k] = procs[i].locals[k].name;			local_vars[n][procs[i].n_locals+1] = NULL;			n++;		}	proc_name_list[n] = NULL;}char *get_file(np,p)	int		np;	char	*p[];{	int		status;	int		v_opt = 0;	int		i,fx;	int		file,stmt,proc,var;	if (np < 2) exit(1);	fx = 0;	for (i = 1; i < np; i++){		if (p[i][0] == '-'){			if (strcmp("-v",p[i]) == 0)v_opt = 1;		}		else fx = i;	}	i = strlen(p[fx]);	p[fx][i-1] = '\0';	status = read_k_file(p[fx]);	if(status){		fprintf (stderr,"%sc: K file status %d\n",p[fx],status);		exit(0);	}	status = read_link_file(p[fx]);	if(status){		fprintf (stderr,"%sc: LINK file status %d\n",p[fx],status);		exit(1);	}	if(v_opt)verify_input(0);	setup_history(p[fx]);	active = create_bit_set (n_procs+1);	slice_set = (bit_set *) malloc (n_files*sizeof(bit_set));	for (i = 0; i < n_files; i++)		slice_set[i] = create_bit_set(files[i].n_stmts+1);	alt_slice_set = (bit_set *) malloc (n_files*sizeof(bit_set));	for (i = 0; i < n_files; i++)		alt_slice_set[i] = create_bit_set(files[i].n_stmts+1);	dice_set = (bit_set *) malloc (n_files*sizeof(bit_set));	for (i = 0; i < n_files; i++)		dice_set[i] = create_bit_set(files[i].n_stmts+1);	primary_set = slice_set;	secondary_set = alt_slice_set;	return p[fx];}do_slice(x,file,stmt,proc,var,line)	int	file,stmt,proc,var,line;	Widget  x;{	int		p,f,i,status;	int		file_proc;	time_t			start,finish,elapsed;	char	cmd[2000],label[1000];	int		n = 0;	time_t	min,sec;	/*	printf ("file %d stmt %d proc %d var %d\n",file,stmt,proc,var);	*/		for (i = 1; i <= n_procs; i++){		if (procs[i].file_id == file)			if ((stmt >= procs[i].entry) &&				(stmt <= procs[i].exit)){					file_proc = i;					break;				}	}	/* printf ("file %d stmt %d proc %d var %d\n",file,stmt,proc,var); */		SliceClearAll(x);	start = time(NULL);	slice(file,file_proc,stmt,proc,var,slice_set,active);	finish = time(NULL);	elapsed = finish - start;	if (elapsed <= 0) elapsed = 1;	for (f = 0; f < n_files; f++){		i = -1;		while ((i = get_next_member(slice_set[f],i)) >= 0){			n++;			SliceSet (x,				files[f].stmts[i].froml+line_map[f],				files[f].stmts[i].fromc,				files[f].stmts[i].tol+line_map[f],				files[f].stmts[i].toc,0);		}	}	min = elapsed/60;	sec = elapsed%60;	sprintf (label,		"slice on %s (in %s) at line %d in %sc (%d stmts in %d:%d)",		var_name(proc,var),proc?procs[proc].proc_name:"global",		line,files[file].name,n,min,sec);	sprintf (cmd,"echo \"%s\" >> HISTORY-S",label);	system (cmd);	SliceRedraw (x);}adjust_popup_list (list)	Widget	list;{	Widget	port,shell,bar;	Dimension	bar_w,list_w,list_h;	int		list_max;	port = XtParent(list);	shell = XtParent(port);	bar = XtNameToWidget (port,"vertical");	XtUnmanageChild(port);	XtUnmanageChild(list);	XtVaGetValues (shell, XtNwidth,&list_w,		XtNheight,&list_h,NULL);	if(bar)XtVaGetValues (bar, XtNwidth,&bar_w,NULL);	else bar_w = 16;	XtVaGetValues (list, XtNwidth,&list_w,		XtNlongest,&list_max,		XtNheight,&list_h,NULL);	XtVaSetValues (shell,		XtNheight,list_h > 450? 430:list_h+5,		XtNwidth, list_max+14+bar_w+5,		NULL);	XtManageChild(list);	XtManageChild(port);	XtVaGetValues (shell, XtNwidth,&list_w,		XtNheight,&list_h,NULL);}void stop_slicing (w,x,y)	Widget	w;	Widget	x;	caddr_t	y;{	abandon_slice = 1;}void helpB (w,x,y)	Widget	w;	Widget	x;	caddr_t	y;{	char	cmd [2000];	sprintf (cmd,"%s/helpu %s/u.help &",home,home);	system (cmd);}void quitB (w,x,y)	Widget	w;	Widget	x;	caddr_t	y;{	char	cmd [2000];	sprintf (cmd,"cat HISTORY-S >> HISTORY");	system (cmd);	exit(0);}void slicecall (x,state,r)	proc_state_ptr state;	Widget	x;	MultiSliceReturn *r;{	int		line,file,stmt;	char	*var_name;	char	label[1000];	int		found;	Pixel	save_fg,save_bg;	if (state->is_running) return;	state->is_running = 1;	if (r->message) slice_set = secondary_set;	else slice_set = primary_set;	disp_to_file_and_line (r->line,&file,&line);	/*	printf ("call slice at line %d (line %d in file %s)\n",r->line,		line,files[file].name);		*/	if (state->pid) var_name =		procs[state->pid].locals[state->slice_var_index].name;	else var_name = globals[state->slice_var_index].name;	/*	printf ("%s var %s\n",state->pid?"local":"global",var_name);	*/	stmt = line_to_stmt(file,line);	sprintf (label,"computing slice on %s at line %d (%d of %sc)",		var_name,r->line,line,files[file].name);	XtVaGetValues (state->display_label,		XtNforeground,&save_fg,		XtNbackground,&save_bg,NULL);	XtVaSetValues (state->display_label,		XtNlabel,label,		XtNforeground,state->active_fg,		XtNbackground,state->active_bg,NULL);	found = find_slice (state->pid,state->slice_var_index,file,stmt);	if (found == -1){		do_slice (x,file,stmt,state->pid,state->slice_var_index,line);		save_slice (state->pid,state->slice_var_index,file,stmt,			abandon_slice,n_files,slice_set);	}	else {		load_slice (x,found,n_files,slice_set,line_map);	}	sprintf (label,"%sslice on %s at line %d (%d of %sc)",		abandon_slice?"(partial) ":"",		var_name,r->line,line,files[file].name);	XtVaSetValues (state->display_label,		XtNlabel,label,		XtNforeground,save_fg,		XtNbackground,save_bg,NULL);	sprintf (label,"%s(%s) %d(%sc)%s",		var_name,state->pid?procs[state->pid].proc_name:"global",		line,files[file].name,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -