12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394(****************************************************************************)(* *)(* This file is part of MOPSA, a Modular Open Platform for Static Analysis. *)(* *)(* Copyright (C) 2017-2019 The MOPSA Project. *)(* *)(* This program is free software: you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License as published *)(* by the Free Software Foundation, either version 3 of the License, or *)(* (at your option) any later version. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this program. If not, see <http://www.gnu.org/licenses/>. *)(* *)(****************************************************************************)(** Policies for grouping heap addresses *)openMopsaopenAsttypeaddr_partitioning+=|G_rangeofrange|G_stack_rangeofcallstack*range|G_stackofcallstacklet()=register_addr_partitioning{compare=(funnextg1g2->matchg1,g2with|G_ranger,G_ranger'->compare_rangerr'|G_stack_range(cs,r),G_stack_range(cs',r')->Compare.compose[(fun()->compare_callstackcscs');(fun()->compare_rangerr');]|G_stack(cs),G_stack(cs')->compare_callstackcscs'|_->nextg1g2);print=(funnextfmtg->matchgwith|G_ranger->pp_relative_rangefmtr|G_stack_range(cs,r)->Format.fprintffmt"%a:%a"pp_callstack_shortcspp_relative_ranger|G_stack(cs)->pp_callstack_shortfmtcs|_->nextfmtg);}letmk_addr_rangeaddr_kindaddr_moderangecs={addr_kind;addr_mode;addr_partitioning=G_rangerange}letmk_addr_stack_rangeaddr_kindaddr_moderangecs={addr_kind;addr_mode;addr_partitioning=G_stack_range(cs,range)}letmk_addr_stackaddr_kindaddr_moderangecs={addr_kind;addr_mode;addr_partitioning=G_stackcs}letmk_addr_alladdr_kindaddr_moderangecs={addr_kind;addr_mode;addr_partitioning=G_all}letmk_addr_chain:(addr_kind->mode->range->callstack->addr)ref=ref(funak___->assertfalse)letmk_addrakmrcs=!mk_addr_chainakmrcsletregister_mk_addrf=mk_addr_chain:=f!mk_addr_chainletregister_option(opt:stringref)(domain_name:string)(key:string)(descr:string)f=register_domain_optiondomain_name{key;category="Heap";doc=Format.asprintf" allocation policy used %s"descr;spec=Symbol(["all";"range";"callstack";"range_callstack"],(functions->opt:=s));default=!opt;};register_mk_addrfletof_stringopt=matchoptwith|"all"->mk_addr_all|"range"->mk_addr_range|"callstack"->mk_addr_stack|"range_callstack"->mk_addr_stack_range|_->panic"unknown policy %s"opt