summaryrefslogtreecommitdiff
path: root/gcc/ada/gnatmem.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2003-10-21 13:42:24 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2003-10-21 13:42:24 +0000
commit9dfe12ae5b94d03c997ea2903022a5d2d5c5f266 (patch)
treebdfc70477b60f1220cb05dd233a4570dd9c6bb5c /gcc/ada/gnatmem.adb
parent1c662558a1113238a624245a45382d3df90ccf13 (diff)
downloadgcc-9dfe12ae5b94d03c997ea2903022a5d2d5c5f266.tar.gz
2003-10-21 Arnaud Charlet <charlet@act-europe.fr>
* 3psoccon.ads, 3veacodu.adb, 3vexpect.adb, 3vsoccon.ads, 3vsocthi.adb, 3vsocthi.ads, 3vtrasym.adb, 3zsoccon.ads, 3zsocthi.adb, 3zsocthi.ads, 50system.ads, 51system.ads, 55system.ads, 56osinte.adb, 56osinte.ads, 56taprop.adb, 56taspri.ads, 56tpopsp.adb, 57system.ads, 58system.ads, 59system.ads, 5aml-tgt.adb, 5bml-tgt.adb, 5csystem.ads, 5dsystem.ads, 5fosinte.adb, 5gml-tgt.adb, 5hml-tgt.adb, 5isystem.ads, 5lparame.adb, 5msystem.ads, 5psystem.ads, 5sml-tgt.adb, 5sosprim.adb, 5stpopsp.adb, 5tsystem.ads, 5usystem.ads, 5vml-tgt.adb, 5vsymbol.adb, 5vtraent.adb, 5vtraent.ads, 5wml-tgt.adb, 5xparame.ads, 5xsystem.ads, 5xvxwork.ads, 5yparame.ads, 5ytiitho.adb, 5zinit.adb, 5zml-tgt.adb, 5zparame.ads, 5ztaspri.ads, 5ztfsetr.adb, 5zthrini.adb, 5ztiitho.adb, 5ztpopsp.adb, 7stfsetr.adb, 7straces.adb, 7strafor.adb, 7strafor.ads, 7stratas.adb, a-excach.adb, a-exexda.adb, a-exexpr.adb, a-exextr.adb, a-exstat.adb, a-strsup.adb, a-strsup.ads, a-stwisu.adb, a-stwisu.ads, bld.adb, bld.ads, bld-io.adb, bld-io.ads, clean.adb, clean.ads, ctrl_c.c, erroutc.adb, erroutc.ads, errutil.adb, errutil.ads, err_vars.ads, final.c, g-arrspl.adb, g-arrspl.ads, g-boubuf.adb, g-boubuf.ads, g-boumai.ads, g-bubsor.adb, g-bubsor.ads, g-comver.adb, g-comver.ads, g-ctrl_c.ads, g-dynhta.adb, g-dynhta.ads, g-eacodu.adb, g-excact.adb, g-excact.ads, g-heasor.adb, g-heasor.ads, g-memdum.adb, g-memdum.ads, gnatclean.adb, gnatsym.adb, g-pehage.adb, g-pehage.ads, g-perhas.ads, gpr2make.adb, gpr2make.ads, gprcmd.adb, gprep.adb, gprep.ads, g-semaph.adb, g-semaph.ads, g-string.adb, g-string.ads, g-strspl.ads, g-wistsp.ads, i-vthrea.adb, i-vthrea.ads, i-vxwoio.adb, i-vxwoio.ads, Makefile.generic, Makefile.prolog, Makefile.rtl, prep.adb, prep.ads, prepcomp.adb, prepcomp.ads, prj-err.adb, prj-err.ads, s-boarop.ads, s-carsi8.adb, s-carsi8.ads, s-carun8.adb, s-carun8.ads, s-casi16.adb, s-casi16.ads, s-casi32.adb, s-casi32.ads, s-casi64.adb, s-casi64.ads, s-casuti.adb, s-casuti.ads, s-caun16.adb, s-caun16.ads, s-caun32.adb, s-caun32.ads, s-caun64.adb, s-caun64.ads, scng.adb, scng.ads, s-exnint.adb, s-exnllf.adb, s-exnlli.adb, s-expint.adb, s-explli.adb, s-geveop.adb, s-geveop.ads, s-hibaen.ads, s-htable.adb, s-htable.ads, sinput-c.adb, sinput-c.ads, s-memcop.ads, socket.c, s-purexc.ads, s-scaval.adb, s-stopoo.adb, s-strcom.adb, s-strcom.ads, s-strxdr.adb, s-rident.ads, s-thread.adb, s-thread.ads, s-tpae65.adb, s-tpae65.ads, s-tporft.adb, s-traent.adb, s-traent.ads, styleg.adb, styleg.ads, styleg-c.adb, styleg-c.ads, s-veboop.adb, s-veboop.ads, s-vector.ads, symbols.adb, symbols.ads, tb-alvms.c, tb-alvxw.c, tempdir.adb, tempdir.ads, vms_conv.ads, vms_conv.adb, vms_data.ads, vxaddr2line.adb: Files added. Merge with ACT tree. * 4dintnam.ads, 4mintnam.ads, 4uintnam.ads, 52system.ads, 5dosinte.ads, 5etpopse.adb, 5mosinte.ads, 5qosinte.adb, 5qosinte.ads, 5qstache.adb, 5qtaprop.adb, 5qtaspri.ads, 5stpopse.adb, 5uintman.adb, 5uosinte.ads, adafinal.c, g-enblsp.adb, io-aux.c, scn-nlit.adb, scn-slit.adb, s-exnflt.ads, s-exngen.adb, s-exngen.ads, s-exnlfl.ads, s-exnlin.ads, s-exnsfl.ads, s-exnsin.ads, s-exnssi.ads, s-expflt.ads, s-expgen.adb, s-expgen.ads, s-explfl.ads, s-explin.ads, s-expllf.ads, s-expsfl.ads, s-expsin.ads, s-expssi.ads, style.adb: Files removed. Merge with ACT tree. * 1ic.ads, 31soccon.ads, 31soliop.ads, 3asoccon.ads, 3bsoccon.ads, 3gsoccon.ads, 3hsoccon.ads, 3ssoccon.ads, 3ssoliop.ads, 3wsoccon.ads, 3wsocthi.adb, 3wsocthi.ads, 3wsoliop.ads, 41intnam.ads, 42intnam.ads, 4aintnam.ads, 4cintnam.ads, 4gintnam.ads, 4hexcpol.adb, 4hintnam.ads, 4lintnam.ads, 4nintnam.ads, 4ointnam.ads, 4onumaux.ads, 4pintnam.ads, 4sintnam.ads, 4vcaldel.adb, 4vcalend.adb, 4vintnam.ads, 4wexcpol.adb, 4wintnam.ads, 4zintnam.ads, 51osinte.adb, 51osinte.ads, 52osinte.adb, 52osinte.ads, 53osinte.ads, 54osinte.ads, 5aosinte.adb, 5aosinte.ads, 5asystem.ads, 5ataprop.adb, 5atasinf.ads, 5ataspri.ads, 5atpopsp.adb, 5avxwork.ads, 5bosinte.adb, 5bosinte.ads, 5bsystem.ads, 5cosinte.ads, 5esystem.ads, 5fintman.adb, 5fosinte.ads, 5fsystem.ads, 5ftaprop.adb, 5ftasinf.ads, 5ginterr.adb, 5gintman.adb, 5gmastop.adb, 5gosinte.ads, 5gproinf.ads, 5gsystem.ads, 5gtaprop.adb, 5gtasinf.ads, 5gtpgetc.adb, 5hosinte.adb, 5hosinte.ads, 5hsystem.ads, 5htaprop.adb, 5htaspri.ads, 5htraceb.adb, 5iosinte.adb, 5itaprop.adb, 5itaspri.ads, 5ksystem.ads, 5kvxwork.ads, 5lintman.adb, 5lml-tgt.adb, 5losinte.ads, 5lsystem.ads, 5mvxwork.ads, 5ninmaop.adb, 5nintman.adb, 5nosinte.ads, 5ntaprop.adb, 5ntaspri.ads, 5ointerr.adb, 5omastop.adb, 5oosinte.adb, 5oosinte.ads, 5oosprim.adb, 5oparame.adb, 5osystem.ads, 5otaprop.adb, 5otaspri.ads, 5posinte.ads, 5posprim.adb, 5pvxwork.ads, 5sintman.adb, 5sosinte.adb, 5sosinte.ads, 5ssystem.ads, 5staprop.adb, 5stasinf.ads, 5staspri.ads, 5svxwork.ads, 5tosinte.ads, 5vasthan.adb, 5vinmaop.adb, 5vinterr.adb, 5vintman.adb, 5vintman.ads, 5vmastop.adb, 5vosinte.adb, 5vosinte.ads, 5vosprim.adb, 5vsystem.ads, 5vtaprop.adb, 5vtaspri.ads, 5vtpopde.adb, 5vtpopde.ads, 5wgloloc.adb, 5wintman.adb, 5wmemory.adb, 5wosprim.adb, 5wsystem.ads, 5wtaprop.adb, 5wtaspri.ads, 5ysystem.ads, 5zinterr.adb, 5zintman.adb, 5zosinte.adb, 5zosinte.ads, 5zosprim.adb, 5zsystem.ads, 5ztaprop.adb, 6vcpp.adb, 6vcstrea.adb, 6vinterf.ads, 7sinmaop.adb, 7sintman.adb, 7sosinte.adb, 7sosprim.adb, 7staprop.adb, 7staspri.ads, 7stpopsp.adb, 7straceb.adb, 9drpc.adb, a-caldel.adb, a-caldel.ads, a-charac.ads, a-colien.ads, a-comlin.adb, adaint.c, adaint.h, ada-tree.def, a-diocst.adb, a-diocst.ads, a-direio.adb, a-except.adb, a-except.ads, a-excpol.adb, a-exctra.adb, a-exctra.ads, a-filico.adb, a-interr.adb, a-intsig.adb, a-intsig.ads, ali.adb, ali.ads, ali-util.adb, ali-util.ads, a-ngcefu.adb, a-ngcoty.adb, a-ngelfu.adb, a-nudira.adb, a-nudira.ads, a-nuflra.adb, a-nuflra.ads, a-reatim.adb, a-reatim.ads, a-retide.ads, a-sequio.adb, a-siocst.adb, a-siocst.ads, a-ssicst.adb, a-ssicst.ads, a-strbou.adb, a-strbou.ads, a-strfix.adb, a-strmap.adb, a-strsea.ads, a-strunb.adb, a-strunb.ads, a-ststio.adb, a-stunau.adb, a-stunau.ads, a-stwibo.adb, a-stwibo.ads, a-stwifi.adb, a-stwima.adb, a-stwiun.adb, a-stwiun.ads, a-tags.adb, a-tags.ads, a-tasatt.adb, a-taside.adb, a-teioed.adb, a-textio.adb, a-textio.ads, a-tienau.adb, a-tifiio.adb, a-tiflau.adb, a-tiflio.adb, a-tigeau.adb, a-tigeau.ads, a-tiinau.adb, a-timoau.adb, a-tiocst.adb, a-tiocst.ads, atree.adb, atree.ads, a-witeio.adb, a-witeio.ads, a-wtcstr.adb, a-wtcstr.ads, a-wtdeio.adb, a-wtedit.adb, a-wtenau.adb, a-wtflau.adb, a-wtinau.adb, a-wtmoau.adb, bcheck.adb, binde.adb, bindgen.adb, bindusg.adb, checks.adb, checks.ads, cio.c, comperr.adb, comperr.ads, csets.adb, cstand.adb, cstreams.c, debug_a.adb, debug_a.ads, debug.adb, decl.c, einfo.adb, einfo.ads, errout.adb, errout.ads, eval_fat.adb, eval_fat.ads, exp_aggr.adb, expander.adb, expander.ads, exp_attr.adb, exp_ch11.adb, exp_ch13.adb, exp_ch2.adb, exp_ch3.adb, exp_ch3.ads, exp_ch4.adb, exp_ch5.adb, exp_ch6.adb, exp_ch7.adb, exp_ch7.ads, exp_ch8.adb, exp_ch9.adb, exp_code.adb, exp_dbug.adb, exp_dbug.ads, exp_disp.adb, exp_dist.adb, expect.c, exp_fixd.adb, exp_imgv.adb, exp_intr.adb, exp_pakd.adb, exp_prag.adb, exp_strm.adb, exp_strm.ads, exp_tss.adb, exp_tss.ads, exp_util.adb, exp_util.ads, exp_vfpt.adb, fe.h, fmap.adb, fmap.ads, fname.adb, fname.ads, fname-uf.adb, fname-uf.ads, freeze.adb, freeze.ads, frontend.adb, g-awk.adb, g-awk.ads, g-busora.adb, g-busora.ads, g-busorg.adb, g-busorg.ads, g-casuti.adb, g-casuti.ads, g-catiio.adb, g-catiio.ads, g-cgi.adb, g-cgi.ads, g-cgicoo.adb, g-cgicoo.ads, g-cgideb.adb, g-cgideb.ads, g-comlin.adb, g-comlin.ads, g-crc32.adb, g-crc32.ads, g-debpoo.adb, g-debpoo.ads, g-debuti.adb, g-debuti.ads, g-diopit.adb, g-diopit.ads, g-dirope.adb, g-dirope.ads, g-dyntab.adb, g-dyntab.ads, g-except.ads, g-exctra.adb, g-exctra.ads, g-expect.adb, g-expect.ads, g-hesora.adb, g-hesora.ads, g-hesorg.adb, g-hesorg.ads, g-htable.adb, g-htable.ads, gigi.h, g-io.adb, g-io.ads, g-io_aux.adb, g-io_aux.ads, g-locfil.adb, g-locfil.ads, g-md5.adb, g-md5.ads, gmem.c, gnat1drv.adb, gnatbind.adb, gnatchop.adb, gnatcmd.adb, gnatfind.adb, gnatkr.adb, gnatlbr.adb, gnatlink.adb, gnatls.adb, gnatmake.adb, gnatmem.adb, gnatname.adb, gnatprep.adb, gnatprep.ads, gnatpsta.adb, gnatxref.adb, g-os_lib.adb, g-os_lib.ads, g-regexp.adb, g-regexp.ads, g-regist.adb, g-regist.ads, g-regpat.adb, g-regpat.ads, g-soccon.ads, g-socket.adb, g-socket.ads, g-socthi.adb, g-socthi.ads, g-soliop.ads, g-souinf.ads, g-speche.adb, g-speche.ads, g-spipat.adb, g-spipat.ads, g-spitbo.adb, g-spitbo.ads, g-sptabo.ads, g-sptain.ads, g-sptavs.ads, g-table.adb, g-table.ads, g-tasloc.adb, g-tasloc.ads, g-thread.adb, g-thread.ads, g-traceb.adb, g-traceb.ads, g-trasym.adb, g-trasym.ads, hostparm.ads, i-c.ads, i-cobol.adb, i-cpp.adb, i-cstrea.ads, i-cstrin.adb, i-cstrin.ads, impunit.adb, init.c, inline.adb, interfac.ads, i-pacdec.ads, itypes.adb, itypes.ads, i-vxwork.ads, lang.opt, lang-specs.h, layout.adb, lib.adb, lib.ads, lib-list.adb, lib-load.adb, lib-load.ads, lib-sort.adb, lib-util.adb, lib-writ.adb, lib-writ.ads, lib-xref.adb, lib-xref.ads, link.c, live.adb, make.adb, make.ads, Makefile.adalib, Makefile.in, Make-lang.in, makeusg.adb, mdll.adb, mdll-fil.adb, mdll-fil.ads, mdll-utl.adb, mdll-utl.ads, memroot.adb, memroot.ads, memtrack.adb, misc.c, mkdir.c, mlib.adb, mlib.ads, mlib-fil.adb, mlib-fil.ads, mlib-prj.adb, mlib-prj.ads, mlib-tgt.adb, mlib-tgt.ads, mlib-utl.adb, mlib-utl.ads, namet.adb, namet.ads, namet.h, nlists.ads, nlists.h, nmake.adt, opt.adb, opt.ads, osint.adb, osint.ads, osint-b.adb, osint-c.adb, par.adb, par-ch10.adb, par-ch11.adb, par-ch2.adb, par-ch3.adb, par-ch4.adb, par-ch5.adb, par-ch6.adb, par-ch9.adb, par-endh.adb, par-labl.adb, par-load.adb, par-prag.adb, par-sync.adb, par-tchk.adb, par-util.adb, prj.adb, prj.ads, prj-attr.adb, prj-attr.ads, prj-com.adb, prj-com.ads, prj-dect.adb, prj-dect.ads, prj-env.adb, prj-env.ads, prj-ext.adb, prj-ext.ads, prj-makr.adb, prj-makr.ads, prj-nmsc.adb, prj-nmsc.ads, prj-pars.adb, prj-pars.ads, prj-part.adb, prj-part.ads, prj-pp.adb, prj-pp.ads, prj-proc.adb, prj-proc.ads, prj-strt.adb, prj-strt.ads, prj-tree.adb, prj-tree.ads, prj-util.adb, prj-util.ads, raise.c, raise.h, repinfo.adb, repinfo.h, restrict.adb, restrict.ads, rident.ads, rtsfind.adb, rtsfind.ads, s-addima.ads, s-arit64.adb, s-assert.adb, s-assert.ads, s-atacco.adb, s-atacco.ads, s-auxdec.adb, s-auxdec.ads, s-bitops.adb, scans.ads, scn.adb, scn.ads, s-crc32.adb, s-crc32.ads, s-direio.adb, sem.adb, sem.ads, sem_aggr.adb, sem_attr.adb, sem_attr.ads, sem_case.adb, sem_case.ads, sem_cat.adb, sem_cat.ads, sem_ch10.adb, sem_ch11.adb, sem_ch12.adb, sem_ch12.ads, sem_ch13.adb, sem_ch13.ads, sem_ch3.adb, sem_ch3.ads, sem_ch4.adb, sem_ch5.adb, sem_ch5.ads, sem_ch6.adb, sem_ch6.ads, sem_ch7.adb, sem_ch7.ads, sem_ch8.adb, sem_ch8.ads, sem_ch9.adb, sem_disp.adb, sem_disp.ads, sem_dist.adb, sem_elab.adb, sem_eval.adb, sem_eval.ads, sem_intr.adb, sem_maps.adb, sem_mech.adb, sem_prag.adb, sem_prag.ads, sem_res.adb, sem_res.ads, sem_type.adb, sem_type.ads, sem_util.adb, sem_util.ads, sem_warn.adb, s-errrep.adb, s-errrep.ads, s-exctab.adb, s-exctab.ads, s-exnint.ads, s-exnllf.ads, s-exnlli.ads, s-expint.ads, s-explli.ads, s-expuns.ads, s-fatflt.ads, s-fatgen.adb, s-fatgen.ads, s-fatlfl.ads, s-fatllf.ads, s-fatsfl.ads, s-fileio.adb, s-fileio.ads, s-finimp.adb, s-finimp.ads, s-finroo.adb, s-finroo.ads, sfn_scan.adb, s-gloloc.adb, s-gloloc.ads, s-imgdec.adb, s-imgenu.adb, s-imgrea.adb, s-imgwch.adb, sinfo.adb, sinfo.ads, s-inmaop.ads, sinput.adb, sinput.ads, sinput-d.adb, sinput-l.adb, sinput-l.ads, sinput-p.adb, sinput-p.ads, s-interr.adb, s-interr.ads, s-intman.ads, s-maccod.ads, s-mastop.adb, s-mastop.ads, s-memory.adb, s-memory.ads, snames.adb, snames.ads, snames.h, s-osprim.ads, s-parame.ads, s-parint.ads, s-pooloc.adb, s-pooloc.ads, s-poosiz.adb, sprint.adb, s-proinf.ads, s-scaval.ads, s-secsta.adb, s-secsta.ads, s-sequio.adb, s-shasto.adb, s-shasto.ads, s-soflin.ads, s-stache.adb, s-stache.ads, s-stalib.adb, s-stalib.ads, s-stoele.ads, s-stopoo.ads, s-stratt.adb, s-stratt.ads, s-strops.adb, s-strops.ads, s-taasde.adb, s-taasde.ads, s-tadeca.adb, s-tadeca.ads, s-tadert.adb, s-tadert.ads, s-taenca.adb, s-taenca.ads, s-taprob.adb, s-taprob.ads, s-taprop.ads, s-tarest.adb, s-tarest.ads, s-tasdeb.adb, s-tasdeb.ads, s-tasinf.adb, s-tasinf.ads, s-tasini.adb, s-tasini.ads, s-taskin.adb, s-taskin.ads, s-tasque.adb, s-tasque.ads, s-tasren.adb, s-tasren.ads, s-tasres.ads, s-tassta.adb, s-tassta.ads, s-tasuti.adb, s-tasuti.ads, s-tataat.adb, s-tataat.ads, s-tpinop.adb, s-tpinop.ads, s-tpoben.adb, s-tpoben.ads, s-tpobop.adb, s-tpobop.ads, s-tposen.adb, s-tposen.ads, s-traceb.adb, s-traceb.ads, stringt.adb, stringt.ads, stringt.h, style.ads, stylesw.adb, stylesw.ads, s-unstyp.ads, s-vaflop.ads, s-valrea.adb, s-valuti.adb, s-vercon.adb, s-vmexta.adb, s-wchcnv.ads, s-wchcon.ads, s-widcha.adb, switch.adb, switch.ads, switch-b.adb, switch-c.adb, switch-m.adb, s-wwdcha.adb, s-wwdwch.adb, sysdep.c, system.ads, table.adb, table.ads, targparm.adb, targparm.ads, targtyps.c, tbuild.adb, tbuild.ads, tracebak.c, trans.c, tree_io.adb, treepr.adb, treeprs.adt, ttypes.ads, types.ads, types.h, uintp.adb, uintp.ads, uintp.h, uname.adb, urealp.adb, urealp.ads, urealp.h, usage.adb, utils2.c, utils.c, validsw.adb, validsw.ads, widechar.adb, xeinfo.adb, xnmake.adb, xref_lib.adb, xref_lib.ads, xr_tabls.adb, xr_tabls.ads, xtreeprs.adb, xsnames.adb, einfo.h, sinfo.h, treeprs.ads, nmake.ads, nmake.adb, gnatvsn.ads: Merge with ACT tree. * gnatvsn.adb: Rewritten in a simpler and more efficient way. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@72751 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/gnatmem.adb')
-rw-r--r--gcc/ada/gnatmem.adb936
1 files changed, 291 insertions, 645 deletions
diff --git a/gcc/ada/gnatmem.adb b/gcc/ada/gnatmem.adb
index 624bf90f3bf..a852b26f8bc 100644
--- a/gcc/ada/gnatmem.adb
+++ b/gcc/ada/gnatmem.adb
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 1997-2002, Ada Core Technologies, Inc. --
+-- Copyright (C) 1997-2003, Ada Core Technologies, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -26,40 +26,41 @@
-- GNATMEM is a utility that tracks memory leaks. It is based on a simple
-- idea:
--- - run the application under gdb
--- - set a breakpoint on __gnat_malloc and __gnat_free
--- - record a reference to the allocated memory on each allocation call
--- - suppress this reference on deallocation
--- - at the end of the program, remaining references are potential leaks.
+
+-- - Read the allocation log generated by the application linked using
+-- instrumented memory allocation and dealocation (see memtrack.adb for
+-- this circuitry). To get access to this functionality, the application
+-- must be relinked with library libgmem.a:
+
+-- $ gnatmake my_prog -largs -lgmem
+
+-- The running my_prog will produce a file named gmem.out that will be
+-- parsed by gnatmem.
+
+-- - Record a reference to the allocated memory on each allocation call.
+
+-- - Suppress this reference on deallocation.
+
+-- - At the end of the program, remaining references are potential leaks.
-- sort them out the best possible way in order to locate the root of
-- the leak.
---
--- GNATMEM can also be used with instrumented allocation/deallocation
--- routine (see a-raise.c with symbol GMEM defined). This is not supported
--- in all platforms, again refer to a-raise.c for further information.
--- In this case the application must be relinked with library libgmem.a:
---
--- $ gnatmake my_prog -largs -lgmem
---
--- The running my_prog will produce a file named gmem.out that will be
--- parsed by gnatmem.
---
+
+-- This capability is not supported on all platforms, please refer to
+-- memtrack.adb for further information.
+
-- In order to help finding out the real leaks, the notion of "allocation
-- root" is defined. An allocation root is a specific point in the program
-- execution generating memory allocation where data is collected (such as
--- number of allocations, quantify of memory allocated, high water mark,
--- etc.).
+-- number of allocations, amount of memory allocated, high water mark, etc.)
-with Ada.Command_Line; use Ada.Command_Line;
+with GNAT.Command_Line; use GNAT.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
-with Ada.Text_IO.C_Streams;
with Ada.Float_Text_IO;
with Ada.Integer_Text_IO;
with Gnatvsn; use Gnatvsn;
with GNAT.Heap_Sort_G;
-with GNAT.OS_Lib;
+with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.HTable; use GNAT.HTable;
-with Interfaces.C_Streams; use Interfaces.C_Streams;
with System; use System;
with System.Storage_Elements; use System.Storage_Elements;
@@ -67,61 +68,32 @@ with Memroot; use Memroot;
procedure Gnatmem is
- ------------------------------------------------
- -- Potentially Target Dependent Subprograms. --
- ------------------------------------------------
-
- function Get_Current_TTY return String;
- -- Give the current tty on which the program is run. This is needed to
- -- separate the output of the debugger from the output of the program.
- -- The output of this function will be used to call the gdb command "tty"
- -- in the gdb script in order to get the program output on the current tty
- -- while the gdb output is redirected and processed by gnatmem.
-
- function popen (File, Mode : System.Address) return FILEs;
- pragma Import (C, popen, "popen");
- -- Execute the program 'File'. If the mode is "r" the standard output
- -- of the program is redirected and the FILEs handler of the
- -- redirection is returned.
-
- procedure System_Cmd (X : System.Address);
- pragma Import (C, System_Cmd, "system");
- -- Execute the program "X".
-
- subtype Cstring is String (1 .. Integer'Last);
- type Cstring_Ptr is access all Cstring;
-
- function ttyname (Dec : Integer) return Cstring_Ptr;
- pragma Import (C, ttyname, "__gnat_ttyname");
- -- Return a null-terminated string containing the current tty
-
- Dir_Sep : constant Character := '/';
-
------------------------
-- Other Declarations --
------------------------
- type Gdb_Output_Elmt is (Eof, Alloc, Deall);
- -- Eof = End of gdb output file
- -- Alloc = found a ALLOC mark in the gdb output
- -- Deall = found a DEALL mark in the gdb output
- Gdb_Output_Format_Error : exception;
+ type Storage_Elmt is record
+ Elmt : Character;
+ -- * = End of log file
+ -- A = found a ALLOC mark in the log
+ -- D = found a DEALL mark in the log
+ Address : Integer_Address;
+ Size : Storage_Count;
+ end record;
+ -- This needs a comment ???
- function Read_Next return Gdb_Output_Elmt;
- -- Read the output of the debugger till it finds either the end of the
- -- output, or the 'ALLOC' mark or the 'DEALL' mark. In the second case,
- -- it sets the Tmp_Size and Tmp_Address global variables, in the
- -- third case it sets the Tmp_Address variable.
+ Log_Name, Program_Name : String_Access;
+ -- These need comments, and should be on separate lines ???
- procedure Create_Gdb_Script;
- -- Create the GDB script and save it in a temporary file
+ function Read_Next return Storage_Elmt;
+ -- Reads next dynamic storage operation from the log file.
function Mem_Image (X : Storage_Count) return String;
-- X is a size in storage_element. Returns a value
- -- in Megabytes, Kiloytes or Bytes as appropriate.
+ -- in Megabytes, Kilobytes or Bytes as appropriate.
procedure Process_Arguments;
- -- Read command line arguments;
+ -- Read command line arguments
procedure Usage;
-- Prints out the option help
@@ -135,19 +107,6 @@ procedure Gnatmem is
-- Initialises the convert_addresses interface by supplying it with
-- the name of the executable file Exename
- procedure Gmem_Read_Next (Buf : out String; Last : out Natural);
- -- Reads the next allocation/deallocation entry and its backtrace
- -- and prepares in the string Buf (up to the position of Last) the
- -- expression compatible with gnatmem parser:
- -- Allocation entry produces the expression "ALLOC^[size]^0x[address]^"
- -- Deallocation entry produces the expression "DEALLOC^0x[address]^"
-
- Argc : constant Integer := Argument_Count;
- Gnatmem_Tmp : aliased constant String := "gnatmem.tmp";
-
- Mode_R : aliased constant String (1 .. 2) := 'r' & ASCII.NUL;
- Mode_W : aliased constant String (1 .. 3) := "w+" & ASCII.NUL;
-
-----------------------------------
-- HTable address --> Allocation --
-----------------------------------
@@ -170,12 +129,8 @@ procedure Gnatmem is
Equal => "=");
BT_Depth : Integer := 1;
- FD : FILEs;
- FT : File_Type;
- File_Pos : Integer := 0;
- Exec_Pos : Integer := 0;
- Target_Pos : Integer := 0;
- Run_Gdb : Boolean := True;
+
+ -- The following need comments ???
Global_Alloc_Size : Storage_Count := 0;
Global_High_Water_Mark : Storage_Count := 0;
@@ -183,17 +138,21 @@ procedure Gnatmem is
Global_Nb_Dealloc : Integer := 0;
Nb_Root : Integer := 0;
Nb_Wrong_Deall : Integer := 0;
- Target_Name : String (1 .. 80);
- Target_Protocol : String (1 .. 80);
- Target_Name_Len : Integer;
- Target_Protocol_Len : Integer;
- Cross_Case : Boolean := False;
-
- Tmp_Size : Storage_Count := 0;
- Tmp_Address : Integer_Address;
+ Minimum_NB_Leaks : Integer := 1;
+
Tmp_Alloc : Allocation;
Quiet_Mode : Boolean := False;
+ -------------------------------
+ -- Allocation roots sorting --
+ -------------------------------
+
+ Sort_Order : String (1 .. 3) := "nwh";
+ -- This is the default order in which sorting criteria will be applied
+ -- n - Total number of unfreed allocations
+ -- w - Final watermark
+ -- h - High watermark
+
--------------------------------
-- GMEM functionality binding --
--------------------------------
@@ -201,7 +160,9 @@ procedure Gnatmem is
function Gmem_Initialize (Dumpname : String) return Boolean is
function Initialize (Dumpname : System.Address) return Boolean;
pragma Import (C, Initialize, "__gnat_gmem_initialize");
+
S : aliased String := Dumpname & ASCII.NUL;
+
begin
return Initialize (S'Address);
end Gmem_Initialize;
@@ -209,51 +170,23 @@ procedure Gnatmem is
procedure Gmem_A2l_Initialize (Exename : String) is
procedure A2l_Initialize (Exename : System.Address);
pragma Import (C, A2l_Initialize, "__gnat_gmem_a2l_initialize");
+
S : aliased String := Exename & ASCII.NUL;
+
begin
A2l_Initialize (S'Address);
end Gmem_A2l_Initialize;
- procedure Gmem_Read_Next (Buf : out String; Last : out Natural) is
+ function Read_Next return Storage_Elmt is
procedure Read_Next (buf : System.Address);
pragma Import (C, Read_Next, "__gnat_gmem_read_next");
- function Strlen (str : System.Address) return Natural;
- pragma Import (C, Strlen, "strlen");
-
- S : String (1 .. 1000);
- begin
- Read_Next (S'Address);
- Last := Strlen (S'Address);
- Buf (1 .. Last) := S (1 .. Last);
- end Gmem_Read_Next;
-
- ---------------------
- -- Get_Current_TTY --
- ---------------------
- function Get_Current_TTY return String is
- Res : Cstring_Ptr;
- stdout : constant Integer := 1;
- Max_TTY_Name : constant Integer := 500;
+ S : Storage_Elmt;
begin
- if isatty (stdout) /= 1 then
- return "";
- end if;
-
- Res := ttyname (1);
- if Res /= null then
- for J in Cstring'First .. Max_TTY_Name loop
- if Res (J) = ASCII.NUL then
- return Res (Cstring'First .. J - 1);
- end if;
- end loop;
- end if;
-
- -- if we fall thru the ttyname result was dubious. Just forget it.
-
- return "";
- end Get_Current_TTY;
+ Read_Next (S'Address);
+ return S;
+ end Read_Next;
-------
-- H --
@@ -264,141 +197,6 @@ procedure Gnatmem is
return Address_Range (A mod Integer_Address (Address_Range'Last));
end H;
- -----------------------
- -- Create_Gdb_Script --
- -----------------------
-
- procedure Create_Gdb_Script is
- FD : File_Type;
-
- begin
- begin
- Create (FD, Out_File, Gnatmem_Tmp);
- exception
- when others =>
- Put_Line ("Cannot create temporary file : " & Gnatmem_Tmp);
- GNAT.OS_Lib.OS_Exit (1);
- end;
-
- declare
- TTY : constant String := Get_Current_TTY;
- begin
- if TTY'Length > 0 then
- Put_Line (FD, "tty " & TTY);
- end if;
- end;
-
- if Cross_Case then
- Put (FD, "target ");
- Put (FD, Target_Protocol (1 .. Target_Protocol_Len));
- Put (FD, " ");
- Put (FD, Argument (Target_Pos));
- New_Line (FD);
- Put (FD, "load ");
- Put_Line (FD, Argument (Exec_Pos));
-
- else
- -- In the native case, run the program before setting the
- -- breakpoints so that gnatmem will also work with shared
- -- libraries.
-
- Put_Line (FD, "set lang c");
- Put_Line (FD, "break main");
- Put_Line (FD, "set lang auto");
- Put (FD, "run");
- for J in Exec_Pos + 1 .. Argc loop
- Put (FD, " ");
- Put (FD, Argument (J));
- end loop;
- New_Line (FD);
-
- -- At this point, gdb knows about __gnat_malloc and __gnat_free
- end if;
-
- -- Make sure that outputting long backtraces do not pause
-
- Put_Line (FD, "set height 0");
- Put_Line (FD, "set width 0");
-
- if Quiet_Mode then
- Put_Line (FD, "break __gnat_malloc");
- Put_Line (FD, "command");
- Put_Line (FD, " silent");
- Put_Line (FD, " set lang c");
- Put_Line (FD, " set print address on");
- Put_Line (FD, " up");
- Put_Line (FD, " set $gm_addr = $pc");
- Put_Line (FD, " printf ""\n\n""");
- Put_Line (FD, " printf ""ALLOC^0x%x^\n"", $gm_addr");
- Put_Line (FD, " set print address off");
- Put_Line (FD, " set lang auto");
- else
- Put_Line (FD, "break __gnat_malloc");
- Put_Line (FD, "command");
- Put_Line (FD, " silent");
- Put_Line (FD, " set lang c");
- Put_Line (FD, " set $gm_size = size");
- Put_Line (FD, " set print address on");
- Put_Line (FD, " up");
- Put_Line (FD, " set $gm_addr = $pc");
- Put_Line (FD, " printf ""\n\n""");
- Put_Line (FD, " printf ""ALLOC^%d^0x%x^\n"", $gm_size, $gm_addr");
- Put_Line (FD, " set print address off");
- Put_Line (FD, " set lang auto");
- end if;
-
- Put (FD, " backtrace");
-
- if BT_Depth /= 0 then
- Put (FD, Integer'Image (BT_Depth + 1));
- end if;
-
- New_Line (FD);
-
- Put_Line (FD, " printf ""\n\n""");
- Put_Line (FD, " continue");
- Put_Line (FD, "end");
- Put_Line (FD, "#");
- Put_Line (FD, "#");
- Put_Line (FD, "break __gnat_free");
- Put_Line (FD, "command");
- Put_Line (FD, " silent");
- Put_Line (FD, " set print address on");
- Put_Line (FD, " printf ""\n\n""");
- Put_Line (FD, " printf ""DEALL^0x%x^\n"", ptr");
- Put_Line (FD, " set print address off");
- Put_Line (FD, " up");
-
- Put (FD, " backtrace");
-
- if BT_Depth /= 0 then
- Put (FD, Integer'Image (BT_Depth + 1));
- end if;
-
- New_Line (FD);
-
- Put_Line (FD, " printf ""\n\n""");
- Put_Line (FD, " continue");
- Put_Line (FD, "end");
- Put_Line (FD, "#");
- Put_Line (FD, "#");
- Put_Line (FD, "#");
-
- if Cross_Case then
- Put (FD, "run ");
- Put_Line (FD, Argument (Exec_Pos));
-
- if Target_Protocol (1 .. Target_Protocol_Len) = "wtx" then
- Put (FD, "unload ");
- Put_Line (FD, Argument (Exec_Pos));
- end if;
- else
- Put_Line (FD, "continue");
- end if;
-
- Close (FD);
- end Create_Gdb_Script;
-
---------------
-- Mem_Image --
---------------
@@ -419,7 +217,7 @@ procedure Gnatmem is
else
Ada.Integer_Text_IO.Put (Buff (1 .. 4), Integer (X));
- return Buff (1 .. 4) & " Bytes";
+ return Buff (1 .. 4) & " Bytes";
end if;
end Mem_Image;
@@ -430,36 +228,26 @@ procedure Gnatmem is
procedure Usage is
begin
New_Line;
- Put ("GNATMEM ");
+ Put ("GNATMEM Pro ");
Put (Gnat_Version_String);
- Put_Line (" Copyright 1997-2002 Free Software Foundation, Inc.");
+ Put_Line (" Copyright 1997-2003 Free Software Foundation, Inc.");
New_Line;
- if Cross_Case then
- Put_Line (Command_Name
- & " [-q] [n] [-o file] target entry_point ...");
- Put_Line (Command_Name & " [-q] [n] [-i file]");
-
- else
- Put_Line ("GDB mode");
- Put_Line (" " & Command_Name
- & " [-q] [n] [-o file] program arg1 arg2 ...");
- Put_Line (" " & Command_Name
- & " [-q] [n] [-i file]");
- New_Line;
- Put_Line ("GMEM mode");
- Put_Line (" " & Command_Name
- & " [-q] [n] -i gmem.out program arg1 arg2 ...");
- New_Line;
- end if;
-
+ Put_Line ("Usage: gnatmem switches [depth] exename");
+ New_Line;
+ Put_Line (" depth backtrace depth to take into account, default is"
+ & Integer'Image (BT_Depth));
+ Put_Line (" exename the name of the executable to be analyzed");
+ New_Line;
+ Put_Line ("Switches:");
+ Put_Line (" -b n same as depth parameter");
+ Put_Line (" -i file read the allocation log from specific file");
+ Put_Line (" default is gmem.out in the current directory");
+ Put_Line (" -m n masks roots with less than n leaks, default is 1");
+ Put_Line (" specify 0 to see even released allocation roots");
Put_Line (" -q quiet, minimum output");
- Put_Line (" n number of frames for allocation root backtraces");
- Put_Line (" default is 1.");
- Put_Line (" -o file save gdb output in 'file' and process data");
- Put_Line (" post mortem. also keep the gdb script around");
- Put_Line (" -i file don't run gdb output. Do only post mortem");
- Put_Line (" processing from file");
+ Put_Line (" -s order sort allocation roots according to an order of");
+ Put_Line (" sort criteria");
GNAT.OS_Lib.OS_Exit (1);
end Usage;
@@ -468,365 +256,182 @@ procedure Gnatmem is
-----------------------
procedure Process_Arguments is
- Arg : Integer;
-
- procedure Check_File (Arg_Pos : Integer; For_Creat : Boolean := False);
- -- Check that Argument (Arg_Pos) is an existing file if For_Creat is
- -- false or if it is possible to create it if For_Creat is true
-
- procedure Check_File (Arg_Pos : Integer; For_Creat : Boolean := False) is
- Name : aliased constant String := Argument (Arg_Pos) & ASCII.NUL;
- X : int;
-
- begin
- if For_Creat then
- FD := fopen (Name'Address, Mode_W'Address);
- else
- FD := fopen (Name'Address, Mode_R'Address);
- end if;
-
- if FD = NULL_Stream then
- New_Line;
- if For_Creat then
- Put_Line ("Cannot create file : " & Argument (Arg_Pos));
- else
- Put_Line ("Cannot locate file : " & Argument (Arg_Pos));
- end if;
- New_Line;
- Usage;
- else
- X := fclose (FD);
- end if;
- end Check_File;
-
- -- Start of processing for Process_Arguments
-
begin
+ -- Parse the options first
- -- Is it a cross version?
-
- declare
- Std_Name : constant String := "gnatmem";
- Name : constant String := Command_Name;
- End_Pref : constant Integer := Name'Last - Std_Name'Length;
-
- begin
- if Name'Length > Std_Name'Length + 9
- and then
- Name (End_Pref + 1 .. Name'Last) = Std_Name
- and then
- Name (End_Pref - 8 .. End_Pref) = "-vxworks-"
- then
- Cross_Case := True;
-
- Target_Name_Len := End_Pref - 1;
- for J in reverse Name'First .. End_Pref - 1 loop
- if Name (J) = Dir_Sep then
- Target_Name_Len := Target_Name_Len - J;
- exit;
- end if;
- end loop;
-
- Target_Name (1 .. Target_Name_Len)
- := Name (End_Pref - Target_Name_Len .. End_Pref - 1);
-
- if Target_Name (1 .. 5) = "alpha" then
- Target_Protocol (1 .. 7) := "vxworks";
- Target_Protocol_Len := 7;
- else
- Target_Protocol (1 .. 3) := "wtx";
- Target_Protocol_Len := 3;
- end if;
- end if;
- end;
-
- Arg := 1;
-
- if Argc < Arg then
- Usage;
- end if;
-
- -- Deal with "-q"
-
- if Argument (Arg) = "-q" then
-
- Quiet_Mode := True;
- Arg := Arg + 1;
-
- if Argc < Arg then
- Usage;
- end if;
- end if;
-
- -- Deal with back trace depth
-
- if Argument (Arg) (1) in '0' .. '9' then
- begin
- BT_Depth := Integer'Value (Argument (Arg));
- exception
- when others =>
- Usage;
- end;
-
- Arg := Arg + 1;
-
- if Argc < Arg then
- Usage;
- end if;
- end if;
+ loop
+ case Getopt ("b: m: i: q s:") is
+ when ASCII.Nul => exit;
- -- Deal with "-o file" or "-i file"
+ when 'b' =>
+ begin
+ BT_Depth := Natural'Value (Parameter);
+ exception
+ when Constraint_Error =>
+ Usage;
+ end;
- while Arg <= Argc and then Argument (Arg) (1) = '-' loop
- Arg := Arg + 1;
+ when 'm' =>
+ begin
+ Minimum_NB_Leaks := Natural'Value (Parameter);
+ exception
+ when Constraint_Error =>
+ Usage;
+ end;
- if Argc < Arg then
- Usage;
- end if;
+ when 'i' =>
+ Log_Name := new String'(Parameter);
- case Argument (Arg - 1) (2) is
- when 'o' =>
- Check_File (Arg, For_Creat => True);
- File_Pos := Arg;
+ when 'q' =>
+ Quiet_Mode := True;
- when 'i' =>
- Check_File (Arg);
- File_Pos := Arg;
- Run_Gdb := False;
- if Gmem_Initialize (Argument (Arg)) then
- Gmem_Mode := True;
- end if;
+ when 's' =>
+ declare
+ S : String (Sort_Order'Range) := Parameter;
+ begin
+ for J in Sort_Order'Range loop
+ if S (J) = 'n' or else S (J) = 'w'
+ or else S (J) = 'h' then
+ Sort_Order (J) := S (J);
+ else
+ raise Constraint_Error;
+ end if;
+ end loop;
+ exception
+ when Constraint_Error =>
+ Put_Line ("Invalid sort criteria string.");
+ GNAT.OS_Lib.OS_Exit (1);
+ end;
when others =>
- Put_Line ("Unknown option : " & Argument (Arg));
- Usage;
+ null;
end case;
-
- Arg := Arg + 1;
-
- if Argc < Arg and then Run_Gdb then
- Usage;
- end if;
end loop;
- -- In the cross case, we first get the target
+ -- Set default log file if -i hasn't been specified
- if Cross_Case then
- Target_Pos := Arg;
- Arg := Arg + 1;
-
- if Argc < Arg and then Run_Gdb then
- Usage;
- end if;
+ if Log_Name = null then
+ Log_Name := new String'("gmem.out");
end if;
- -- Now all the following arguments are to be passed to gdb
+ -- Get the optional backtrace length and program name
- if Run_Gdb then
- Exec_Pos := Arg;
- Check_File (Exec_Pos);
+ declare
+ Str1 : constant String := GNAT.Command_Line.Get_Argument;
+ Str2 : constant String := GNAT.Command_Line.Get_Argument;
- elsif Gmem_Mode then
- if Arg > Argc then
+ begin
+ if Str1 = "" then
Usage;
- else
- Exec_Pos := Arg;
- Check_File (Exec_Pos);
- Gmem_A2l_Initialize (Argument (Exec_Pos));
end if;
- -- ... in other cases further arguments are disallowed
-
- elsif Arg <= Argc then
- Usage;
- end if;
- end Process_Arguments;
-
- ---------------
- -- Read_Next --
- ---------------
-
- function Read_Next return Gdb_Output_Elmt is
- Max_Line : constant Integer := 100;
- Line : String (1 .. Max_Line);
- Last : Integer := 0;
+ if Str2 = "" then
+ Program_Name := new String'(Str1);
+ else
+ BT_Depth := Natural'Value (Str1);
+ Program_Name := new String'(Str2);
+ end if;
- Curs1, Curs2 : Integer;
- Separator : constant Character := '^';
+ exception
+ when Constraint_Error =>
+ Usage;
+ end;
- function Next_Separator return Integer;
- -- Return the index of the next separator after Curs1 in Line
+ -- Ensure presence of executable suffix in Program_Name
- function Next_Separator return Integer is
- Curs : Integer := Curs1;
+ declare
+ Suffix : String_Access := Get_Executable_Suffix;
+ Tmp : String_Access;
begin
- loop
- if Curs > Last then
- raise Gdb_Output_Format_Error;
+ if Suffix.all /= ""
+ and then
+ Program_Name.all
+ (Program_Name.all'Last - Suffix.all'Length + 1 ..
+ Program_Name.all'Last) /= Suffix.all
+ then
+ Tmp := new String'(Program_Name.all & Suffix.all);
+ Free (Program_Name);
+ Program_Name := Tmp;
+ end if;
- elsif Line (Curs) = Separator then
- return Curs;
- end if;
+ Free (Suffix);
- Curs := Curs + 1;
- end loop;
- end Next_Separator;
+ -- Search the executable on the path. If not found in the PATH, we
+ -- default to the current directory. Otherwise, libaddr2line will
+ -- fail with an error:
- -- Start of processing for Read_Next
+ -- (null): Bad address
- begin
- Line (1) := ' ';
+ Tmp := Locate_Exec_On_Path (Program_Name.all);
- loop
- if Gmem_Mode then
- Gmem_Read_Next (Line, Last);
- else
- Get_Line (FT, Line, Last);
+ if Tmp = null then
+ Tmp := new String'('.' & Directory_Separator & Program_Name.all);
end if;
- if Line (1 .. 14) = "Program exited" then
- return Eof;
-
- elsif Line (1 .. 5) = "ALLOC" then
- -- ALLOC ^ <size> ^0x <addr> ^
-
- -- Read the size
-
- Curs1 := 7;
- Curs2 := Next_Separator - 1;
-
- if not Quiet_Mode then
- Tmp_Size := Storage_Count'Value (Line (Curs1 .. Curs2));
- end if;
+ Free (Program_Name);
+ Program_Name := Tmp;
+ end;
- -- Read the address, skip "^0x"
+ if not Is_Regular_File (Log_Name.all) then
+ Put_Line ("Couldn't find " & Log_Name.all);
+ GNAT.OS_Lib.OS_Exit (1);
+ end if;
- Curs1 := Curs2 + 4;
- Curs2 := Next_Separator - 1;
- Tmp_Address := Integer_Address'Value (
- "16#" & Line (Curs1 .. Curs2) & "#");
- return Alloc;
+ if not Gmem_Initialize (Log_Name.all) then
+ Put_Line ("File " & Log_Name.all & " is not a gnatmem log file");
+ GNAT.OS_Lib.OS_Exit (1);
+ end if;
- elsif Line (1 .. 5) = "DEALL" then
- -- DEALL ^ 0x <addr> ^
+ if not Is_Regular_File (Program_Name.all) then
+ Put_Line ("Couldn't find " & Program_Name.all);
+ end if;
- -- Read the address, skip "^0x"
+ Gmem_A2l_Initialize (Program_Name.all);
- Curs1 := 9;
- Curs2 := Next_Separator - 1;
- Tmp_Address := Integer_Address'Value (
- "16#" & Line (Curs1 .. Curs2) & "#");
- return Deall;
- end if;
- end loop;
exception
- when End_Error =>
- New_Line;
- Put_Line ("### incorrect user program termination detected.");
- Put_Line (" following data may not be meaningful");
- New_Line;
- return Eof;
- end Read_Next;
+ when GNAT.Command_Line.Invalid_Switch =>
+ Ada.Text_IO.Put_Line ("Invalid switch : "
+ & GNAT.Command_Line.Full_Switch);
+ Usage;
+ end Process_Arguments;
+
+ Cur_Elmt : Storage_Elmt;
-- Start of processing for Gnatmem
begin
Process_Arguments;
- if Run_Gdb then
- Create_Gdb_Script;
- end if;
-
- -- Now we start the gdb session using the following syntax
-
- -- gdb --nx --nw -batch -x gnatmem.tmp
-
- -- If there is a -o option we redirect the gdb output in the specified
- -- file, otherwise we just read directly from a pipe.
-
- if File_Pos /= 0 then
- declare
- Name : aliased String := Argument (File_Pos) & ASCII.NUL;
-
- begin
- if Run_Gdb then
- if Cross_Case then
- declare
- Cmd : aliased String := Target_Name (1 .. Target_Name_Len)
- & "-gdb --nx --nw -batch -x " & Gnatmem_Tmp & " > "
- & Name;
- begin
- System_Cmd (Cmd'Address);
- end;
- else
-
- declare
- Cmd : aliased String
- := "gdb --nx --nw " & Argument (Exec_Pos)
- & " -batch -x " & Gnatmem_Tmp & " > "
- & Name;
- begin
- System_Cmd (Cmd'Address);
- end;
- end if;
- end if;
-
- if not Gmem_Mode then
- FD := fopen (Name'Address, Mode_R'Address);
- end if;
- end;
-
- else
- if Cross_Case then
- declare
- Cmd : aliased String := Target_Name (1 .. Target_Name_Len)
- & "-gdb --nx --nw -batch -x " & Gnatmem_Tmp & ASCII.NUL;
- begin
- FD := popen (Cmd'Address, Mode_R'Address);
- end;
- else
- declare
- Cmd : aliased String := "gdb --nx --nw " & Argument (Exec_Pos)
- & " -batch -x " & Gnatmem_Tmp & ASCII.NUL;
-
- begin
- FD := popen (Cmd'Address, Mode_R'Address);
- end;
- end if;
- end if;
-
- -- Open the FD file as a regular Text_IO file
-
- if not Gmem_Mode then
- Ada.Text_IO.C_Streams.Open (FT, In_File, FD);
- end if;
-
- -- Main loop analysing the data generated by the debugger
- -- for each allocation, the backtrace is kept and stored in a htable
- -- whose entry is the address. Fore ach deallocation, we look for the
+ -- Main loop analysing the data generated by the instrumented routines.
+ -- For each allocation, the backtrace is kept and stored in a htable
+ -- whose entry is the address. For each deallocation, we look for the
-- corresponding allocation and cancel it.
Main : loop
- case Read_Next is
- when EOF =>
+ Cur_Elmt := Read_Next;
+
+ case Cur_Elmt.Elmt is
+ when '*' =>
exit Main;
- when Alloc =>
+ when 'A' =>
-- Update global counters if the allocated size is meaningful
if Quiet_Mode then
- Tmp_Alloc.Root := Read_BT (BT_Depth, FT);
+ Tmp_Alloc.Root := Read_BT (BT_Depth);
+
if Nb_Alloc (Tmp_Alloc.Root) = 0 then
Nb_Root := Nb_Root + 1;
end if;
+
Set_Nb_Alloc (Tmp_Alloc.Root, Nb_Alloc (Tmp_Alloc.Root) + 1);
- Address_HTable.Set (Tmp_Address, Tmp_Alloc);
+ Address_HTable.Set (Cur_Elmt.Address, Tmp_Alloc);
- elsif Tmp_Size > 0 then
+ elsif Cur_Elmt.Size > 0 then
- Global_Alloc_Size := Global_Alloc_Size + Tmp_Size;
+ Global_Alloc_Size := Global_Alloc_Size + Cur_Elmt.Size;
Global_Nb_Alloc := Global_Nb_Alloc + 1;
if Global_High_Water_Mark < Global_Alloc_Size then
@@ -835,7 +440,7 @@ begin
-- Read the corresponding back trace
- Tmp_Alloc.Root := Read_BT (BT_Depth, FT);
+ Tmp_Alloc.Root := Read_BT (BT_Depth);
-- Update the number of allocation root if this is a new one
@@ -846,12 +451,12 @@ begin
-- Update allocation root specific counters
Set_Alloc_Size (Tmp_Alloc.Root,
- Alloc_Size (Tmp_Alloc.Root) + Tmp_Size);
+ Alloc_Size (Tmp_Alloc.Root) + Cur_Elmt.Size);
Set_Nb_Alloc (Tmp_Alloc.Root, Nb_Alloc (Tmp_Alloc.Root) + 1);
- if High_Water_Mark (Tmp_Alloc.Root)
- < Alloc_Size (Tmp_Alloc.Root)
+ if High_Water_Mark (Tmp_Alloc.Root) <
+ Alloc_Size (Tmp_Alloc.Root)
then
Set_High_Water_Mark (Tmp_Alloc.Root,
Alloc_Size (Tmp_Alloc.Root));
@@ -859,27 +464,27 @@ begin
-- Associate this allocation root to the allocated address
- Tmp_Alloc.Size := Tmp_Size;
- Address_HTable.Set (Tmp_Address, Tmp_Alloc);
+ Tmp_Alloc.Size := Cur_Elmt.Size;
+ Address_HTable.Set (Cur_Elmt.Address, Tmp_Alloc);
- -- non meaninful output, just consumes the backtrace
+ -- non meaningful output, just consumes the backtrace
else
- Tmp_Alloc.Root := Read_BT (BT_Depth, FT);
+ Tmp_Alloc.Root := Read_BT (BT_Depth);
end if;
- when Deall =>
+ when 'D' =>
-- Get the corresponding Dealloc_Size and Root
- Tmp_Alloc := Address_HTable.Get (Tmp_Address);
+ Tmp_Alloc := Address_HTable.Get (Cur_Elmt.Address);
if Tmp_Alloc.Root = No_Root_Id then
-- There was no prior allocation at this address, something is
- -- very wrong. Mark this allocation root as problematic a
+ -- very wrong. Mark this allocation root as problematic
- Tmp_Alloc.Root := Read_BT (BT_Depth, FT);
+ Tmp_Alloc.Root := Read_BT (BT_Depth);
if Nb_Alloc (Tmp_Alloc.Root) = 0 then
Set_Nb_Alloc (Tmp_Alloc.Root, Nb_Alloc (Tmp_Alloc.Root) - 1);
@@ -892,6 +497,7 @@ begin
if not Quiet_Mode then
Global_Alloc_Size := Global_Alloc_Size - Tmp_Alloc.Size;
end if;
+
Global_Nb_Dealloc := Global_Nb_Dealloc + 1;
-- Update allocation root specific counters
@@ -900,31 +506,26 @@ begin
Set_Alloc_Size (Tmp_Alloc.Root,
Alloc_Size (Tmp_Alloc.Root) - Tmp_Alloc.Size);
end if;
+
Set_Nb_Alloc (Tmp_Alloc.Root, Nb_Alloc (Tmp_Alloc.Root) - 1);
-- update the number of allocation root if this one disappear
- if Nb_Alloc (Tmp_Alloc.Root) = 0 then
+ if Nb_Alloc (Tmp_Alloc.Root) = 0
+ and then Minimum_NB_Leaks > 0 then
Nb_Root := Nb_Root - 1;
end if;
-- De-associate the deallocated address
- Address_HTable.Remove (Tmp_Address);
+ Address_HTable.Remove (Cur_Elmt.Address);
end if;
+
+ when others =>
+ raise Program_Error;
end case;
end loop Main;
- -- We can get rid of the temp file now
-
- if Run_Gdb and then File_Pos = 0 then
- declare
- X : int;
- begin
- X := unlink (Gnatmem_Tmp'Address);
- end;
- end if;
-
-- Print out general information about overall allocation
if not Quiet_Mode then
@@ -956,6 +557,7 @@ begin
Bogus_Dealls : Root_Array (1 .. Nb_Wrong_Deall);
Deall_Index : Natural := 0;
+ Nb_Alloc_J : Natural := 0;
procedure Move (From : Natural; To : Natural);
function Lt (Op1, Op2 : Natural) return Boolean;
@@ -967,14 +569,54 @@ begin
end Move;
function Lt (Op1, Op2 : Natural) return Boolean is
+ function Apply_Sort_Criterion (S : Character) return Integer;
+ -- Applies a specific sort criterion; returns -1, 0 or 1 if Op1 is
+ -- smaller than, equal, or greater than Op2 according to criterion
+
+ function Apply_Sort_Criterion (S : Character) return Integer is
+ LOp1, LOp2 : Integer;
+ begin
+ case S is
+ when 'n' =>
+ LOp1 := Nb_Alloc (Leaks (Op1));
+ LOp2 := Nb_Alloc (Leaks (Op2));
+
+ when 'w' =>
+ LOp1 := Integer (Alloc_Size (Leaks (Op1)));
+ LOp2 := Integer (Alloc_Size (Leaks (Op2)));
+
+ when 'h' =>
+ LOp1 := Integer (High_Water_Mark (Leaks (Op1)));
+ LOp2 := Integer (High_Water_Mark (Leaks (Op2)));
+
+ when others =>
+ return 0; -- Can't actually happen
+ end case;
+
+ if LOp1 < LOp2 then
+ return -1;
+ elsif LOp1 > LOp2 then
+ return 1;
+ else
+ return 0;
+ end if;
+ exception
+ when Constraint_Error =>
+ return 0;
+ end Apply_Sort_Criterion;
+
+ Result : Integer;
+
begin
- if Nb_Alloc (Leaks (Op1)) > Nb_Alloc (Leaks (Op2)) then
- return True;
- elsif Nb_Alloc (Leaks (Op1)) = Nb_Alloc (Leaks (Op2)) then
- return Alloc_Size (Leaks (Op1)) > Alloc_Size (Leaks (Op2));
- else
- return False;
- end if;
+ for S in Sort_Order'Range loop
+ Result := Apply_Sort_Criterion (Sort_Order (S));
+ if Result = -1 then
+ return False;
+ elsif Result = 1 then
+ return True;
+ end if;
+ end loop;
+ return False;
end Lt;
-- Start of processing for Print_Back_Traces
@@ -985,7 +627,7 @@ begin
Tmp_Alloc.Root := Get_First;
while Tmp_Alloc.Root /= No_Root_Id loop
- if Nb_Alloc (Tmp_Alloc.Root) = 0 then
+ if Nb_Alloc (Tmp_Alloc.Root) = 0 and then Minimum_NB_Leaks > 0 then
null;
elsif Nb_Alloc (Tmp_Alloc.Root) < 0 then
@@ -1009,7 +651,7 @@ begin
end if;
for J in 1 .. Bogus_Dealls'Last loop
- Print_BT (Bogus_Dealls (J));
+ Print_BT (Bogus_Dealls (J), Short => Quiet_Mode);
New_Line;
end loop;
end if;
@@ -1023,34 +665,38 @@ begin
Root_Sort.Sort (Nb_Root);
for J in 1 .. Leaks'Last loop
- if Quiet_Mode then
- if Nb_Alloc (Leaks (J)) = 1 then
- Put_Line (Integer'Image (Nb_Alloc (Leaks (J)))
- & " leak at :");
+ Nb_Alloc_J := Nb_Alloc (Leaks (J));
+ if Nb_Alloc_J >= Minimum_NB_Leaks then
+ if Quiet_Mode then
+ if Nb_Alloc_J = 1 then
+ Put_Line (" 1 leak at :");
+ else
+ Put_Line (Integer'Image (Nb_Alloc_J) & " leaks at :");
+ end if;
+
else
- Put_Line (Integer'Image (Nb_Alloc (Leaks (J)))
- & " leaks at :");
- end if;
- else
- Put_Line ("Allocation Root #" & Integer'Image (J));
- Put_Line ("-------------------");
+ Put_Line ("Allocation Root #" & Integer'Image (J));
+ Put_Line ("-------------------");
- Put (" Number of non freed allocations :");
- Ada.Integer_Text_IO.Put (Nb_Alloc (Leaks (J)), 4);
- New_Line;
+ Put (" Number of non freed allocations :");
+ Ada.Integer_Text_IO.Put (Nb_Alloc_J, 4);
+ New_Line;
+
+ Put_Line
+ (" Final Water Mark (non freed mem) :"
+ & Mem_Image (Alloc_Size (Leaks (J))));
- Put_Line (" Final Water Mark (non freed mem) :"
- & Mem_Image (Alloc_Size (Leaks (J))));
+ Put_Line
+ (" High Water Mark :"
+ & Mem_Image (High_Water_Mark (Leaks (J))));
- Put_Line (" High Water Mark :"
- & Mem_Image (High_Water_Mark (Leaks (J))));
+ Put_Line (" Backtrace :");
+ end if;
- Put_Line (" Backtrace :");
+ Print_BT (Leaks (J), Short => Quiet_Mode);
+ New_Line;
end if;
- Print_BT (Leaks (J));
- New_Line;
end loop;
end if;
end Print_Back_Traces;
-
end Gnatmem;