Author Topic: Debug: go back to line before  (Read 8666 times)

Offline hqt

  • Multiple posting newcomer
  • *
  • Posts: 16
Debug: go back to line before
« on: September 09, 2011, 10:08:35 am »
I'm using Code::Block nightly built version, and I have a small problem when I debug a program.
for example, I debug at line 10: a function call, and I hit F7, it will goto line 11 (of course, I don't want :( because I want to go through this function to view how it work by Shift+F7) So, I must start again from beginning function, and go through some loop to go here again :(-->and It's too slow.
So, I don't know how can back again 1 line. It mean,it will come back to line 10 again(and of course, no variable change :) )

so who know this problem, please help me please.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Debug: go back to line before
« Reply #1 on: September 09, 2011, 10:17:18 am »
Show us the sample code. Also, Could you use more formal items like "step into" "step" instead of the short-cut key name.
I have different short-cut key mapping, so I event don't know what "F7" means.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline hqt

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Debug: go back to line before
« Reply #2 on: September 09, 2011, 10:44:17 am »
Oh, I'm sorry so much, because I often use default shortcut, so I rarely think there some people different from me.
So, this is my problem:
Code
int main(){
            For(i=1;i<=n;i++){
                 ...... some line of code;
                 Function();
               printf();
                ....... some line of code;
            }
}
I debug at line Function(), and I want to go through this function-> press "step into". But I have pressed "next line" (But I don't want to), so I will go to line "printf" ---> so I cannot see what  "function" do (and most of case, It have wrong answer, so I need to view it carefully).
So, the unique solution that I know is: I will restart debug, and debug again from int main(). It seem easy, but if my program run right from (i=1-->10), and wrong when i=11, so I must go through tenth times :-O

that's my problem, hope that clearer for you.
so, thanks for all :)


Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Debug: go back to line before
« Reply #3 on: September 09, 2011, 11:09:56 am »
Code
Menu->debug->Set Next Statement.
This will help you. Mostly you don't need this command, you can set a bp in the Function body to see whether something is wrong.

BTW: This command may not work correctly or will crash your app, because you directly set the PC pointer. Take care!!!
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Debug: go back to line before
« Reply #4 on: September 09, 2011, 09:59:21 pm »
So, I don't know how can back again 1 line. It mean,it will come back to line 10 again(and of course, no variable change :) )
"no variable change" <- this is almost impossible.

Probably you can try command line gdb + reversed debugging (I think it works only on linux and it is quite slow)

For other sane usages "set next statements" is quite good, but you need debugger's branch nightly.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]