Skip to content

Instantly share code, notes, and snippets.

@theidexisted
Created May 29, 2015 00:12
Show Gist options
  • Save theidexisted/f70203836b3d761ee127 to your computer and use it in GitHub Desktop.
Save theidexisted/f70203836b3d761ee127 to your computer and use it in GitHub Desktop.
#include <iostream>
class Base {
public:
virtual void DoCall() { std::cout << "base docall" << std::endl; }
void Display() { DoCall(); }
};
class Derived : public Base {
public:
Derived() { int i = 0; }
virtual void DoCall() { std::cout << "derived docall" << std::endl; }
};
int main() {
Derived d;
d.Display();
return 0;
}
/*
0x40093d <main()> push %rbp │
│0x40093e <main()+1> mov %rsp,%rbp │
│0x400941 <main()+4> sub $0x10,%rsp │
B+ │0x400945 <main()+8> lea -0x10(%rbp),%rax │
│0x400949 <main()+12> mov %rax,%rdi │
│0x40094c <main()+15> callq 0x400a18 <Derived::Derived()> │
│0x400951 <main()+20> lea -0x10(%rbp),%rax │
> │0x400955 <main()+24> mov %rax,%rdi │
│0x400958 <main()+27> callq 0x4009e0 <Base::Display()> │
│0x40095d <main()+32> mov $0x0,%eax
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
>│0x4009e0 <Base::Display()> push %rbp │
│0x4009e1 <Base::Display()+1> mov %rsp,%rbp │
│0x4009e4 <Base::Display()+4> sub $0x10,%rsp │
│0x4009e8 <Base::Display()+8> mov %rdi,-0x8(%rbp) │
│0x4009ec <Base::Display()+12> mov -0x8(%rbp),%rax │
│0x4009f0 <Base::Display()+16> mov (%rax),%rax │
│0x4009f3 <Base::Display()+19> mov (%rax),%rax │
│0x4009f6 <Base::Display()+22> mov -0x8(%rbp),%rdx │
│0x4009fa <Base::Display()+26> mov %rdx,%rdi │
│0x4009fd <Base::Display()+29> callq *%rax
*/
@theidexisted
Copy link
Author

where
#0 Derived::DoCall (this=0x400a30 Derived::Derived()+24) at template-method.cpp:13
#1 0x00000000004009ff in Base::Display (this=0x7fffffffdeb0) at template-method.cpp:6
#2 0x000000000040095d in main () at template-method.cpp:18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment