Is it possible to find out which lines of source code were executed?

I am debugging C / C ++ code using Visual Studio. There is a loop called 10,000 times, and in one of the interactions, at the end of the loop, an error occurs because the program is trying to access the value N + 1 of an array of length N. I want to go back and debug the origin of the error, and I wonder if Visual Studio in debug mode to visually display or say which lines of source code were executed. Then it would be easier to find a mistake. Does anyone know if this is possible?

If this is not possible for VS, what other approaches can do this?

thank

EDIT: I also wonder if this can be done with any other IDE (Eclipse, Xcode, command line, etc.).

+3
source share
9 answers

put a conditional breakpoint where access to the array occurs. Thus, your program will be divided into N + 1st access, and you will have a full stack trace for work.

+9
source

If you know how many iterations you have to do (in this case 10,000), you can insert the hit counter into the loop for n (one before the error), and then do the next iteration using Intellisense to give you information about what might cause Problems?

alt text

Do you have a code that we can see that can help us help?

+6
source

- , .

if(somethingThatMightNotHappen) {
    printf("This happened.\n");
    ...
}
+1

, VS Debugger .

. , N- ( N-1- - ) (, idx > 1000) .

+1

Visual Studio, , , , .

, , , (, 10) . , , , , , , .

, , , , . :

  • ,
  • ,
  • ,
  • 1

( ) - .

0

unit test , . unit test, , . , .

, unit test ( ), " " " ". , , , .

Nifty, eh?

++ , ++, . , , . , " ". , .

0

! try, catch- .

0

, , ++, ScottGu .

I assume that you already know about this, but it sounds to me as if you are looking for the call stack tab in debug mode. You can use the scoring mode or conditional debugging mode in a loop, and when an error occurs, you return down the call stack from where the data came from and set some breakpoints. Then you can run your program again and check how the data is created.

0
source

Source: https://habr.com/ru/post/1765857/


All Articles