debugging android with trace32 - lauterbach.com · telephony manager resource ... reference: ......

51
VM Vision Hagen Patzke 2011-06-16 www.lauterbach.com 1 Debugging Android with TRACE32 Today Work In Progress VM Debugging Primer VM Debugging with TRACE32 Vision

Upload: vonhan

Post on 21-Jul-2018

261 views

Category:

Documents


0 download

TRANSCRIPT

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 1

Debugging Android with TRACE32

Today Work In Progress VM Debugging Primer VM Debugging with TRACE32 Vision

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 2

APPLICATION FRAMEWORKAPPLICATION FRAMEWORKActivity ManagerActivity Manager Window ManagerWindow Manager Content ProvidersContent Providers View SystemView System NotificationNotification

ManagerManager

Package ManagerPackage Manager TelephonyTelephonyManagerManager Resource ManagerResource Manager Location ManagerLocation Manager ......

APPLICATIONSAPPLICATIONS

ContactsContacts Voice DialVoice Dial EmailEmail CalendarCalendar Media PlayerMedia Player Photo AlbumPhoto Album ClockClock ......

HomeHome DialerDialer SMS/MMSSMS/MMS IMIM BrowserBrowser CameraCamera AlarmAlarm CalculatorCalculator

HARDWARE ABSTRACTION LAYERHARDWARE ABSTRACTION LAYERGraphicsGraphics AudioAudio CameraCamera BluetoothBluetooth GPSGPS Radio (RIL)Radio (RIL) WiFiWiFi ......

LINUX KERNELLINUX KERNELDisplay DriverDisplay Driver Camera DriverCamera Driver Bluetooth DriverBluetooth Driver Shared MemoryShared Memory

DriverDriver Binder (IPC) DriverBinder (IPC) Driver

USB DriverUSB Driver Keypad DriverKeypad Driver WiFi DriverWiFi Driver Audio DriversAudio Drivers PowerPowerManagementManagement

LIBRARIESLIBRARIES

OpenGL|ESOpenGL|ES AudioAudioManagerManager FreeTypeFreeType SSLSSL ......

SurfaceSurfaceManagerManager

MediaMediaFrameworkFramework SQLiteSQLite WebKitWebKit LibcLibc

ANDROID RUNTIMEANDROID RUNTIMECore LibrariesCore Libraries

Dalvik Virtual MachineDalvik Virtual Machine

Debugging Android with TRACE32

Info: Android Architecture

Ref

eren

ce: h

ttp://

deve

lope

r.and

roid

.com

/gui

de/b

asic

s/w

hat-i

s-an

droi

d.ht

ml

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 3

Debugging Android with TRACE32

Available Today Native Machine Code Debugging

needs Embedded Debugger HW+SW for specific machine(JTAG/SWD, Register Layout, MMU Types, Peripherals, ...)

for Assembly and HLL Level Debugging (C/C++) Linux Task Debugging

needs Linux 'Operating System Awareness' for Task-Aware Debugging of Services and Native Applications

Virtual Machine Application Debugging What have we got today? How do we proceed?

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 4

Debugging Android with TRACE32

Today: Native Machine Code Debugging

Android TargetAndroid TargetHostHost

TRACE32

TCP/IPTCP/IPor USBor USBstackstack

JTAG

TAP

POWERDEBUG

LINUX KERNELLINUX KERNELDISPDISP CAMCAM BTBT MEMMEM IPCIPC

USBUSB KBDKBD WiFiWiFi AUDAUD PWRPWR

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 5

Debugging Android with TRACE32

Today: Native Machine Code Debugging (ASM + HLL)

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 6

Debugging Android with TRACE32

Today: Linux Task Debugging

Android TargetAndroid TargetHostHost

TRACE32

TCP/IPTCP/IPor USBor USBstackstack

Linux OSAwareness

JTAG

TAP

POWERDEBUG

HARDWARE ABSTRACTION LAYERHARDWARE ABSTRACTION LAYERGRA AUD CAM BT GPS RIL WiFi ...

LINUX KERNELLINUX KERNELDISPDISP CAMCAM BTBT MEMMEM IPCIPC

USBUSB KBDKBD WiFiWiFi AUDAUD PWRPWR

LIB(+SVC)LIB(+SVC)

GLGL AUAU FTFT SSLSSL ......SMSM MFMF DBDB WKWK LibcLibc

AND RTAND RT

Dalvik VMDalvik VM

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 7

Debugging Android with TRACE32

Today: Linux Task Debugging

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 8

HARDWARE ABSTRACTION LAYERHARDWARE ABSTRACTION LAYERGraphicsGraphics AudioAudio CameraCamera BluetoothBluetooth GPSGPS Radio (RIL)Radio (RIL) WiFiWiFi ......

LINUX KERNELLINUX KERNELDisplay DriverDisplay Driver Camera DriverCamera Driver Bluetooth DriverBluetooth Driver Shared MemoryShared Memory

DriverDriver Binder (IPC) DriverBinder (IPC) Driver

USB DriverUSB Driver Keypad DriverKeypad Driver WiFi DriverWiFi Driver Audio DriversAudio Drivers PowerPowerManagementManagement

LIBRARIESLIBRARIES

OpenGL|ESOpenGL|ES AudioAudioManagerManager FreeTypeFreeType SSLSSL ......

SurfaceSurfaceManagerManager

MediaMediaFrameworkFramework SQLiteSQLite WebKitWebKit LibcLibc

ANDROID RUNTIMEANDROID RUNTIME

Dalvik Virtual MachineDalvik Virtual Machine

Debugging Android with TRACE32

Native Machine Code + Linux Task Debugging

TRACE32 with Linux OS Awareness can debug all hardware and operating system specific components via JTAG:

Linux Kernel and Drivers, Hardware Abstraction Layer, Libraries, Dalvik Virtual Machine

These are the components necessary for porting to new hardware and for infrastructure-level optimizations.

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 9

Debugging Android with TRACE32

Virtual Machine Application Debugging Assisted Run-Mode VM Application Debugging

Today: Eclipse/ADT VM run-mode application debugging via ETHin parallel to TRACE32 stop-mode debugging for native code

Today: Assisted Run-Mode Debugging via JTAGWork In Progress: Unassisted Stop-Mode Debugging

Today: TRACE32 stop-mode VM process list and stack view

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 10

Google's Android Development Toolscan be used to debug Dalvik VM Application components:

Applications, Application Framework, Core Libraries

APPLICATION FRAMEWORKAPPLICATION FRAMEWORKActivity ManagerActivity Manager Window ManagerWindow Manager Content ProvidersContent Providers View SystemView System NotificationNotification

ManagerManager

Package ManagerPackage Manager TelephonyTelephonyManagerManager Resource ManagerResource Manager Location ManagerLocation Manager ......

APPLICATIONSAPPLICATIONS

ContactsContacts Voice DialVoice Dial EmailEmail CalendarCalendar Media PlayerMedia Player Photo AlbumPhoto Album ClockClock ......

HomeHome DialerDialer SMS/MMSSMS/MMS IMIM BrowserBrowser CameraCamera AlarmAlarm CalculatorCalculator

ANDROID RUNTIMEANDROID RUNTIMECore LibrariesCore Libraries

Debugging Android VM Applications

Assisted Run-Mode VM Application Debugging

...but the core system must already be “live“!

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 11

Debugging Android VM Applications

Assisted Run-Mode VM Application Debugging

AndroidAndroidTargetTarget

Virtual Machine Process

VM Core LibrariesVM Core LibrariesCode + ObjectsCode + Objects

Dalvik VMDalvik VM

VM ApplicationVM ApplicationCode + ObjectsCode + Objects

MemoryModel

VMInterpreter

VMControl

adbadbdaemondaemon

TCP/IPTCP/IPor USBor USBstackstack

VM DebugSupport

HostHost

Eclipse IDE

ADT

adbadbserverserver

TCP/IPTCP/IPor USBor USBstackstack

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 12

Debugging Android VM Applications

Info: DalvikVM Run-Mode Debugging Support

ANDROID RUNTIMEANDROID RUNTIME

Core LibrariesCore Libraries

Dalvik Virtual MachineDalvik Virtual Machine

VM InstructionInterpreter

Just-In-TimeCompiler

GarbageCollection

VM MemoryModel

VM InterpreterTrace

VMControl

JDWP (+ADB)Communication

VM DebugSupport

DebuggingInterpreter

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 13

Debugging Android with TRACE32

Example: VM Application debugging with ADT via TCP/IP

MEP-6410MEP-6410Android 2.1Android 2.1Linux Kernel 2.6.29Linux Kernel 2.6.29

TCP/IPTCP/IP

LaptopLaptopUbuntu 9.10Ubuntu 9.10

TCP/IPTCP/IP adbdadbdadbadbserverserver

JTAGJTAGUSB/ETHUSB/ETH PowerDebug

Eclipse

TRACE32 stop-mode debugging

run-mode debugging

ETH switch

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 14

Debugging Android with TRACE32

Example: VM Application debugging with ADT via USB

MEP-6410MEP-6410Android 2.1Android 2.1Linux Kernel 2.6.29Linux Kernel 2.6.29

USBUSB

LaptopLaptopUbuntu 9.10Ubuntu 9.10

USBUSB adbdadbdadbadbserverserver

JTAGJTAGUSB/ETHUSB/ETH PowerDebug

Eclipse

TRACE32 stop-mode debugging

run-mode debugging

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 15

Debugging Android with TRACE32

Assisted Run-Mode VM Application Debugging via USB:Native Debugging 'stop' leads to loss of USB communication

AndroidAndroidTargetTarget

Virtual Machine Process

VM Core LibrariesVM Core LibrariesCode + ObjectsCode + Objects

Dalvik VMDalvik VM

VM ApplicationVM ApplicationCode + ObjectsCode + Objects

MemoryModel

VMInterpreter

VMControl

adbadbdaemondaemon

USBUSB

VM DebugSupport

HostHost

Eclipse IDE

ADT

adbadbserverserver

USBUSB

USB comm losson JTAG 'break'

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 16

Debugging Android with TRACE32

Available Today Assisted Run-Mode Debugging via JTAG

Implemented as TRACE32 JTAG bridge that can replace USB and TCP/IP connection for VM application debugging

Allows to debug VM applications during early stages of porting(when e.g. Ethernet drivers not stable yet)

Allows to debug native code, task and VM applications on development platforms which don't have an ETH interface

Separate 'TRACE32 JTAG Bridge'presentation available in July 2011

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 17

Debugging Android with TRACE32

Assisted Run-Mode Debugging via JTAG bridge

AndroidAndroidTargetTarget

Virtual Machine Process

VM Core LibrariesVM Core LibrariesCode + ObjectsCode + Objects

Dalvik VMDalvik VM

VM ApplicationVM ApplicationCode + ObjectsCode + Objects

MemoryModel

VMInterpreter

VMControl

adbadbdaemondaemon

TRACE32TRACE32JTAGJTAGbridgebridge

VM DebugSupport

HostHost

Eclipse IDE

ADT

adbadbserverserver

TRACE32TRACE32JTAGJTAGbridgebridge

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 18

Debugging Android with TRACE32

Application Debugging via TRACE32 JTAG Bridge

Android TargetAndroid TargetHostHost

FDXFDX

JTAGJTAGUSB/ETHUSB/ETH PowerDebug

TRACE32

TCP/IP

TCP/IP

adbadbdaemondaemon

adbadbserverserver

application debuggingEclipse DVMDVM

ARMARMDCCDCC

USB

USB

adb

PIPEPIPE

application debugging

run-mode debugging

stop-mode debugging

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 19

Debugging Android with TRACE32

Work In Progress Assisted Run-Mode Debugging via JTAG

urgent demand for USB-only development platforms Linux host support OK 2011-04-08 Windows host support OK 2011-05-24 SMP (MultiCore) support OK 2011-06-10

Unassisted Stop-Mode Debugging List DalvikVM Tasks OK 2010-10-05 View DalvikVM Stack OK 2010-10-11 VM Source Code List in progress

Urgent 'TRACE32 JTAG Bridge' requestcomplete, resuming Stop-Mode work...

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 20

Debugging Android with TRACE32

TodayWork In Progress

VM Debugging Primer VM Debugging with TRACE32 Vision

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 21

Challenge:

Technical Difficulty: for a CPU, any VM is “just” one application (of possibly many). The debugger needs to find the task, then to analyze and manipulate its internal state to provide VM debugging. JIT adds even more complexity.

Moving Target: if developers change the VM's implementation (e.g. when porting), this breaks any hardwired debugging support.

Expanding: several Java and other VMs already in use, more expected. Resources: Debugging Awareness dev+support resources limited.

Solution:

➔ Empower customer and 3rd parties to change / adapt / develop the VM Debugging Awareness for their specific needs: as TRACE32 EXTension

Debugging Android with TRACE32

Unassisted Stop-Mode Debugging for VM Applications

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 22

Hardwired

JVM

KAFFE

J2ME_CLDC

J2ME_CDC

PEARL90

VM Debugging Awareness EXTension

DVM

v1.5

v2.1

v2.3

v1.6

v2.2

?

JVM

Other VMs

3rd party

3rd party

●flexible, extensible, adaptable●closed-source VM Debugging Awareness possible●VM change → VM Debugging Awareness change●we use Android's DVM as R&D platform and reference → initially free VM Debugging Awareness for DalvikVM

●easy to configure●VM changes break debug support

●need VM source to implement support

Virtual Machine Stop-Mode Debugging Support

VM Debugging: Flexibility by Extension

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 23

VMLINFRA VMV

LIST

CTRL

PROF

implemented

work in progress

planned next step

future R&DJIT OBJS

Virtual Machine Stop-Mode Debugging Support

Work Package Dependencies

Work In ProgressDesign / Details may change!

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 24

[INFRA] Prepare TRACE32 Infrastructure for VM Awareness ● PRJ: add VMDALVIK project and accounting● T32: Extend (RT)OS Awareness Extension Mechanism for Virtual Machine Awareness

[load additional extension for VM Awareness]● EDK: Prepare adding of vm_api functions to Extension Development Kit library● DOC: add documentation units 'api_vm' and 'vmdalvik'● DEV: set up initial development environment for multiple Android versions and targets

[VML] Display list of Dalvik VM processes● API: Make Task List from Linux Awareness available to VM Awareness● EXT: detect DVMs by analyzing Linux task list hierarchy,

and display with context sensitive text fields● EDK: add low-level api calls to EDK library● DOC: add documentation to 'api_vm' and 'vmdalvik'

Virtual Machine Stop-Mode Debugging Support

Work Packages

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 25

[VMV] Display Dalvik Stack for one DVM task● T32: add Local Symbol Creation to SymDB, map regs->names to access 'mterp' data● API: get pointer from local task stack [level]● EXT: walk single task stack to 'mterp' , get DVM struct pointers,

analyze and display DVM stack data for one task● EDK: add low-level api calls to EDK library● DOC: add documentation to 'api_vm' and 'vmdalvik'

[LIST] Display corresponding Java Source line for one DVM task● DVM: modify Dalvik Exchange (dx) to emit Debug information for release builds● DVM: modify dexopt to emit corrected Debug information for ODEX files on a PC● T32: Load and process DVM Debug Information● API: add call to map method offset to source line and to construct source window● EXT: access and process class path, compute DVM method offset, call vm_api function

to map offset to source line and to display corresponding source● EDK: add low-level api calls to EDK library● DOC: add documentation to 'api_vm' and 'vmdalvik'

Virtual Machine Stop-Mode Debugging Support

Work Packages

Work In ProgressDesign / Details may change!

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 26

[CTRL] Dalvik VM run control● T32: modify/add JAVA Data.List code to accommodate VM Awareness extension● API: setup callbacks and helper functions for Data.List-like VM Source Code window● EXT: provide callbacks for DVM stop/go/step and breakpoints● EDK: add low-level api calls to EDK library● DOC: add documentation to 'api_vm' and 'vmdalvik'

[PROF] DVM task / function profiling support● DVM: add system trace patch to plot function changes● API: check if extensions to Linux profiling support are necessary● EXT: if necessary, provide callbacks for object handling● EDK: add low-level api calls to EDK library● DOC: add documentation to 'api_vm' and 'vmdalvik'

Virtual Machine Stop-Mode Debugging Support

Work Packages

Work In ProgressDesign / Details may change!

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 27

[OBJS] Display Java objects for one DVM task● T32: modify/extend call stack and var windows for VM objects● API: research if object-specific interpretation callbacks are required● EXT: if needed, provide callbacks for object handling● EDK: add low-level api calls to EDK library● DOC: add documentation to 'api_vm' and 'vmdalvik'

[JIT] Dalvik VM debugging with Just-In-Time compiler support● DVM: build external host application to synthesize debug information

using parametrized external JIT compiler model● T32: add communication API to/from external JIT model● API: add functions to support interpreted and JIT compiled mixed debugging● EXT: provide callbacks for DVM stop/go/step and breakpoints● EDK: add low-level api calls to EDK library● DOC: add documentation to 'api_vm' and 'vmdalvik'

Virtual Machine Stop-Mode Debugging Support

Work Packages

Work In ProgressDesign / Details may change!

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 28

VMLINFRA VMV

LIST

CTRL

PROF

implemented

work in progress

planned next step

future R&DJIT OBJS

Virtual Machine Stop-Mode Debugging Support

Work Package Dependencies

Work In ProgressDesign / Details may change!

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 29

TRACE32 Virtual Machine Support – Design (partial)

Virtual Machine Debugging with TRACE32

Support for more than one loaded extension VM Awareness Extension API 'infrastructure'

Get and display the list of Virtual Machine applications that are currently executed. Get and display Virtual Machine Stack information for a selected VM application. Virtual Machine Source Code lookup: for the current “VM program pointer” of a given

application, display the matching source code line that belongs to it. “Basic VM Debug Control” for a selected VM application: the user can “break” into a running

VM application, single-”step” through a VM application, and resume execution (“go”). “VM breakpoint control”: for a selected VM application, breakpoints can be set and deleted. “Just-In-Time-awareness”: perform the above for VMs that use Just-In-Time compilation. “Profiling and Trace support”: analyze and display the VM internal status for e.g. method

display. “VM data support”: get and display VM application variables “VM data breakpoint control”: allow setting breakpoints triggered by VM data manipulation

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 30

TRACE32 Virtual Machine Support – Implementation Status

Virtual Machine Debugging with TRACE32

Support for more than one loaded extension VM Awareness Extension API 'infrastructure'

Get and display the list of Virtual Machine applications that are currently executed

Get and display Virtual Machine Stack information for a selected VM application

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 31

Virtual Machine Debugging with TRACE32

STATUS: TRACE32 Dalvik VM Awareness

Current Research & Development to enable debugging in stop-mode, via JTAG, without VM assistance, for Dalvik VM Applications Application Framework Core Libraries

First results (2010Q4): Dalvik VM Extension load + debug Dalvik VM process list Dalvik VM process stack view

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 32

Virtual Machine Debugging with TRACE32

Virtual Machine Application Debugging for Android – Today

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 33

TRACE32 Virtual Machine Support – Current Focus

Virtual Machine Debugging with TRACE32

Virtual Machine Source Code lookup: for the current 'VM program pointer' of a given application, display the matching source code line that belongs to it stack walk, lookup register for saved DVM-PC re-map [.java] ← [.class] ← [.dex] ← [.odex]

change DX (Dalvik eXchange) to emit debug information for release-level code

annotate [.odex] data made by dexopt / DVM process class file (from [.apk] / [.jar]) for

TRACE32 symbol database

Work In ProgressDesign / Details may change!

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 34

Virtual Machine Debugging with TRACE32

Virtual Machine Application Debugging for Android

Android TargetAndroid TargetHostHost

TRACE32

TCP/IPTCP/IPor USBor USBstackstack

Linux OSAwareness

Dalvik VMAwareness

JTAG

TAP

POWERDEBUG

APPLICATION FRAMEWORKAPPLICATION FRAMEWORKActMActM WinMWinM CProCPro VSysVSys NotMNotM

PkMPkM TelMTelM ResMResM LocMLocM ......

APPLICATIONSAPPLICATIONS

ContCont VDVD MailMail CalCal PlayPlay PAPA ClkClk ......

HomHom DialDial SMSSMS IMIM WebWeb CamCam AlmAlm CalcCalc

HARDWARE ABSTRACTION LAYERHARDWARE ABSTRACTION LAYERGRA AUD CAM BT GPS RIL WiFi ...

LINUX KERNELLINUX KERNELDISPDISP CAMCAM BTBT MEMMEM IPCIPC

USBUSB KBDKBD WiFiWiFi AUDAUD PWRPWR

LIBRARIESLIBRARIES

GLGL AUAU FTFT SSLSSL ......SMSM MFMF DBDB WKWK LibcLibc

AND RTAND RTCore LibsCore Libs

Dalvik VMDalvik VM

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 35

Virtual Machine Debugging with TRACE32

Virtual Machine Application Debugging for Android

Android TargetAndroid Target

Virtual Machine Process

VM Core LibrariesVM Core LibrariesCode + ObjectsCode + Objects

Dalvik VMDalvik VM

VM ApplicationVM ApplicationCode + ObjectsCode + Objects

VMInterpreter

VMControl

HostHost

TRACE32

TCP/IPTCP/IPor USBor USBstackstack

Linux OSAwareness

Dalvik VMAwareness

JTAG

TAP

POWERDEBUG

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 36

Debugging Android with TRACE32

Today Work In Progress

VM Debugging Primer VM Debugging with TRACE32 Vision

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 37

Reference: Smith, James E. and Nair, Ravi, "The Architecture of Virtual Machines", IEEE Computer, May 2005, pp. 32–38

Background: Virtual Machine Debugging

Process VM – Environment and Architecture

Computer System Architecture

Execution Hardware

Main Memory

MemoryTranslation

I/O Devices

System Interconnect (Bus)

Application Programs

Native Application Libraries

Operating System

VirtualMachineProcess

A

NativeApplication

Process

VirtualMachineProcess

B

Virtual Machine Process B

VM Core LibrariesVM Core Libraries

Virtual MachineVirtual Machine

VM ApplicationVM Application

InstructionInterpreter

Just-In-TimeCompilerGarbageCollection

VM MemoryModel

VM DebugSupport

VMControl

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 38

Background: Virtual Machine Debugging

Process VM – Principle of OperationSimplified Process Virtual Machine 'interpreter view':

1. read 'VM opcode' from 'VM application' data array

2. look-up and call 'VM opcode' implementing function

3. 'VM opcode' execution:(a)fetch 'VM opcode' parameter 'VM data'(b)compute 'VM opcode' result 'VM data'(c)store 'VM opcode' result 'VM data'

4. continue with 1.

Note:For the target processor, 'VM opcode' and 'VM data' are all just data.

init

fetch

dispatch

execute

finish

?

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 39

HTTPServer

TrafficControlProgram

Background: Virtual Machine Debugging

Process VM – Debugging Challenges The Virtual Machine itself is not fixed (in silicon),

but can be changed by the platform developer. For the 'host' processor, the Virtual Machine “looks” just like any

other operating system module or application program, e.g. an SQL Database Server engine, a Traffic Light control program, or any program supporting a scripting language. SQL

DatabaseServer

VirtualMachine

For 'VM application debugging', external debuggers must know and manipulate VM-internal structures.

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 40

Background: Virtual Machine Debugging

VM Debugging – How?Q: How do existing VM debuggers work?

A: Alternative 1: They talk to 'VM built-in debugging support'. Advantages

Target+Host platform independent debugging is possible VM presents standardized external debug interface,

VM implementation details are handled by VM helper functions VM operation mode can be switched for debugging, if necessary

Disadvantages Only Run-Mode debugging is possible (VM+comms must run) Performance penalty if debugging global common 'VM code' Not possible to attach+debug a randomly 'hung' device Not possible to profile and trace with the 'real' timing

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 41

Background: Virtual Machine Debugging

VM Debugging – How?Q: How do existing VM debuggers work?

A: Alternative 2: They set a breakpoint in the interpreter loop. Advantages

No VM debug assistance necessary Stop-Mode debugging possible Built-in, easy to configure Good performance

Disadvantages Only possible for a class of VMs (interpreter loop) Need VM source code and symbols VM changes can break debug mechanism Combinatorial explosion (VM Types x Core Families) for testing

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 42

Debugging Android with TRACE32

Today Work In Progress VM Debugging Primer

VM Debugging with TRACE32 Vision

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 43

Virtual Machine Debugging with TRACE32

VM Support - TRACE32 History

J2ME_CDC Sun Connected Device Configurationreference VM

J2ME_CLDC Sun Connected Limited Device Configuration reference VM (= Kilobyte Virtual Machine, KVM)

KAFFE open-source VM

PEARL90 non-Java VM ('legacy')

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 44

Customer Requests for VM Application Debugging

Virtual Machine Debugging with TRACE32

Lauterbach Customer Survey 2010 result: Highest interest for proprietary Java VMs

and for Android/Dalvik VM Normal VM Application Debugging is not a problem

on Target and Simulator JVMs: JDWP + Eclipse DVM/Android: JDWP + ADT + Eclipse

For some special cases customers need:

STOP-Mode debugging without support from the VM itself

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 45

TRACE32 Virtual Machine Support - Requirements

Virtual Machine Debugging with TRACE32

enable customer or third party to add TRACE32 VM support for their proprietary VM implementation support closed-source VMs support modified VMs support all relevant core/chip families

if VM runs on a platform with an OS,get and use data from (RT)OS Support Extension

support different VM debugging models non-invasive stop-mode VM debugging (required) other models (bridge, run-mode) should be possible

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 46

TRACE32 Virtual Machine Support - Solution

Virtual Machine Debugging with TRACE32

re-use TRACE32 Extension Mechanism'(RT)OS support model' works well (Linux, QNX, uCos, ...)

add TRACE32 infrastructure for VM Awareness Extensionto 'RTOS API' (api_rtos.pdf)

use popular OS/VM combo as R&D prototype

Refined requirement set:➜ Extend TRACE32 Extension mechanism➜ Develop VM Awareness Extension API 'infrastructure'➜ Use Android Dalvik VM as R&D sample target

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 47

Virtual Machine Debugging with TRACE32

VM Debugging – How?Q: How can TRACE32 implement VM stop mode debugging?

A: By interpreting target VM data with a VM-specific extension. Advantages

Works in stop-mode: attach+debug possible on 'release' devices Does not affect timing (for hunting down lock-ups, race conditions) Can be implemented by customer and third parties if necessary Extension mechanism already used by (RT)OS extensions

Disadvantages Complex problem ➜ infrastructure development takes time 'Program Trace' not enough for VM application (=data!) trace Extension needs updating whenever VM data structures change

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 48

Debugging Android with TRACE32

Today Work In Progress VM Debugging Primer VM Debugging with TRACE32

Vision

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 49

TRACE32 VM Debugging Vision

Our Vision Integrated Native and VM System+Application Debugging

for any Native Platform for any Operating System for any Virtual Machine with support for Just-In-Time compilers empower Customer or 3rd Party to perform

implementation / adaptation / tuning of debug system for a given platform/OS/VM combo

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 50

TRACE32 VM Debugging Vision

Integrated Native and VM System and Application Debugging

Custom TargetCustom Target

Virtual Machine Process

VM Core LibrariesVM Core LibrariesCode + ObjectsCode + Objects

Custom VMCustom VM

VM ApplicationVM ApplicationCode + ObjectsCode + Objects

VMInterpreter

VMControl

Debug HostDebug Host

TRACE32

TCP/IPTCP/IPor USBor USBstackstack

Custom OSAwareness

Custom VMAwareness

JTAG

TAP

POWERDEBUG

VM Vision ▪ Hagen Patzke ▪ 2011-06-16 www.lauterbach.com ▪ 51

Thank You! Hagen Patzke

[email protected]

http://www.lauterbach.com/vmandroid.html