Debug Info Tutorial Eric Christopher (echristo@gmail.com), David - - PowerPoint PPT Presentation

debug info tutorial
SMART_READER_LITE
LIVE PREVIEW

Debug Info Tutorial Eric Christopher (echristo@gmail.com), David - - PowerPoint PPT Presentation

Debug Info Tutorial Eric Christopher (echristo@gmail.com), David Blaikie (dblaikie@gmail.com) What is debug info? Mapping of source to binary Program structure, lines, columns, variables Debuggers, Profiling, Editors Kaleidoscope Background


slide-1
SLIDE 1

Debug Info Tutorial

Eric Christopher (echristo@gmail.com), David Blaikie (dblaikie@gmail.com)

slide-2
SLIDE 2

What is debug info?

Mapping of source to binary Program structure, lines, columns, variables Debuggers, Profiling, Editors

slide-3
SLIDE 3

Kaleidoscope Background

What is it? http://llvm.org/docs/tutorial/ How does it work? Jitting and top level statements

slide-4
SLIDE 4

Kaleidoscope Background

Example program:

slide-5
SLIDE 5

Kaleidoscope Background - Changes

JIT disabled Optimization passes disabled Remove helpful prompts and status

slide-6
SLIDE 6

What is DWARF then?

Standard for how to encode program structure, lines, columns, variables Permissive standard with vendor extensions Probably a bit too permissive

slide-7
SLIDE 7

DWARF Vaguaries

DWARF consumers not generalized because they’ve only seen output from one tool (GDB works great with GCC’s DWARF output) is_stmt - a line table feature “indicating that the current instruction is a recommended breakpoint location” - omitting this caused GDB to do… strange things.

slide-8
SLIDE 8

DWARF Structure

debug_info: source construct description (functions, types, namespaces, etc) debug_line: instruction -> source line mapping Use and similar tools to examine this data in object and executable files. Bunch of other implementation details probably not worth discussing on a first pass: debug_loc, debug_ranges, debug_string, debug_abbrev, etc.

slide-9
SLIDE 9

DWARF Structure - Info

Hierarchical tag+attribute format, imagine something like a binary XML.

slide-10
SLIDE 10

DWARF Structure - Line Table

State machine & all that, but if you’re just reading it it’s fairly simple

slide-11
SLIDE 11

DIBuilder Background

The debug info equivalent of IRBuilder - a helper API for building LLVM IR metadata for debug info

… … …

slide-12
SLIDE 12

Module level setup

Add a module flag with the debug info version! Not all targets support all dwarf!

slide-13
SLIDE 13

Kaleidoscope Dwarf Additions

Language Name - DW_LANG_KS Couple of simple places to put it in LLVM. No vendor range for this so use with caution.

slide-14
SLIDE 14

Creating the Compile Unit - Code

slide-15
SLIDE 15

Creating the Compile Unit - Metadata

slide-16
SLIDE 16

Creating the Compile Unit - DWARF

slide-17
SLIDE 17

Types - Code

slide-18
SLIDE 18

Types - Metadata

… [ ] [ ] [line 0, size 64, align 64, offset 0, enc DW_ATE_float]

slide-19
SLIDE 19

Types - DWARF

slide-20
SLIDE 20

Functions - Code

slide-21
SLIDE 21

Functions - Code

slide-22
SLIDE 22

Functions - Metadata

… … … … … … …

slide-23
SLIDE 23

Functions - DWARF

slide-24
SLIDE 24

Line Information - A Digression

Build source location information into your front end! Build AST and Lexer dumping mechanisms!

slide-25
SLIDE 25

Line Information - Code

slide-26
SLIDE 26

Line Information - Metadata

Optimizations know how to propagate this information when transforming instructions.

slide-27
SLIDE 27

Line Information - DWARF

slide-28
SLIDE 28

Line Information - DWARF

slide-29
SLIDE 29

Variables - Code

slide-30
SLIDE 30

Variables - A Bit More Code

slide-31
SLIDE 31

Variables - Metadata

Only works well with allocas, some limited support when in reg.

… … … … …

slide-32
SLIDE 32

Variables - DWARF

slide-33
SLIDE 33

Inlining

you are investigating issues in inlining debug info quality you want to simulate inlining in your front end’s codegen you’re implementing a custom inlining pass in LLVM

… … … …

slide-34
SLIDE 34

Inlining DWARF

Allows debuggers to simulate distinct function calls, even after they’ve been inlined.

… …

slide-35
SLIDE 35

Debugger Support

DW_LANG_KS isn’t supported by any debugger… … but DW_LANG_C is!

slide-36
SLIDE 36

Questions?