text
stringlengths
0
601k
let get_int_result errmsg res = match fetch res with | None -> failwith errmsg | Some row -> strip errmsg row . ( 0 ) |> int_of_string
let null_str dbhandle = ml2rstr dbhandle " "
let bool_to_tinyint = function | true -> 1 | false -> 0
let get_insert_id dbhandle = let res = mysql_exec dbhandle " SELECT LAST_INSERT_ID ( ) ; " in get_int_result " failed to get insert id " res
let rec reader bzch inch buf pos total = let full_pass = ( total - pos ) >= bz_block_size in let read_size = if full_pass then bz_block_size else total - pos in Pervasives . really_input inch buf 0 read_size ; Bz2 . write bzch buf 0 read_size ; if full_pass then reader bzch inch buf ( pos + bz_block_size ) total else (...
let bzip_a_file origin bzfile = let inch = Pervasives . open_in origin in let outch = Pervasives . open_out bzfile in let bzch = Bz2 . open_out outch in let n = in_channel_length inch in let buf = Bytes . create bz_block_size in reader bzch inch buf 0 n ; Bz2 . close_out bzch ; Pervasives . close_out outch ; Pervasives...
let load_blob state = let logfile = get_logfile state . working_dir in let bzfile = Filename . concat ( Filename . dirname logfile ) " log . bz2 " in let ( ) = bzip_a_file logfile bzfile in let ch = open_in bzfile in let n = in_channel_length ch in let s = Bytes . create n in really_input ch s 0 n ; close_in ch ; s
let insert_campaign state dbhandle = let log = load_blob state in let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO campaign_tbl VALUES % s ; " ( values [ null_str dbhandle ; ml2rstr dbhandle ( time_string state . initial_time ) ; ml2rstr dbhandle ( schedule_to_string state . knobs . scheduling ) ; ml2rblob ...
let insert_client state dbhandle = let new_client state dbhandle = let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO client_tbl VALUES % s " ( values [ null_str dbhandle ; ml2rstr dbhandle Envmanager . os ; ml2rstr dbhandle Envmanager . kernel ; ml2rstr dbhandle Envmanager . arch ; ml2rstr dbhandle Envmanage...
let insert_seed dbhandle conf = let seed_hash = Digest . file conf . seed_file |> Digest . to_hex in let new_seed dbhandle conf = let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO seed_tbl VALUES % s " ( values [ null_str dbhandle ; ml2int conf . input_size ; ml2rstr dbhandle conf . seed_file ; ml2rstr dbhan...
let insert_program dbhandle conf = let prog_path = List . hd conf . cmds in let prog_name = Filename . basename prog_path in let prog_hash = Digest . file prog_path |> Digest . to_hex in let prog_size = get_filesize prog_path in let new_prog dbhandle conf = let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO p...
let insert_conf state dbhandle conf sid pid = let seed_start , seed_end = state . knobs . seed_range in let mratio_start , mratio_end = conf . mratio in let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO fuzz_conf_tbl VALUES % s " ( values [ null_str dbhandle ; ml2rstr dbhandle ( alg_to_string state . knobs ....
let insert_fuzzing dbhandle stats conf cpid clid cfid = let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO fuzzing_tbl VALUES % s " ( values [ null_str dbhandle ; ml2rstr dbhandle ( time_string stats . ( conf . confid ) . start_time ) ; ml2rstr dbhandle ( time_string stats . ( conf . confid ) . finish_time ) ...
let insert_stats dbhandle stats conf fid = let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO stats_tbl VALUES % s " ( values [ null_str dbhandle ; ml2int ( Hashtbl . length stats . ( conf . confid ) . unique_set ) ; ml2int stats . ( conf . confid ) . num_crashes ; ml2int stats . ( conf . confid ) . num_runs ...
let insert_crash_case dbhandle stats conf stid = let new_crash dbhandle crashid = let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO crash_case_tbl VALUES % s " ( values [ null_str dbhandle ; ml2rstr dbhandle crashid . hashval ; ml2rstr dbhandle crashid . backtrace ] ) ) in get_insert_id dbhandle in Hashtbl ....
let insert_crash_case dbhandle state conf stid = if state . knobs . triage_on_the_fly then insert_crash_case dbhandle state . stats conf stid else ( )
let insert_per_conf with_seed state dbhandle confs cpid clid = List . iter ( fun conf -> let sid = if with_seed then insert_seed dbhandle conf else null in let pid = insert_program dbhandle conf in let cfid = insert_conf state dbhandle conf sid pid in let fid = insert_fuzzing dbhandle state . stats conf cpid clid cfid ...
let insert_per_conf state dbhandle confs cpid clid = match state . knobs . testgen_alg with | BallMutational | SurfaceMutational | ZzufMutational -> insert_per_conf true state dbhandle confs cpid clid | _ -> insert_per_conf false state dbhandle confs cpid clid
let push_result state dbhandle confs = let _ = mysql_exec dbhandle " START TRANSACTION ; " in let cpid = insert_campaign state dbhandle in let clid = insert_client state dbhandle in let _ = insert_per_conf state dbhandle confs cpid clid in let _ = mysql_exec dbhandle " COMMIT ; " in ( )
let push_result state confs = let dbhandle = dbconnect state . knobs in match dbhandle with | None -> ( ) | Some dbhandle -> push_result state dbhandle confs
type open_flag = Dbm_rdonly | Dbm_wronly | Dbm_rdwr | Dbm_create
type dbm_flag = DBM_INSERT | DBM_REPLACE = " caml_dbm_open "
let opendbm file flags mode = try raw_opendbm file flags mode with Dbm_error msg -> raise ( Dbm_error ( " Can ' t open file " ^ file ) )
let _ = Callback . register_exception " dbmerror " ( Dbm_error " " )
let iter f t = let rec walk = function None -> ( ) | Some k -> f k ( find t k ) ; walk ( try Some ( nextkey t ) with Not_found -> None ) in walk ( try Some ( firstkey t ) with Not_found -> None )
let later = ref [ ]
let last = ref [ ]
let met = Hashtbl . create 512
let eom ( ) = List . iter ( fun f -> f ( ) ) ! later ; later := [ ] ; Hashtbl . reset met
let add lab expr loc last_loc nb_occur = let has_val = match expr . exp_desc with | Texp_construct ( _ , { cstr_name = " None " ; _ } , _ ) -> false | _ -> true in let occur = let occur = if not ( Hashtbl . mem nb_occur lab ) then Hashtbl . add nb_occur lab 1 else Hashtbl . find nb_occur lab + 1 |> Hashtbl . replace nb...
let rec process loc args = List . iter ( function | ( _ , Some e ) -> check e | _ -> ( ) ) args ; if is_ghost loc then ( ) else begin let nb_occur = Hashtbl . create 256 in let last_loc = ! last_loc in let add lab expr = add lab expr loc last_loc nb_occur in let add = function | ( Asttypes . Optional lab , Some expr ) ...
let node_build loc expr = let rec loop loc expr = match expr . exp_desc with | Texp_function { arg_label = lab ; cases = [ { c_lhs = { pat_type ; _ } ; c_rhs = exp ; _ } ] ; _ } -> DeadType . check_style pat_type expr . exp_loc . Location . loc_start ; begin match lab with | Asttypes . Optional s -> if ! DeadFlag . opt...
let wrap f x y = if DeadFlag . ( ! optn . print || ! opta . print ) then f x y else ( )
let process val_loc args = wrap process val_loc args
let bad_files = ref [ ]
let main_files = Hashtbl . create 256
let rec collect_export ( ? mod_type = false ) path u stock = function | Sig_value ( id , ( { Types . val_loc ; val_type ; _ } as value ) ) when not val_loc . Location . loc_ghost && stock == decs -> if ! DeadFlag . exported . DeadFlag . print then export path u stock id val_loc ; let path = Ident . { id with name = id ...
let rec treat_exp exp args = match exp . exp_desc with | Texp_apply ( exp , in_args ) -> treat_exp exp ( in_args @ args ) | Texp_ident ( _ , _ , { Types . val_loc = { Location . loc_start = loc ; _ } ; _ } ) | Texp_field ( _ , _ , { lbl_loc = { Location . loc_start = loc ; _ } ; _ } ) -> DeadArg . process loc args ; | ...
let value_binding super self x = let old_later = ! DeadArg . later in DeadArg . later := [ ] ; incr depth ; let open Asttypes in begin match x with | { vb_pat = { pat_desc = Tpat_var ( _ , { loc = { Location . loc_start = loc1 ; loc_ghost = false ; _ } ; _ } ) ; _ } ; vb_expr = { exp_desc = Texp_ident ( _ , _ , { val_l...
let structure_item super self i = let open Asttypes in begin match i . str_desc with | Tstr_type ( _ , l ) when ! DeadFlag . typ . DeadFlag . print -> List . iter DeadType . tstr l | Tstr_module { mb_name = { txt ; _ } ; _ } -> mods := txt :: ! mods ; DeadMod . defined := String . concat " . " ( List . rev ! mods ) :: ...
let pat super self p = let pat_loc = p . pat_loc . Location . loc_start in let u s = let err = ( ! current_src , pat_loc , Printf . sprintf " unit pattern % s " s ) in style := err :: ! style in let open Asttypes in if DeadType . is_unit p . pat_type && ! DeadFlag . style . DeadFlag . unit_pat then begin match p . pat_...
let expr super self e = let rec extra = function | [ ] -> ( ) | ( Texp_coerce ( _ , typ ) , _ , _ ) :: l -> DeadObj . coerce e typ . ctyp_type ; extra l | _ :: l -> extra l in extra e . exp_extra ; let exp_loc = e . exp_loc . Location . loc_start in let open Ident in begin match e . exp_desc with | Texp_ident ( path , ...
let collect_references = let super = Tast_mapper . default in let wrap f loc self x = let l = ! last_loc in let ll = ( loc x ) . Location . loc_start in if ll <> Lexing . dummy_pos then last_loc := ll ; let prev_last_class = ! DeadObj . last_class in let r = f self x in DeadObj . last_class := prev_last_class ; last_lo...
let starts_with prefix s = let len = String . length prefix in if len > String . length s then false else String . sub s 0 len = prefix
let ends_with suffix s = let len = String . length suffix in let s_len = String . length s in if len > s_len then false else String . sub s ( s_len - len ) len = suffix
let remove_wrap name = let n = String . length name in let rec loop i = if i < n - 1 then if name . [ i ] == ' _ ' && name . [ i + 1 ] == ' _ ' then String . uncapitalize_ascii ( String . sub name ( i + 2 ) ( n - i - 2 ) ) else loop ( i + 1 ) else name in loop 0
let kind fn = if not ( Sys . file_exists fn ) then begin prerr_endline ( " Warning : ' " ^ fn ^ " ' not found " ) ; ` Ignore end else if not ( DeadFlag . is_excluded fn ) then begin let good_exts base exts = let open DeadFlag in let good_ext base ext = let fn = base ^ ext in Sys . file_exists fn && not ( is_excluded fn...
let regabs fn = current_src := fn ; hashtbl_add_unique_to_list abspath ( unit fn ) fn ; if ! DeadCommon . declarations then hashtbl_add_unique_to_list main_files ( unit fn ) ( )
let read_interface fn src = let open Cmi_format in try regabs src ; let u = unit fn in if ! DeadFlag . exported . DeadFlag . print || ! DeadFlag . obj . DeadFlag . print || ! DeadFlag . typ . DeadFlag . print then let f = collect_export [ Ident . create ( String . capitalize_ascii u ) ] u decs in List . iter f ( read_c...
let assoc decs ( loc1 , loc2 ) = let fn1 = loc1 . Lexing . pos_fname and fn2 = loc2 . Lexing . pos_fname in let is_implem fn = fn . [ String . length fn - 1 ] <> ' i ' in let has_iface fn = fn . [ String . length fn - 1 ] = ' i ' || ( unit fn = unit ! current_src && try Sys . file_exists ( find_abspath fn ^ " i " ) wit...
let clean references loc = let fn = loc . Lexing . pos_fname in if ( fn . [ String . length fn - 1 ] <> ' i ' && unit fn = unit ! current_src ) then LocHash . remove references loc
let eom loc_dep = DeadArg . eom ( ) ; List . iter ( assoc decs ) loc_dep ; List . iter ( assoc DeadType . decs ) ! DeadType . dependencies ; if Sys . file_exists ( ! current_src ^ " i " ) then begin let clean = List . iter ( fun ( loc1 , loc2 ) -> clean references loc1 ; clean references loc2 ) in clean loc_dep ; clean...
let rec load_file fn = match kind fn with | ` Iface src when ! DeadCommon . declarations -> last_loc := Lexing . dummy_pos ; if ! DeadFlag . verbose then Printf . eprintf " Scanning % s \ n " %! fn ; read_interface fn src | ` Implem src -> let open Cmt_format in last_loc := Lexing . dummy_pos ; if ! DeadFlag . verbose ...
let analyze_opt_args ( ) = List . iter ( fun f -> f ( ) ) ! DeadArg . last ; let all = ref [ ] in let tbl = Hashtbl . create 256 in let dec_loc loc = Hashtbl . mem main_files ( unit loc . Lexing . pos_fname ) in let analyze = fun ( loc , lab , has_val , call_site ) -> let slot = try Hashtbl . find tbl ( loc , lab ) wit...
let report_opt_args s l = let opt = if s = " NEVER " then ! DeadFlag . optn else ! DeadFlag . opta in let percent = percent opt in let rec report_opt_args nb_call = let open DeadFlag in let l = List . filter ( fun ( _ , _ , slot , ratio , _ ) -> let ratio = 1 . . - ratio in if opt . threshold . optional = ` Both then r...
let report_unused_exported ( ) = report_basic decs " UNUSED EXPORTED VALUES " ! DeadFlag . exported
let report_style ( ) = section " CODING STYLE " ; if ! style <> [ ] then begin style := List . fast_sort compare ! style ; let change = let ( fn , _ , _ ) = List . hd ! style in dir fn in List . iter ( fun ( fn , l , s ) -> if change fn then print_newline ( ) ; prloc ~ fn l ; print_endline s ) ! style ; end ; print_new...
let parse ( ) = let update_all print ( ) = DeadFlag . ( update_style ( ( if print = " all " then " " + else " " ) - ^ " all " ) ; update_basic " - E " DeadFlag . exported print ; update_basic " - M " obj print ; update_basic " - T " typ print ; update_opt opta print ; update_opt optn print ) in Arg . ( parse [ " -- exc...
let ( ) = try parse ( ) ; DeadCommon . declarations := false ; let oldstyle = ! DeadFlag . style in DeadFlag . update_style " - all " ; List . iter load_file ! DeadFlag . directories ; DeadFlag . style := oldstyle ; Printf . eprintf " [ DONE ] \ n \ n " ; %! let open DeadFlag in ! DeadLexiFi . prepare_report DeadType ....
module LocSet = Set . Make ( struct type t = Lexing . position let compare = compare end )
module LocHash = struct include Hashtbl . Make ( struct type t = Lexing . position let hash x = let s = Filename . basename x . Lexing . pos_fname in Hashtbl . hash ( x . Lexing . pos_cnum , s ) let equal x y = x = y end ) let find_set h k = try find h k with Not_found -> LocSet . empty let add_set h k v = let l = find...
let abspath : ( string , string ) Hashtbl . t = Hashtbl . create 256
let decs : ( Lexing . position , string * string ) Hashtbl . t = Hashtbl . create 256
let incl : ( Lexing . position , string * string ) Hashtbl . t = Hashtbl . create 256
let references : LocSet . t LocHash . t = LocHash . create 256
let fields : ( string , Lexing . position ) Hashtbl . t = Hashtbl . create 256
let style : ( string * Lexing . position * string ) list ref = ref [ ]
let last_loc = ref Lexing . dummy_pos
let current_src = ref " "
let mods : string list ref = ref [ ]
let depth = ref ( - 1 )
let declarations = ref true
let _variant = " : variant " :
let unit fn = try Filename . chop_extension ( Filename . basename fn ) with Invalid_argument _ -> fn
let is_ghost loc = loc . Lexing . pos_lnum <= 0 || loc . Lexing . pos_cnum - loc . Lexing . pos_bol < 0 || loc . Lexing . pos_fname = _none || loc . Lexing . pos_fname = " "
let check_underscore name = not ! DeadFlag . underscore || name . [ 0 ] <> ' _ '
let hashtbl_find_list hashtbl key = Hashtbl . find_all hashtbl key
let hashtbl_add_to_list hashtbl key elt = Hashtbl . add hashtbl key elt
let hashtbl_add_unique_to_list hashtbl key elt = if not ( List . mem elt ( hashtbl_find_list hashtbl key ) ) then Hashtbl . add hashtbl key elt
let rec hashtbl_remove_list hashtbl key = if Hashtbl . mem hashtbl key then begin Hashtbl . remove hashtbl key ; hashtbl_remove_list hashtbl key end
let hashtbl_replace_list hashtbl key l = hashtbl_remove_list hashtbl key ; List . iter ( fun elt -> hashtbl_add_to_list hashtbl key elt ) l
let hashtbl_merge_unique_list tbl1 key1 tbl2 key2 = List . iter ( fun elt -> hashtbl_add_unique_to_list tbl1 key1 elt ) ( hashtbl_find_list tbl2 key2 )
let find_path fn ( ? sep = ' ' ) / l = List . find ( fun path -> let lp = String . length path and lf = String . length fn in ( lp > lf && path . [ lp - lf - 1 ] = sep || lp = lf ) && String . sub path ( lp - lf ) lf = fn ) l
let find_abspath fn = find_path fn ( hashtbl_find_list abspath ( unit fn ) )
let exported ( flag : DeadFlag . basic ref ) loc = let fn = loc . Lexing . pos_fname in ! flag . DeadFlag . print && LocHash . find_set references loc |> LocSet . cardinal <= ! flag . DeadFlag . threshold && ( flag == DeadFlag . typ || ! DeadFlag . internal || fn . [ String . length fn - 1 ] = ' i ' || unit ! current_s...
let section ( ? sub = false ) title = Printf . printf " % s % s :\ n % s \ n " ( if sub then " . >-> " else " . " ) > title ( String . make ( ( if sub then 5 else 2 ) + String . length title + 1 ) ( if sub then ' ' ~ else ' ' ) ) =
let separator ( ) = print_endline " Nothing else to report in this section " ; Printf . printf " % s \ n \ n \ n " ( String . make 80 ' ' ) -
let prloc ( ? call_site = false ) ? fn ( loc : Lexing . position ) = let file = loc . Lexing . pos_fname in let line = loc . Lexing . pos_lnum in let col = loc . Lexing . pos_cnum - loc . Lexing . pos_bol in begin match fn with | Some s -> print_string s | _ -> match find_abspath file with | s -> print_string s | excep...
type opt_arg = { mutable with_val : Lexing . position list ; mutable without_val : Lexing . position list ; }
let opt_args : ( Lexing . position * string * bool * Lexing . position ) list ref = ref [ ]
module VdNode = struct type t = ( string list * Lexing . position option ) let vd_nodes = LocHash . create 256 let parents = LocHash . create 256 let get loc = assert ( not ( is_ghost loc ) ) ; try ( LocHash . find vd_nodes loc ) with Not_found -> let r = ( [ ] , None ) in LocHash . add vd_nodes loc r ; r let get_opts ...
let export ( ? sep = " . " ) path u stock id loc = let value = String . concat " . " ( List . rev_map Ident . name path ) ^ sep ^ id . Ident . name in if not loc . Location . loc_ghost && ( u = unit loc . Location . loc_start . Lexing . pos_fname || u == _include ) && check_underscore id . Ident . name then hashtbl_add...
let abs loc = match find_abspath loc . Lexing . pos_fname with | s -> s | exception Not_found -> loc . Lexing . pos_fname
let dir first = let prev = ref @@ Filename . dirname first in fun s -> let s = Filename . dirname s in ! prev <> s && ( prev := s ; true )
let rec check_length len = function | [ ] -> len = 0 | _ :: l when len > 0 -> check_length ( len - 1 ) l | _ -> false
let pretty_print_call ( ) = let ghost = ref false in function | loc when not ( is_ghost loc ) -> prloc ~ call_site : true loc |> print_newline | _ when ! ghost -> ( ) | _ -> print_endline " ~ ghost " ; ~ ghost := true
let percent ( opt : DeadFlag . opt ) base = let open DeadFlag in 1 . . - ( float_of_int base ) . * ( 1 . . - opt . threshold . percentage ) . / 10 .
let report s ( ~ opt : DeadFlag . opt ) ( ? extra = " Called " ) l continue nb_call pretty_print reporter = if nb_call = 0 || l <> [ ] then begin section ~ sub ( : nb_call <> 0 ) @@ ( if nb_call = 0 then s else if DeadFlag . ( opt . threshold . optional ) = ` Both || extra = " Called " then Printf . sprintf " % s : % s...
let report_basic ? folder decs title ( flag : DeadFlag . basic ) = let folder = match folder with | Some folder -> folder | None -> fun nb_call -> fun loc ( fn , path ) acc -> let rec cut_main s pos = if pos = String . length s then s else if s . [ pos ] = ' . ' then String . sub s ( pos + 1 ) ( String . length s - pos...
module DeadLexiFi = struct let sig_value : ( Types . value_description -> unit ) ref = ref ( fun _ -> ( ) ) let export_type : ( Lexing . position -> string -> unit ) ref = ref ( fun _ _ -> ( ) ) let type_ext : ( Typedtree . core_type -> unit ) ref = ref ( fun _ -> ( ) ) let type_decl : ( Typedtree . type_declaration ->...