Skip to content

Commit

Permalink
Merge branch 'feature/threading'
Browse files Browse the repository at this point in the history
  • Loading branch information
mhahnFr committed Aug 23, 2023
2 parents 87d2e63 + f399ea0 commit 9b34862
Show file tree
Hide file tree
Showing 16 changed files with 737 additions and 288 deletions.
38 changes: 35 additions & 3 deletions LeakSanitizer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
BF23A2DF289ECE6A00B17349 /* lsan_stats.h in Headers */ = {isa = PBXBuildFile; fileRef = BF23A2DD289ECE6A00B17349 /* lsan_stats.h */; settings = {ATTRIBUTES = (Public, ); }; };
BF23A2E2289ED24200B17349 /* Stats.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF23A2E0289ED24200B17349 /* Stats.cpp */; };
BF23A2E3289ED24200B17349 /* Stats.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BF23A2E1289ED24200B17349 /* Stats.hpp */; };
BF30D8592A7815E8001D4EBF /* ThreadAllocInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF30D8572A7815E8001D4EBF /* ThreadAllocInfo.cpp */; };
BF30D85A2A7815E8001D4EBF /* ThreadAllocInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF30D8572A7815E8001D4EBF /* ThreadAllocInfo.cpp */; };
BF30D85B2A7815E8001D4EBF /* ThreadAllocInfo.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BF30D8582A7815E8001D4EBF /* ThreadAllocInfo.hpp */; };
BF30D85C2A7815E8001D4EBF /* ThreadAllocInfo.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BF30D8582A7815E8001D4EBF /* ThreadAllocInfo.hpp */; };
BF378F932919482E00A4DAA9 /* Stats.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BF23A2E1289ED24200B17349 /* Stats.hpp */; };
BF378F962919483900A4DAA9 /* LeakSani.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BF72C3C92885CB9E00C7AE5C /* LeakSani.hpp */; };
BF378F992919483B00A4DAA9 /* MallocInfo.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BFBF736428831FC200BC4208 /* MallocInfo.hpp */; };
Expand Down Expand Up @@ -64,6 +68,9 @@
BF23A2DD289ECE6A00B17349 /* lsan_stats.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = lsan_stats.h; sourceTree = "<group>"; };
BF23A2E0289ED24200B17349 /* Stats.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Stats.cpp; sourceTree = "<group>"; };
BF23A2E1289ED24200B17349 /* Stats.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Stats.hpp; sourceTree = "<group>"; };
BF30D8572A7815E8001D4EBF /* ThreadAllocInfo.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadAllocInfo.cpp; sourceTree = "<group>"; };
BF30D8582A7815E8001D4EBF /* ThreadAllocInfo.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ThreadAllocInfo.hpp; sourceTree = "<group>"; };
BF34157C2A8405AD00DEEF10 /* deprecation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = deprecation.h; sourceTree = "<group>"; };
BF378FB42919496000A4DAA9 /* libcallstack.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcallstack.a; path = CallstackLibrary/libcallstack.a; sourceTree = "<group>"; };
BF49A5D72899599300BC1FFD /* signalHandlers.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = signalHandlers.cpp; sourceTree = "<group>"; };
BF49A5D82899599300BC1FFD /* signalHandlers.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = signalHandlers.hpp; sourceTree = "<group>"; };
Expand All @@ -89,6 +96,7 @@
BFBF736928832F8100BC4208 /* wrap_malloc.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = wrap_malloc.hpp; sourceTree = "<group>"; };
BFBF736B2883323100BC4208 /* crash.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = crash.cpp; sourceTree = "<group>"; };
BFBF736C2883323100BC4208 /* crash.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = crash.hpp; sourceTree = "<group>"; };
BFC898552A8530BB00F7CB6D /* ATracker.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ATracker.hpp; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -111,6 +119,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
BF30D8562A78159E001D4EBF /* threadAllocInfo */ = {
isa = PBXGroup;
children = (
BF30D8572A7815E8001D4EBF /* ThreadAllocInfo.cpp */,
BF30D8582A7815E8001D4EBF /* ThreadAllocInfo.hpp */,
);
path = threadAllocInfo;
sourceTree = "<group>";
};
BF378FB32919496000A4DAA9 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand All @@ -119,13 +136,24 @@
name = Frameworks;
sourceTree = "<group>";
};
BF41CC5D2A813B4500EAA3A1 /* statistics */ = {
isa = PBXGroup;
children = (
BF23A2DC289ECE6A00B17349 /* lsan_stats.cpp */,
BF23A2E0289ED24200B17349 /* Stats.cpp */,
BF23A2E1289ED24200B17349 /* Stats.hpp */,
);
path = statistics;
sourceTree = "<group>";
};
BF643E5C28A40C970080DB21 /* include */ = {
isa = PBXGroup;
children = (
BF23A2DD289ECE6A00B17349 /* lsan_stats.h */,
BF72C3CB2885CB9E00C7AE5C /* leaksan.h */,
BF621FDC28A291DE00414EE4 /* lsan_internals.h */,
BF72C3CC2885CB9E00C7AE5C /* stdlib.h */,
BF34157C2A8405AD00DEEF10 /* deprecation.h */,
);
path = include;
sourceTree = "<group>";
Expand Down Expand Up @@ -156,15 +184,14 @@
BF9DD3A428A6761400AEBC17 /* code */ = {
isa = PBXGroup;
children = (
BF41CC5D2A813B4500EAA3A1 /* statistics */,
BF30D8562A78159E001D4EBF /* threadAllocInfo */,
BFAFADC428B4FDA40060076C /* Formatter.cpp */,
BFAFADC528B4FDA40060076C /* Formatter.hpp */,
BF621FE028A2B61E00414EE4 /* bytePrinter.cpp */,
BF621FE128A2B61E00414EE4 /* bytePrinter.hpp */,
BF23A2DC289ECE6A00B17349 /* lsan_stats.cpp */,
BF621FDB28A291DE00414EE4 /* lsan_internals.cpp */,
BF72C3CA2885CB9E00C7AE5C /* LeakSani.cpp */,
BF23A2E0289ED24200B17349 /* Stats.cpp */,
BF23A2E1289ED24200B17349 /* Stats.hpp */,
BF72C3C92885CB9E00C7AE5C /* LeakSani.hpp */,
BFBF736328831FC200BC4208 /* MallocInfo.cpp */,
BFBF736428831FC200BC4208 /* MallocInfo.hpp */,
Expand All @@ -176,6 +203,7 @@
BF49A5D82899599300BC1FFD /* signalHandlers.hpp */,
BFBF736C2883323100BC4208 /* crash.hpp */,
BFBF736928832F8100BC4208 /* wrap_malloc.hpp */,
BFC898552A8530BB00F7CB6D /* ATracker.hpp */,
);
path = code;
sourceTree = "<group>";
Expand All @@ -187,6 +215,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
BF30D85C2A7815E8001D4EBF /* ThreadAllocInfo.hpp in Headers */,
BF378FA82919484A00A4DAA9 /* lsan_stats.h in Headers */,
BF378FAE2919484E00A4DAA9 /* lsan_internals.h in Headers */,
BF0F1353291947C9008F0FCD /* bytePrinter.hpp in Headers */,
Expand All @@ -206,6 +235,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
BF30D85B2A7815E8001D4EBF /* ThreadAllocInfo.hpp in Headers */,
BF23A2DF289ECE6A00B17349 /* lsan_stats.h in Headers */,
BF621FDE28A291DE00414EE4 /* lsan_internals.h in Headers */,
BFBF736E2883323100BC4208 /* crash.hpp in Headers */,
Expand Down Expand Up @@ -307,6 +337,7 @@
BF0F133B29194791008F0FCD /* LeakSani.cpp in Sources */,
BF0F133E29194794008F0FCD /* Stats.cpp in Sources */,
BF0F134129194797008F0FCD /* MallocInfo.cpp in Sources */,
BF30D85A2A7815E8001D4EBF /* ThreadAllocInfo.cpp in Sources */,
BF0F1347291947A2008F0FCD /* wrap_malloc.cpp in Sources */,
BF0F13442919479B008F0FCD /* warn.cpp in Sources */,
BF0F134A291947A6008F0FCD /* crash.cpp in Sources */,
Expand All @@ -325,6 +356,7 @@
BF23A2DE289ECE6A00B17349 /* lsan_stats.cpp in Sources */,
BF621FDD28A291DE00414EE4 /* lsan_internals.cpp in Sources */,
BFBF736528831FC200BC4208 /* MallocInfo.cpp in Sources */,
BF30D8592A7815E8001D4EBF /* ThreadAllocInfo.cpp in Sources */,
BF72C3CE2885CB9E00C7AE5C /* LeakSani.cpp in Sources */,
BFBF736828832C3300BC4208 /* wrap_malloc.cpp in Sources */,
BFBF736D2883323100BC4208 /* crash.cpp in Sources */,
Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ LIB_NAME = $(CORE_NAME).a
SHARED_L = $(CORE_NAME).so
DYLIB_NA = $(CORE_NAME).dylib

SRC = $(shell find . -name \*.cpp \! -path \*CallstackLibrary\*)

OBJS = $(patsubst %.cpp, %.o, $(SRC))
DEPS = $(patsubst %.cpp, %.d, $(SRC))

LIBCALLSTACK_NAME = libcallstack
LIBCALLSTACK_DIR = ./CallstackLibrary
LIBCALLSTACK_A = $(LIBCALLSTACK_DIR)/$(LIBCALLSTACK_NAME).a
Expand All @@ -36,6 +31,10 @@ LIBCALLSTACK_DY = $(LIBCALLSTACK_DIR)/$(LIBCALLSTACK_NAME).dylib
LIBCALLSTACK_EXTR = tmpLibCallstack
LIBCALLSTACK_FLAG = 'CXX_DEMANGLER=true'

SRC = $(shell find . -name \*.cpp \! -path $(LIBCALLSTACK_DIR)\*)
OBJS = $(patsubst %.cpp, %.o, $(SRC))
DEPS = $(patsubst %.cpp, %.d, $(SRC))

LDFLAGS = -ldl -L$(LIBCALLSTACK_DIR) -lcallstack
CXXFLAGS = -std=c++17 -Wall -pedantic -fPIC -Ofast

Expand Down
74 changes: 74 additions & 0 deletions code/ATracker.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* LeakSanitizer - Small library showing information about lost memory.
*
* Copyright (C) 2023 mhahnFr
*
* This file is part of the LeakSanitizer. This library is free software:
* you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This library 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this library, see the file LICENSE. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef ATracker_hpp
#define ATracker_hpp

#include "MallocInfo.hpp"

/**
* This class defines the functionality of an allocation tracker.
*/
class ATracker {
public:
virtual ~ATracker() {}

/**
* Adds the given allocation record to the tracked allocations.
*
* @param info the allocation record to be added
*/
virtual void addMalloc(MallocInfo && info) = 0;
/**
* Attempts to exchange the allocation record associated with the given
* allocation record by the given allocation record.
*
* Implementors note: the record should be searched for globally if it is not
* found in this instance.
*
* @param info the allocation record to be exchanged
* @return whether the record was replaced
*/
virtual auto changeMalloc(const MallocInfo & info) -> bool = 0;
/**
* Attempts to remove the allocation record associated with the given pointer.
*
* Implementors note: the record should be searched for globally if it is not
* found in this instance.
*
* @param pointer the deallocated pointer
* @return whether the record was removed
*/
virtual auto removeMalloc(const void * pointer) -> bool = 0;

/**
* Attempts to remove the allocation record associated with the given record.
*
* Implementors note: the record should be searched for globally if it is not
* found in this instance.
*
* @param info the allocation record
* @return whether the record was removed
*/
inline auto removeMalloc(MallocInfo && info) -> bool {
return removeMalloc(info.getPointer());
}
};

#endif /* ATracker_hpp */
Loading

0 comments on commit 9b34862

Please sign in to comment.