uftrace: A function graph tracer for C/C++ userspace programs

Size: px
Start display at page:

Download "uftrace: A function graph tracer for C/C++ userspace programs"

Transcription

1 uftrace: A function graph tracer for C/C++ userspace programs Lightning Talk at CppCon 2016 September 23, 2016 Namhyung Kim, Honggyu Kim LG Electronics {namhyung.kim, hong.gyu.kim@lge.com

2 uftrace

3

4 int main() {

5 void foo() { int main() { foo();

6 void bar() { void foo() { bar(); int main() { foo();

7 $ gcc test.c void bar() { void foo() { bar(); int main() { foo();

8 $ gcc test.c void bar() { void foo() { bar(); int main() { foo(); <bar>: ret <foo>: call <bar> ret <main>: call <foo> ret

9 $ gcc pg test.c void bar() { void foo() { bar(); int main() { foo(); <bar>: call <mcount@plt> ret <foo>: call <mcount@plt> call <bar> ret <main>: call <mcount@plt> call <foo> ret

10 $ gcc pg test.c

11 $ gcc pg test.c $ uftrace record a.out

12 $ gcc pg test.c $ uftrace record a.out $ uftrace replay

13 $ gcc pg test.c $ uftrace record a.out $ uftrace replay # DURATION TID FUNCTION us [21315] monstartup(); us [21315] cxa_atexit(); [21315] main() { [21315] foo() { us [21315] bar(); us [21315] /* foo */ us [21315] /* main */

14 $ gcc pg test.c $ uftrace live a.out # DURATION TID FUNCTION us [21315] monstartup(); us [21315] cxa_atexit(); [21315] main() { [21315] foo() { us [21315] bar(); us [21315] /* foo */ us [21315] /* main */

15 $ gcc pg test.c $ uftrace a.out # DURATION TID FUNCTION us [21315] monstartup(); us [21315] cxa_atexit(); [21315] main() { [21315] foo() { us [21315] bar(); us [21315] /* foo */ us [21315] /* main */

16 $ gcc pg test.c $ uftrace a.out # DURATION TID FUNCTION us [21315] monstartup(); us [21315] cxa_atexit(); [21315] main() { [21315] foo() { us [21315] bar(); us [21315] /* foo */ us [21315] /* main */

17 $ gcc pg test.c $ uftrace a.out # DURATION TID FUNCTION us [21315] monstartup(); us [21315] cxa_atexit(); [21315] main() { [21315] foo() { us [21315] bar(); us [21315] /* foo */ us [21315] /* main */

18 $ gcc pg test.c $ uftrace a.out # DURATION TID FUNCTION us [21315] monstartup(); us [21315] cxa_atexit(); [21315] main() { [21315] foo() { us [21315] bar(); us [21315] /* foo */ us [21315] /* main */

19 $ gcc pg test.c $ uftrace a.out # DURATION TID FUNCTION us [21315] monstartup(); us [21315] cxa_atexit(); [21315] main() { [21315] foo() { us [21315] bar(); us [21315] /* foo */ us [21315] /* main */

20 $ gcc pg test.c $ uftrace -t 200ns a.out # DURATION TID FUNCTION us [21315] monstartup(); us [21315] cxa_atexit(); [21315] main() { [21315] foo() { us [21315] bar(); us [21315] /* foo */ us [21315] /* main */ -t TIME, --time-filter=time Do not show small functions under the time threshold.

21 $ gcc pg test.c $ uftrace -t 200ns a.out # DURATION TID FUNCTION us [32476] monstartup(); us [32476] cxa_atexit(); [32476] main() { us [32476] foo(); us [32476] /* main */ -t TIME, --time-filter=time Do not show small functions under the time threshold.

22

23 $ gcc pg test.c $ uftrace record a.out

24 $ gcc pg test.c $ uftrace record a.out $ uftrace report

25 $ gcc pg test.c $ uftrace record a.out $ uftrace report Total time Self time Calls Function ========== ========== ========== ================= us us 1 main us us 1 foo us us 1 monstartup us us 1 cxa_atexit us us 1 bar

26

27 $ gcc pg fibonacci.c

28 $ gcc pg fibonacci.c $ uftrace fibonacci 5 fib(5) = 5

29 $ gcc pg fibonacci.c $ uftrace fibonacci 5 fib(5) = 5 # DURATION TID FUNCTION us [31321] monstartup(); us [31321] cxa_atexit(); [31321] main() { us [31321] atoi(); [31321] fib() { [31321] fib() { [31321] fib() { us [31321] fib(); us [31321] fib(); us [31321] /* fib */ us [31321] fib(); us [31321] /* fib */ [31321] fib() { us [31321] fib(); us [31321] fib(); us [31321] /* fib */ us [31321] /* fib */ us [31321] printf(); us [31321] /* main */

30 $ gcc pg fibonacci.c $ uftrace -A fib@arg1 fibonacci 5 fib(5) = 5 # DURATION TID FUNCTION us [31365] monstartup(); us [31365] cxa_atexit(); [31365] main() { us [31365] atoi(); [31365] fib(5) { [31365] fib(4) { [31365] fib(3) { us [31365] fib(2); us [31365] fib(1); us [31365] /* fib */ us [31365] fib(2); us [31365] /* fib */ [31365] fib(3) { us [31365] fib(2); us [31365] fib(1); us [31365] /* fib */ us [31365] /* fib */ us [31365] printf(); us [31365] /* main */

31 $ gcc pg fibonacci.c $ uftrace -A fib@arg1 -R fib@retval fibonacci 5 fib(5) = 5 # DURATION TID FUNCTION us [31379] monstartup(); us [31379] cxa_atexit(); [31379] main() { us [31379] atoi(); [31379] fib(5) { [31379] fib(4) { [31379] fib(3) { us [31379] fib(2) = 1; us [31379] fib(1) = 1; us [31379] = 2; /* fib */ us [31379] fib(2) = 1; us [31379] = 3; /* fib */ [31379] fib(3) { us [31379] fib(2) = 1; us [31379] fib(1) = 1; us [31379] = 2; /* fib */ us [31379] = 5; /* fib */ us [31379] printf(); us [31379] /* main */

32 $ gcc pg fibonacci.c

33 $ gcc pg fibonacci.c $ uftrace record fibonacci 5 fib(5) = 5

34 $ gcc pg fibonacci.c $ uftrace record fibonacci 5 fib(5) = 5 $ uftrace dump

35 $ gcc pg fibonacci.c $ uftrace record fibonacci 5 fib(5) = 5 $ uftrace dump --chrome

36 $ gcc pg fibonacci.c $ uftrace record fibonacci 5 fib(5) = 5 $ uftrace dump --chrome {"traceevents":[ {"ts": ,"ph":"b","pid":32256,"name":" monstartup", {"ts": ,"ph":"e","pid":32256,"name":" monstartup", {"ts": ,"ph":"b","pid":32256,"name":" cxa_atexit", {"ts": ,"ph":"e","pid":32256,"name":" cxa_atexit", {"ts": ,"ph":"b","pid":32256,"name":"main", {"ts": ,"ph":"b","pid":32256,"name":"atoi", {"ts": ,"ph":"e","pid":32256,"name":"atoi", {"ts": ,"ph":"b","pid":32256,"name":"fib", {"ts": ,"ph":"b","pid":32256,"name":"fib",... {"ts": ,"ph":"e","pid":32256,"name":"fib", {"ts": ,"ph":"e","pid":32256,"name":"fib", {"ts": ,"ph":"e","pid":32256,"name":"fib", {"ts": ,"ph":"b","pid":32256,"name":"printf", {"ts": ,"ph":"e","pid":32256,"name":"printf", {"ts": ,"ph":"e","pid":32256,"name":"main" ], "metadata": { "command_line":"uftrace record fibonacci 5 ", "recorded_time":"thu Sep 22 22:31: "

37 $ gcc pg fibonacci.c $ uftrace record fibonacci 5 fib(5) = 5 $ uftrace dump --chrome > fib.json

38 1. Open Chrome Browser

39 1. Open Chrome Browser 2. Load JSON file in chrome://tracing

40 1. Open Chrome Browser 2. Load JSON file in chrome://tracing

41 1. Open Chrome Browser 2. Load JSON file in chrome://tracing Timeline

42 1. Open Chrome Browser 2. Load JSON file in chrome://tracing Timeline Call Depth

43 Analyzing STL (shared_ptr)

44 Analyzing STL (shared_ptr) int main() { shared_ptr<int> s1(new int);

45 Analyzing STL (shared_ptr) int main() { shared_ptr<int> s1(new int); { shared_ptr<int> s2 = s1;

46 Analyzing STL (shared_ptr) $ g++ -pg shared_ptr.cc int main() { shared_ptr<int> s1(new int); { shared_ptr<int> s2 = s1;

47 Analyzing STL (shared_ptr) $ g++ -pg shared_ptr.cc $ uftrace a.out int main() { shared_ptr<int> s1(new int); { shared_ptr<int> s2 = s1;

48 Analyzing STL (shared_ptr) $ g++ -pg shared_ptr.cc $ uftrace D.. -F.. -A.. -R.. a.out int main() { shared_ptr<int> s1(new int); { shared_ptr<int> s2 = s1; $ uftrace -D 4 \ -F main -F "operator.* -F "std::shared_ptr::.*" \ -A "operator new"@arg1 -R "operator new"@retval \ -A "operator delete"@arg1 \ shared_ptr

49 # DURATION TID FUNCTION [10471] main() { us [10471] operator new(4) = 0x ; [10471] std::shared_ptr::shared_ptr() { [10471] std:: shared_ptr:: shared_ptr() { [10471] std:: shared_count:: shared_count() { us [10471] operator new(24) = 0x122d630; us [10471] std::_sp_counted_ptr::_sp_counted_ptr(); us [10471] /* std:: shared_count:: shared_count */ us [10471] std:: enable_shared_from_this_helper(); us [10471] /* std:: shared_ptr:: shared_ptr */ us [10471] /* std::shared_ptr::shared_ptr */ [10471] std::shared_ptr::shared_ptr() { [10471] std:: shared_ptr:: shared_ptr() { [10471] std:: shared_count:: shared_count() { us [10471] std::_sp_counted_base::_m_add_ref_copy(); us [10471] /* std:: shared_count:: shared_count */ us [10471] /* std:: shared_ptr:: shared_ptr */ us [10471] /* std::shared_ptr::shared_ptr */ [10471] std::shared_ptr::~shared_ptr() { [10471] std:: shared_ptr::~ shared_ptr() { [10471] std:: shared_count::~ shared_count() { us [10471] std::_sp_counted_base::_m_release(); us [10471] /* std:: shared_count::~ shared_count */ us [10471] /* std:: shared_ptr::~ shared_ptr */ us [10471] /* std::shared_ptr::~shared_ptr */ [10471] std::shared_ptr::~shared_ptr() { [10471] std:: shared_ptr::~ shared_ptr() { [10471] std:: shared_count::~ shared_count() { [10471] std::_sp_counted_base::_m_release() { us [10471] operator delete(0x ); us [10471] operator delete(0x122d630); us [10471] /* std::_sp_counted_base::_m_release */ us [10471] /* std:: shared_count::~ shared_count */ us [10471] /* std:: shared_ptr::~ shared_ptr */ us [10471] /* std::shared_ptr::~shared_ptr */ us [10471] /* main */

50 # DURATION TID FUNCTION [10471] main() { us [10471] operator new(4) = 0x ; [10471] std::shared_ptr::shared_ptr() { [10471] std:: shared_ptr:: shared_ptr() { [10471] std:: shared_count:: shared_count() { us [10471] operator new(24) = 0x122d630; us [10471] std::_sp_counted_ptr::_sp_counted_ptr(); us [10471] /* std:: shared_count:: shared_count */ us [10471] std:: enable_shared_from_this_helper(); us [10471] /* std:: shared_ptr:: shared_ptr */ us [10471] /* std::shared_ptr::shared_ptr */ [10471] std::shared_ptr::shared_ptr() { [10471] std:: shared_ptr:: shared_ptr() { [10471] std:: shared_count:: shared_count() { us [10471] std::_sp_counted_base::_m_add_ref_copy(); us [10471] /* std:: shared_count:: shared_count */ us [10471] /* std:: shared_ptr:: shared_ptr */ us [10471] /* std::shared_ptr::shared_ptr */ [10471] std::shared_ptr::~shared_ptr() { [10471] std:: shared_ptr::~ shared_ptr() { [10471] std:: shared_count::~ shared_count() { us [10471] std::_sp_counted_base::_m_release(); us [10471] /* std:: shared_count::~ shared_count */ us [10471] /* std:: shared_ptr::~ shared_ptr */ us [10471] /* std::shared_ptr::~shared_ptr */ [10471] std::shared_ptr::~shared_ptr() { [10471] std:: shared_ptr::~ shared_ptr() { [10471] std:: shared_count::~ shared_count() { [10471] std::_sp_counted_base::_m_release() { us [10471] operator delete(0x ); us [10471] operator delete(0x122d630); us [10471] /* std::_sp_counted_base::_m_release */ us [10471] /* std:: shared_count::~ shared_count */ us [10471] /* std:: shared_ptr::~ shared_ptr */ us [10471] /* std::shared_ptr::~shared_ptr */ us [10471] /* main */ alloc!

51 # DURATION TID FUNCTION [10471] main() { us [10471] operator new(4) = 0x ; [10471] std::shared_ptr::shared_ptr() { [10471] std:: shared_ptr:: shared_ptr() { [10471] std:: shared_count:: shared_count() { us [10471] operator new(24) = 0x122d630; us [10471] std::_sp_counted_ptr::_sp_counted_ptr(); us [10471] /* std:: shared_count:: shared_count */ us [10471] std:: enable_shared_from_this_helper(); us [10471] /* std:: shared_ptr:: shared_ptr */ us [10471] /* std::shared_ptr::shared_ptr */ [10471] std::shared_ptr::shared_ptr() { [10471] std:: shared_ptr:: shared_ptr() { [10471] std:: shared_count:: shared_count() { us [10471] std::_sp_counted_base::_m_add_ref_copy(); us [10471] /* std:: shared_count:: shared_count */ us [10471] /* std:: shared_ptr:: shared_ptr */ us [10471] /* std::shared_ptr::shared_ptr */ [10471] std::shared_ptr::~shared_ptr() { [10471] std:: shared_ptr::~ shared_ptr() { [10471] std:: shared_count::~ shared_count() { us [10471] std::_sp_counted_base::_m_release(); us [10471] /* std:: shared_count::~ shared_count */ us [10471] /* std:: shared_ptr::~ shared_ptr */ us [10471] /* std::shared_ptr::~shared_ptr */ [10471] std::shared_ptr::~shared_ptr() { [10471] std:: shared_ptr::~ shared_ptr() { [10471] std:: shared_count::~ shared_count() { [10471] std::_sp_counted_base::_m_release() { us [10471] operator delete(0x ); us [10471] operator delete(0x122d630); us [10471] /* std::_sp_counted_base::_m_release */ us [10471] /* std:: shared_count::~ shared_count */ us [10471] /* std:: shared_ptr::~ shared_ptr */ us [10471] /* std::shared_ptr::~shared_ptr */ us [10471] /* main */ ++refcnt

52 # DURATION TID FUNCTION [10471] main() { us [10471] operator new(4) = 0x ; [10471] std::shared_ptr::shared_ptr() { [10471] std:: shared_ptr:: shared_ptr() { [10471] std:: shared_count:: shared_count() { us [10471] operator new(24) = 0x122d630; us [10471] std::_sp_counted_ptr::_sp_counted_ptr(); us [10471] /* std:: shared_count:: shared_count */ us [10471] std:: enable_shared_from_this_helper(); us [10471] /* std:: shared_ptr:: shared_ptr */ us [10471] /* std::shared_ptr::shared_ptr */ [10471] std::shared_ptr::shared_ptr() { [10471] std:: shared_ptr:: shared_ptr() { [10471] std:: shared_count:: shared_count() { us [10471] std::_sp_counted_base::_m_add_ref_copy(); us [10471] /* std:: shared_count:: shared_count */ us [10471] /* std:: shared_ptr:: shared_ptr */ us [10471] /* std::shared_ptr::shared_ptr */ [10471] std::shared_ptr::~shared_ptr() { [10471] std:: shared_ptr::~ shared_ptr() { [10471] std:: shared_count::~ shared_count() { us [10471] std::_sp_counted_base::_m_release(); us [10471] /* std:: shared_count::~ shared_count */ us [10471] /* std:: shared_ptr::~ shared_ptr */ us [10471] /* std::shared_ptr::~shared_ptr */ [10471] std::shared_ptr::~shared_ptr() { [10471] std:: shared_ptr::~ shared_ptr() { [10471] std:: shared_count::~ shared_count() { [10471] std::_sp_counted_base::_m_release() { us [10471] operator delete(0x ); us [10471] operator delete(0x122d630); us [10471] /* std::_sp_counted_base::_m_release */ us [10471] /* std:: shared_count::~ shared_count */ us [10471] /* std:: shared_ptr::~ shared_ptr */ us [10471] /* std::shared_ptr::~shared_ptr */ us [10471] /* main */ --refcnt

53 # DURATION TID FUNCTION [10471] main() { us [10471] operator new(4) = 0x ; [10471] std::shared_ptr::shared_ptr() { [10471] std:: shared_ptr:: shared_ptr() { [10471] std:: shared_count:: shared_count() { us [10471] operator new(24) = 0x122d630; us [10471] std::_sp_counted_ptr::_sp_counted_ptr(); us [10471] /* std:: shared_count:: shared_count */ us [10471] std:: enable_shared_from_this_helper(); us [10471] /* std:: shared_ptr:: shared_ptr */ us [10471] /* std::shared_ptr::shared_ptr */ [10471] std::shared_ptr::shared_ptr() { [10471] std:: shared_ptr:: shared_ptr() { [10471] std:: shared_count:: shared_count() { us [10471] std::_sp_counted_base::_m_add_ref_copy(); us [10471] /* std:: shared_count:: shared_count */ us [10471] /* std:: shared_ptr:: shared_ptr */ us [10471] /* std::shared_ptr::shared_ptr */ [10471] std::shared_ptr::~shared_ptr() { [10471] std:: shared_ptr::~ shared_ptr() { [10471] std:: shared_count::~ shared_count() { us [10471] std::_sp_counted_base::_m_release(); us [10471] /* std:: shared_count::~ shared_count */ us [10471] /* std:: shared_ptr::~ shared_ptr */ us [10471] /* std::shared_ptr::~shared_ptr */ [10471] std::shared_ptr::~shared_ptr() { [10471] std:: shared_ptr::~ shared_ptr() { [10471] std:: shared_count::~ shared_count() { [10471] std::_sp_counted_base::_m_release() { us [10471] operator delete(0x ); us [10471] operator delete(0x122d630); us [10471] /* std::_sp_counted_base::_m_release */ us [10471] /* std:: shared_count::~ shared_count */ us [10471] /* std:: shared_ptr::~ shared_ptr */ us [10471] /* std::shared_ptr::~shared_ptr */ us [10471] /* main */ dealloc!

54 Analyzing Clang $ uftrace -t 2ms -F cc1_main./clang fibonacci.c # DURATION TID FUNCTION [ 9045] cc1_main() { [ 9045] clang::compilerinvocation::createfromargs() { ms [ 9045] ParseCodeGenArgs(); ms [ 9045] /* clang::compilerinvocation::createfromargs */ [ 9045] clang::executecompilerinvocation() { [ 9045] clang::compilerinstance::executeaction() { ms [ 9045] clang::frontendaction::beginsourcefile(); [ 9045] clang::frontendaction::execute() { [ 9045] clang::codegenaction::executeaction() { [ 9045] clang::astfrontendaction::executeaction() { [ 9045] clang::parseast() { [ 9045] clang::parser::initialize() { ms [ 9045] clang::preprocessor::lex(); ms [ 9045] /* clang::parser::initialize */ [ 9045] clang::backendconsumer::handletranslationunit() { [ 9045] clang::emitbackendoutput() { [ 9045] llvm::llvmtargetmachine::addpassestoemitfile() { ms [ 9045] addpassestogeneratecode(); ms [ 9045] /* llvm::llvmtargetmachine::addpassestoemitfile */ [ 9045] llvm::legacy::passmanager::run() { ms [ 9045] llvm::legacy::passmanagerimpl::run(); ms [ 9045] /* llvm::legacy::passmanager::run */ ms [ 9045] /* clang::emitbackendoutput */ ms [ 9045] /* clang::backendconsumer::handletranslationunit */ ms [ 9045] /* clang::parseast */ ms [ 9045] /* clang::astfrontendaction::executeaction */ ms [ 9045] /* clang::codegenaction::executeaction */ ms [ 9045] /* clang::frontendaction::execute */ ms [ 9045] /* clang::compilerinstance::executeaction */ ms [ 9045] /* clang::executecompilerinvocation */ ms [ 9045] /* cc1_main */

55 Analyzing Clang $ uftrace -t 2ms -F cc1_main./clang fibonacci.c # DURATION TID FUNCTION [ 9045] cc1_main() { [ 9045] clang::compilerinvocation::createfromargs() { ms [ 9045] ParseCodeGenArgs(); ms [ 9045] /* clang::compilerinvocation::createfromargs */ [ 9045] clang::executecompilerinvocation() { [ 9045] clang::compilerinstance::executeaction() { ms [ 9045] clang::frontendaction::beginsourcefile(); [ 9045] clang::frontendaction::execute() { [ 9045] clang::codegenaction::executeaction() { [ 9045] clang::astfrontendaction::executeaction() { [ 9045] clang::parseast() { [ 9045] clang::parser::initialize() { ms [ 9045] clang::preprocessor::lex(); ms [ 9045] /* clang::parser::initialize */ [ 9045] clang::backendconsumer::handletranslationunit() { [ 9045] clang::emitbackendoutput() { [ 9045] llvm::llvmtargetmachine::addpassestoemitfile() { ms [ 9045] addpassestogeneratecode(); ms [ 9045] /* llvm::llvmtargetmachine::addpassestoemitfile */ [ 9045] llvm::legacy::passmanager::run() { ms [ 9045] llvm::legacy::passmanagerimpl::run(); ms [ 9045] /* llvm::legacy::passmanager::run */ ms [ 9045] /* clang::emitbackendoutput */ ms [ 9045] /* clang::backendconsumer::handletranslationunit */ ms [ 9045] /* clang::parseast */ ms [ 9045] /* clang::astfrontendaction::executeaction */ ms [ 9045] /* clang::codegenaction::executeaction */ ms [ 9045] /* clang::frontendaction::execute */ ms [ 9045] /* clang::compilerinstance::executeaction */ ms [ 9045] /* clang::executecompilerinvocation */ ms [ 9045] /* cc1_main */ ParseAST

56 Analyzing Clang $ uftrace -t 2ms -F cc1_main./clang fibonacci.c # DURATION TID FUNCTION [ 9045] cc1_main() { [ 9045] clang::compilerinvocation::createfromargs() { ms [ 9045] ParseCodeGenArgs(); ms [ 9045] /* clang::compilerinvocation::createfromargs */ [ 9045] clang::executecompilerinvocation() { [ 9045] clang::compilerinstance::executeaction() { ms [ 9045] clang::frontendaction::beginsourcefile(); [ 9045] clang::frontendaction::execute() { [ 9045] clang::codegenaction::executeaction() { [ 9045] clang::astfrontendaction::executeaction() { [ 9045] clang::parseast() { [ 9045] clang::parser::initialize() { ms [ 9045] clang::preprocessor::lex(); ms [ 9045] /* clang::parser::initialize */ [ 9045] clang::backendconsumer::handletranslationunit() { [ 9045] clang::emitbackendoutput() { [ 9045] llvm::llvmtargetmachine::addpassestoemitfile() { ms [ 9045] addpassestogeneratecode(); ms [ 9045] /* llvm::llvmtargetmachine::addpassestoemitfile */ [ 9045] llvm::legacy::passmanager::run() { ms [ 9045] llvm::legacy::passmanagerimpl::run(); ms [ 9045] /* llvm::legacy::passmanager::run */ ms [ 9045] /* clang::emitbackendoutput */ ms [ 9045] /* clang::backendconsumer::handletranslationunit */ ms [ 9045] /* clang::parseast */ ms [ 9045] /* clang::astfrontendaction::executeaction */ ms [ 9045] /* clang::codegenaction::executeaction */ ms [ 9045] /* clang::frontendaction::execute */ ms [ 9045] /* clang::compilerinstance::executeaction */ ms [ 9045] /* clang::executecompilerinvocation */ ms [ 9045] /* cc1_main */ Backend Code Gen

57 Analyzing Clang TMP expansion $ clang++ tmpfib.cc #include <iostream> #define fibnum 8 template <unsigned N> struct Fibonacci { enum { value = Fibonacci<N-1>::value + Fibonacci<N-2>::value ; ; template <> struct Fibonacci<1> { enum { value = 1 ; ; template <> struct Fibonacci<0> { enum { value = 0 ; ; int main(void) { std::cout << "Fibonacci(" << fibnum << ") = "; std::cout << Fibonacci<fibnum>::value; std::cout << std::endl;

58 Analyzing Clang TMP expansion $ clang++ tmpfib.cc #include <iostream> #define fibnum 8 template <unsigned N> struct Fibonacci { enum { value = Fibonacci<N-1>::value + Fibonacci<N-2>::value ; ; template <> struct Fibonacci<1> { enum { value = 1 ; ; template <> struct Fibonacci<0> { enum { value = 0 ; ; int main(void) { std::cout << "Fibonacci(" << fibnum << ") = "; std::cout << Fibonacci<fibnum>::value; std::cout << std::endl;

59 Analyzing Clang TMP expansion $ clang++ tmpfib.cc #include <iostream> #define fibnum 8 template <unsigned N> struct Fibonacci { enum { value = Fibonacci<N-1>::value + Fibonacci<N-2>::value ; ; template <> struct Fibonacci<1> { enum { value = 1 ; ; template <> struct Fibonacci<0> { enum { value = 0 ; ; int main(void) { std::cout << "Fibonacci(" << fibnum << ") = "; std::cout << Fibonacci<fibnum>::value; std::cout << std::endl; Recursive Expansion

60 Analyzing Clang TMP expansion $ clang++ tmpfib.cc #include <iostream> #define fibnum 8 template <unsigned N> struct Fibonacci { enum { value = Fibonacci<N-1>::value + Fibonacci<N-2>::value ; ; template <> struct Fibonacci<1> { enum { value = 1 ; ; template <> struct Fibonacci<0> { enum { value = 0 ; ; int main(void) { std::cout << "Fibonacci(" << fibnum << ") = "; std::cout << Fibonacci<fibnum>::value; std::cout << std::endl; Recursive Expansion

61 Analyzing Clang TMP expansion $ uftrace record -t 1ms clang++ tmpfib.cc #include <iostream> #define fibnum 8 template <unsigned N> struct Fibonacci { enum { value = Fibonacci<N-1>::value + Fibonacci<N-2>::value ; ; template <> struct Fibonacci<1> { enum { value = 1 ; ; template <> struct Fibonacci<0> { enum { value = 0 ; ; int main(void) { std::cout << "Fibonacci(" << fibnum << ") = "; std::cout << Fibonacci<fibnum>::value; std::cout << std::endl; Recursive Expansion

62 DEMO Clang / LLVM (can only be opened in chrome browsers)

63 DEMO V8 JavaScript Engine (can only be opened in chrome browsers)

64 Thanks!

65 $ gcc test.c void bar() { void foo() { bar(); int main() { foo(); <bar>: ret <foo>: call <bar> ret <main>: call <foo> ret

66 $ gcc pg test.c void bar() { void foo() { bar(); int main() { foo(); <bar>: call <mcount@plt> ret <foo>: call <mcount@plt> call <bar> ret <main>: call <mcount@plt> call <foo> ret

67 $ gcc pg fno-omit-frame-pointer test.c void bar() { void foo() { bar(); int main() { foo(); <bar>: push %rbp mov %rsp,%rbp call <mcount@plt> ret <foo>: push %rbp mov %rsp,%rbp call <mcount@plt> call <bar> ret <main>: push %rbp mov %rsp,%rbp call <mcount@plt> call <foo> ret

68 $ gcc test.c void bar() { void foo() { bar(); int main() { foo(); <bar>: ret <foo>: call <bar> ret <main>: call <foo> ret

69 $ gcc finstrument-functions test.c void bar() { void foo() { bar(); int main() { foo(); <bar>: call < cyg_profile_func_enter@plt> ret <foo>: call < cyg_profile_func_enter@plt> call <bar> ret <main>: call < cyg_profile_func_enter@plt> call <foo> ret

70 $ gcc finstrument-functions test.c void bar() { void foo() { bar(); int main() { foo(); <bar>: call < cyg_profile_func_enter@plt> call < cyg_profile_func_exit@plt> ret <foo>: call < cyg_profile_func_enter@plt> call <bar> call < cyg_profile_func_exit@plt> ret <main>: call < cyg_profile_func_enter@plt> call <foo> call < cyg_profile_func_exit@plt> ret

71 $ gcc pg test.c $ uftrace -D 2 a.out # DURATION TID FUNCTION us [32431] monstartup(); us [32431] cxa_atexit(); [32431] main() { us [32431] foo(); us [32431] /* main */ -D DEPTH, --depth=depth Set global trace limit in nesting level.

72 $ gcc pg test.c $ uftrace -F foo a.out # DURATION TID FUNCTION [32432] foo() { us [32432] bar(); us [32432] /* foo */ -F FUNC, --filter=func Set filter to trace selected functions only.

73 $ gcc pg test.c $ uftrace -N foo a.out # DURATION TID FUNCTION us [32436] monstartup(); us [32436] cxa_atexit(); us [32436] main(); -N FUNC, --notrace=func Set filter not to trace selected functions (and children)

74 $ uftrace -A -R fibonacci 5 ARGUMENTS <argument> := <symbol> "@" <specs> <specs> := <spec> <spec> "," <spec> <spec> := ( <int_spec> <float_spec> <ret_spec> ) <int_spec> := "arg" N [ "/" <format> [ <size> ] ] [ "%" ( <reg> <stack> ) ] <float_spec> := "fparg" N [ "/" ( <size> "80" ) ] [ "%" ( <reg> <stack> ) ] <ret_spec> := "retval" [ "/" <format> [ <size> ] ] <format> := "i" "u" "x" "s" "c" "f" <size> := "8" "16" "32" "64" <reg> := <arch-specific register name> # "rdi", "xmm0", "r0",... <stack> := "stack" [ "+" ] <offset>

75 $ uftrace -A -R fibonacci 5 ARGUMENTS <argument> := <symbol> "@" <specs> <specs> := <spec> <spec> "," <spec> <spec> := ( <int_spec> <float_spec> <ret_spec> ) <int_spec> := "arg" N [ "/" <format> [ <size> ] ] [ "%" ( <reg> <stack> ) ] <float_spec> := "fparg" N [ "/" ( <size> "80" ) ] [ "%" ( <reg> <stack> ) ] <ret_spec> := "retval" [ "/" <format> [ <size> ] ] <format> := "i" "u" "x" "s" "c" "f" <size> := "8" "16" "32" "64" <reg> := <arch-specific register name> # "rdi", "xmm0", "r0",... <stack> := "stack" [ "+" ] <offset>

76 $ uftrace -A -R fibonacci 5 ARGUMENTS <argument> := <symbol> "@" <specs> <specs> := <spec> <spec> "," <spec> <spec> := ( <int_spec> <float_spec> <ret_spec> ) <int_spec> := "arg" N [ "/" <format> [ <size> ] ] [ "%" ( <reg> <stack> ) ] <float_spec> := "fparg" N [ "/" ( <size> "80" ) ] [ "%" ( <reg> <stack> ) ] <ret_spec> := "retval" [ "/" <format> [ <size> ] ] <format> := "i" "u" "x" "s" "c" "f" <size> := "8" "16" "32" "64" <reg> := <arch-specific register name> # "rdi", "xmm0", "r0",... <stack> := "stack" [ "+" ] <offset>

77 $ uftrace -A -R fibonacci 5 ARGUMENTS <argument> := <symbol> "@" <specs> <specs> := <spec> <spec> "," <spec> <spec> := ( <int_spec> <float_spec> <ret_spec> ) <int_spec> := "arg" N [ "/" <format> [ <size> ] ] [ "%" ( <reg> <stack> ) ] <float_spec> := "fparg" N [ "/" ( <size> "80" ) ] [ "%" ( <reg> <stack> ) ] <ret_spec> := "retval" [ "/" <format> [ <size> ] ] <format> := "i" "u" "x" "s" "c" "f" <size> := "8" "16" "32" "64" <reg> := <arch-specific register name> # "rdi", "xmm0", "r0",... <stack> := "stack" [ "+" ] <offset>

78 Analyzing Kernel Functions $ gcc pg hello-cppcon.c

79 Analyzing Kernel Functions $ gcc pg hello-cppcon.c $ sudo uftrace -k a.out Hello CppCon!

80 Analyzing Kernel Functions $ gcc pg hello-cppcon.c $ sudo uftrace -k a.out Hello CppCon! # DURATION TID FUNCTION us [ 8926] monstartup(); us [ 8926] cxa_atexit(); [ 8926] main() { [ 8926] puts() { us [ 8926] sys_newfstat(); us [ 8926] do_page_fault(); us [ 8926] /* puts */ [ 8926] fflush() { us [ 8926] sys_write(); us [ 8926] /* fflush */ us [ 8926] /* main */

uftrace: function graph tracer for C/C++

uftrace: function graph tracer for C/C++ uftrace: function graph tracer for C/C++ Namhyung Kim ( 김남형 ) namhyung@gmail.com namhyung.kim@lge.com Open Source Summit 2017 2017.9.11 "Powered by Marp" uftrace overview function tracer for C/C++ inspired

More information

Here hands-on tutorials with. Taeung Song 송태웅, KOSSLAB

Here hands-on tutorials with. Taeung Song 송태웅, KOSSLAB Goodbye Talk Title! printf() Here hands-on tutorials with uftrace: Author Name,function Company graph tracer for C/C++ Taeung Song 송태웅, KOSSLAB Why use printf()? during development As you know.. Program

More information

Programming in C - Part 2

Programming in C - Part 2 Programming in C - Part 2 CPSC 457 Mohammad Reza Zakerinasab May 11, 2016 These slides are forked from slides created by Mike Clark Where to find these slides and related source code? http://goo.gl/k1qixb

More information

Stack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15

Stack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15 Stack Frames Geoffrey Brown Bryce Himebaugh Indiana University September 2, 2016 Geoffrey Brown, Bryce Himebaugh 2015 September 2, 2016 1 / 15 Outline Preserving Registers Saving and Restoring Registers

More information

Assembly Programming (III)

Assembly Programming (III) Assembly Programming (III) Lecturer: Annie Guo S2, 2006 COMP9032 Week6 1 Lecture Overview Stack and stack operations Functions and function calls Calling conventions S2, 2006 COMP9032 Week6 2 What is stack?

More information

6.001 Recitation 23: Register Machines and Stack Frames

6.001 Recitation 23: Register Machines and Stack Frames 6.001 Recitation 23: Register achines and Stack Frames RI: Gerald Dalley, dalleyg@mit.edu, 8 ay 2007 http://people.csail.mit.edu/dalleyg/6.001/sp2007/ iscellany apply: See the IT Scheme documentation for

More information

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011 More C++ David Chisnall March 17, 2011 Exceptions A more fashionable goto Provides a second way of sending an error condition up the stack until it can be handled Lets intervening stack frames ignore errors

More information

An Evil Copy: How the Loader Betrays You

An Evil Copy: How the Loader Betrays You An Evil Copy: How the Loader Betrays You Xinyang Ge 1,3, Mathias Payer 2 and Trent Jaeger 3 Microsoft Research 1 Purdue University 2 Penn State University 3 Page 1 Problem: A Motivating Example // main.c

More information

Your first C and C++ programs

Your first C and C++ programs Your first C and C++ programs Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++,

More information

Assembly Programming (III) Lecturer: Sri Parameswaran Notes by: Annie Guo Dr. Hui Wu

Assembly Programming (III) Lecturer: Sri Parameswaran Notes by: Annie Guo Dr. Hui Wu Assembly Programming (III) Lecturer: Sri Parameswaran Notes by: Annie Guo Dr. Hui Wu 1 Lecture overview Stack and stack operations Functions and function calls Calling conventions 2 Stack What is stack?

More information

Object Oriented Programming in C++

Object Oriented Programming in C++ Object Oriented Programming in C++ Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague Lecture 11 B3B36PRG C Programming Language Jan Faigl,

More information

Chapter 17 Recursion

Chapter 17 Recursion Chapter 17 Recursion What is Recursion? A recursive function is one that solves its task by calling itself on smaller pieces of data. Similar to recurrence function in mathematics. Like iteration -- can

More information

Scope: Global and Local. Concept of Scope of Variable

Scope: Global and Local. Concept of Scope of Variable Concept of Scope of Variable : Computer Architecture I Instructor: Prof. Bhagi Narahari Dept. of Computer Science Course URL: www.seas.gwu.edu/~bhagiweb/cs135/ In assembly, who has access to a memory location/variable?

More information

CSE 303: Concepts and Tools for Software Development

CSE 303: Concepts and Tools for Software Development CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects

More information

Please refer to the turn-in procedure document on the website for instructions on the turn-in procedure.

Please refer to the turn-in procedure document on the website for instructions on the turn-in procedure. 1 CSE 131 Winter 2013 Compiler Project #2 -- Code Generation Due Date: Friday, March 15 th 2013 @ 11:59pm Disclaimer This handout is not perfect; corrections may be made. Updates and major clarifications

More information

CSCI 350: Getting Started with C Written by: Stephen Tsung-Han Sher June 12, 2016

CSCI 350: Getting Started with C Written by: Stephen Tsung-Han Sher June 12, 2016 CSCI 350: Getting Started with C Written by: Stephen Tsung-Han Sher June 12, 2016 Introduction As you have been informed, your work with Pintos will be almost exclusively with C. Since you have taken CSCI-103

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

CSE 333 Lecture smart pointers

CSE 333 Lecture smart pointers CSE 333 Lecture 14 -- smart pointers Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington Administrivia New exercise out today, due Wednesday morning Exam Friday

More information

C++ Programming Lecture 7 Software Engineering Group

C++ Programming Lecture 7 Software Engineering Group C++ Programming Lecture 7 Software Engineering Group Philipp D. Schubert Contents 1. Template metaprogramming 2. Variadic template arguments 3. Smart pointer Template metaprogramming Template metaprogramming

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14 BIL 104E Introduction to Scientific and Engineering Computing Lecture 14 Because each C program starts at its main() function, information is usually passed to the main() function via command-line arguments.

More information

Calling Conventions. See P&H 2.8 and Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University

Calling Conventions. See P&H 2.8 and Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University Calling Conventions See P&H 2.8 and 2.12 Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University Goals for Today Review: Calling Conventions call a routine (i.e. transfer control to

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: February 28, 2018 at 06:32 CS429 Slideset 9: 1 Mechanisms in Procedures

More information

18-600: Recitation #4 Exploits

18-600: Recitation #4 Exploits 18-600: Recitation #4 Exploits 20th September 2016 Agenda More x86-64 assembly Buffer Overflow Attack Return Oriented Programming Attack 3 Recap: x86-64: Register Conventions Arguments passed in registers:

More information

C to Assembly SPEED LIMIT LECTURE Performance Engineering of Software Systems. I-Ting Angelina Lee. September 13, 2012

C to Assembly SPEED LIMIT LECTURE Performance Engineering of Software Systems. I-Ting Angelina Lee. September 13, 2012 6.172 Performance Engineering of Software Systems SPEED LIMIT PER ORDER OF 6.172 LECTURE 3 C to Assembly I-Ting Angelina Lee September 13, 2012 2012 Charles E. Leiserson and I-Ting Angelina Lee 1 Bugs

More information

C++ Programming Lecture 7 Software Engineering Group

C++ Programming Lecture 7 Software Engineering Group C++ Programming Lecture 7 Software Engineering Group Philipp D. Schubert Contents 1. Template metaprogramming 2. Variadic template arguments 3. Smart pointer Template metaprogramming Template metaprogramming

More information

Functions. Ray Seyfarth. August 4, Bit Intel Assembly Language c 2011 Ray Seyfarth

Functions. Ray Seyfarth. August 4, Bit Intel Assembly Language c 2011 Ray Seyfarth Functions Ray Seyfarth August 4, 2011 Functions We will write C compatible function C++ can also call C functions using extern "C" {...} It is generally not sensible to write complete assembly programs

More information

Improve your C++! John Richardson. Lab Study Meeting 2013

Improve your C++! John Richardson. Lab Study Meeting 2013 Improve your C++! John Richardson Lab Study Meeting 2013 Objectives How do I use the standard library correctly? What is C++11? Should I use it? Skills for debugging...? What kind of profiling is possible

More information

18-600: Recitation #4 Exploits (Attack Lab)

18-600: Recitation #4 Exploits (Attack Lab) 18-600: Recitation #4 Exploits (Attack Lab) September 19th, 2017 Announcements Some students have triggered the bomb multiple times Use breakpoints for explode_bomb() Attack lab will be released on Sep.

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010 CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)

More information

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information

Ftrace Kernel Hooks: More than just tracing. Presenter: Steven Rostedt Red Hat

Ftrace Kernel Hooks: More than just tracing. Presenter: Steven Rostedt Red Hat Ftrace Kernel Hooks: More than just tracing Presenter: Steven Rostedt rostedt@goodmis.org Red Hat Ftrace Function Hooks Function Tracer Function Graph Tracer Function Profiler Stack Tracer Kprobes Uprobes

More information

CSE 333 Lecture smart pointers

CSE 333 Lecture smart pointers CSE 333 Lecture 14 -- smart pointers Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia Midterm Friday - Review in sections this week - Closed book; topic list

More information

Topics. bool and string types input/output library functions comments memory allocation templates classes

Topics. bool and string types input/output library functions comments memory allocation templates classes C++ Primer C++ is a major extension of c. It is similar to Java. The lectures in this course use pseudo-code (not C++). The textbook contains C++. The labs involve C++ programming. This lecture covers

More information

Homework 4. Any questions?

Homework 4. Any questions? CSE333 SECTION 8 Homework 4 Any questions? STL Standard Template Library Has many pre-build container classes STL containers store by value, not by reference Should try to use this as much as possible

More information

CSC 1600 Memory Layout for Unix Processes"

CSC 1600 Memory Layout for Unix Processes CSC 16 Memory Layout for Unix Processes" 1 Lecture Goals" Behind the scenes of running a program" Code, executable, and process" Memory layout for UNIX processes, and relationship to C" : code and constant

More information

CSE Lecture In Class Example Handout

CSE Lecture In Class Example Handout CSE 30321 Lecture 07-09 In Class Example Handout Part A: A Simple, MIPS-based Procedure: Swap Procedure Example: Let s write the MIPS code for the following statement (and function call): if (A[i] > A

More information

System Software Assignment 1 Runtime Support for Procedures

System Software Assignment 1 Runtime Support for Procedures System Software Assignment 1 Runtime Support for Procedures Exercise 1: Nested procedures Some programming languages like Oberon and Pascal support nested procedures. 1. Find a run-time structure for such

More information

238P: Operating Systems. Lecture 3: Calling conventions. Anton Burtsev October, 2018

238P: Operating Systems. Lecture 3: Calling conventions. Anton Burtsev October, 2018 238P: Operating Systems Lecture 3: Calling conventions Anton Burtsev October, 2018 What does CPU do internally? (Remember Lecture 01 - Introduction?) CPU execution loop CPU repeatedly reads instructions

More information

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization Spring 2013 CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization Kitty Reeves TWRF 8:00-8:55am 1 Compiler Drivers = GCC When you invoke GCC, it normally does preprocessing,

More information

Mechanisms in Procedures. CS429: Computer Organization and Architecture. x86-64 Stack. x86-64 Stack Pushing

Mechanisms in Procedures. CS429: Computer Organization and Architecture. x86-64 Stack. x86-64 Stack Pushing CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: February 28, 2018 at 06:32 Mechanisms in Procedures Passing Control

More information

143A: Principles of Operating Systems. Lecture 4: Calling conventions. Anton Burtsev October, 2017

143A: Principles of Operating Systems. Lecture 4: Calling conventions. Anton Burtsev October, 2017 143A: Principles of Operating Systems Lecture 4: Calling conventions Anton Burtsev October, 2017 Recap from last time Stack and procedure calls What is stack? Stack It's just a region of memory Pointed

More information

Compiler Drivers = GCC

Compiler Drivers = GCC Compiler Drivers = GCC When you invoke GCC, it normally does preprocessing, compilation, assembly and linking, as needed, on behalf of the user accepts options and file names as operands % gcc O1 -g -o

More information

Machine Programming 3: Procedures

Machine Programming 3: Procedures Machine Programming 3: Procedures CS61, Lecture 5 Prof. Stephen Chong September 15, 2011 Announcements Assignment 2 (Binary bomb) due next week If you haven t yet please create a VM to make sure the infrastructure

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

LLVM code generation and implementation of nested functions for the SimpliC language

LLVM code generation and implementation of nested functions for the SimpliC language LLVM code generation and implementation of nested functions for the SimpliC language Oscar Legetth Lunds University dat12ole@student.lth.se Gustav Svensson Lunds University dat12gs1@student.lth.se Abstract

More information

C++ internals. Francis Visoiu Mistrih - 1 / 41

C++ internals. Francis Visoiu Mistrih - 1 / 41 C++ internals Francis Visoiu Mistrih - francis@lse.epita.fr 1 / 41 Language features Standard Standard library ISO C++ Committee 2 / 41 ABI Specifies an interface between object files Implementation details:

More information

Stream Computing using Brook+

Stream Computing using Brook+ Stream Computing using Brook+ School of Electrical Engineering and Computer Science University of Central Florida Slides courtesy of P. Bhaniramka Outline Overview of Brook+ Brook+ Software Architecture

More information

CSE351 Autumn 2012 Midterm Exam (5 Nov 2012)

CSE351 Autumn 2012 Midterm Exam (5 Nov 2012) CSE351 Autumn 2012 Midterm Exam (5 Nov 2012) Please read through the entire examination first! We designed this exam so that it can be completed in 50 minutes and, hopefully, this estimate will prove to

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++ CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many

More information

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine

More information

The Nifty Way to Call Hell from Heaven ANDREAS LÖSCHER AND KONSTANTINOS SAGONAS UPPSAL A UNIVERSIT Y

The Nifty Way to Call Hell from Heaven ANDREAS LÖSCHER AND KONSTANTINOS SAGONAS UPPSAL A UNIVERSIT Y The Nifty Way to Call Hell from Heaven ANDREAS LÖSCHER AND KONSTANTINOS SAGONAS UPPSAL A UNIVERSIT Y There is a lot of C Code out there C Erlang Source: www.langpop.com (Normalized statistic) How can we

More information

See P&H 2.8 and 2.12, and A.5-6. Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University

See P&H 2.8 and 2.12, and A.5-6. Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University See P&H 2.8 and 2.12, and A.5-6 Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University Upcoming agenda PA1 due yesterday PA2 available and discussed during lab section this week

More information

Machine Program: Procedure. Zhaoguo Wang

Machine Program: Procedure. Zhaoguo Wang Machine Program: Procedure Zhaoguo Wang Requirements of procedure calls? P() { y = Q(x); y++; 1. Passing control int Q(int i) { int t, z; return z; Requirements of procedure calls? P() { y = Q(x); y++;

More information

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Hakim Weatherspoon CS 3410 Computer Science Cornell University Hakim Weatherspoon CS 3410 Computer Science Cornell University The slides are the product of many rounds of teaching CS 3410 by Professors Weatherspoon, Bala, Bracy, McKee, and Sirer. compute jump/branch

More information

Security Workshop HTS. LSE Team. February 3rd, 2016 EPITA / 40

Security Workshop HTS. LSE Team. February 3rd, 2016 EPITA / 40 Security Workshop HTS LSE Team EPITA 2018 February 3rd, 2016 1 / 40 Introduction What is this talk about? Presentation of some basic memory corruption bugs Presentation of some simple protections Writing

More information

Lecture 3: C Programm

Lecture 3: C Programm 0 3 E CS 1 Lecture 3: C Programm ing Reading Quiz Note the intimidating red border! 2 A variable is: A. an area in memory that is reserved at run time to hold a value of particular type B. an area in memory

More information

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27 Procedure Calls Young W. Lim 2016-11-05 Sat Young W. Lim Procedure Calls 2016-11-05 Sat 1 / 27 Outline 1 Introduction References Stack Background Transferring Control Register Usage Conventions Procedure

More information

Arguments and Return Values. EE 109 Unit 16 Stack Frames. Assembly & HLL s. Arguments and Return Values

Arguments and Return Values. EE 109 Unit 16 Stack Frames. Assembly & HLL s. Arguments and Return Values 1 Arguments and Return Values 2 EE 109 Unit 16 Stack Frames MIPS convention is to use certain registers for this task used to pass up to 4 arguments. If more arguments, use the stack used for return value

More information

CMSC 313 Lecture 12 [draft] How C functions pass parameters

CMSC 313 Lecture 12 [draft] How C functions pass parameters CMSC 313 Lecture 12 [draft] How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP removes an

More information

Layers of Abstraction CS 3330: C. Compilation Steps. What s in those files? Higher-level language: C. Assembly: X86-64.

Layers of Abstraction CS 3330: C. Compilation Steps. What s in those files? Higher-level language: C. Assembly: X86-64. Layers of Abstraction CS 3330: C 25 August 2016 x += y add %rbx, %rax 60 03 Higher-level language: C Assembly: X86-64 Machine code: Y86 (we ll talk later) Logic and Registers 1 2 Compilation Steps compile:

More information

Procedure Call. Procedure Call CS 217. Involves following actions

Procedure Call. Procedure Call CS 217. Involves following actions Procedure Call CS 217 Procedure Call Involves following actions pass arguments save a return address transfer control to callee transfer control back to caller return results int add(int a, int b) { return

More information

Chapter 17 Recursion

Chapter 17 Recursion Chapter 17 Recursion What is Recursion? A recursive function is one that solves its task by calling itself on smaller pieces of data. Similar to recurrence relation in mathematics. Sometimes recursion

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 4 LAST TIME Enhanced our processor design in several ways Added branching support Allows programs where work is proportional to the input values

More information

C++14 Reflections Without Macros, Markup nor External Tooling

C++14 Reflections Without Macros, Markup nor External Tooling C++14 Reflections Without Macros, Markup nor External Tooling Metaprogramming Tricks for POD Types Antony Polukhin Boost libraries maintainer (DLL, LexicalCast, Any, TypeIndex, Conversion) + Boost.CircularBuffer,

More information

C and C++ 7. Exceptions Templates. Alan Mycroft

C and C++ 7. Exceptions Templates. Alan Mycroft C and C++ 7. Exceptions Templates Alan Mycroft University of Cambridge (heavily based on previous years notes thanks to Alastair Beresford and Andrew Moore) Michaelmas Term 2013 2014 1 / 20 Exceptions

More information

struct Buffer { Buffer(int s) { buf = new char[s]; } ~Buffer() { delete [] buf; } char *buf; };

struct Buffer { Buffer(int s) { buf = new char[s]; } ~Buffer() { delete [] buf; } char *buf; }; struct Buffer { Buffer(int s) { buf = new char[s]; ~Buffer() { delete [] buf; char *buf; ; struct FBuffer : public Buffer { FBuffer(int s) : Buffer(s) { f = fopen("file", "w"); ~FBuffer() { fclose(f);

More information

Calling Conventions. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See P&H 2.8 and 2.12

Calling Conventions. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See P&H 2.8 and 2.12 Calling Conventions Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H 2.8 and 2.12 Goals for Today Calling Convention for Procedure Calls Enable code to be reused by allowing

More information

PROGRAMMING IN C++ KAUSIK DATTA 18-Oct-2017

PROGRAMMING IN C++ KAUSIK DATTA 18-Oct-2017 PROGRAMMING IN C++ KAUSIK DATTA 18-Oct-2017 Objectives Recap C Differences between C and C++ IO Variable Declaration Standard Library Introduction of C++ Feature : Class Programming in C++ 2 Recap C Built

More information

syscall_intercept A user space library for intercepting system calls Author Name, Company Krzysztof Czuryło, Intel

syscall_intercept A user space library for intercepting system calls Author Name, Company Krzysztof Czuryło, Intel Talk syscall_intercept Title Here A user space library for intercepting system calls Author Name, Company Krzysztof Czuryło, Intel What it is? Provides a low-level interface for hooking Linux system calls

More information

C++ Tutorial AM 225. Dan Fortunato

C++ Tutorial AM 225. Dan Fortunato C++ Tutorial AM 225 Dan Fortunato Anatomy of a C++ program A program begins execution in the main() function, which is called automatically when the program is run. Code from external libraries can be

More information

Intel assembly language using gcc

Intel assembly language using gcc QOTD Intel assembly language using gcc Assembly language programming is difficult. Make no mistake about that. It is not for wimps and weaklings. - Tanenbaum s 6th, page 519 These notes are a supplement

More information

What is Recursion? Chapter 17 Recursion. Executing RunningSum. High-Level Example: Binary Search

What is Recursion? Chapter 17 Recursion. Executing RunningSum. High-Level Example: Binary Search Chapter 17 Recursion Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University! A recursive function is one that solves its task by calling

More information

CS 318 Principles of Operating Systems

CS 318 Principles of Operating Systems CS 318 Principles of Operating Systems Fall 2017 Lecture 5: Thread Ryan Huang Administrivia HW1 solution released on Piazza resources Lab 0 grading - In progress - Cheating policy Lab 1 review session

More information

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e CPSC 213 Introduction to Computer Systems Unit 1e Procedures and the Stack 1 Reading Companion 2.8 Textbook Procedures, Out-of-Bounds Memory References and Buffer Overflows 3.7, 3.12 2 Local Variables

More information

Copyright The McGraw-Hill Companies, Inc. Persion required for reproduction or display. What is Recursion?

Copyright The McGraw-Hill Companies, Inc. Persion required for reproduction or display. What is Recursion? Chapter 17 Recursion Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University! A recursive function is one that solves its task by calling

More information

Suppose that you want to use two libraries with a bunch of useful classes and functions, but some names collide:

Suppose that you want to use two libraries with a bunch of useful classes and functions, but some names collide: COMP151 Namespaces Motivation [comp151] 1 Suppose that you want to use two libraries with a bunch of useful classes and functions, but some names collide: // File: gnutils.h class Stack {... ; class Some

More information

6.S096 Lecture 4 Style and Structure

6.S096 Lecture 4 Style and Structure 6.S096 Lecture 4 Style and Structure Transition from C to C++ Andre Kessler Andre Kessler 6.S096 Lecture 4 Style and Structure 1 / 24 Outline 1 Assignment Recap 2 Headers and multiple files 3 Coding style

More information

Introduction to clang tools scan-build and clang-tidy.

Introduction to clang tools scan-build and clang-tidy. Introduction to clang tools scan-build and clang-tidy. Jan 5 th, 2017 www.quoininc.com Boston Charlotte New York Washington DC Managua Intro to clang tools Scan-build static analyzer. Clang-tidy static

More information

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED Outline - Function Definitions - Function Prototypes - Data

More information

Introduction to C++11 and its use inside Qt

Introduction to C++11 and its use inside Qt Introduction to C++11 and its use inside Qt Olivier Goffart February 2013 1/43 Introduction to C++11 and its use inside Qt About Me http://woboq.com http://code.woboq.org 2/43 Introduction to C++11 and

More information

CS 376b Computer Vision

CS 376b Computer Vision CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves

More information

Topic 6: A Quick Intro To C

Topic 6: A Quick Intro To C Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions

More information

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements Welcome to MCS 360 1 About the Course content expectations 2 our first C++ program using g++ input and output streams the namespace std 3 Greatest Common Divisor Euclid s algorithm the while and do-while

More information

Why C++? C vs. C Design goals of C++ C vs. C++ - 2

Why C++? C vs. C Design goals of C++ C vs. C++ - 2 Why C++? C vs. C++ - 1 Popular and relevant (used in nearly every application domain): end-user applications (Word, Excel, PowerPoint, Photoshop, Acrobat, Quicken, games) operating systems (Windows 9x,

More information

Bruce Merry. IOI Training Dec 2013

Bruce Merry. IOI Training Dec 2013 IOI Training Dec 2013 Outline 1 2 3 Outline 1 2 3 You can check that something is true using assert: #include int main() { assert(1 == 2); } Output: test_assert: test_assert.cpp:4: int main():

More information

Anne Bracy CS 3410 Computer Science Cornell University

Anne Bracy CS 3410 Computer Science Cornell University Anne Bracy CS 3410 Computer Science Cornell University The slides are the product of many rounds of teaching CS 3410 by Professors Weatherspoon, Bala, Bracy, McKee, and Sirer. See P&H 2.8 and 2.12, and

More information

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e CPSC 213 Introduction to Computer Systems Unit 1e Procedures and the Stack 1 Readings for Next 3 Lectures Textbook Procedures - 3.7 Out-of-Bounds Memory References and Buffer Overflow - 3.12 2 Local Variables

More information

The Stack & Procedures

The Stack & Procedures The Stack & Procedures CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Homework 2 due

More information

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University (5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University Key Concepts 2 Object-Oriented Design Object-Oriented Programming

More information

CS 318 Principles of Operating Systems

CS 318 Principles of Operating Systems CS 318 Principles of Operating Systems Fall 2018 Lecture 5: Thread Ryan Huang Slides adapted from Geoff Voelker s and David Mazières lectures Administrivia Lab 0 grading in progress Lab 1 review session

More information

Important From Last Time

Important From Last Time Important From Last Time Embedded C Pros and cons Macros and how to avoid them Intrinsics Interrupt syntax Inline assembly Today Advanced C What C programs mean How to create C programs that mean nothing

More information

Introduction to C++ Introduction to C++ 1

Introduction to C++ Introduction to C++ 1 1 What Is C++? (Mostly) an extension of C to include: Classes Templates Inheritance and Multiple Inheritance Function and Operator Overloading New (and better) Standard Library References and Reference

More information

Data Structures And Algorithms

Data Structures And Algorithms Data Structures And Algorithms Recursion Eng. Anis Nazer First Semester 2016-2017 Recursion Recursion: to define something in terms of itself Example: factorial n!={ 1 n=0 n (n 1)! n>0 Recursion Example:

More information

Areas for growth: I love feedback

Areas for growth: I love feedback Assembly part 2 1 Areas for growth: I love feedback Speed, I will go slower. Clarity. I will take time to explain everything on the slides. Feedback. I give more Kahoot questions and explain each answer.

More information

Stack Debugging. Young W. Lim Sat. Young W. Lim Stack Debugging Sat 1 / 40

Stack Debugging. Young W. Lim Sat. Young W. Lim Stack Debugging Sat 1 / 40 Stack Debugging Young W. Lim 2017-07-22 Sat Young W. Lim Stack Debugging 2017-07-22 Sat 1 / 40 Outline 1 Introduction References Compiling to IA32 Assembly Checking /proc//maps file Checking Stack

More information

C Functions. Object created and destroyed within its block auto: default for local variables

C Functions. Object created and destroyed within its block auto: default for local variables 1 5 C Functions 5.12 Storage Classes 2 Automatic storage Object created and destroyed within its block auto: default for local variables auto double x, y; Static storage Variables exist for entire program

More information

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING PREVIEW SLIDES 16, SPRING 2013

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING PREVIEW SLIDES 16, SPRING 2013 CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING PREVIEW SLIDES 16, SPRING 2013 CONST POINTERS CONST POINTERS 4 ways to declare pointers in combination with const:!! int *ptr! const int *ptr!

More information

Red Hat Developer Tools

Red Hat Developer Tools Red Hat Developer Tools 2018.4 Using Clang and LLVM Toolset Installing and Using Clang and LLVM Toolset Last Updated: 2018-11-29 Red Hat Developer Tools 2018.4 Using Clang and LLVM Toolset Installing

More information

Fosdem perf status on ARM and ARM64

Fosdem perf status on ARM and ARM64 Fosdem 2015 perf status on ARM and ARM64 jean.pihet@newoldbits.com 1 Contents Introduction Scope of the presentation Supported tools Call stack unwinding General Methods Corner cases ARM and ARM64 support

More information