简体   繁体   中英

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.

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);
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM