Porting LLDB Hafiz Abid Qadeer mentor.com/embedded Android is a - - PowerPoint PPT Presentation

porting lldb
SMART_READER_LITE
LIVE PREVIEW

Porting LLDB Hafiz Abid Qadeer mentor.com/embedded Android is a - - PowerPoint PPT Presentation

Porting LLDB Hafiz Abid Qadeer mentor.com/embedded Android is a trademark of Google Inc. Use of this trademark is subject to Google Permissions. Linux is the registered trademark of Linus Torvalds in the U.S. and other countries. Outline


slide-1
SLIDE 1

mentor.com/embedded

Android is a trademark of Google Inc. Use of this trademark is subject to Google Permissions. Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.

Hafiz Abid Qadeer

Porting LLDB

slide-2
SLIDE 2

2 mentor.com/embedded 2

Outline

 Introduction  A Typical Debug Session  LLDB Architecture  Porting LLDB  Roles of Plugins  Questions

slide-3
SLIDE 3

3 mentor.com/embedded

 LLVM Debugger  Open Sourced in 2010  Written in C++  Small but helpful community  Status

Default debugger for xcode

Linux and FreeBSD ports are working

Package available in many distros.

Windows support is coming online

Introduction

slide-4
SLIDE 4

4 mentor.com/embedded

> lldb hello (lldb) target create "hello" Current executable set to 'hello' (x86_64). (lldb) b main Breakpoint 1: where = hello`main + 4 at hello.c:5, address = 0x0000000000400531 (lldb) r Process 7093 launching Process 7093 launched: '/home/abidh/demos/hello' (x86_64) Process 7093 stopped * thread #1: tid = 7093, 0x0000000000400531 hello`main + 4 at hello.c:5, name = 'hello', stop reason = breakpoint 1.1 frame #0: 0x0000000000400531 hello`main + 4 at hello.c:5 2 int counter = 10; 3 int main(void) 4 {

  • > 5

printf("Hello World!"); 6 counter++; 7 return 0; 8 } (lldb) p counter (int) $0 = 10 (lldb) bt * thread #1: tid = 7093, 0x0000000000400531 hello`main + 4 at hello.c:5, name = 'hello', stop reason = breakpoint 1.1 * frame #0: 0x0000000000400531 hello`main + 4 at hello.c:5 frame #1: 0x00007ffff7a35ec5 libc.so.6`__libc_start_main + 245 frame #2: 0x0000000000400469 hello

Example Session

slide-5
SLIDE 5

5 mentor.com/embedded

 Read the object file  Find symbols information if available  Provide execution control

run, stop, break

 Provide visibility into the program

Variables and expressions

Register, memory, disassembly

Target function call

Dynamic Objects

OS Awareness

So a debugger needs to …

slide-6
SLIDE 6

6 mentor.com/embedded 6

Architecture

 Provides a C++ API which can be used by various clients

lldb API

Process Disassembly Symbols Object Files

Gdb Remote LLVM Dwarf Elf Mach-o

lldb-mi Core

slide-7
SLIDE 7

7 mentor.com/embedded

 PluginManager  Initialize

Register itself with the PluginManager

 Find a Plugin to do something

Call PluginManager::FindPlugin with enough information

 CreateInstance  Overload required functions  Terminate

Unregister itself from PluginManager

Life cycle of a Plugin

slide-8
SLIDE 8

8 mentor.com/embedded

 Read the object file  Find symbols information if available  Provide execution control

run, stop, break

 Provide visibility into the program

Variables and expressions

Register, memory, disassembly

Target function call

Dynamic Objects

OS Awareness

So a debugger needs to …

slide-9
SLIDE 9

9 mentor.com/embedded

 Chances are that your file is already supported

Elf, mach-o, PE-coff

 Creation

If able to handle a given object file

 CreateSections

Figure out how many sections are in this object file

 ReadSectionData

Read data from a given section

 Other useful information

ByteOrder, AddressSize, Architecture

EntryAddress

ObjectFile

slide-10
SLIDE 10

10 mentor.com/embedded

 Read the object file  Find symbols information if available  Provide execution control

run, stop, break

 Provide visibility into the program

Variables and expressions

Register, memory, disassembly

Target function call

Dynamic Objects

OS Awareness

So a debugger needs to …

slide-11
SLIDE 11

11 mentor.com/embedded

 SymbolFile

Dwarf

 SymbolVendor

Controls the process of finding symbols

Separate or multiple symbols file

SymbolFile & SymbolVendor

LLDB Module Symbol Vendor Symbol File

slide-12
SLIDE 12

12 mentor.com/embedded

Example Session

(lldb) target module dump line-table hello.c Line table for /home/abidh/demos/hello.c in `hello 0x000000000040052d: /home/abidh/demos/hello.c:4 0x0000000000400531: /home/abidh/demos/hello.c:5 0x0000000000400540: /home/abidh/demos/hello.c:6 0x000000000040054f: /home/abidh/demos/hello.c:7 0x0000000000400554: /home/abidh/demos/hello.c:8 0x0000000000400556: /home/abidh/demos/hello.c:8

(lldb) target module dump sections Dumping sections for 3 modules. Sections for '/home/abidh/demos/hello' (x86_64): SectID Type Load Address File Off. File Size Flags Section Name

  • --------- ---------------- --------------------------------------- ---------- ---------- ---------- ----------------------------

0x00000001 regular 0x00000000 0x00000000 0x00000000 hello. 0x00000002 regular [0x0000000000400238-0x0000000000400254) 0x00000238 0x0000001c 0x00000002 hello..interp 0x00000003 regular [0x0000000000400254-0x0000000000400274) 0x00000254 0x00000020 0x00000002 hello..note.ABI-tag 0x00000004 regular [0x0000000000400274-0x0000000000400298) 0x00000274 0x00000024 0x00000002 hello..note.gnu.build-id ….

slide-13
SLIDE 13

13 mentor.com/embedded

 Read the object file  Find symbols information if available  Provide execution control

run, stop, break

 Provide visibility into the program

Variables and expressions

Register, memory, disassembly

Target function call

Dynamic Objects

OS Awareness

So a debugger needs to …

slide-14
SLIDE 14

14 mentor.com/embedded

 What already there

Linux

FreeBSD

Window

Gdb-remote

Elf-core

 If your target is not one of these

Is remote debugging an option for you

Process Plugin

LLDB stub Target

slide-15
SLIDE 15

15 mentor.com/embedded

 Selection  Major Components

Process

– Attach, connect – Read/write memory – Breakpoint – Run/stop

Thread

– Stop Reason – Target specific step operation – GetUnwinder

Register Access

– Recognize PC, SP, FP

Process Plugin

slide-16
SLIDE 16

16 mentor.com/embedded

Process Plugin

LLDB Process Plugin Target Asynch Events Thread

slide-17
SLIDE 17

17 mentor.com/embedded

 WillLaunch, DoLaunch  DoConnect  WillResume, DoResume  WillHalt, DoHalt  EnableBreakpointSite, DisableBreakpointSite  DoReadMemory, DoWriteMemory  DoAllocateMemory  UpdateThreadList  GetStatus  DoDestroy

Process Plugin

slide-18
SLIDE 18

18 mentor.com/embedded

 Read the object file  Find symbols information if available  Provide execution control

run, stop, break

 Provide visibility into the program

Variables and expressions

Register, memory, disassembly

Target function call

Dynamic Objects

OS Awareness

So a debugger needs to …

slide-19
SLIDE 19

19 mentor.com/embedded

 Register  Memory

Done by Process Plugin

 Disassembler

LLVM disassembler

 Stack

Good debug information

UnwindAssembly Plugin

 Expressions

Clang integration

Program Visibility

slide-20
SLIDE 20

20 mentor.com/embedded

 Target Function Call

ABI Plugin

 DynamicLoader

Shared Objects

Step over function trampoline

TLS

 OperatingSystem Plugin

OS awareness

Program Visibility

slide-21
SLIDE 21

21 mentor.com/embedded

 ArchSpec

Provides target description

 Elf header

Handles your architecture

 Thread::Unwinder

Select default unwinder

 Add your Plugins in the build  Call your Initialize/Terminate functions  Test cases

Add test cases specific to your architectures

Misc Stuff

slide-22
SLIDE 22

22 mentor.com/embedded

 Read the object file  Find symbols information if available  Provide execution control

run, stop, break

 Provide visibility into the program

Variables and expressions

Register, memory, disassembly

Target function call

Dynamic Objects

OS Awareness

Hurray …

slide-23
SLIDE 23

23 mentor.com/embedded 23

QUESTIONS