While it is possible to develop free standing applications that can be launched directly from the shell as others are describing, it sounds like your code runs within the Android application framework. Therefore, you don't have an executable and instead have an APK that contains your Dalvik class files along with other resources including your native shared object.
Launching an application in an APK involves several steps
- The system_server process receives an intent requesting your application.
- The zygote process is told to fork off a new process and run a method of your class.
- Your application runs in the new process.
While you can't launch an APK directly by passing an executable to gdbserver, its fairly easy to trigger a launch it from the shell using the am
command.
$ adb -d shell
# am
usage: am [subcommand] [options]
start an Activity: am start [-D] <INTENT>
-D: enable debugging
send a broadcast Intent: am broadcast <INTENT>
start an Instrumentation: am instrument [flags] <COMPONENT>
-r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)
-e <NAME> <VALUE>: set argument <NAME> to <VALUE>
-p <FILE>: write profiling data to <FILE>
-w: wait for instrumentation to finish before returning
start profiling: am profile <PROCESS> start <FILE>
stop profiling: am profile <PROCESS> stop
<INTENT> specifications include these flags:
[-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[-n <COMPONENT>] [-f <FLAGS>] [<URI>]
# am start -n com.android.browser/.BrowserActivity
Starting: Intent { cmp=com.android.browser/.BrowserActivity }
#
Once your application is running, use gdbserver --attach <pid>
like you have before. If you are lucky your application waits for some user interaction before calling into your native code to give you a chance to attach and set your breakpoints in GDB.