aBothe / Mono-D

D Add-In for MonoDevelop
http://wiki.dlang.org/Mono-D
Other
113 stars 26 forks source link

Debugger malfunctions when "pushpin" for watching variables is used #322

Open AthanasiusOfAlex opened 11 years ago

AthanasiusOfAlex commented 11 years ago

Thanks for your help yesterday. I have upgraded to 0.5.8 of the binding add-in.

I realize that the debugger is a work in progress :), but it does something interesting:

Note: with further testing, it seems that these issues arise when I set one of those pop-up pins that watch a variable's values. I had a stray one open that I couldn't find, and the problem mostly disappeared once I closed it. Thus, readers might be interested that, for the moment, the D debugger is incompatible with the popup watch pins.

[looks like this when I first hit F5:]

image

[After I hit F9 twice:]

image

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
  at MonoDevelop.Debugger.Gdb.D.DGdbBacktrace.CreateVarObject (System.String exp) [0x00000] in <filename unknown>:0 
  at MonoDevelop.Debugger.Gdb.GdbBacktrace.GetExpressionValues (Int32 frameIndex, System.String[] expressions, Mono.Debugging.Client.EvaluationOptions options) [0x00000] in <filename unknown>:0 
  at Mono.Debugging.Client.StackFrame.GetExpressionValues (System.String[] expressions, Mono.Debugging.Client.EvaluationOptions options) [0x00089] in /run/media/lx/Home.alt/lx/Dokumente/Projects/monodevelop/main/external/debugger-libs/Mono.Debugging/Mono.Debugging.Client/StackFrame.cs:225 
  at Mono.Debugging.Client.StackFrame.GetExpressionValues (System.String[] expressions, Boolean evaluateMethods) [0x0001c] in /run/media/lx/Home.alt/lx/Dokumente/Projects/monodevelop/main/external/debugger-libs/Mono.Debugging/Mono.Debugging.Client/StackFrame.cs:208 
  at MonoDevelop.Debugger.ObjectValueTreeView.GetValues (System.String[] names) [0x00065] in /run/media/lx/Home.alt/lx/Dokumente/Projects/monodevelop/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ObjectValueTreeView.cs:1643 
  at MonoDevelop.Debugger.ObjectValueTreeView.Refresh () [0x000fb] in /run/media/lx/Home.alt/lx/Dokumente/Projects/monodevelop/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ObjectValueTreeView.cs:516 
  at MonoDevelop.Debugger.ObjectValueTreeView.Update () [0x0000d] in /run/media/lx/Home.alt/lx/Dokumente/Projects/monodevelop/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ObjectValueTreeView.cs:490 
  at MonoDevelop.Debugger.ObjectValueTreeView.set_Frame (Mono.Debugging.Client.StackFrame value) [0x00001] in /run/media/lx/Home.alt/lx/Dokumente/Projects/monodevelop/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ObjectValueTreeView.cs:329 
  at MonoDevelop.Debugger.ObjectValuePad.OnUpdateList () [0x0001e] in /run/media/lx/Home.alt/lx/Dokumente/Projects/monodevelop/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ObjectValuePad.cs:109 
  at MonoDevelop.Debugger.ObjectValuePad.<Initialize>m__E (System.Object , System.EventArgs ) [0x0000d] in /run/media/lx/Home.alt/lx/Dokumente/Projects/monodevelop/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ObjectValuePad.cs:97 
  at MonoDevelop.Ide.Gui.PadWindow.NotifyContentShown () [0x0003c] in /run/media/lx/Home.alt/lx/Dokumente/Projects/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/IPadContainer.cs:305 
  at MonoDevelop.Ide.Gui.DefaultWorkbench+<AddPad>c__AnonStorey42.<>m__42 (System.Object , System.EventArgs ) [0x00017] in /run/media/lx/Home.alt/lx/Dokumente/Projects/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DefaultWorkbench.cs:1343 
  at MonoDevelop.Components.Docking.DockItem.UpdateContentVisibleStatus () [0x00033] in /run/media/lx/Home.alt/lx/Dokumente/Projects/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Docking/DockItem.cs:384 
  at MonoDevelop.Components.Docking.DockItem.SetupContent (System.Object ob, System.EventArgs args) [0x0009f] in /run/media/lx/Home.alt/lx/Dokumente/Projects/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Docking/DockItem.cs:211 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <filename unknown>:0 
  at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0 
  at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0 
  at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00000] in <filename unknown>:0 

Thanks for your quick responses!

aBothe commented 11 years ago

Could you give me parts of your code you tried to debug? I just stepped through my entire trivial program and it never crashed..I see that variables' contents aren't shown in the tool tip box. But for variable watches, most of the stuff works (except trying to access field members)

AthanasiusOfAlex commented 11 years ago

Sorry should have thought of that. I was able to reproduce this effect with the following code (taken and slightly modified from the tuturial on http://www.informit.com/articles/article.aspx?p=1381876&seqNum=5):

module main;

import std.algorithm, std.ascii, std.regex, std.range, std.stdio, std.string;

string INPUT = "  Pol. Marry, I will teach you! Think yourself a baby\n" ~
    "    That you have ta'en these tenders for true pay,\n" ~
        "    Which are not sterling. Tender yourself more dearly,\n" ~
        "    Or (not to crack the wind of the poor phrase,\n" ~
        "    Running it thus) you'll tender me a fool.\n" ~
        "  Oph. My lord, he hath importun'd me with love\n" ~
        "    In honourable fashion.\n" ~
        "  Pol. Ay, fashion you may call it. Go to, go to!\n";

struct PersonaData {
    ulong totalWordsSpoken;
    ulong[string] wordCount;
}

void main(string[] args){
    PersonaData[string] info;

    introduce();

    // Fill info
    string currentParagraph;
    char[][] inputArray = cast(char[][])splitLines(INPUT);

    foreach (line; inputArray) {
        if (line.startsWith("   ") && line.length > 4 && isAlpha(line[4])) {
            // Persona is continuing a line
            currentParagraph ~= line[3 .. $];
        } else if (line.startsWith(" ") && line.length > 2 && isAlpha(line[2])) {
            // Persona just started speaking
            addParagraph(currentParagraph, info);
            currentParagraph = line[2 .. $].idup;
        }
    }
    addParagraph(currentParagraph, info);  // Don't forget to do it for the last time.

    // Done, now print collected information
    printResults(info);
    //dumpResults(info);
}

void introduce(){
    writeln("This is the text we will be analysing:\n");
    writeln(INPUT);
}

void addParagraph(string line, ref PersonaData[string] info) {
    // Figure out persona and sentence
    line = strip(line);
    auto sentence = line.find(". ");
    if (sentence.empty) {
        return;
    }
    auto persona = line[0 .. $ - sentence.length];
    // Purify the sentence of various characters;
    sentence = toLower(strip(sentence[2 .. $]));
    sentence = strip(sentence);

    // Get the words spoken
    auto words = split(sentence);
    // Insert or update information

    PersonaData* data = persona in info;
    if (data) {
        // heard this persona before
        data.totalWordsSpoken += words.length;
        foreach (word; words) ++data.wordCount[word];
    } else {
        // first time this persona speaketh
        PersonaData newData;
        newData.totalWordsSpoken = words.length;
        foreach (word; words) newData.wordCount[word]++;
        info[persona] = newData;
    }
}

void printResults(PersonaData[string] info) {
    foreach (persona, data; info) {
        writefln("%20s %6u %6u", persona, data.totalWordsSpoken,
                 data.wordCount.length);
    }
}

void dumpResults(PersonaData[string] info){
    foreach (persona, data; info) {
        writeln(persona,":");
        foreach(word, number; data.wordCount){
            writeln("\t", word, "\t", number);
        }
    }
}
aBothe commented 11 years ago

Okay, this exception was thrown because it didn't catch the internal gdb exception when a symbol wasn't found..fixed this.

AthanasiusOfAlex commented 11 years ago

Great! The update solves 95% of the problem. (It runs pretty smoothly now, it no longer crashes, and the popups work without any problem.)

However, try setting a break point at line 52. (It should read line = strip(line); in any case, the first line of the void addParagraph function.) Again, the yellow highlighting disappears. The good news is that it reappears after I hit F10 a couple of times, and it does not crash. I consider it a minor issue at this point, but there may be an underlying bug that would be interesting to fix.

Thanks for your help!

Louis Melahn, L.C.

aBothe commented 11 years ago

it's probably just some notification and threading issue deep somewhere in the MD code..perhaps it's just required not to use ThreadPool functions for incoming gdb messages but the DispatchService of MD or so..so many possibilites :)