/* ******************************************************************************* * Copyright (c) 1996 Martin Poole ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * $Source: /home/cvs/cvsroot/onelan/onelan/src/mplib1/util/sh_diag_i.c,v $ * $Author: mpoole $ * $Date: 2002/10/07 09:37:30 $ * $Revision: 1.2 $ * ******************************************************************************* * * Change History * * $Log: sh_diag_i.c,v $ * Revision 1.2 2002/10/07 09:37:30 mpoole * Initial checkin of mplib1-3.1.0 * * Revision 1.1 2002/10/07 09:37:09 mpoole * Initial checkin of mplib1-3.1.0 * * * * ******************************************************************************* */ #ident "$Header: /home/cvs/cvsroot/onelan/onelan/src/mplib1/util/sh_diag_i.c,v 1.2 2002/10/07 09:37:30 mpoole Exp $" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #ifdef __linux__ #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "include/bpo_init_internal.h" #include "include/bpo_q_internal.h" #include "include/bpo_proc_internal.h" #include #include "sh_diag.h" /* ------------------------------------------------------------------ defines ------------------------------------------------------------------ */ extern int diag_Validate_Shalloc( void *where, int which, int do_clean ); extern int diag_Validate_Resources( void *vp, int clean_up ); extern int diag_Validate_Queues( void *vp, int clean_up ); extern int diag_Validate_Processes( void *vp, int clean_up ); extern int do_hex_dump( FILE *fp, off_t curoff, char *where, int how_much ); #define GENOFF(a,b) (off_t)((char *)a-(char *)b) #define GANNODE(bp,off) (bpo_Node_t *)((char *)bp+off) static char sodb_name[]=SODB_BASE_NAME; static long int debug_level=0; static char help_str[]="Help details for interactive sh_diag\n\ Available commands\n\n\ shalloc [summary|used|free|all]\tlist allocation details as requested.\n\ resource [clean]\tlist (and clean) resources\n\ queue [clean]\tlist (and clean) queues\n\ process [clean]\tlist (and clean) process table\n\ list [check|list|node]\tcheck or display a list\n\ hexdump \tdisplay memory (values in hex)\n\ set [byte|word|long|string] \tchange value at given location\n\ debug \tSet internal debug level\n\ config \tset config keyword to value\n\ show \tShow details of given type at given offset\n\ define \tPass line to vre software\n\ read \tRead contents of file into vre system\n\ \nquit\n\n"; static struct match_token com_1[] = { { 1, "^shalloc clean" }, { 2, "^shalloc" }, { 3, "^resource clean" }, { 4, "^resource" }, { 5, "^queue clean" }, { 6, "^queue" }, { 7, "^process clean" }, { 8, "^process" }, { 9, "^list" }, { 10, "^hexdump" }, { 11, "^debug" }, { 12, "^config" }, { 13, "^fix" }, { 14, "^help" }, { 99, "^quit" }, { 0, NULL } }; static struct match_token list_modes[] = { { 1, "^check" }, { 2, "^list" }, { 3, "^node" }, { 4, "^show" }, { 0, NULL } }; static struct match_token shalloc_modes[] = { { 1, "^summary" }, { 2, "^free" }, { 4, "^used" }, { 7, "^all" }, { 0, NULL } }; static void *my_seg_base=NULL; /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ static long int get_hex_param( char *np, char **nnp ) { long int rv; rv = strtol( np, nnp, 16 ); return(rv); } static void show_item( void *vp, bpo_Node_t *bnp, void *cp ) { char *ep; ep = (char *)cp + strlen(cp); sprintf( ep, "%08lx", bnp->lno_Item ); vre_Interactive_Loop( cp, stdout, vp ); *ep = '\0'; return; } static void my_bpo_Walk_List( void *vp, bpo_List_t *l_ptr, void (*disp)( void *, bpo_Node_t *, void * ), void *param ) { bpo_Node_t *n_ptr,*nn_ptr; char *seg_base; seg_base = Find_SODB_Resource( l_ptr, sodb_name ); n_ptr = GANNODE( seg_base, l_ptr->lno_Head.lno_Succ ); while (n_ptr->lno_Succ) { /* save the next pointer just in case they mash the list */ nn_ptr = GANNODE( seg_base, n_ptr->lno_Succ) ; (*disp)( vp, n_ptr, param ); if (n_ptr == nn_ptr) break; n_ptr = nn_ptr; }; return; } static int display_this_item( bpo_Node_t *npp, void *base ) { node_list_details( base, npp, fprintf, stdout ); return(0); } static int display_this_list( bpo_List_t *blp, void *base ) { bpo_Walk_List_N( blp, (bpo_Walk_List_N_t)display_this_item, base ); return(0); } static int list_check( void *vp, char *np ) { bpo_List_t *rlp; off_t offst; char *nnp,*cp; int rv,sv; sv = match_a_string( np, list_modes, &nnp ); offst= vre_Get_ADDR( nnp, &nnp ); rlp = (bpo_List_t *)((char *)vp + offst); switch(sv) { case 1 : /* check the list */ rv = bpo_Validate_List( rlp ); if (rv==0) fprintf(stdout, "List is clean\n" ); break; case 2 : /* list the list */ rv = bpo_Validate_List( rlp ); if (rv==0) { node_list_header( fprintf, stdout ); bpo_Work_List( rlp, (bpo_Work_List_t)display_this_list, vp ); } break; case 3 : /* list the node */ node_list_header( fprintf, stdout ); node_list_details( vp, (bpo_Node_t *)rlp, fprintf, stdout ); break; case 4 : /* show a list by type */ if ( vre_Find_Type( nnp ) && ( cp = malloc( strlen(nnp) + 16 ) ) ) { sprintf( cp, "show %s ", nnp ); my_bpo_Walk_List( vp, rlp, show_item, cp ); free(cp); } break; default : fprintf(stderr, "Unknown list mode\n" ); break; } return(1); } static int dump_some_hex( void *vp, char *np ) { char *nnp; off_t offst; long int ln; offst = (off_t)get_hex_param( np, &nnp ); ln = get_hex_param( nnp, NULL ); if (ln) do_hex_dump( stdout, offst, ((char *)vp + offst), ln ); return(1); } static int me_test( off_t *mep, off_t me ) { int rv=0; if (*mep != me) { rv=1; fprintf( stderr, "Structure at %08lx has incorrect lno_me %08lx\n", me, *mep ); } return(rv); } static int fix_links( void *vp, char *np ) { char *nnp; off_t v1,v2,v3; bpo_Node_t *bp1,*bp2,*bp3; v1 = (off_t)get_hex_param( np, &nnp ); v2 = (off_t)get_hex_param( nnp, &nnp ); v3 = (off_t)get_hex_param( nnp, &nnp ); bp1 = (bpo_Node_t *)( (char *)vp + v1 ); bp2 = (bpo_Node_t *)( (char *)vp + v2 ); bp3 = (bpo_Node_t *)( (char *)vp + v3 ); if (v1 != v2) { if (v2!=v3 && v3!=0) { if ( me_test( &bp1->lno_me, v1 ) || me_test( &bp2->lno_me, v2 ) || me_test( &bp3->lno_me, v3 ) ) { ; } else /* three params, link the second in between the first and third */ if (bp1->lno_List != bp3->lno_List) { fprintf( stderr, "Items not on same list\n" ); }else { bp1->lno_Succ = v2; bp3->lno_Pred = v2; bp2->lno_Succ = v3; bp2->lno_Pred = v1; bp2->lno_List = bp1->lno_List; } }else { if ( me_test( &bp1->lno_me, v1 ) || me_test( &bp2->lno_me, v2 ) ) { ; } else /* two param, just link them */ if (bp1->lno_List != bp2->lno_List) { fprintf( stderr, "Items not on same list\n" ); }else { bp1->lno_Succ = v2; bp2->lno_Pred = v1; } } }else { fprintf(stderr, "Unsufficient parameters\n" ); } return(1); } int interactive_loop( void *vp ) { char lbuf[255]; char *np=NULL; int loop=1,clean_up; int sv,sv2; my_seg_base = vp; vre_Init_Disp_Primitives( stderr ); (void)sh_diag_disp_init(); while ( loop==1 && fgetline( stdin, lbuf, 255 )==0 ) { clean_up=0; sv = match_a_string( lbuf, com_1, &np ); switch( sv ) { case 99 : /* quit */ loop = 0; break; case 1 : /* shalloc, clean */ fprintf( stderr, "Obsolete command\n" ); break; case 2 : /* shalloc */ sv2 = match_a_string( np, shalloc_modes, &np ); if (sv2==0) sv2=1; diag_Validate_Shalloc( vp, sv2, clean_up ); break; case 3 : /* resource, clean */ clean_up=1; case 4 : /* resource */ diag_Validate_Resources( vp, clean_up ); break; case 5 : /* queue, clean */ clean_up=1; case 6 : /* queue */ diag_Validate_Queues( vp, clean_up ); break; case 7 : /* process, clean */ clean_up=1; case 8 : /* process */ diag_Validate_Processes( vp, clean_up ); break; case 9 : /* listcheck */ list_check( vp, np ); break; case 10 : /* hexdump */ dump_some_hex( vp, np ); break; case 11 : /* set debug level */ debug_level = get_hex_param( np, NULL ); break; case 12 : /* set config value */ read_config_string( np ); break; case 13 : /* fix */ fix_links( vp, np ); break; case 14 : /* help */ printf( "%s\n", help_str ); break; default : if (strlen(lbuf)) { vre_Interactive_Loop( lbuf, stdout, vp ); } continue; } } return(1); } /* -- End of File -- */