Commit 982bdb7f by Szeberényi Imre

új memtrace

parent d1f5956e
......@@ -44,10 +44,6 @@
<Unit filename="obj.h" />
<Unit filename="ocean.cpp" />
<Unit filename="ocean.h" />
<Extensions>
<code_completion />
<envvars />
<debugger />
</Extensions>
<Extensions />
</Project>
</CodeBlocks_project_file>
......@@ -5,8 +5,9 @@ Keszitette: Peregi Tamas, BME IIT, 2011
Kanari: Szeberenyi Imre, 2013.
VS 2012: Szeberényi Imre, 2015.,
mem_dump: 2016.
meset felszabaditaskor: 2018.
memset felszabaditaskor: 2018.
typo: 2019.
poi_check: 2021.
*********************************/
/*definialni kell, ha nem paracssorbol allitjuk be (-DMEMTRACE) */
......@@ -178,7 +179,6 @@ START_NAMESPACE
dying = TRUE;
exit(120);
}
static void initialize();
END_NAMESPACE
......@@ -188,6 +188,7 @@ END_NAMESPACE
#ifdef MEMTRACE_TO_MEMORY
START_NAMESPACE
typedef struct _registry_item {
void * p; /* mem pointer*/
size_t size; /* size*/
......@@ -197,6 +198,12 @@ START_NAMESPACE
static registry_item registry; /*sentinel*/
static registry_item *find_registry_item(void * p) {
registry_item *n = &registry;
for(; n->next && n->next->p != p ; n=n->next);
return n;
}
static void print_registry_item(registry_item * p) {
if (p) {
print_registry_item(p->next);
......@@ -225,6 +232,13 @@ START_NAMESPACE
}
return 0;
}
/* Ellenorzi, hogy a pointer regisztralt-e. Ha nem, akkor 0-val tér vissza */
int poi_check(void *pu) {
if (pu == NULL) return 1;
initialize();
return find_registry_item(P(pu))->next != NULL;
}
END_NAMESPACE
#endif/*MEMTRACE_TO_MEMORY*/
......@@ -271,14 +285,6 @@ START_NAMESPACE
return TRUE;
}
#ifdef MEMTRACE_TO_MEMORY
static registry_item *find_registry_item(void * p) {
registry_item *n = &registry;
for(; n->next && n->next->p != p ; n=n->next);
return n;
}
#endif
static void unregister_memory(void * p, call_t call) {
initialize();
#ifdef MEMTRACE_TO_FILE
......@@ -487,7 +493,15 @@ void operator delete(void * p) THROW_NOTHING {
void operator delete[](void * p) THROW_NOTHING {
memtrace::traced_delete(p,FDELETEARR);
}
#if __cplusplus >= 201402L
void operator delete(void * p, size_t) THROW_NOTHING {
memtrace::traced_delete(p,FDELETE);
}
void operator delete[](void * p, size_t) THROW_NOTHING {
memtrace::traced_delete(p,FDELETEARR);
}
#endif
/* Visual C++ 2012 miatt kell, mert háklis, hogy nincs megfelelő delete, bár senki sem használja */
void operator delete(void * p, int, const char *) THROW_NOTHING {
......
......@@ -5,7 +5,7 @@ Keszitette: Peregi Tamas, BME IIT, 2011
Kanari: Szeberenyi Imre, 2013.,
VS 2012: Szeberényi Imre, 2015.,
mem_dump: 2016.
inclue-ok: 2017., 2018. 2019.
inclue-ok: 2017., 2018., 2019., 2021.
*********************************/
#ifndef MEMTRACE_H
......@@ -102,6 +102,7 @@ END_NAMESPACE
#if defined(MEMTRACE_TO_MEMORY)
START_NAMESPACE
int mem_check(void);
int poi_check(void*);
END_NAMESPACE
#endif
......@@ -153,6 +154,17 @@ END_NAMESPACE
#include <map>
#include <algorithm>
#include <functional>
#include <memory>
#include <iomanip>
#include <locale>
#include <typeinfo>
#include <ostream>
#include <stdexcept>
#include <ctime>
#if __cplusplus >= 201103L
#include <iterator>
#include <regex>
#endif
#endif
#ifdef MEMTRACE_CPP
namespace std {
......@@ -178,8 +190,7 @@ START_NAMESPACE
#define realloc(old,size) TRACEC(traced_realloc)(old,size,#size,__LINE__,__FILE__)
void * traced_realloc(void * old, size_t size, const char *size_txt, int line, const char * file);
void mem_dump(void const *mem, size_t size, FILE* fp);
void mem_dump(void const *mem, size_t size, FILE* fp = stdout);
END_NAMESPACE
#endif/*MEMTRACE_C*/
......@@ -200,6 +211,12 @@ void * operator new[](size_t size) THROW_BADALLOC;
void operator delete(void * p) THROW_NOTHING;
void operator delete[](void * p) THROW_NOTHING;
#if __cplusplus >= 201402L
// sized delete miatt: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3536.html
void operator delete(void * p, size_t) THROW_NOTHING;
void operator delete[](void * p, size_t) THROW_NOTHING;
#endif
/* Visual C++ 2012 miatt kell, mert háklis, hogy nincs megfelelő delete, bár senki sem használja */
void operator delete(void *p, int, const char *) THROW_NOTHING;
void operator delete[](void *p, int, const char *) THROW_NOTHING;
......@@ -215,5 +232,8 @@ void operator delete[](void *p, int, const char *) THROW_NOTHING;
#endif /*MEMTRACE_CPP*/
#endif /*FROM_MEMTRACE_CPP*/
#endif /*MEMCHECK*/
#else
#pragma message ( "MEMTRACE NOT DEFINED" )
#endif /*MEMTRACE*/
#endif /*MEMTRACE_H*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment