Bug 1224 - Debugger steps over code which is not executed
Summary: Debugger steps over code which is not executed
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Linux
: High normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2011-10-04 09:10 UTC by Marek Safar
Modified: 2012-02-07 05:47 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Marek Safar 2011-10-04 09:10:46 UTC
using System;

namespace test9
	class MainClass
		public static int Main (string[] args)
			try {
				bool b = true;
				if (!b)		// Set a breakpoint here and hit F10 (Step Over)
					return 3;  // Debugger continues here and that's wrong
			} finally {
			return 0;
Comment 1 Jeffrey Stedfast 2011-11-28 18:16:15 UTC
Visual Studio continues at the "}" after "return 3;"

Anyways, this seems like a SoftDebugger issue.
Comment 2 Zoltan Varga 2011-11-29 13:31:24 UTC
This is a problem with the line number info emitted by mcs.
The method looks like the following:

	.try { // 0
	  IL_0000:  ldc.i4.1 
	  IL_0001:  stloc.0 
	  IL_0002:  ldloc.0 
	  IL_0003:  brtrue IL_000f

	  IL_0008:  ldc.i4.3 
	  IL_0009:  stloc.1 
	  IL_000a:  leave IL_0017

	  IL_000f:  leave IL_0015

	} // end .try 0
	finally  { // 0
	  IL_0014:  endfinally 
	} // end handler 0
	IL_0015:  ldc.i4.0 
	IL_0016:  ret 
	IL_0017:  ldloc.1 
	IL_0018:  ret 

The line number table is the following:

IL0 -> 8
IL0 -> 9
IL0 -> 9
IL0 -> 10
IL2 -> 11
IL8 -> 12
IL14 -> 13
IL15 -> 16
IL17 -> 17
IL17 -> 17

The Step Over goes the IL offset f, which has no matching line number, so the debugger chooses the last one, 8, which has line number 12 associated with it.
Comment 3 Marek Safar 2012-02-07 05:47:54 UTC
Fixed in master