Using the Dalvik Debug Monitoring Service (DDMS) tool

Source: Internet
Author: User

Android comes with a debugging tool called Dalvik Debug Monitoring Service (DDMS), which provides port forwarding services, screen captures on devices, thread and stack information on devices, logcat, processes, and wireless status information, receiving calls and SMS spoofing, location data spoofing, and more. This article only describes the general features of DDMS and does not elaborate on its features and functions.

DDMS is located in the SDK tools/ directory. Enter this directory from a terminal or control port and type ddms (or on ./ddms mac/linux) to run it, DDMS will run on the emulator or on a connected device, and if both the emulator and the connected device are running, DDMS runs on the emulator by default.

How DDMS Works

DDMS, as an intermediary, connects the IDE to the application running on the device. On Android, each application runs in his own process, manages their own virtual machines (VMS), and each process listens to the debugger on different ports.

When it starts, DDMS connects to the ADB and establishes a device monitoring service between them, notifies DDMS when the device is connected or disconnected, a virtual monitoring service is established between ADB and DDMS, and when a virtual machine on the device starts or terminates, it notifies DDMS, once the virtual machine is running, DDMS obtains the process ID through ADB and establishes a connection to the virtual machine debugger through the adb Daemon (ADBD) program on the device. DDMS is able to use custom wired protocols and virtual machine communication.

On each virtual machine on the device, DDMS opens a port to listen to the debugger. For the first virtual machine, Ddms listens to the debugger on port 8600, the next on port 8601, and so on. When one of the debuggers is connected to one of these ports, all traffic is transferred between the debugger and the corresponding virtual machine. DDMS is able to debug like a remote debugging session.

DDMS also opens another local port, DDMS "Basic port" (8700, by default), it also acts as a listener port for the debugger, and when a debugger connects to this port, all currently selected traffic in DDMS is forwarded to the virtual machine, so he is the default connection port for the debugger.

For more information about DDMS port forwarding, read configuring your IDE to bind to 8700-port debugging.

tip: You can set the DDMS configuration port in the File > Preferences menu. The configuration is saved in the "$HOME/.ddmsrc" file.

Learn about the debugging knowledge of Dalvik
Debugging the application on the Dalvik virtual machine is the same as on other virtual machines, but when stepping out of the synchronization code, the "current line" cursor jumps to the last line of the method.

Left frame

The left side of the debug monitor shows the current health of each emulator/device, with a list of virtual machines on each emulator/device, and a virtual machine that is uniquely identified by the package name of the application running on it.

Use this list to find and bundle the processes you want to debug to the virtual machine, the list is near the virtual machine name is a "debug communication" port (in the rightmost column), if you connect the debugger to a port in the list, you will be connected to the corresponding virtual machine on the device. However, when using DDMS, just connect to port 8700, and DDMS forwards all traffic here to the currently selected VM (Note: When you select a virtual machine in the list, the listed ports contain 8700) so that every time you switch the virtual machines, You do not need to reconfigure the port of the debugger.

When an application running on a device calls Waitfordebugger (or you select this option in the developer options), a red icon will appear on the side of the client's name, and the icon will turn green when it waits for the debugger to bind to the virtual machine, and when a debugger is connected.

If you see a bug with a strikethrough icon, it means: DDMS cannot establish a connection between the debugger and the virtual machine because it cannot open the local port of the virtual machine, and if you see this icon on all the VMS on this device, It is likely that there is another DDMS instance running (this includes the Eclipse plugin).

If you see a question mark in an application package space, which means that DDMS receives the application's PID from the ADB, and it somehow can't shake with the virtual machine's process, you can try restarting Ddms.

Right frame

On the right, the debug monitor displays useful information and some pretty cool tools through tabs.

Information

This view displays general information about the currently selected virtual machine, including the process ID, package name, and virtual machine version.

Thread

The thread view has a list of threads running on the target virtual machine, in order to reduce the amount of data sent, when the thread button is pressed on the toolbar, only the thread update information is sent, and this button corresponds to each virtual machine, and this list contains the following information:

    • ID -A unique thread ID assigned by a virtual machine. In Dalvik, these odd numbers start at 3.
    • Tid -the Linux thread ID. As the main thread of a process, it equals the ID of the process.
    • Status-the virtual machine thread state, when the daemon thread is displayed with an asterisk, it will be one of the following states:
      • running -executing application code
      • sleeping -Call Thread.Sleep ()
      • Monitor -wait for a monitoring lock
      • wait -in object.wait ()
      • native -Executing local code
      • vmwait -Waiting for a virtual machine resource
      • Zombie -Threads in the dead process
      • Init -line is impersonating is initializing (you will not see this step)
      • starting -line Cheng do not run (you will not see it here)
    • Utime -The total time that the user code was executed, in "jiffies" (usually 10ms), only available under Linux.
    • stime -The total time that the system code was executed, in "jiffies" (usually 10ms).
    • Name-the names of the threads.

The "ID" and "Name" are set when the thread is started and the reserved area is updated periodically (by default, 4 seconds).

VM Heap

Displays some heap states that are updated during garbage collection, and if a virtual machine is selected, the virtual machine heap view prompts you to disallow heap updates. Click the Show heap Updates button located on the top left toolbar to return to the virtual machine heap view, click cause GC for garbage collection and update the heap status.

Allocation tracking

In this view, you can track the memory allocations for each virtual machine. Select a virtual machine on the left, then click Start Tracking , then click Get Assignment to see the memory allocation information from the beginning of the tracking, the corresponding data will be displayed in the table below, click it again to refresh the list.

Competition control

With these controls, you can simulate special device states and activities that include the following features:

  • Phone Status -change voice phone status and data plan (local, roaming, search, etc.), and can simulate different kinds of network speed and delay (GPRS, EDGE, UTMS, etc.)
  • phone activity -analog to simulator for phone calls and SMS short messages
  • Position Control-Send false location data to the simulator so you can form a positioning operation like GPS mapping.

    To use location control, launch your app in the Android emulator and open Ddms, click on the Simulator Control tab and press position control, from then on you can:

    • Manually send separate latitude/longitude coordinates to the device.

      Click Manual, select the coordinate format, fill in the data in the field and click Send.

    • The
    • uses a GPX file to describe the playback of the path on the device.

      Select the GPX file and load the file, and once loaded, click the Play button to replay the path of the location operation program.

      When you start playback from GPX, you can adjust the playback speed on the DDMS panel and control playback by pausing, skipping buttons, DDMS will parse the locus point ( <wpt> , in the first table), and the track ( < Trk> , in the second table, through the simple combination of <trkseg> to support multiple segments), only the tracks can be played, Click the track point in the first list to send its coordinates to the device only, and when you select a track, you can play it.

    • Use a KML file to describe the location point of the sequential playback on the device

      Click and open a KML file and once the file is loaded, click the play button to send coordinates to your locator.

      When using a KML file, it parses an <coordinates> element whose value consists of a set of longitude, latitude, and height values. For example:

      <coordinates>-122.084143,37.421972,4</coordinates>

      In your file, you can include multiple <Placemark> elements, each containing an <coordinates> element. When you do this, the location tag collection is added to the track, and Ddms sends a location to the device every second.

      A suitable KML file is generated by finding a location on Google Earth, right-clicking the location, selecting the "Save as" menu item on the left-hand pop-up menu, and selecting the storage format as KML.

      Note: DDMS is not supported by <MultiGeometry><LineString>lat1, long1, lat2, long2, ....</LineString></MultiGeometry> method to create a road warp. Also currently does not support <TimeStamp> nodes in <Placemark> , future versions may support time locations and paths that have a separate location element.

    Get more data-based spoofing methods to view location-based APIs documents.

File browser

Through the file browser, you can browse the device file system and perform basic management, like drag-and-drop files, which surround the ADB's drag commands and provide a GUI experience.

Open DDMS, select device > File Browser ... menu to open the File browser window, you can drag the file into the device directory, but not to drag out the device. When you copy a file from your device, select the file and click the Remove files from Device button on the toolbar, and when you delete the file, use the toolbar's delete button.

If you are interested in an SD card image on the emulator, you can mksdcard create an image with a command and load it when the emulator starts. For example, in the /tools directory, execute:

$ mksdcard 1024M./img$ emulator-sdcard./img

Now, when the emulator is running, the Ddms file browser will be able to read and write the SDcard directory. However, your files are not automatically displayed. For example, if you add a MP3 file to the SDcard directory, the media Player will not see the file until you restart the emulator. (When you restart the emulator from the command line, be sure to load sdcard again.) )

For more information on creating an SD card image, see the documentation for other tools.

Screen capture

You can capture a screen image on a device or emulator by selecting the Device > Screen capture menu, or by pressing the Ctrl-s shortcut key.

Browse process

You can get the same output as the command on a specific virtual machine by selecting device > Show process Status in the menu bar 使用ps -x .

Causes the GC to produce

Press the Trash Can button on the toolbar for garbage collection.

Run Dumpsys and dumpstate on device (LOGCAT)
    • From Dalvik run dumpsys (logcat), select Devices on the menu bar > run Logcat....
    • Run dumpstate from Dalvik, select device > Show Device Statuson the menu bar ....
Test Wireless Status

By default, the wireless status is not output on a standard Logcat (contains a lot of information). To view wireless information, you can click devices > Show wireless Status ... menu, or run the Logcat that describes the wireless information in the recording.

Stop a virtual machine

You can choose the action > Suspend virtual Machine menu to stop a virtual machine and press this menu to cause the virtual machine to call System.exit(1) .

Learn about the flaws of DDMS

DDMS has the following known defects:

    • If you connect and disconnect a debugger, DDMS discards and re-connects to the customer, the virtual machine then thinks the debugger is down. This will eventually be fixed.
About translation Authors

Andriodin Forum user name: zxg1982

Contact information: [Email protected]

Using the Dalvik Debug Monitoring Service (DDMS) tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.