Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I include line numbers in a stack trace without a pdb?

We are currently distributing a WinForms app without .pdb files to conserve space on client machines and download bandwidth. When we get stack traces, we are getting method names but not line numbers. Is there any way to get the line numbers without resorting to distributing the .pdb files?

like image 995
JoelFan Avatar asked Aug 25 '09 14:08

JoelFan


People also ask

How can I get line number in stack trace?

The java. lang. StackTraceElement. getLineNumber() method returns the line number of the source line containing the execution point represented by this stack trace element.

Does PDB contain source code?

pdb files contain the following information: The names of all local variables. The names of all source code files and the mapping from IL instructions onto lines within those files.

How do I use PDB debugging?

The easiest way to use the PDB file is to let Visual Studio do the heavy lifting - either launch your program with Visual Studio's "Debug" command (F5 by default), or run the program and use the "Attach to Process" item in Visual Studio's Debug menu.

What is stack trace in C#?

A trace of the method calls is called a stack trace. The stack trace listing provides a way to follow the call stack to the line number in the method where the exception occurs. The StackTrace property returns the frames of the call stack that originate at the location where the exception was thrown.


2 Answers

You can't get a stack trace with line numbers directly from your application unless you bundle the PDB. However, if you have the PDB files for the same version of the app that you ship to your customers, and you don't mind some light scripting, then you can turn the .NET stack trace and IL offsets back into line numbers.

During your build process, use Mike Stall's pdb2xml converter, distributed as part of his excellent MDbg managed code debugger, and store them some place secure (e.g., source control). When you get a stack trace back from the client, you can query the IL offset from the XML data to determine the relevant line number. If your stack traces get submitted to a website, you can even automate the conversion, so that developers will already be getting fully detailed stack traces by the time the cases hit their inbox.

like image 144
Benjamin Pollack Avatar answered Sep 21 '22 11:09

Benjamin Pollack


No. The line numbers are part of the debugging information, which is only stored in the PDB file. That is the reason PDB files exist in the first place.

like image 42
Reed Copsey Avatar answered Sep 19 '22 11:09

Reed Copsey