16
Dynamic Tracing in Userspace An introductory analysis of possible approaches with focus on DyninstAPI and GDB Suchakrapani Datt Sharma May 2, 2013 ´ Ecole Polytechnique de Montr´ eal Laboratoire DORSAL

Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

Dynamic Tracing in UserspaceAn introductory analysis of possible approaches with

focus on DyninstAPI and GDB

Suchakrapani Datt SharmaMay 2, 2013

Ecole Polytechnique de MontrealLaboratoire DORSAL

Page 2: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

Agenda

1 IntroductionDyninstGDB’s Tracing Infra

2 Tests & ResultsDyninst Overhead AnalysisGDB Overhead Analysis

3 What Next?

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 2/13 – dorsal.polymtl.ca

Page 3: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

Introduction

Aim

The goal is to investigate tools which can be of use to providedynamic tracing with UST without compromising performance.

Some tools investigated recently

• Dyninst API for dynamic instrumentation

• GDB’s fast tracing infrastructure

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 3/13 – dorsal.polymtl.ca

Page 4: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

Dyninst

A mutator program mutates the target program (mutatee) bybuilding and inserting code (snippets) during runtime

How Dyninst works

• BPatch object : processCreate(), processAttach()..

• Build snippets : BPatch arithExpr, BPatch varExp..

• Find points : appImage->findFunction(), findPoint()

• Insert Snippet : appAddrSpace->insertSnippet()

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 4/13 – dorsal.polymtl.ca

Page 5: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

Dyninst

A mutator program mutates the target program (mutatee) bybuilding and inserting code (snippets) during runtime

How Dyninst works

• BPatch object : processCreate(), processAttach()..

• Build snippets : BPatch arithExpr, BPatch varExp..

• Find points : appImage->findFunction(), findPoint()

• Insert Snippet : appAddrSpace->insertSnippet()

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 4/13 – dorsal.polymtl.ca

Page 6: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

Dyninst

A mutator program mutates the target program (mutatee) bybuilding and inserting code (snippets) during runtime

How Dyninst works

• BPatch object : processCreate(), processAttach()..

• Build snippets : BPatch arithExpr, BPatch varExp..

• Find points : appImage->findFunction(), findPoint()

• Insert Snippet : appAddrSpace->insertSnippet()

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 4/13 – dorsal.polymtl.ca

Page 7: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

Dyninst

A mutator program mutates the target program (mutatee) bybuilding and inserting code (snippets) during runtime

How Dyninst works

• BPatch object : processCreate(), processAttach()..

• Build snippets : BPatch arithExpr, BPatch varExp..

• Find points : appImage->findFunction(), findPoint()

• Insert Snippet : appAddrSpace->insertSnippet()

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 4/13 – dorsal.polymtl.ca

Page 8: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

GDB’s Tracing Infra

Fast Tracepoints : Similar approach by jumping to a smalltrampoline (jump pad). Faster than normal trap based tracepoints

How GDB’s fast tracepoints work

• Can be placed only at instructions 5 bytes or longer (4 byteson some targets)

• Needs In-process agent (IPA) library loaded in inferior process

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 5/13 – dorsal.polymtl.ca

Page 9: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

Tests & ResultsGDB and Dyninst elementary overhead analysis

Intel Core i5-3317U (1700Mhz x 4), 4GB RAM, Fedora 18(3.8.1-201.fc18.x86 64)

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 6/13 – dorsal.polymtl.ca

Page 10: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

Dyninst Overhead Analysis

Test Scenario : Consists of a dummy program and a mutatorprogram mutating it. It instruments the function bar() in dummy.The function bar() originally just increments a variable by 1.

void bar(){ ch=ch+1; }

The mutator builds a snippet to initialize another variable withzero and inserts this snippet during dummy runtime. Time for 10billion runs of bar() is observed using clock gettime() for aclean vs mutated run

a = appAddrSpace->malloc(*appImage->findType("int"));

BPatch arithExpr initSnippet(BPatch assign, *a, zero);

appAddrSpace->insertSnippet(initSnippet, *functionEntry);

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 7/13 – dorsal.polymtl.ca

Page 11: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

Results

• Mean difference of 11.83s and an overhead of 50.38%

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 8/13 – dorsal.polymtl.ca

Page 12: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

Results

• Mean mutation time : 1.29s

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 9/13 – dorsal.polymtl.ca

Page 13: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

GDB Overhead Analysis

Test Scenario : Consists of a dummy program with a functionbar(). The function bar() originally just increments a variable by1. The dummy application is started with GDBserver whilepre-loading the IPA library.

gdbserver --wrapper env LD PRELOAD=/usr/lib64/libinproctrace.so

:2222 dummy

Through GDB, fast tracepoint is set at beginning of bar() andtrace experiment is conducted without any ‘actions’. Time for 10billion runs of bar() is observed using clock gettime() for aclean vs traced run

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 10/13 – dorsal.polymtl.ca

Page 14: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

Results

• Mean difference of 1.60s and an overhead of 6.83%

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 11/13 – dorsal.polymtl.ca

Page 15: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

What Next?

• Run more rigorous and real life tests on multiple test setups

• Analyze pros and cons for each dynamic instrumentationcandidate

• Investigate ways to utilize GDB’s dynamic tracing infra forUST

• A glance at other tools - DynamoRIO, Pin

Long Term Vision

The long term goal now is eventually merging the functionality oftracing, profiling and debugging in an integrated tool.

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 12/13 – dorsal.polymtl.ca

Page 16: Dynamic Tracing in Userspace - Polytechnique Montréal · 2018. 2. 6. · Analyze pros and cons for each dynamic instrumentation candidate Investigate ways to utilize GDB’s dynamic

POLYTECHNIQUE MONTREAL Introduction Tests & Results What Next?

Questions and Suggestions?

[email protected]

suchakra on #lttng

Dynamic Tracing Analysis – Suchakrapani Datt Sharma 13/13 – dorsal.polymtl.ca