anonymous38653
anonymous38653

Reputation: 403

how to know which statement got executed while debugging

In my code, sometimes when multiple function calls can be made in a single line. I do not get which function is running right now. for example-

int foo(){
    if(m==0||n==0) return 0;
    return std::max(foo(a,b,m-1,n),foo(a,b,m,n-1));
}

While debugging, understanding which function was called based on all parameters becomes clumsy and sometimes doesn't even work. Is there any option to see processes within a line while debugging. I use codelite IDE.

Upvotes: 0

Views: 59

Answers (2)

Code-Apprentice
Code-Apprentice

Reputation: 83517

When you are having difficulty debugging code, it usually means you are doing too much in a single line. This means you should split a complex statement into multiple statements. In your case, something like this:

int foo(){
    if(m==0||n==0) return 0;
    auto a = foo(a,b,m-1,n);
    auto b = foo(a,b,m,n-1);
    return std::max(a, b);
}

Upvotes: 3

Alex Guteniev
Alex Guteniev

Reputation: 13634

Alternatives to the current answer could be:

  • Stepping into statements. Not likely to work if foo calls are inlined
  • Debugging disassembly

These alternatives may not work, but if when they work, they allow debugging unaltered code.

Upvotes: 1

Related Questions