Summary: First version of an analyzer collecting classes transitively touched. Reviewed By: mbouaziz Differential Revision: D10448025 fbshipit-source-id: 0ddfefd46master
							parent
							
								
									7e7913d5ee
								
							
						
					
					
						commit
						4334225e67
					
				| @ -0,0 +1,51 @@ | ||||
| (* | ||||
|  * Copyright (c) 2018-present, Facebook, Inc. | ||||
|  * | ||||
|  * This source code is licensed under the MIT license found in the | ||||
|  * LICENSE file in the root directory of this source tree. | ||||
|  *) | ||||
| open! IStd | ||||
| module F = Format | ||||
| module L = Logging | ||||
| 
 | ||||
| module Payload = SummaryPayload.Make (struct | ||||
|   type t = ClassLoadsDomain.summary | ||||
| 
 | ||||
|   let update_payloads post (payloads : Payloads.t) = {payloads with class_loads= Some post} | ||||
| 
 | ||||
|   let of_payloads (payloads : Payloads.t) = payloads.class_loads | ||||
| end) | ||||
| 
 | ||||
| module TransferFunctions (CFG : ProcCfg.S) = struct | ||||
|   module CFG = CFG | ||||
|   module Domain = ClassLoadsDomain | ||||
| 
 | ||||
|   type extras = unit | ||||
| 
 | ||||
|   let exec_instr (astate : Domain.astate) {ProcData.pdesc} _ (instr : HilInstr.t) = | ||||
|     match instr with | ||||
|     | Call (_, Direct callee, _, _, loc) -> | ||||
|         Payload.read pdesc callee | ||||
|         |> Option.value_map ~default:astate ~f:(Domain.integrate_summary astate callee loc) | ||||
|     | _ -> | ||||
|         astate | ||||
| 
 | ||||
| 
 | ||||
|   let pp_session_name _node fmt = F.pp_print_string fmt "class loads" | ||||
| end | ||||
| 
 | ||||
| module Analyzer = LowerHil.MakeAbstractInterpreter (ProcCfg.Normal) (TransferFunctions) | ||||
| 
 | ||||
| let die_if_not_java proc_desc = | ||||
|   let is_java = | ||||
|     Procdesc.get_proc_name proc_desc |> Typ.Procname.get_language |> Language.(equal Java) | ||||
|   in | ||||
|   if not is_java then L.(die InternalError "Not supposed to run on non-Java code yet.") | ||||
| 
 | ||||
| 
 | ||||
| let analyze_procedure {Callbacks.proc_desc; tenv; summary} = | ||||
|   die_if_not_java proc_desc ; | ||||
|   let initial = ClassLoadsDomain.empty in | ||||
|   let proc_data = ProcData.make proc_desc tenv () in | ||||
|   Analyzer.compute_post proc_data ~initial | ||||
|   |> Option.value_map ~default:summary ~f:(fun astate -> Payload.update_summary astate summary) | ||||
| @ -0,0 +1,10 @@ | ||||
| (* | ||||
|  * Copyright (c) 2018-present, Facebook, Inc. | ||||
|  * | ||||
|  * This source code is licensed under the MIT license found in the | ||||
|  * LICENSE file in the root directory of this source tree. | ||||
|  *) | ||||
| 
 | ||||
| open! IStd | ||||
| 
 | ||||
| val analyze_procedure : Callbacks.proc_callback_t | ||||
| @ -0,0 +1,38 @@ | ||||
| (* | ||||
|  * Copyright (c) 2018-present, Facebook, Inc. | ||||
|  * | ||||
|  * This source code is licensed under the MIT license found in the | ||||
|  * LICENSE file in the root directory of this source tree. | ||||
|  *) | ||||
| open! IStd | ||||
| module F = Format | ||||
| module ClassLoad = String | ||||
| module Event = ExplicitTrace.MakeTraceElem (ClassLoad) | ||||
| include Event.FiniteSet | ||||
| 
 | ||||
| let add ({Event.trace} as x) astate = | ||||
|   match find_opt x astate with | ||||
|   | None -> | ||||
|       add x astate | ||||
|   | Some ({Event.trace= trace'} as x') -> | ||||
|       if Int.( <= ) (List.length trace') (List.length trace) then astate | ||||
|       else remove x' astate |> add x | ||||
| 
 | ||||
| 
 | ||||
| let union xs ys = fold add xs ys | ||||
| 
 | ||||
| let integrate_summary astate callee_pname loc callee_summary = | ||||
|   match callee_pname with | ||||
|   | Typ.Procname.Java java_pname -> | ||||
|       let clazz = Typ.Procname.Java.get_class_name java_pname in | ||||
|       let new_event = Event.make clazz loc in | ||||
|       let callsite = CallSite.make callee_pname loc in | ||||
|       let summary = with_callsite callee_summary callsite in | ||||
|       add new_event astate |> union summary | ||||
|   | _ -> | ||||
|       astate | ||||
| 
 | ||||
| 
 | ||||
| type summary = astate | ||||
| 
 | ||||
| let pp_summary = pp | ||||
| @ -0,0 +1,16 @@ | ||||
| (* | ||||
|  * Copyright (c) 2018-present, Facebook, Inc. | ||||
|  * | ||||
|  * This source code is licensed under the MIT license found in the | ||||
|  * LICENSE file in the root directory of this source tree. | ||||
|  *) | ||||
| open! IStd | ||||
| module F = Format | ||||
| 
 | ||||
| include AbstractDomain.WithBottom | ||||
| 
 | ||||
| type summary = astate | ||||
| 
 | ||||
| val pp_summary : F.formatter -> summary -> unit | ||||
| 
 | ||||
| val integrate_summary : astate -> Typ.Procname.t -> Location.t -> summary -> astate | ||||
					Loading…
					
					
				
		Reference in new issue