- Xdebug Helper Firefox
- Xdebug Phpstorm
- Xdebug Firefox
- Xdebug Firefox Toolbar
- Xdebug Firefox Extension Chrome
Debugging a problem in an application is like solving a puzzle. There are certain tools that can help you solve the puzzle. This page documents some of the strategies, tools and tricks that you can use in solving these puzzles.
IntelliJ IDEA 模块依赖关系IntelliJ IDEA 模块依赖是模块使用的东西。模块依赖关系可能包括:一个 SDK,如果在模块依赖关系中存在,则被称为模块 SDK。. Phpxdebug 2.5.x or later (development environments only; can have an adverse effect on performance) There is a known issue with xdebug that can affect Magento installations or access to the storefront or Magento Admin after installation. For details, see Known issue with xdebug.
You can find bugs by using a debugger: setting breakpoints, running the code line-by-line, examining variables, changing its state, exploring what other threads are doing, and see what the call stacks for each routines are. See the sections Debugging with GDB and Debugging with LLDB for more information on this.
You can also debug an application by looking at stack traces. These are typically the result of an exception being thrown, or are the result of the code containing explicit calls to Console.WriteLine(Environment.StackTrace)
. This helps you understand what the call frames were at the point of the stack traces and you can use this to understand what could have lead to the particular state that you are exploring (the crash, the exception, the report).
Xdebug Helper Firefox. Xdebug Helper for Firefox by BrianGilbert This extension is very useful for PHP developers that are using PHP tools with Xdebug support like PHPStorm, Eclipse with PDT, Netbeans and MacGDBp or any other Xdebug compatible profiling tool like KCacheGrind, WinCacheGrind or Webgrind. Firebug is a Firefox plug-in for web development, also has a profiler for JavaScript. Microsoft Visual Studio AJAX Profiling Extensions is a free profiling tool for JavaScript by Microsoft Research.NET. CLR Profiler is a free memory profiler provided by Microsoft for CLR applications.
Debuggers and stack traces are not enough, sometimes you want to see what is happening as the application runs, “trace” its execution and look at parameters and return values that are being passed around. See the Tracing Programming Execution section for details on this technique.
Another diagnostics mechanism is exploring which exceptions are being thrown (you might be accidentally capturing exceptions that should be propagated, or your program might be performing sub optimally). See the section on Exceptions to understand how to see these.
Debugging information
To debug applications or obtain line number information in stack traces, it is necessary to compile your programs with debugging information. This is achieved using the -debug command line option of the C# compiler. In Mono 1.0.x this embeds the debugging information in the resulting assembly, in Mono 1.1.x a separate file with the extension .mdb is produced.
To get stack traces with line number information, you need to run your program like this:
Xdebug Helper Firefox
Notice that the program will need to be compiled with the -debug flag and that running with –debug will slow down the execution.
Debugging with GDB
GDB can be used to obtain some information about your application and debug some problems. This section covers the details on debugging your Mono application with GDB.
First and foremost, Mono support libraries use a couple of signals internally that confuse gdb, to work around this, put this in your .gdbinit file (in your $HOME path):
If you use GDB to debug your mono process, you can use the function mono_print_method_from_ip
(which takes an address) to obtain the name of a method given an address. This is particularly useful when examining stack traces. The function was renamed to mono_pmip
in the Mono 1.1.x series (For a while the function was called mono_print_method_from_ip
).
For example, when faced with a stack trace, like this:
You can find out what methods are at each address using the mono_print_method_from_ip function (or mono_pmip if you are using Mono 1.1.x):
Sometimes you will want to produce a complete dump of all the managed names from within gdb, this can be achieved with a gdb macro. Put this in your .gdbinit file in your HOME directory:
Then you can issue the “mono_backtrace 15” from the gdb prompt to obtain a trace of the last 15 frames.
If you use P/Invoke often, it is often helpful to set a breakpoint in an unmanaged function and then print a managed stack trace. Starting with 1.1.13.4, you can add the following gdb macro to your .gdbinit file. (Note, this has only been tested on x86):
Using “mono_stack” from gdb will print a managed stack trace to the program’s stdout. It will not print out in your gdb console! You can also use “thread apply all mono_stack” to print stacks for all threads.
Output will look something like this:
In versions after Mono 1.1.18, a few new functions are available to assist in debugging applications from within GDB.
Use mono_object_describe
to get a small description of the object obj.
Use mono_object_describe_fields
to get a small description of all the fields on the given object.
Use mono_value_describe_fields
to prints to stdout a small description of each field of the value type stored at @addr of type @klass.
Use mono_class_describe_statics
to prints to stdout a small description of each static field of the type @klass in the current application domain.
Use mono_debug_print_vars
to prints to stdout the information about the local variables in a method (if @only_arguments is false) or about the arguments.
The information includes the storage info (where the variable lives, in a register or in memory). The method is found by looking up what method has been emitted at the instruction address @ip.
Here is an example session:
Debugging with LLDB
You can use the following LLDB python script to get backtraces in lldb: monobt.py
Assuming the above script is saved in ~/Library/lldb/monobt.py
, you can load it automatically in every lldb session by putting the following into .lldbinit (in your $HOME directory):
Once the script is loaded, you can type monobt
to get a backtrace of the currently selected thread with managed frames symbolicated.
Usually you will debug Mono after building it yourself, but it is possible todebug a prebuilt Mono package, using LLDB’starget.source-map
facility.
Known limitiations
If a segmentation fault occurs (EXC_BAD_ACCESS
) LLDB can’t resume to the signal handler. Unfortunately this conflicts with implicit null checks used by Mono. Workarounds until this is fixed:
- Run mono with
MONO_DEBUG=explicit-null-checks
, so the runtime won’t use mentioned technique. Performance-wise this is a bit slower, but for debugging purposes that’s fine. - Use
gdb
. Unfortunately this requires some work on macOS these days.
Debugging With Visual Studio on Windows
Most of the techniques that you can use in GDB can also be used on Windows using the Visual Studio debugger. You can use the Immediate Window to enter your commands. if the gdb command is:
the equivalent command for the immediate window is the same without the p, and explicitly casting the argument to a void*
When mono was loaded from a dynamic library, and the above command doesn’t work, you can tell visual studio more explicitly where to find the function. Assuming mono was loaded from “mono.dll”, the somewhat cryptic command is:
Debugging Managed Lock Deadlocks
Managed locks (implemented in the Monitor class and usually invoked with the lock () construct in C#) are subject to the same incorrect uses of normal locks, though they can be safely taken recursively by the same thread.
One of the obviously incorrect way to use locks is to have multiple locks and acquire them in different orders in different codepaths. Here is an example:
There is an explicit Sleep () call to make the race condition happen almost every time you run such a program. The issue with such deadlocks is that usually the race time window is very small and it will go unnoticed during testing. The new feature in the mono runtime is designed to help find the issue when a process is stuck and we don’t know why.
Now you can attach to the stuck process using gdb and issue the following command:
which results in output like this:
You can see that there are three locks currently held by three different threads. The first has been recursively acquired 2 times. The other two are more interesting because they each have a thread waiting on a semaphore associated with the lock structure: they must be the ones involved in the deadlock.
Once we know the threads that are deadlocking and the objects that hold the lock we might have a better idea of where exactly to look in the code for incorrect ordering of lock statements.
In this particular case it’s pretty easy since the objects used for locking are static fields. The easy way to get the class is to notice that the object which is locked twice (0x2ffd8) is of the same class as the static fields:
Now we know the class (0x820922c) and we can get a list of the static fields and their values and correlate with the objects locked in the mono_locks_dump () list:
Note that the lockA and lockB objects are the ones listed above as deadlocking.
Debugging Unmanaged Deadlocks
If the deadlock you’re experiencing is not caused by your code, it might be a Mono runtime issue. To find out, get some backtraces with these steps:
- Get your application to deadlock.
- Launch gdb from the command line.
- Execute
attach <the-mono-process-id>
(to find the process, pursueps -A | grep mono
). - Execute
thread apply all bt
.
The output you got with the last step is good to diagnose the problem or to attach to a bug.
Debugging Pinned Objects
The Mono GC will conservatively scan part of the stacks of the threads to find if they reference objects that thus would need to be kept alive. Sometimes the stack, though, contains integers or other data that look like a pointer to an object, but it isn’t really used to hold a reference to managed memory. When using the SGen GC, to help debug those cases, you can call the function find_pinning_ref_from_thread(obj, obj_size) to check whether the object obj is being pinned from some thread locations. Make sure you have a mono debug build, as the linker could optimize away this function from production builds.
Triggering the Debugger
From managed code, you can invoke the System.Diagnostics.Debugger.Break () method in your code to break execution and get to the GDB prompt.
From unmanaged code, you can use the G_BREAKPOINT() macro in your code.
Debugging with GDB in XDEBUG mode
With mono 2.6 or later, it is now possible to ask the runtime to generate debugging information which can be used by gdb. This currently only works on amd64/x86/arm linux. To use it:
For gdb 7.0
- No setup is needed, gdb will automatically load the mono mode written in python, and the the runtime will register debugging information with gdb using the new JIT interface in gdb 7.0.
gdb is not designed to handle 1000s of symbol files (one per JITted method), so the runtime groups them into fewer symbol files. This can lead to debug info missing for recently JITted methods. Typing ‘xdb’ will flush the debug info collected by the runtime.
For older gdb versions
- Set the MONO_XDEBUG env variable to ‘1’.
- Add the following to your .gdbinit:
- Run mono under gdb with –debug (if you want to run moon, just launch ‘firefox -d gdb’, or ‘firefox -g -d gdb’ in case you’re using Firefox > 3.5). Having .mdb files available helps a lot.
- When the program is stopped, type ‘xdb’. This will cause the runtime to generate the debugging info, and gdb to load it.
The output will now look like this:
The XDEBUG support in mono is modeled after the similar functionality in Kaffe.
Exceptions
Sometimes try/catch sequences can hide underlying problems in your code, you might want to look at the exceptions produced by your program using Mono’s trace facility, to use this, try:
That will display the exceptions that you program is throwing.
If you want to look into where those exceptions are being produced using gdb, you can use the following trick:
This requires a Mono with symbols to be installed though. Then you can inspect various aspects of your program:
Tracing Program Execution
Xdebug Phpstorm
Tracing allows developers to see when methods are entered/left as their application runs. This is enabled by passing the –trace command line argument to mono. The output can be quite verbose:
The default will output traces for all methods invoked in your application which can be a lot of data. It is possible to pass filter the routines that will be traced by passing options to the trace command line to limit its scope, for example:
The above example will limit the tracing to methods in the MyApplication namespace.
Or to trace multiple namespaces:
The full options available are:
For example, to trace a namespace but ignore some types:
You can toggle the trace output by sending the SIGUSR2 signal to the mono process. And you might also want to start your application with the tracing output turned off until your application reaches the point that you are interested in debugging:
Then from another console, you can turn on the output:
Where `pid’ is the process ID of the Mono process that is being traced.
You can turn off the output by sending the USR2 signal again to the process.
Runtime Logging
You can ask the runtime to log various message to stdout using: MONO_LOG_LEVEL=debug
Using Valgrind on Mono
Sometimes it might be useful to run Mono with Valgrind to track problems in the application. This is particularly helpful when debugging problems with P/Invoked libraries or bindings.
Historically Mono and Valgrind didn’t always played well together. If this has discouraged you in the past then it’s time to try it again!
Recent valgrind versions are able to deal with for self-modifying programs (which is what the mono JIT does) by using the –smc-check=all option.
As an extra bonus, Paolo (lupus) has shared his suppression file for Mono. This removes a lot, but not all, false positives (or unimportant) logs coming from the Mono runtime. This makes it easier and faster to find what you’re looking for. The suppression file is available in Mono’s git as /mono/data/mono.supp
Xdebug Firefox
Sample usage:
Xdebug Firefox Toolbar
This will run the app.exe application using mono and create a log file named “log.####” (where #### is the process id). The log file will indicates what leaked (and from where), what was (badly) reused after being freed
libgdiplus
Cairo supplies it’s own suppression file that is useful to add if your application depends on System.Drawing (or System.Windows.Forms).
Xdebug Firefox Extension Chrome
The file is located under libgdiplus/cairo/test/.valgrind-suppressions
and can be used simultaneously with the one provided for Mono.