Avinash Kumar
Avinash Kumar

Reputation: 777

Cannot evaluate function -- may be inlined

I wrote a function similar to this:

class abc {
    private :
    int m_var ;
    public :
    int func() { return m_var ; }
};

When I try to print the func() using an abc object pointer in gdb, it is giving the error:

**Cannot evaluate function -- may be inlined**

How to can I print values from an inlined function?

Upvotes: 39

Views: 32735

Answers (2)

nicky_zs
nicky_zs

Reputation: 3773

You got this error because you put func's definition in the class body and it's small enough, so, first, the compiler inlined this function ---- that means, the compile will substitute all the appearance of this function's call with its definition, and no definition of this function will be in the executable file. And, second, you didn't really call that function in your program, so in fact, this function never exist in your final executable file!

To solve that:

  1. You can put the definition of func outside the class body.
  2. Call func in your program anywhere.

Upvotes: 25

Scott Lawrence
Scott Lawrence

Reputation: 1073

When the function is inlined, it doesn't appear as a proper symbol in the executable, so there's no way for gdb to execute it. The simplest thing to do is probably to compile with function inlining disabled, either by -fno-inline-functions or (still better) -O0.

Upvotes: 18

Related Questions