Bug 38219 - pdb2mdb throws exceptions
Summary: pdb2mdb throws exceptions
Status: RESOLVED ANSWERED
Alias: None
Product: Runtime
Classification: Mono
Component: Tools ()
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-30 11:07 UTC by awb99
Modified: 2016-02-01 10:05 UTC (History)
3 users (show)

Tags:
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:
Status:
RESOLVED ANSWERED

Description awb99 2016-01-30 11:07:15 UTC
Hi!

I need Stacktraces with linenumbers in Mono. I compile on windows with .net 4.5.2 and then run on Mono on
Linux.

I compile with SharpDevelop on Windows and tested with both FULL and MDB only in release mode and debug mode with no optimizations.

On Linux I tried with ARCH and DEBIAN

I run: pdb2mdb MonoTest.pdb

And  always get the following exception :


Unhandled Exception:
System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
  at Mono.Cecil.PE.ImageReader.ReadImage () <0x403faa60 + 0x0015f> in <filename unknown>:0 
  at Mono.Cecil.PE.ImageReader.ReadImageFrom (System.IO.Stream stream) <0x403f8960 + 0x00053> in <filename unknown>:0 
  at Mono.Cecil.ModuleDefinition.ReadModule (System.IO.Stream stream, Mono.Cecil.ReaderParameters parameters) <0x403f87c0 + 0x00057> in <filename unknown>:0 
  at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName, Mono.Cecil.ReaderParameters parameters) <0x403f66d0 + 0x00043> in <filename unknown>:0 
  at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName) <0x403f6690 + 0x0002b> in <filename unknown>:0 
  at Mono.Cecil.AssemblyDefinition.ReadAssembly (System.String fileName) <0x403f6650 + 0x0000f> in <filename unknown>:0 
  at Pdb2Mdb.Driver.Main (System.String[] args) <0x403f4e10 + 0x0005f> in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
  at Mono.Cecil.PE.ImageReader.ReadImage () <0x403faa60 + 0x0015f> in <filename unknown>:0 
  at Mono.Cecil.PE.ImageReader.ReadImageFrom (System.IO.Stream stream) <0x403f8960 + 0x00053> in <filename unknown>:0 
  at Mono.Cecil.ModuleDefinition.ReadModule (System.IO.Stream stream, Mono.Cecil.ReaderParameters parameters) <0x403f87c0 + 0x00057> in <filename unknown>:0 
  at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName, Mono.Cecil.ReaderParameters parameters) <0x403f66d0 + 0x00043> in <filename unknown>:0 
  at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName) <0x403f6690 + 0x0002b> in <filename unknown>:0 
  at Mono.Cecil.AssemblyDefinition.ReadAssembly (System.String fileName) <0x403f6650 + 0x0000f> in <filename unknown>:0 
  at Pdb2Mdb.Driver.Main (System.String[] args) <0x403f4e10 + 0x0005f> in <filename unknown>:0 


Any ideas?

My solution is really simple:


using System;

namespace MonoTest
{
	class Program
	{
		public static void Main(string[] args)
		{
			Console.WriteLine("Mono difference test!");
			
			Console.WriteLine("Determining if we see the stacktrace (depends on .pdb)");
			DivideByZeroTest (0);
			
			Console.WriteLine("Determining if null references are diagnosed.");
			NullPointerTest (null);
						
			Console.Write("Press any key to continue . . . ");
			Console.ReadKey(true);
		}
		
		static void DivideByZeroTest (int by)
		{
			try{
				int j = 10/by;  // divide by zero
			}
			catch (Exception ex)
			{
				Console.WriteLine ("Ex: {0} stack:{1}", ex.Message, ex.StackTrace );
			}
		}
		
		class C{
			public double a;
			public double b;
		}
		
		static void NullPointerTest (C c)
		{
			try{
				// c is null,
				c.a = 13.0;
				c.b = 14.0;
			}
			catch (Exception ex)
			{
				Console.WriteLine ("Ex: {0} stack:{1}", ex.Message, ex.StackTrace );
			}
		}
		
		
	}
}

Regards
Andreas
Comment 1 Zoltan Varga 2016-02-01 04:14:04 UTC
pdb2mdb requires an assembly as an argument, not a pdb file, i.e.
pdb2mdb hello.exe will read hello.exe and hello.pdb.
Comment 2 awb99 2016-02-01 10:05:15 UTC
What a simple answer. Thank you Zoltan! I already was absolutely convinced that the tool was broken! THANK!!