-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-cross-debug.sh
More file actions
186 lines (148 loc) · 5.83 KB
/
build-cross-debug.sh
File metadata and controls
186 lines (148 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
# Cross-compilation build script for Linux with full debug symbols
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Configuration
BUILD_TYPE="${1:-RelWithDebInfo}" # Debug, Release, or RelWithDebInfo
TARGET_ARCH="${2:-x64}" # x64 or arm64
TARGET_OS="linux"
TARGET_RID="${TARGET_OS}-${TARGET_ARCH}"
echo "=== Cross-compiling for ${TARGET_RID} with ${BUILD_TYPE} configuration ==="
# Step 1: Clean previous builds
echo "Step 1: Cleaning previous builds..."
rm -rf build-cross
rm -rf publish-cross
mkdir -p build-cross
mkdir -p publish-cross
# Step 2: Build native C library with debug symbols
echo "Step 2: Building native C library for ${TARGET_ARCH}..."
cd NativeLibrary
# Set cross-compilation toolchain if needed
if [ "$TARGET_ARCH" = "arm64" ]; then
export CC=aarch64-linux-gnu-gcc
export CXX=aarch64-linux-gnu-g++
CMAKE_TOOLCHAIN_ARGS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=aarch64 -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++"
else
CMAKE_TOOLCHAIN_ARGS=""
fi
mkdir -p build-cross
cd build-cross
# Configure with comprehensive debug options
cmake ${CMAKE_TOOLCHAIN_ARGS} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DCMAKE_C_FLAGS="-g3 -gdwarf-4 -fno-omit-frame-pointer -Wall -Wextra" \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,--build-id" \
-DCMAKE_VERBOSE_MAKEFILE=ON \
..
# Build with verbose output
make -j$(nproc) VERBOSE=1
# Verify debug symbols
echo "Verifying native library debug symbols..."
file libNativeWorker.so
objdump -h libNativeWorker.so | grep -E "(debug|dwarf)" || echo "Debug sections present"
readelf -S libNativeWorker.so | grep -E "(debug|dwarf)" || echo "DWARF sections present"
# Copy to output directory
mkdir -p ../../build-cross/native
cp libNativeWorker.so ../../build-cross/native/
# Generate separate debug symbols if possible
objcopy --only-keep-debug libNativeWorker.so ../../build-cross/native/libNativeWorker.so.debug 2>/dev/null || echo "Debug symbols embedded"
objcopy --strip-debug --add-gnu-debuglink=../../build-cross/native/libNativeWorker.so.debug libNativeWorker.so 2>/dev/null || echo "Using embedded debug symbols"
cd ../..
echo "✅ Native library built successfully for ${TARGET_ARCH}"
# Step 3: Build .NET application for target platform
echo "Step 3: Building .NET application for ${TARGET_RID}..."
# Copy native library to .NET output directories
mkdir -p StressTestApp/runtimes/${TARGET_RID}/native
cp build-cross/native/libNativeWorker.so StressTestApp/runtimes/${TARGET_RID}/native/
# Build with debug symbols
dotnet restore --runtime ${TARGET_RID}
dotnet build \
--configuration ${BUILD_TYPE} \
--runtime ${TARGET_RID} \
--no-restore \
-p:DebugType=portable \
-p:DebugSymbols=true \
-p:EmbedUntrackedSources=true \
-p:IncludeSymbols=true \
StressTestApp/StressTestApp.csproj
# Publish with debug symbols
echo "Step 4: Publishing for ${TARGET_RID}..."
dotnet publish \
--configuration ${BUILD_TYPE} \
--runtime ${TARGET_RID} \
--no-self-contained \
--no-restore \
--no-build \
-p:DebugType=portable \
-p:DebugSymbols=true \
-p:EmbedUntrackedSources=true \
-p:IncludeSymbols=true \
-o publish-cross/${TARGET_RID} \
StressTestApp/StressTestApp.csproj
# Copy native library and debug symbols to publish directory
cp build-cross/native/libNativeWorker.so publish-cross/${TARGET_RID}/
cp build-cross/native/libNativeWorker.so.debug publish-cross/${TARGET_RID}/ 2>/dev/null || echo "Using embedded debug symbols"
# Step 5: Verify debug symbols in published application
echo "Step 5: Verifying debug symbols..."
echo "=== .NET Debug Symbols ==="
ls -la publish-cross/${TARGET_RID}/*.pdb 2>/dev/null || echo "No separate PDB files (embedded symbols)"
ls -la publish-cross/${TARGET_RID}/*.dll | head -5
echo "=== Native Library Debug Symbols ==="
file publish-cross/${TARGET_RID}/libNativeWorker.so
objdump -h publish-cross/${TARGET_RID}/libNativeWorker.so | grep -E "(debug|dwarf)" || echo "Debug sections verified"
# Step 6: Create debugging package
echo "Step 6: Creating debugging package..."
cd publish-cross/${TARGET_RID}
# Create debug information file
cat > debug-info.txt << EOF
=== Debug Information for ${TARGET_RID} Build ===
Build Type: ${BUILD_TYPE}
Target: ${TARGET_RID}
Build Date: $(date)
=== Files with Debug Symbols ===
.NET Assemblies:
$(ls -la *.dll | head -10)
.NET Debug Symbols:
$(ls -la *.pdb 2>/dev/null || echo "Embedded in assemblies")
Native Library:
$(file libNativeWorker.so)
Native Debug Symbols:
$(ls -la *.debug 2>/dev/null || echo "Embedded in library")
=== Debugging Commands ===
# Debug .NET application:
dotnet --additional-deps app.deps.json StressTestApp.dll
# Debug with GDB (native code):
gdb --args dotnet StressTestApp.dll
(gdb) set environment LD_LIBRARY_PATH=.
(gdb) run
# Attach GDB to running process:
sudo gdb -p \$(pgrep -f StressTestApp)
# Memory debugging with Valgrind:
valgrind --tool=memcheck --leak-check=full --track-origins=yes dotnet StressTestApp.dll
# Performance profiling:
perf record -F 99 -a -g -- dotnet StressTestApp.dll
perf report
=== Environment Setup ===
export LD_LIBRARY_PATH=\$(pwd):\$LD_LIBRARY_PATH
export DOTNET_EnableDiagnostics=1
export COMPlus_EnableDiagnostics=1
EOF
cd ../..
echo "✅ Cross-compilation completed successfully!"
echo ""
echo "📁 Output directory: publish-cross/${TARGET_RID}/"
echo "📋 Debug info: publish-cross/${TARGET_RID}/debug-info.txt"
echo ""
echo "🚀 To run the application:"
echo " cd publish-cross/${TARGET_RID}"
echo " export LD_LIBRARY_PATH=\$(pwd):\$LD_LIBRARY_PATH"
echo " dotnet StressTestApp.dll"
echo ""
echo "🐛 To debug with GDB:"
echo " cd publish-cross/${TARGET_RID}"
echo " gdb --args dotnet StressTestApp.dll"
echo ""
echo "📊 To profile with perf:"
echo " cd publish-cross/${TARGET_RID}"
echo " perf record -F 99 -g -- dotnet StressTestApp.dll"