Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Information about debugging engines used by the debugger

In Visual Studio, if you want to attach debugger to any processes, you have the possibility to select some specific engine (code type) or set of engines you would like to use:

enter image description here

Next (after you selected any engines and processes), if you click Attach button, the debugger attach operation is started. Then also debug-related events are fired. IDebugEventCallback2::Event can be used to grab such events (and e.g. extract the names of the processes debugger is actually attaching to):

public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program,
                 IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, 
                 uint attributes)
{
    if (debugEvent is IDebugProcessCreateEvent2)
    {
        string processname;
        if(process != null)
            process.GetName((uint) enum_GETNAME_TYPE.GN_FILENAME, out processname);
        //...
    }
}

Is there any similar way to get some information about the engines which have been chosen?

UPDATE: a bit more detailed code:

public class DebugEventsHunter : IVsDebuggerEvents, IDebugEventCallback2
{
    private readonly IVsDebugger _debugger;
    private uint _cookie;

    public DebugEventsHunter(IVsDebugger debugger) { _debugger = debugger; }

    public void Start()
    {
        _debugger.AdviseDebuggerEvents(this, out _cookie);
        _debugger.AdviseDebugEventCallback(this);
    }   

    public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program,
                     IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, uint attributes)
    {
        if (debugEvent is IDebugProcessCreateEvent2)
        {
            // get process name (shown before) 
        }               
        if (debugEvent is IDebugEngineCreateEvent2)
        {
            // why execution flow never enters this scope?
            IDebugEngine2 e;
            ((IDebugEngineCreateEvent2)debugEvent).GetEngine(out e);
        }
        // engine parameter is also always null within this scope
        return VSConstants.S_OK;
    }

    public int OnModeChange(DBGMODE mode) { /*...*/ }
}

and the usage:

var debugger = GetService(typeof(SVsShellDebugger)) as IVsDebugger;
var hunter = new DebugEventsHunter(debugger);
hunter.Start();
like image 955
jwaliszko Avatar asked Apr 16 '13 13:04

jwaliszko


People also ask

What is the debugger used for?

A debugger is a software tool that can help the software development process by identifying coding errors at various stages of the operating system or application development. Some debuggers will analyze a test run to see what lines of code were not executed.

What is debugging and types of debugging?

There are two types of debugging techniques: reactive debugging and preemptive debugging. Most debugging is reactive — a defect is reported in the application or an error occurs, and the developer tries to find the root cause of the error to fix it.

What are three tools for debugging?

Best Debugging Tools include:Chrome DevTools, Progress Telerik Fiddler, GDB (GNU Debugger), Data Display Debugger, SonarLint, Froglogic Squish, and TotalView HPC Debugging Software.

What is debugging explain the process of debugging in detail?

In the context of software engineering, debugging is the process of fixing a bug in the software. In other words, it refers to identifying, analyzing, and removing errors. This activity begins after the software fails to execute properly and concludes by solving the problem and successfully testing the software.


1 Answers

When a debug engine launches a process or attaches to an existing process, it will send the IDebugLoadCompleteEvent2 event in a timely manner. You can use this event to determine exactly which debug engines were selected for debugging.

Edit: To determine the name of the debug engine, you can use the IDebugProgram2 instance that is included with the above event, and call the IDebugProgram2.GetEngineInfo method. This method provides the name and ID of the debug engine. Note that the name of the debug engine may not match what you are used to seeing in the debugger dialogs, in which case you will need to convert the canonical name returned by this method to a "friendly" name using your own mapping implementation.

like image 139
Sam Harwell Avatar answered Sep 20 '22 20:09

Sam Harwell