GDB
- PDF for offline use:
Let us know how you feel about this.
0/250
Overview
Xamarin.Android 4.10 introduced partial support for using gdb
by using the the _Gdb MSBuild target.
gdb support requires that the Android NDK be installed.
There are three ways to use gdb:
- Debug builds with Fast Deployment enabled .
- Debug builds with Fast Deployment disabled .
- Release builds .
When things go wrong, please see the Troubleshooting section.
Debug Builds with Fast Deployment
When building and deploying a Debug build with Fast Deployment enabled, gdb can be attached by using the _Gdb MSBuild target.
First, install the the app. This can be done via the IDE, or via the command line:
$ /Library/Frameworks/Mono.framework/Commands/xbuild /t:Install *.csproj
Secondly, run the _Gdb target. At the end of execution, a gdb command line will be printed:
$ /Library/Frameworks/Mono.framework/Commands/xbuild /t:_Gdb *.csproj
...
Target _Gdb:
"/opt/android/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-gdb" -x "/Users/jon/Development/Projects/Scratch.HelloXamarin20//gdb-symbols/gdb.env"
...
The _Gdb target will launch an arbitrary launcher Activity
declared within your AndroidManifest.xml file. To explicitly
specify which Activity to run, use the RunActivity MSBuild
property. Starting Services and other Android constructs is not supported at
this time.
The _Gdb target will create a gdb-symbols directory
and copy the contents of your target's /system/lib and $APPDIR/lib directories there.
Note: The contents of the gdb-symbols directory are tied
to the Android target you deployed to, and will not be automatically replaced
should you change the target. (Consider this a bug.) If you change Android target
devices, you will need to manually delete this directory.
Finally, copy the generated gdb command and execute it in your
shell:
$ "/opt/android/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-gdb" -x "/Users/jon/Development/Projects/Scratch.HelloXamarin20//gdb-symbols/gdb.env"
GNU gdb (GDB) 7.3.1-gg2
...
(gdb) bt
#0 0x40082e84 in nanosleep () from /Users/jon/Development/Projects/Scratch.HelloXamarin20/gdb-symbols/libc.so
#1 0x4008ffe6 in sleep () from /Users/jon/Development/Projects/Scratch.HelloXamarin20/gdb-symbols/libc.so
#2 0x74e46240 in ?? ()
#3 0x74e46240 in ?? ()
(gdb) c
Debug builds with Fast Deployment operate by copying the Android NDK's
There are two workarounds: To set the Once the system property has been set, execute the To include Once the app has been reinstalled, execute the The App debugging can be enabled by either setting the
ApplicationAttribute.Debugging custom attribute property to An accessible One wrinkle: The The To enable calling functions located in Then restart your debugging session. When the This is usually a sign that the contents of the Please delete the Debug Builds without Fast Deployment
gdbserver program into the Fast Deployment .__override__
directory. When Fast Deployment is disbaled, this directory may not exist.
debug.mono.log system property so that the
.__override__ directory is created.gdbserver within your .apk.
Setting the
debug.mono.log System Propertydebug.mono.log system property, use the
adb command:$ adb shell setprop debug.mono.log gc_Gdb target
and the printed gdb command, as with the Debug Builds with Fast
Deployment configuration:$ /Library/Frameworks/Mono.framework/Commands/xbuild /t:_Gdb *.csproj
...
Target _Gdb:
"/opt/android/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-gdb" -x "/Users/jon/Development/Projects/Scratch.HelloXamarin20//gdb-symbols/gdb.env"
...
$ "/opt/android/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-gdb" -x "/Users/jon/Development/Projects/Scratch.HelloXamarin20//gdb-symbols/gdb.env"
GNU gdb (GDB) 7.3.1-gg2
...
(gdb) cIncluding
gdbserver in your appgdbserver within your app:
gdbserver within your Android NDK (it should be in
$ANDROID_NDK_PATH/prebuilt/android-arm/gdbserver/gdbserver),
and copy it into your Project directory.gdbserver to libs\armeabi-v7a\libgdbserver.so.libs\armeabi-v7a\libgdbserver.so to your Project with a
Build action of AndroidNativeLibrary._Gdb target
and the printed gdb command, as with the Debug Builds with Fast
Deployment configuration:$ /Library/Frameworks/Mono.framework/Commands/xbuild /t:_Gdb *.csproj
...
Target _Gdb:
"/opt/android/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-gdb" -x "/Users/jon/Development/Projects/Scratch.HelloXamarin20//gdb-symbols/gdb.env"
...
$ "/opt/android/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-gdb" -x "/Users/jon/Development/Projects/Scratch.HelloXamarin20//gdb-symbols/gdb.env"
GNU gdb (GDB) 7.3.1-gg2
...
(gdb) cRelease Builds
gdb support requires three things:
INTERNET permission.gdbserver.INTERNET permission is enabled by default in Debug apps.
If it is not already present in your application, you may add it either by
editing Properties\AndroidManifest.xml or by editing the
Project Properties.true,
or by editing Properties\AndroidManifest.xml and setting the
//application/@android:debuggable attribute to true:<application android:label="Example.Name.Here" android:debuggable="true">gdbserver may be provided by following the
Debug Builds without Fast Deployment
section._Gdb MSBuild target will kill any previously
running app instances. This will not work on pre-Android v4.0 targets.Troubleshooting
mono_pmip doesn't workmono_pmip function (useful for
obtaining
managed stack frames) is exported from libmonosgen-2.0.so,
which the _Gdb target does not currently pull down.
(This will be fixed in a future release.)libmonosgen-2.0.so,
copy it from the target device into the gdb-symbols directory:$ adb pull /data/data/Mono.Android.DebugRuntime/lib/libmonosgen-2.0.so Project/gdb-symbolsBus error: 10 when running the gdb commandgdb command errors out with "Bus error: 10",
restart the Android device.$ "/path/to/arm-linux-androideabi-gdb" -x "Project/gdb-symbols/gdb.env"
GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 Free Software Foundation, Inc.
...
Bus error: 10
$No stack trace after attach
$ "/path/to/arm-linux-androideabi-gdb" -x "Project/gdb-symbols/gdb.env"
GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 Free Software Foundation, Inc.
...
(gdb) bt
No stack.gdb-symbols
directory are not synchronized with your Android target.
(Did you change your Android target?)gdb-symbols directory and try again.
Let us know how you feel about this.
0/250
Xamarin Workbook
If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.