Skip to content

Commit

Permalink
Merge branch 'feature/callstack-update'
Browse files Browse the repository at this point in the history
  • Loading branch information
mhahnFr committed Jun 12, 2024
2 parents d0cb84a + 2b0a98e commit 4c969ad
Show file tree
Hide file tree
Showing 29 changed files with 387 additions and 748 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#
# LeakSanitizer - Small library showing information about lost memory.
#
# Copyright (C) 2022, 2024 mhahnFr
Expand All @@ -17,7 +16,6 @@
#
# You should have received a copy of the GNU General Public License along with the
# LeakSanitizer, see the file LICENSE. If not, see <https://www.gnu.org/licenses/>.
#

# Prerequisites
*.d
Expand Down Expand Up @@ -69,9 +67,9 @@ dkms.conf
# Xcode project user data
xcuserdata/

# macOS spcific
# macOS specific
.DS_Store
*.dSYM/

*~
.*
*.dSYM/
2 changes: 1 addition & 1 deletion CallstackLibrary
Submodule CallstackLibrary updated 89 files
+12 −8 .gitignore
+0 −732 CallstackLibrary.xcodeproj/project.pbxproj
+0 −7 CallstackLibrary.xcodeproj/project.xcworkspace/contents.xcworkspacedata
+0 −8 CallstackLibrary.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
+0 −67 CallstackLibrary.xcodeproj/xcshareddata/xcschemes/Callstack Library.xcscheme
+1 −1 DC4C
+37 −21 Makefile
+41 −38 README.md
+27 −15 include/callstack.h
+19 −17 include/callstack.hpp
+21 −17 include/callstack_exception.hpp
+61 −12 include/callstack_frame.h
+21 −13 include/callstack_internals.h
+18 −12 include/callstack_type.h
+18 −15 src/callstack.c
+25 −16 src/callstackInternal.c
+13 −11 src/callstackInternal.h
+23 −16 src/callstack_frame.c
+12 −10 src/callstack_internals.c
+55 −0 src/dlMapper/dlMapper.c
+32 −0 src/dlMapper/dlMapper.h
+29 −0 src/dlMapper/dlMapper_platform.h
+28 −0 src/dlMapper/elf/dlMapper.c
+39 −0 src/dlMapper/loadedLibInfo.h
+95 −0 src/dlMapper/macho/dlMapper.c
+29 −0 src/dlMapper/macho/pair_address.h
+31 −0 src/dlMapper/vector_loadedLibInfo.h
+41 −0 src/lcs_builtins.h
+11 −11 src/parser/callstack_parser.c
+13 −11 src/parser/callstack_parser.h
+0 −29 src/parser/file/UInt64Vector.h
+28 −8 src/parser/file/binaryFile.c
+21 −9 src/parser/file/binaryFile.h
+17 −13 src/parser/file/debugInfo.h
+54 −0 src/parser/file/dwarf/definitions.h
+51 −22 src/parser/file/dwarf/dwarf_lineInfo.h
+163 −205 src/parser/file/dwarf/dwarf_parser.c
+111 −17 src/parser/file/dwarf/dwarf_parser.h
+31 −0 src/parser/file/dwarf/v3/definitions.h
+31 −0 src/parser/file/dwarf/v4/definitions.h
+9 −11 src/parser/file/dwarf/v4/fileNameEntry.h
+138 −0 src/parser/file/dwarf/v4/parser.c
+48 −0 src/parser/file/dwarf/v4/parser.h
+31 −0 src/parser/file/dwarf/v4/vector_fileNameEntry.h
+42 −0 src/parser/file/dwarf/v5/definitions.h
+45 −0 src/parser/file/dwarf/v5/fileAttribute.h
+31 −0 src/parser/file/dwarf/v5/optional_uint64_t.h
+31 −0 src/parser/file/dwarf/v5/optional_vector_fileAttribute.h
+31 −0 src/parser/file/dwarf/v5/pair_uint64.h
+458 −0 src/parser/file/dwarf/v5/parser.c
+46 −0 src/parser/file/dwarf/v5/parser.h
+31 −0 src/parser/file/dwarf/v5/vector_fileAttribute.h
+31 −0 src/parser/file/dwarf/v5/vector_pair_uint64.h
+11 −9 src/parser/file/dwarf/vector_dwarf_lineInfo.h
+0 −27 src/parser/file/dwarf/vector_string.h
+11 −9 src/parser/file/dwarf/vector_uint8.h
+163 −0 src/parser/file/elf/cpp_optimized/elfFile.c
+167 −0 src/parser/file/elf/cpp_optimized/elfFile_optimized.cpp
+0 −59 src/parser/file/elf/elfFile.c
+83 −13 src/parser/file/elf/elfFile.h
+235 −0 src/parser/file/elf/elfFile_shared.c
+0 −0 src/parser/file/function.c
+0 −0 src/parser/file/function.h
+46 −0 src/parser/file/lcs_section.h
+50 −0 src/parser/file/loader.c
+81 −0 src/parser/file/loader.h
+0 −29 src/parser/file/macho/FunctionVector.h
+0 −32 src/parser/file/macho/OptionalFuncFilePair.h
+0 −29 src/parser/file/macho/OptionalFunction.h
+5 −16 src/parser/file/macho/archive.c
+12 −9 src/parser/file/macho/cache.c
+14 −11 src/parser/file/macho/cpp_optimized/machoFile.c
+13 −10 src/parser/file/macho/cpp_optimized/machoFile_optimized.cpp
+17 −12 src/parser/file/macho/cpp_optimized/objectFile.c
+17 −14 src/parser/file/macho/cpp_optimized/objectFile_optimized.cpp
+14 −12 src/parser/file/macho/machoFile.h
+17 −34 src/parser/file/macho/machoFile_shared.c
+3 −2 src/parser/file/macho/macho_parser.h
+27 −13 src/parser/file/macho/objectFile.h
+68 −65 src/parser/file/macho/objectFile_shared.c
+35 −0 src/parser/file/macho/optional_pair_funcFile.h
+12 −10 src/parser/file/macho/vector_boolString.h
+0 −29 src/parser/file/macho/vector_pairFuncFile.h
+31 −0 src/parser/file/macho/vector_pair_funcFile.h
+0 −27 src/parser/file/macho/vector_string.h
+31 −0 src/parser/file/optional_function.h
+31 −0 src/parser/file/vector_function.h
+29 −0 src/parser/file/vector_string.h
+31 −0 src/parser/file/vector_uint64.h
14 changes: 8 additions & 6 deletions LeakSanitizer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
BF378F9F2919484100A4DAA9 /* signalHandlers.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BF49A5D82899599300BC1FFD /* signalHandlers.hpp */; };
BF378FA52919484800A4DAA9 /* wrap_malloc.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BFBF736928832F8100BC4208 /* wrap_malloc.hpp */; };
BF378FA82919484A00A4DAA9 /* lsan_stats.h in Headers */ = {isa = PBXBuildFile; fileRef = BF23A2DD289ECE6A00B17349 /* lsan_stats.h */; settings = {ATTRIBUTES = (Public, ); }; };
BF378FAB2919484C00A4DAA9 /* leaksan.h in Headers */ = {isa = PBXBuildFile; fileRef = BF72C3CB2885CB9E00C7AE5C /* leaksan.h */; };
BF378FAE2919484E00A4DAA9 /* lsan_internals.h in Headers */ = {isa = PBXBuildFile; fileRef = BF621FDC28A291DE00414EE4 /* lsan_internals.h */; settings = {ATTRIBUTES = (Public, ); }; };
BF378FB52919496000A4DAA9 /* libcallstack.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BF378FB42919496000A4DAA9 /* libcallstack.a */; };
BF4368F52AACF04700252E2A /* crashWarner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF4368F32AACF04700252E2A /* crashWarner.cpp */; };
Expand Down Expand Up @@ -67,8 +66,6 @@
BF621FE128A2B61E00414EE4 /* bytePrinter.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = bytePrinter.hpp; sourceTree = "<group>"; };
BF72C3C92885CB9E00C7AE5C /* LeakSani.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = LeakSani.hpp; sourceTree = "<group>"; };
BF72C3CA2885CB9E00C7AE5C /* LeakSani.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LeakSani.cpp; sourceTree = "<group>"; };
BF72C3CB2885CB9E00C7AE5C /* leaksan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = leaksan.h; sourceTree = "<group>"; };
BF72C3CC2885CB9E00C7AE5C /* stdlib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stdlib.h; sourceTree = "<group>"; };
BF84625A2AD1B2D3003B05F5 /* init.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = init.hpp; sourceTree = "<group>"; };
BF84625B2AD1B489003B05F5 /* lsanMisc.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = lsanMisc.cpp; sourceTree = "<group>"; };
BF84625C2AD1B489003B05F5 /* lsanMisc.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = lsanMisc.hpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -141,9 +138,7 @@
isa = PBXGroup;
children = (
BF23A2DD289ECE6A00B17349 /* lsan_stats.h */,
BF72C3CB2885CB9E00C7AE5C /* leaksan.h */,
BF621FDC28A291DE00414EE4 /* lsan_internals.h */,
BF72C3CC2885CB9E00C7AE5C /* stdlib.h */,
BF34157C2A8405AD00DEEF10 /* deprecation.h */,
);
path = include;
Expand Down Expand Up @@ -247,7 +242,6 @@
BF378F932919482E00A4DAA9 /* Stats.hpp in Headers */,
BF378F992919483B00A4DAA9 /* MallocInfo.hpp in Headers */,
BF378FA52919484800A4DAA9 /* wrap_malloc.hpp in Headers */,
BF378FAB2919484C00A4DAA9 /* leaksan.h in Headers */,
BF378F9F2919484100A4DAA9 /* signalHandlers.hpp in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -344,6 +338,10 @@
GCC_ENABLE_CPP_EXCEPTIONS = YES;
GCC_ENABLE_CPP_RTTI = YES;
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
HEADER_SEARCH_PATHS = (
CallstackLibrary/include,
include,
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/CallstackLibrary",
Expand All @@ -369,6 +367,10 @@
GCC_ENABLE_CPP_RTTI = YES;
GCC_OPTIMIZATION_LEVEL = fast;
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
HEADER_SEARCH_PATHS = (
CallstackLibrary/include,
include,
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/CallstackLibrary",
Expand Down
25 changes: 14 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
#
# Copyright (C) 2022 - 2024 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 file is part of the LeakSanitizer.
#
# This library is distributed in the hope that it will be useful,
# The LeakSanitizer 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.
#
# The LeakSanitizer 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/>.
# You should have received a copy of the GNU General Public License along with the
# LeakSanitizer, see the file LICENSE. If not, see <https://www.gnu.org/licenses/>.
#

CORE_NAME = liblsan
Expand All @@ -25,7 +27,7 @@ DYLIB_NA = $(CORE_NAME).dylib
LIBCALLSTACK_NAME = libcallstack
LIBCALLSTACK_DIR = ./CallstackLibrary
LIBCALLSTACK_A = $(LIBCALLSTACK_DIR)/$(LIBCALLSTACK_NAME).a
LIBCALLSTACK_FLAG = 'CXX_OPTIMIZED=true' 'CXX_FUNCTIONS=true'
LIBCALLSTACK_FLAG = 'CXX_OPTIMIZED=true' 'CXX_FUNCTIONS=true' 'USE_BUILTINS=false'

SRC = $(shell find src -name \*.cpp \! -path $(LIBCALLSTACK_DIR)\*)
OBJS = $(patsubst %.cpp, %.o, $(SRC))
Expand All @@ -34,7 +36,7 @@ DEPS = $(patsubst %.cpp, %.d, $(SRC))
BENCHMARK = false

LDFLAGS = -ldl -L$(LIBCALLSTACK_DIR) -lcallstack
CXXFLAGS = -std=c++17 -Wall -Wextra -pedantic -fPIC -Ofast
CXXFLAGS = -std=c++17 -Wall -Wextra -pedantic -fPIC -Ofast -I 'include' -I CallstackLibrary/include

ifeq ($(BENCHMARK),true)
CXXFLAGS += -DBENCHMARK
Expand All @@ -43,7 +45,7 @@ endif
LINUX_SONAME_FLAG = -Wl,-soname,$(abspath $@)

ifeq ($(shell uname -s),Darwin)
LDFLAGS += -current_version 1.8 -compatibility_version 1 -install_name $(abspath $@)
LDFLAGS += -current_version 1.9 -compatibility_version 1 -install_name $(abspath $@)

NAME = $(DYLIB_NA)
else
Expand Down Expand Up @@ -78,7 +80,7 @@ install:
mkdir -p $(INSTALL_PATH)/lib
mkdir -p "$(INSTALL_PATH)/include/lsan"
mv $(NAME) $(INSTALL_PATH)/lib
find "include" -name \*.h \! -path \*/stdlib.h \! -path \*/leaksan.h -exec cp {} "$(INSTALL_PATH)/include/lsan" \;
find "include" -name \*.h -exec cp {} "$(INSTALL_PATH)/include/lsan" \;

uninstall:
- $(RM) $(INSTALL_PATH)/lib/$(NAME)
Expand All @@ -91,6 +93,7 @@ release:

update:
$(MAKE) fclean
git fetch --tags
git pull
git submodule update
git -C $(LIBCALLSTACK_DIR) submodule update
Expand Down
67 changes: 23 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ To use this sanitizer simply link your application against it (recommended) or p
#### Linking (_recommended_)
- Add `-L<path/to/library>` if this sanitizer has not been installed in one of the default
directories.
- On Linux add `-rdynamic` to the linking flags.

Link with: `-llsan`

> [!TIP]
> - Example **macOS**: `-L<path/to/library> -llsan`
> - Example **Linux**: `-rdynamic -L<path/to/library> -llsan`
> - Example: `-L<path/to/library> -llsan`
#### Preloading
Add this sanitizer's library to the dynamic loader preload environment variable:
Expand Down Expand Up @@ -108,66 +106,35 @@ int main(void) {
free(a);
}
```
Compiled and linked on macOS with `cc main.c -L<path/to/library> -llsan` creates the following output:
Compiled and linked on macOS with `cc main.c -g -L<path/to/library> -llsan` creates the following output:
```
Exiting
Leak of size 13 B, allocation stacktrace:
At: (/usr/lib/system/libsystem_c.dylib) strdup + 32
in: (a.out) main + 34
at: (/usr/lib/dyld) start + 1903
Leak of size 1023 B, allocation stacktrace:
In: (a.out) main + 18
at: (/usr/lib/dyld) start + 1903
Summary: 2 leaks, 1.01 KiB lost.
```

#### Line numbers
##### macOS
Simply compile your code with debug symbols to add line numbers to the output.
> [!TIP]
> Usually, the appropriate flag is `-g`.
The previous example compiled and linked on macOS with `cc -g main.c -L<path/to/library> -llsan` creates the following output:

```
Exiting
Leak of size 13 B, allocation stacktrace:
Leak of size 13 B
At: (/usr/lib/system/libsystem_c.dylib) strdup + 32
in: (a.out) main (main.c:8:9)
at: (/usr/lib/dyld) start + 1903
Leak of size 1023 B, allocation stacktrace:
Leak of size 1023 B
In: (a.out) main (main.c:7:16)
at: (/usr/lib/dyld) start + 1903
Summary: 2 leaks, 1.01 KiB lost.
```

##### Linux
To (partially) add line numbers, you can add `-Wno-gnu-include-next -I<path/to/library>/include` to the compiling flags
of your code.

The previous example compiled and linked on Debian with
`gcc main.c -Wno-gnu-include-next -I<path/to/library>/include -rdynamic -L<path/to/library> -llsan` creates the following output:

Compiled and linked on Debian with `gcc main.c -g -L<path/to/library> -llsan` creates the following output:
```
Exiting
Leak of size 1023 B, allocated at main.c:7
In: (a.out) main + 33
Leak of size 1023 B
In: (a.out) main (main.c:7:16)
at: (/usr/lib/x86_64-linux-gnu/libc.so.6) << Unknown >>
at: (/usr/lib/x86_64-linux-gnu/libc.so.6) __libc_start_main + 133
at: (a.out) _start + 33
Leak of size 13 B, allocation stacktrace:
Leak of size 13 B
At: (/usr/lib/x86_64-linux-gnu/libc.so.6) __strdup + 26
in: (a.out) main + 52
in: (a.out) main (main.c:8:9)
at: (/usr/lib/x86_64-linux-gnu/libc.so.6) << Unknown >>
at: (/usr/lib/x86_64-linux-gnu/libc.so.6) __libc_start_main + 133
at: (a.out) _start + 33
Expand All @@ -176,6 +143,18 @@ at: (a.out) _start + 33
Summary: 2 leaks, 1.01 KiB lost.
```

#### Line numbers
Simply compile your code with debug symbols to add line numbers to the output.
> [!TIP]
> Usually, the appropriate flag is `-g`.
Currently, debug symbols in the following formats are supported:
- DWARF in ELF binary files
- DWARF in Mach-O debug maps (using Mach-O object files)
- `.dSYM` Mach-O bundles

The DWARF parser supports DWARF in version **2**, **3**, **4** and **5**.

### Behaviour
Since version 1.6 the behaviour of this sanitizer can be adjusted by setting the
following environment variables to their indicated values:
Expand Down Expand Up @@ -246,7 +225,7 @@ the detected memory leaks are printed.
The backtraces are translated using the [CallstackLibrary][5].

## Final notes
This project is licensed under the terms of the GPL 3.0.
This project is licensed under the terms of the GNU GPL in version 3 or later.

© Copyright 2022 - 2024 [mhahnFr][6] and contributors

Expand Down
71 changes: 0 additions & 71 deletions include/leaksan.h

This file was deleted.

Loading

0 comments on commit 4c969ad

Please sign in to comment.