Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit dac8bfc

Browse files
authored
Merge pull request #9049 from mono/native-crash-pinvoke
Add example of how to crash from a pinvoke
2 parents 6b2e91d + 665e511 commit dac8bfc

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ obj/
2323
/main/build/MacOSX/monostub
2424
/main/build/MacOSX/monostub-nogui
2525
/main/build/MacOSx/monostub-test
26-
/main/build/MacOSX/libsystemnative.dylib
26+
/main/build/MacOSX/libdebugcrash.dylib
2727
/local-libs
2828
/main/build/tests
2929
/main/monodevelop_version

main/build/MacOSX/Makefile.am

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,28 @@ MONOSTUB_RPATH=-Wl,-rpath,/Library/Frameworks/Mono.framework/Libraries/ \
4040
-Wl,-rpath,/usr/lib/ \
4141
-Wl,-rpath,/usr/local/lib/
4242

43-
all: monostub monostub-nogui monostub-test
43+
all: monostub monostub-nogui monostub-test debugcrash
4444

4545
render.exe: render.cs
4646
mcs -r:System.Drawing render.cs
4747

4848
dmg: render.exe app
4949
./make-dmg-bundle.sh
5050

51+
if !RELEASE_BUILDS
52+
debugcrash: libdebugcrash.dylib
53+
cp $^ ../bin
54+
else
55+
debugcrash:
56+
endif
57+
58+
if !RELEASE_BUILDS
59+
libdebugcrash.dylib: debugcrash.c
60+
clang -g -shared -fpic -o $@ $^
61+
endif
62+
5163
monostub.o: monostub.mm $(MONOSTUB_EXTRA_SOURCEFILES)
52-
g++ -g $(HYBRID_SUSPEND_ABORT) -c -Wall -m64 -o $@ monostub.mm
64+
g++ -g $(HYBRID_SUSPEND_ABORT) $(ENABLE_DEBUG_CRASHER) -c -Wall -m64 -o $@ monostub.mm
5365

5466
monostub-nogui.o: monostub.mm $(MONOSTUB_EXTRA_SOURCEFILES)
5567
g++ -g $(HYBRID_SUSPEND_ABORT) -DNOGUI -c -Wall -m64 -o $@ monostub.mm
@@ -160,4 +172,4 @@ app: monostub monostub-test
160172
@echo ""
161173
@rm -f missing-stuff
162174

163-
.PHONY: app dmg
175+
.PHONY: app dmg debugcrash

main/build/MacOSX/debugcrash.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
void debug_trigger_sigsegv()
2+
{
3+
void *p = (void*)0x12345;
4+
*(int *)p = 0;
5+
}
6+

main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/Commands.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,16 @@ protected override void Run ()
201201
Thread.Sleep (TimeSpan.FromMinutes(2));
202202
}
203203
}
204+
205+
class InduceNativePInvokeCrashHandler : CommandHandler
206+
{
207+
[DllImport ("libdebugcrash.dylib")]
208+
static extern void debug_trigger_sigsegv ();
209+
210+
protected override void Run ()
211+
{
212+
debug_trigger_sigsegv ();
213+
}
214+
}
204215
#endif
205216
}

main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/Properties/ReliabilityDiagnostics.addin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<Command id="PerformanceDiagnosticsAddIn.InduceHang"
1616
defaultHandler="PerformanceDiagnosticsAddIn.InduceHangHandler"
1717
_label="Induce Hang" />
18+
<Command id="PerformanceDiagnosticsAddIn.InduceNativePInvokeCrash"
19+
defaultHandler="PerformanceDiagnosticsAddIn.InduceNativePInvokeCrashHandler"
20+
_label="Induce PInvoke Crash" />
1821

1922
</Extension>
2023
<Extension path="/MonoDevelop/Ide/MainMenu/Help">
@@ -24,6 +27,7 @@
2427
<CommandItem id="PerformanceDiagnosticsAddIn.InduceManagedCrash" />
2528
<CommandItem id="PerformanceDiagnosticsAddIn.InduceNativeCrash" />
2629
<CommandItem id="PerformanceDiagnosticsAddIn.InduceHang" />
30+
<CommandItem id="PerformanceDiagnosticsAddIn.InduceNativePInvokeCrash" />
2731

2832
</ItemSet>
2933
</Extension>

0 commit comments

Comments
 (0)