c++ Détection Fuite de Mémoire sur Mac OSX
Je suis en train d'écrire le code en c++ à l'aide de texte wrangler pour écrire le code et le compiler à l'aide de g++ à partir de la ligne de commande. Je voudrais être en mesure de détecter si mon code a des fuites de mémoire. J'ai essayé d'utiliser valgrind, mais il ne semble pas fonctionner correctement pour mavericks, j'ai essayé de lancer "une fuite."si un.est le résultat de l'exécution de "g++ *.h *.cc", mais j'obtiens un message d'erreur "fuites ne trouvez pas un processus que vous avez accès à ce qui a un nom, comme" un."" toutes les idées comment faire une fuite de mémoire?
c'est la sortie
==1317== Memcheck, a memory error detector
==1317== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==1317== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==1317== Command: ./a.out
==1317==
==1317== WARNING: Support on MacOS 10.8 is experimental and mostly broken.
==1317== WARNING: Expect incorrect results, assertions and crashes.
==1317== WARNING: In particular, Memcheck on 32-bit programs will fail to
==1317== WARNING: detect any errors associated with heap-allocated data.
==1317==
--1317-- Valgrind options:
--1317-- --leak-check=full
--1317-- -v
--1317-- Contents of /proc/version:
--1317-- can't open /proc/version
--1317-- Arch and hwcaps: AMD64, amd64-sse3-cx16-avx
--1317-- Page sizes: currently 4096, max supported 4096
--1317-- Valgrind library directory: /usr/local/lib/valgrind
--1317-- ./a.out (rx at 0x100000000, rw at 0x100002000)
--1317-- reading syms from primary file (14 7)
--1317-- dSYM directory is missing; consider using --dsymutil=yes
--1317-- /usr/lib/dyld (rx at 0x7fff5fc00000, rw at 0x7fff5fc34000)
--1317-- reading syms from primary file (6 1183)
--1317-- Scheduler: using generic scheduler lock implementation.
--1317-- Reading suppressions file: /usr/local/lib/valgrind/default.supp
==1317== embedded gdbserver: reading from /var/folders/b8/2knh_y5j1q9gn4874f4c10yh0000gn/T//vgdb-pipe-from-vgdb-to-1317-by-joelmalchiondo-on-???
==1317== embedded gdbserver: writing to /var/folders/b8/2knh_y5j1q9gn4874f4c10yh0000gn/T//vgdb-pipe-to-vgdb-from-1317-by-joelmalchiondo-on-???
==1317== embedded gdbserver: shared mem /var/folders/b8/2knh_y5j1q9gn4874f4c10yh0000gn/T//vgdb-pipe-shared-mem-vgdb-1317-by-joelmalchiondo-on-???
==1317==
==1317== TO CONTROL THIS PROCESS USING vgdb (which you probably
==1317== don't want to do, unless you know exactly what you're doing,
==1317== or are doing some strange experiment):
==1317== /usr/local/lib/valgrind/../../bin/vgdb --pid=1317 ...command...
==1317==
==1317== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==1317== /path/to/gdb ./a.out
==1317== and then give GDB the following command
==1317== target remote | /usr/local/lib/valgrind/../../bin/vgdb --pid=1317
==1317== --pid is optional if only one valgrind process is running
==1317==
--1317-- REDIR: 0x7fff5fc1b798 (arc4random) redirected to 0x238056b0e (???)
--1317-- REDIR: 0x7fff5fc21560 (strcmp) redirected to 0x238056a70 (???)
--1317-- REDIR: 0x7fff5fc1b560 (strlen) redirected to 0x238056a3f (???)
--1317-- REDIR: 0x7fff5fc1b4c0 (strcpy) redirected to 0x238056a8c (???)
--1317-- REDIR: 0x7fff5fc1ec4f (strcat) redirected to 0x238056a50 (???)
--1317-- /usr/local/lib/valgrind/vgpreload_core-amd64-darwin.so (rx at 0x1000, rw at 0x2000)
--1317-- reading syms from primary file (3 31)
--1317-- dSYM= /usr/local/lib/valgrind/vgpreload_core-amd64-darwin.so.dSYM/Contents/Resources/DWARF/vgpreload_core-amd64-darwin.so
--1317-- reading dwarf3 from dsyms file
--1317-- /usr/local/lib/valgrind/vgpreload_memcheck-amd64-darwin.so (rx at 0x4000, rw at 0x8000)
--1317-- reading syms from primary file (47 244)
--1317-- dSYM= /usr/local/lib/valgrind/vgpreload_memcheck-amd64-darwin.so.dSYM/Contents/Resources/DWARF/vgpreload_memcheck-amd64-darwin.so
--1317-- reading dwarf3 from dsyms file
UNKNOWN fcntl 61!--1317-- /usr/lib/libc++.1.dylib (rx at 0xc000, rw at 0x5f000)
--1317-- reading syms from primary file (2070 1507)
UNKNOWN fcntl 61!--1317-- /usr/lib/libSystem.B.dylib (rx at 0xba000, rw at 0xbc000)
--1317-- reading syms from primary file (31 4)
UNKNOWN fcntl 61!--1317-- /usr/lib/libc++abi.dylib (rx at 0xc2000, rw at 0xec000)
--1317-- reading syms from primary file (322 178)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libcache.dylib (rx at 0xf9000, rw at 0xfe000)
--1317-- reading syms from primary file (29 24)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libcommonCrypto.dylib (rx at 0x102000, rw at 0x10d000)
--1317-- reading syms from primary file (203 183)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libcompiler_rt.dylib (rx at 0x11a000, rw at 0x122000)
--1317-- reading syms from primary file (454 8)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libcopyfile.dylib (rx at 0x12d000, rw at 0x135000)
--1317-- reading syms from primary file (11 28)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libcorecrypto.dylib (rx at 0x13b000, rw at 0x18a000)
--1317-- reading syms from primary file (341 430)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libdispatch.dylib (rx at 0x19a000, rw at 0x1b5000)
--1317-- reading syms from primary file (176 737)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libdyld.dylib (rx at 0x1ce000, rw at 0x1d2000)
--1317-- reading syms from primary file (78 96)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libkeymgr.dylib (rx at 0x1d8000, rw at 0x1d9000)
--1317-- reading syms from primary file (12 4)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/liblaunch.dylib (rx at 0x1dd000, rw at 0x1e5000)
--1317-- reading syms from primary file (112 1)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libmacho.dylib (rx at 0x1ec000, rw at 0x1f2000)
--1317-- reading syms from primary file (86 1)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libquarantine.dylib (rx at 0x1f7000, rw at 0x1fa000)
--1317-- reading syms from primary file (66 32)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libremovefile.dylib (rx at 0x1ff000, rw at 0x201000)
--1317-- reading syms from primary file (15 4)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_asl.dylib (rx at 0x206000, rw at 0x218000)
--1317-- reading syms from primary file (127 106)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_blocks.dylib (rx at 0x221000, rw at 0x223000)
--1317-- reading syms from primary file (25 23)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_c.dylib (rx at 0x227000, rw at 0x2b1000)
--1317-- reading syms from primary file (1288 783)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_configuration.dylib (rx at 0x2dc000, rw at 0x2df000)
--1317-- reading syms from primary file (27 58)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_dnssd.dylib (rx at 0x2e4000, rw at 0x2ed000)
--1317-- reading syms from primary file (68 34)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_info.dylib (rx at 0x2f3000, rw at 0x31b000)
--1317-- reading syms from primary file (526 526)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_kernel.dylib (rx at 0x330000, rw at 0x34d000)
--1317-- reading syms from primary file (931 2486)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_m.dylib (rx at 0x36f000, rw at 0x39f000)
--1317-- reading syms from primary file (573 1)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_malloc.dylib (rx at 0x3a9000, rw at 0x3c5000)
--1317-- reading syms from primary file (102 199)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_network.dylib (rx at 0x3ce000, rw at 0x3f6000)
--1317-- reading syms from primary file (168 1053)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_notify.dylib (rx at 0x411000, rw at 0x41b000)
--1317-- reading syms from primary file (137 48)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_platform.dylib (rx at 0x423000, rw at 0x42a000)
--1317-- reading syms from primary file (114 1463)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_pthread.dylib (rx at 0x43c000, rw at 0x444000)
--1317-- reading syms from primary file (137 54)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_sandbox.dylib (rx at 0x44f000, rw at 0x451000)
--1317-- reading syms from primary file (61 8)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libsystem_stats.dylib (rx at 0x455000, rw at 0x45a000)
--1317-- reading syms from primary file (20 42)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libunc.dylib (rx at 0x460000, rw at 0x462000)
--1317-- reading syms from primary file (31 4)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libunwind.dylib (rx at 0x467000, rw at 0x46d000)
--1317-- reading syms from primary file (102 52)
UNKNOWN fcntl 61!--1317-- /usr/lib/system/libxpc.dylib (rx at 0x473000, rw at 0x498000)
--1317-- reading syms from primary file (349 818)
UNKNOWN fcntl 61!--1317-- /usr/lib/libobjc.A.dylib (rx at 0x4b4000, rw at 0x662000)
--1317-- reading syms from primary file (342 735)
UNKNOWN fcntl 61!--1317-- /usr/lib/libauto.dylib (rx at 0x682000, rw at 0x6c5000)
--1317-- reading syms from primary file (68 742)
UNKNOWN fcntl 61!--1317-- /usr/lib/libDiagnosticMessagesClient.dylib (rx at 0x6dc000, rw at 0x6de000)
--1317-- reading syms from primary file (21 14)
eq_SyscallStatus:
{78 0 43}
{78 0 40}
valgrind: m_syswrap/syswrap-main.c:380 (Bool eq_SyscallStatus(SyscallStatus *, SyscallStatus *)): the 'impossible' happened.
==1317== at 0x23803C34B: ???
==1317== by 0x23803C2F0: ???
==1317== by 0x2380B1983: ???
==1317== by 0x2380B107D: ???
==1317== by 0x2380AF5F2: ???
==1317== by 0x2380AD72A: ???
==1317== by 0x2380BF1C0: ???
sched status:
running_tid=1
Thread 1: status = VgTs_Runnable
==1317== at 0x341966: _kernelrpc_mach_vm_map_trap (in /usr/lib/system/libsystem_kernel.dylib)
==1317== by 0x3ABF6F: allocate_pages (in /usr/lib/system/libsystem_malloc.dylib)
==1317== by 0x3ABA11: create_scalable_zone (in /usr/lib/system/libsystem_malloc.dylib)
==1317== by 0x3B93ED: _malloc_initialize (in /usr/lib/system/libsystem_malloc.dylib)
==1317== by 0x3BA27D: malloc (in /usr/lib/system/libsystem_malloc.dylib)
==1317== by 0x7FFF5FC12D4F: malloc (in /usr/lib/dyld)
==1317== by 0x7FFF5FC1A3BD: operator new(unsigned long) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC090EC: std::__1::__split_buffer<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::__1::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)>&) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC08A44: std::__1::vector<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*), std::__1::allocator<char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)> >::insert(std::__1::__wrap_iter<char const* (* const*)(dyld_image_states, unsigned int, dyld_image_info const*)>, char const* (* const&)(dyld_image_states, unsigned int, dyld_image_info const*)) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0426B: dyld::registerImageStateBatchChangeHandler(dyld_image_states, char const* (*)(dyld_image_states, unsigned int, dyld_image_info const*)) (in /usr/lib/dyld)
==1317== by 0x1D08F0: dyld_register_image_state_change_handler (in /usr/lib/system/libdyld.dylib)
==1317== by 0x1D06B1: _dyld_initializer (in /usr/lib/system/libdyld.dylib)
==1317== by 0xBBA9D: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==1317== by 0x7FFF5FC11C2D: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC11DB9: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0EA61: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0E9EA: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0E8F5: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC021B6: dyld::initializeMainExecutable() (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0555F: dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0127A: dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) (in /usr/lib/dyld)
==1317== by 0x7FFF5FC0105D: _dyld_start (in /usr/lib/dyld)
Note: see also the FAQ in the source distribution.
It contains workarounds to several common problems.
In particular, if Valgrind aborted or crashed after
identifying problems in your program, there's a good chance
that fixing those problems will prevent Valgrind aborting or
crashing, especially if it happened in m_mallocfree.c.
If that doesn't help, please report this bug to: www.valgrind.org
In the bug report, send all the above text, the valgrind
version, and what OS and version you are using. Thanks.
Avez-vous essayé d'utiliser Instruments ? Fallait venir avec votre mise à jour de Xcode.
Les Instruments ne fonctionnent pas avec l'Intégrité du Système de Protection est activé.
Les Instruments ne fonctionnent pas avec l'Intégrité du Système de Protection est activé.
OriginalL'auteur lufthansa747 | 2013-10-31
Vous devez vous connecter pour publier un commentaire.
Valgrind pouvez exécuter votre programme et de faire une vérification de mémoire avec
Il va exécuter votre programme et vous donner de détails sur l'utilisation de la mémoire et de fuites possibles. Aussi, vous devez compiler votre programme avec les symboles de débogage à l'aide de :
Puis remonter une fuite de mémoire de la cause peut être difficile. Vous pouvez consulter cet article :
http://www.cprogramming.com/debugging/valgrind.html
ou
http://valgrind.org/docs/manual/mc-manual.html#mc-manual.leaks
Si vous affichez la sortie, nous pouvons vous aider à le comprendre. Ou essayer les autres outils proposés.
==867== attention: le Support sur MacOS 10.8 sont expérimentales et principalement cassé. ==867== AVERTISSEMENT: Attendez-vous à des résultats incorrects, les assertions et les accidents. ==867== ATTENTION: En particulier, Memcheck sur les programmes 32 bits échouera t 0x39f000) --867-- la lecture syms de fichier principal (573 1) INCONNU fcntl 61!--867-- /usr/lib/système/libsystem_malloc.dylib (rx à 0x3a9000, rw à 0x3c5000) --867-- la lecture syms de fichier principal (102 199) INCONNU fcntl 61!--867-- /usr/lib/système/libsystem_network.dylib (rx à 0x3ce000, rw à 0x3f6000)
c'est même pas certains de, ses juste la ligne après la ligne de non-sens
Une chose à noter: lors de l'utilisation de valgrind pour vérifier les fuites de mémoire, assurez-vous que votre processus s'arrête naturellement. Si vous forcez l'arrêt du processus (p. ex. via control-c ou de le "tuer", vous allez obtenir un grand nombre de faux positifs que le processus n'est jamais eu la chance de le libérer de sa mémoire avant de sortir)
OriginalL'auteur Rémi Benoit
Valgrind est ok et non-intrusive.
Mais si vous le pouvez, le ralentissement devrait être beaucoup moins avec D'addresssanitizer.
Il est inclus dans
g++-4.8
etclang
, n'oubliez pas la version. Vous devez compiler avec le drapeau-fsanitize=address
.Même pas dans clang?
Non, pas même dans Clang. J'ai quelques patch de ce genre de travaux, mais il a besoin de polissage. Désolé pour la réponse tardive.
OriginalL'auteur Germán Diago
Vous pouvez utiliser
iprofiler
(page de manuel), qui est la méthode de l'aide Instruments sur un utilitaire de ligne de commande. Vous l'exécutez sur l'utilité et de la il crée un.dtps
bundle, qui peut ensuite être ouvert dans Instruments pour l'inspection.de même pour moi. L'exécution manuelle iprofiler et aussi le mac app instruments de fuites, je ne vois pas évident de fuites...
OriginalL'auteur trojanfoe