Bug 45021 - Debugger won't stop at breakpoint in partial class in PCL.
Summary: Debugger won't stop at breakpoint in partial class in PCL.
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Cecil (show other bugs)
Version: 4.8.0 (C9)
Hardware: PC Mac OS
: High normal
Target Milestone: Untriaged
Assignee: Jb Evain
URL:
: 44515 46704 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-10-04 18:29 UTC by Jon Lipsky
Modified: 2016-12-20 04:00 UTC (History)
9 users (show)

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


Attachments
A sample project to reproduce the issue. (12.24 KB, application/zip)
2016-10-04 18:29 UTC, Jon Lipsky
Details


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:
Status:
RESOLVED FIXED

Description Jon Lipsky 2016-10-04 18:29:51 UTC
Created attachment 17873 [details]
A sample project to reproduce the issue.

I have found an issue where the Xamarin Studio debugger will not break at a breakpoint set within a method in a partial class.  In my scenario, a Xamarin.iOS project was calling a method in a static partial class within a PCL.  That method would then call a second method in the same partial class, but in another file.  If you set breakpoint in that second method, it will never break even though the code executes.  If I move that method into the first file (the same as the first method), then it can break in that method.

This issue only happens in Xamarin Studio.  If I run the same sample in Visual Studio, I am able to stop at the breakpoints.

I have attached a sample which can be used to reproduce the issue.  Set a breakpoint in the "MyAsyncAction1" method of the "TestService" class in the "BreakpointTest.Portable" project.  When you run the sample, press the button titled "Press Me 1" which will call that method.  The breakpoint won't be hit. 

This screen capture demonstrates the issue:
https://elevenworks.box.com/s/3yjcp48kktu0gdjju51n8pd0fjw15c8n




Xamarin Studio Enterprise
Version 6.1.1 (build 15)
Installation UUID: 2d44ddb9-f3de-41a5-830c-84a513b818ba
Runtime:
	Mono 4.6.1 (mono-4.6.0-branch-c8sr0/abb06f1) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406010003

NuGet
Version: 3.4.3.0

Xamarin.Profiler
Version: 0.34.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Xamarin.Android
Version: 7.0.1.2 (Xamarin Enterprise)
Android SDK: /Users/jlipsky/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 25.1.1
SDK Platform Tools Version: 23.1
SDK Build Tools Version: 23.0.3

Java SDK: /usr
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Apple Developer Tools
Xcode 8.0 (11246)
Build 8A218a

Xamarin.iOS
Version: 10.0.1.8 (Xamarin Enterprise)
Hash: 3983064
Branch: cycle8-sr0-xi
Build date: 2016-09-23 15:34:54-0400

Xamarin.Mac
Version: 2.10.0.103 (Xamarin Enterprise)

Xamarin Inspector
Version: 0.8.1.0
Hash: 95792d1
Branch: master
Build date: Thu May 12 22:20:04 UTC 2016

Build Information
Release ID: 601010015
Git revision: fa52f02641726146e2589ed86ec4097fbe101888
Build date: 2016-09-22 08:03:02-04
Xamarin addins: 75d65712af93d54dc39ae4c42b21dfa574859fd6
Build lane: monodevelop-lion-cycle8-sr0

Operating System
Mac OS X 10.11.6
Darwin jlipsky-rmb13.local 15.6.0 Darwin Kernel Version 15.6.0
    Mon Aug 29 20:21:34 PDT 2016
    root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64
Comment 1 Marek Safar 2016-10-06 09:19:03 UTC
This is linker issue. Setting Linker behaviour to "Don't link" fixes the issue.

The underlying problem is in wrongly rewritten BreakpointTest.Portable.dll.mdb. The first issue is that the file should probably not be touched at all and still 

-rw-r--r--+ 1 marek  staff  423  6 Oct 11:11 BreakpointTest.app/BreakpointTest.Portable.dll.mdb
-rw-r--r--+ 1 marek  staff  1110  6 Oct 11:09 BreakpointTest.Portable.dll.mdb

Inspecting mdb differences, the new file wrong rewritten information

Original file

<?xml version="1.0" encoding="utf-8"?>
<symbols>
  <files>
    <file id="1" name="TestService.cs" checksum="1fdaa20b7677aa8510bf854623230a7c" />
    <file id="2" name="AssemblyInfo.cs" checksum="a81739c16aacb8d699216f2786f7ec3b" />
    <file id="3" name="TestService.Actions.cs" checksum="7f4b3ac9effc1f38ca7c24bdf1f2193d" />
    <file id="4" name=".NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttribute.cs" checksum="e2c32b40343f27def013dbf0ff6c4593" />
  </files>
  <methods>
    <method token="0x6000001" signature="System.Threading.Tasks.Task BreakpointTest.Portable.TestService::DoSomething1()">
      <sequencepoints />
      <locals />
      <scopes />
    </method>
    <method token="0x6000002" signature="System.Threading.Tasks.Task BreakpointTest.Portable.TestService::DoSomething2()">
      <sequencepoints />
      <locals />
      <scopes />
    </method>
    <method token="0x6000003" signature="System.Threading.Tasks.Task BreakpointTest.Portable.TestService::MyAsyncAction2()">
      <sequencepoints />
      <locals />
      <scopes />
    </method>
    <method token="0x6000004" signature="System.Threading.Tasks.Task BreakpointTest.Portable.TestService::MyAsyncAction1()">
      <sequencepoints />
      <locals />
      <scopes />
    </method>
    <method token="0x6000005" signature="System.Void BreakpointTest.Portable.TestService/&lt;DoSomething1&gt;c__async0::MoveNext()">
      <sequencepoints>
        <entry il="0x21" row="10" col="9" file_ref="1" />
        <entry il="0x22" row="11" col="13" file_ref="1" />
        <entry il="0x89" row="12" col="9" file_ref="1" />
      </sequencepoints>
      <locals />
      <scopes />
    </method>
    <method token="0x6000006" signature="System.Void BreakpointTest.Portable.TestService/&lt;DoSomething1&gt;c__async0::SetStateMachine(System.Runtime.CompilerServices.IAsyncStateMachine)">
      <sequencepoints />
      <locals />
      <scopes />
    </method>
    <method token="0x6000007" signature="System.Void BreakpointTest.Portable.TestService/&lt;DoSomething2&gt;c__async1::MoveNext()">
      <sequencepoints>
        <entry il="0x21" row="15" col="9" file_ref="1" />
        <entry il="0x22" row="16" col="13" file_ref="1" />
        <entry il="0x89" row="17" col="9" file_ref="1" />
      </sequencepoints>
      <locals />
      <scopes />
    </method>
    <method token="0x6000008" signature="System.Void BreakpointTest.Portable.TestService/&lt;DoSomething2&gt;c__async1::SetStateMachine(System.Runtime.CompilerServices.IAsyncStateMachine)">
      <sequencepoints />
      <locals />
      <scopes />
    </method>
    <method token="0x6000009" signature="System.Void BreakpointTest.Portable.TestService/&lt;MyAsyncAction2&gt;c__async2::MoveNext()">
      <sequencepoints>
        <entry il="0x21" row="20" col="9" file_ref="1" />
        <entry il="0x22" row="21" col="13" file_ref="1" />
        <entry il="0x6c" row="22" col="13" file_ref="1" />
        <entry il="0x71" row="22" col="19" file_ref="1" />
        <entry il="0x94" row="23" col="9" file_ref="1" />
      </sequencepoints>
      <locals />
      <scopes />
    </method>
    <method token="0x600000a" signature="System.Void BreakpointTest.Portable.TestService/&lt;MyAsyncAction2&gt;c__async2::SetStateMachine(System.Runtime.CompilerServices.IAsyncStateMachine)">
      <sequencepoints />
      <locals />
      <scopes />
    </method>
    <method token="0x600000b" signature="System.Void BreakpointTest.Portable.TestService/&lt;MyAsyncAction1&gt;c__async3::MoveNext()">
      <sequencepoints>
        <entry il="0x21" row="9" col="9" file_ref="3" />
        <entry il="0x22" row="10" col="13" file_ref="3" />
        <entry il="0x6c" row="11" col="13" file_ref="3" />
        <entry il="0x71" row="11" col="19" file_ref="3" />
        <entry il="0x94" row="12" col="9" file_ref="3" />
      </sequencepoints>
      <locals />
      <scopes />
    </method>
    <method token="0x600000c" signature="System.Void BreakpointTest.Portable.TestService/&lt;MyAsyncAction1&gt;c__async3::SetStateMachine(System.Runtime.CompilerServices.IAsyncStateMachine)">
      <sequencepoints />
      <locals />
      <scopes />
    </method>
  </methods>
</symbols>


new file / one with wrong file_ref, wrong locals, wrong col

<?xml version="1.0" encoding="utf-8"?>
<symbols>
  <files>
    <file id="1" name="TestService.cs" checksum="1fdaa20b7677aa8510bf854623230a7c" />
  </files>
  <methods>
    <method token="0x6000005" signature="System.Void BreakpointTest.Portable.TestService/&lt;DoSomething1&gt;c__async0::MoveNext()">
      <sequencepoints>
        <entry il="0x21" row="10" col="-1" file_ref="1" />
        <entry il="0x22" row="11" col="-1" file_ref="1" />
        <entry il="0x89" row="12" col="-1" file_ref="1" />
      </sequencepoints>
      <locals>
        <entry name="" il_index="0" scope_ref="0" />
        <entry name="" il_index="1" scope_ref="0" />
      </locals>
      <scopes />
    </method>
    <method token="0x6000007" signature="System.Void BreakpointTest.Portable.TestService/&lt;DoSomething2&gt;c__async1::MoveNext()">
      <sequencepoints>
        <entry il="0x21" row="15" col="-1" file_ref="1" />
        <entry il="0x22" row="16" col="-1" file_ref="1" />
        <entry il="0x89" row="17" col="-1" file_ref="1" />
      </sequencepoints>
      <locals>
        <entry name="" il_index="0" scope_ref="0" />
        <entry name="" il_index="1" scope_ref="0" />
      </locals>
      <scopes />
    </method>
    <method token="0x6000009" signature="System.Void BreakpointTest.Portable.TestService/&lt;MyAsyncAction2&gt;c__async2::MoveNext()">
      <sequencepoints>
        <entry il="0x21" row="20" col="-1" file_ref="1" />
        <entry il="0x22" row="21" col="-1" file_ref="1" />
        <entry il="0x6c" row="22" col="-1" file_ref="1" />
        <entry il="0x71" row="22" col="-1" file_ref="1" />
        <entry il="0x94" row="23" col="-1" file_ref="1" />
      </sequencepoints>
      <locals>
        <entry name="" il_index="0" scope_ref="0" />
        <entry name="" il_index="1" scope_ref="0" />
      </locals>
      <scopes />
    </method>
    <method token="0x600000b" signature="System.Void BreakpointTest.Portable.TestService/&lt;MyAsyncAction1&gt;c__async3::MoveNext()">
      <sequencepoints>
        <entry il="0x21" row="9" col="-1" file_ref="1" />
        <entry il="0x22" row="10" col="-1" file_ref="1" />
        <entry il="0x6c" row="11" col="-1" file_ref="1" />
        <entry il="0x71" row="11" col="-1" file_ref="1" />
        <entry il="0x94" row="12" col="-1" file_ref="1" />
      </sequencepoints>
      <locals>
        <entry name="" il_index="0" scope_ref="0" />
        <entry name="" il_index="1" scope_ref="0" />
      </locals>
      <scopes />
    </method>
  </methods>
</symbols>
Comment 2 Marek Safar 2016-10-06 09:20:34 UTC
*** Bug 44515 has been marked as a duplicate of this bug. ***
Comment 3 Sebastien Pouliot 2016-10-07 13:30:53 UTC
The linker code does not directly deal with debugging symbols. It ask Cecil to load them (if present) and then to save them (if the assembly is updated).

I strongly suspect this is an issue with the .mdb support of Cecil. I tried on master (which use the latest cecil) and I can duplicate the issue - so it does not look fixed. c.c. JB for comments
Comment 4 Marek Safar 2016-10-07 14:39:23 UTC
Sebastien but why is that file touched at the first place? It's not SDK file but user provided dll.
Comment 5 Sebastien Pouliot 2016-10-07 14:58:32 UTC
@Marek, unrelated to the issue - that's still a problem for "link all" and in other cases, e.g. partial classes are used in the BCL.

The user assemblies are not linked with "link sdk" (i.e. no type/method/fields... gets marked/removed) but they can be updated and saved back (as well as the .mdb file).

Rolf gave you one reason on #ios (removing security declarations) and there's a few other cases where the code won't change but other metadata needs to be updated otherwise the unmodified assembly would not be usable (or way bigger*). 

Since the types, methods and IL are not modified the .mdb should be identical, or at least equivalent, and it should not change the files where the original source is located.

* e.g. we don't want to ship the PCL facades, just the resolved assemblies to the code.
Comment 6 Marek Safar 2016-10-07 15:05:54 UTC
I just wanted to point out that there could be 2 different issues not only Cecil issue even "hello world"-like user dll ends up being linked with LinkSDK only settings
Comment 7 Sebastien Pouliot 2016-10-14 14:53:59 UTC
The loss of information happens by just roundtripping [1] the .dll/.mdb with the latest (NuGet) cecil, nothing from XI being involved.

[1] https://gist.github.com/spouliot/7d86498f8a5e55f6b639afc2daa3dd7f
Comment 8 Jb Evain 2016-10-17 22:32:34 UTC
This has been fixed upstream on master.

If you need the fix, I can publish a beta-2 NuGet. Let me know what works best for you.
Comment 9 Rolf Bjarne Kvinge [MSFT] 2016-10-18 10:18:43 UTC
@Marek, can you bump mono's cecil dependency to get this fix?
Comment 10 Marek Safar 2016-10-18 12:19:18 UTC
Mono dependency bumped
Comment 11 Rolf Bjarne Kvinge [MSFT] 2016-10-24 08:36:04 UTC
The cecil dependency in mono's 4.8 branch was bumped here: https://github.com/mono/mono/commit/412e5314042a94be4442154d161aa3fa582ef816

xamarin-macios/master bumped its mono dependency past that commit here: https://github.com/xamarin/xamarin-macios/commit/3e1204278baa060c45f3a876492f91bd5582d3c5

So marking this as fixed.
Comment 12 David Karlaš 2016-12-20 04:00:23 UTC
*** Bug 46704 has been marked as a duplicate of this bug. ***