Run-as bug workaround

This page describes how to easily launch the Android gdbserver from your app using the framework provided by VisualGDB to work around the 'run-as: Package not found' bug. Before you begin, please install VisualGDB 5.1 or later.

  1. Open VisualGDB Project Properties and go to the Debug Settings page. Select "Start gdbserver - Manually from the app":
  2. Go to the Makefile Settings page and add "-DLAUNCH_GDBSERVER_FROM_APP" to both CFLAGS and CXXFLAGS. Then add "-llog" to System Library Names:
  3. Press "OK". VisualGDB will add a file called "gdbserver_launcher.c" to your project. Build the project and ensure that the file is added to the LOCAL_SRC_FILES field of the first loaded native library that you want to debug:
  4. Open the AndroidManifest.xml file and add the following permission there:
    <uses-permission android:name="android.permission.INTERNET" />
  5. Now you can press F5 to start debugging your application as usual. The following events will take place
    1. Your app will be started.
    2. As soon as the library containing gdbserver_launcher.c will get loaded, the GDBServerInitializer() function marked with the 'constructor' attribute will get launched.
    3. GDBServerInitializer() will in turn call LaunchGDBServer() that will start listening to a socket and output the socket information to via the logcat mechanism
    4. VisualGDB will connect to the socket and send instructions on launching the gdbserver
    5. The LaunchGDBServer() function will actually launch the gdbserver and redirect its output to VisualGDB
    6. VisualGDB will automatically begin debugging
    The overall debugging experience will be the same as if you were debugging on a device without the run-as problem:
  6. If you encounter problems with gdbserver_launcher, check the logcat view for errors reported by the launcher. Normally it should only report the PID and the port of the socket waiting for commands, however if it encounters any problems, it will output them to the logcat window: