Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: killerbot on October 01, 2009, 06:17:09 pm

Title: debugging vectors
Post by: killerbot on October 01, 2009, 06:17:09 pm
I remember a few months ago we improved the debugger experience so it could show std::vector.

But it seems none of that works anymore. Or did I miss something ?
Title: Re: debugging vectors
Post by: MortenMacFly on October 01, 2009, 09:10:59 pm
But it seems non of that works anymore. Or did I miss something ?
Works fine here. What version of compiler/debugger are you using? I remember it did not work for me either until I got the "right" pair of GCC tools.
BTW: Do you mean the debugger branch?
Title: Re: debugging vectors
Post by: killerbot on October 01, 2009, 11:07:19 pm
no I am using trunk.

And I think these things have worked in the past.
Title: Re: debugging vectors
Post by: oBFusCATed on October 01, 2009, 11:34:49 pm
Test code please?
Works here with the debugger branch, not tested trunk in a while
Title: Re: debugging vectors
Post by: ollydbg on October 02, 2009, 04:40:56 pm
The test code both failed in the trunk and debugger branch( with your patch )

Code
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<string> vstr;

int main()
{
    vstr v;
    v.push_back("bla bla");
    string v0 = v[0];
    cout << "Hello world!" << endl;
    return 0;
}


both v and v0 didn't show correctly in the watch window.
Title: Re: debugging vectors
Post by: oBFusCATed on October 02, 2009, 04:52:59 pm
Can you tell me the output of the command "whatis v" at the cout line?

Update:

 I've tested it and here is the output
Code
> whatis v
type = vstr
This means that there is no way to make it work.

I'll try to fix the string problem, thought

Update2:
Here is the patch for the string parsing:
Code
Index: src/scripts/gdb_types.script
===================================================================
--- src/scripts/gdb_types.script        (revision 5837)
+++ src/scripts/gdb_types.script        (working copy)
@@ -24,7 +24,7 @@
     // STL String
     driver.RegisterType(
         _T("STL String"),
-        _T("^std::basic_string<.*>$"),
+        _T("(^std::basic_string<.*)|(^string$)|(^const string$)|(^string &$)|(^const string &$)"),
         _T("Evaluate_StlString"),
         _T("Parse_StlString")
     );
@@ -32,7 +32,7 @@
     // STL Vector
     driver.RegisterType(
         _T("STL Vector"),
-        _T("^std::vector<(.*)>$"),
+        _T("^std::vector<.*"),
         _T("Evaluate_StlVector"),
         _T("Parse_StlVector")
     );
@@ -109,16 +109,17 @@
 
 function Evaluate_StlString(type, a_str, start, count)
 {
+    local v_str = _T("(") + a_str + _T(")");
     local oper = _T(".");
 
     if (type.Find(_T("*"), false) > 0)
         oper = _T("->");
 
-    local result = _T("output ") + a_str + oper + _T("c_str()[") + start + _T("]@");
+    local result = _T("output ") + v_str + oper + _T("c_str()[") + start + _T("]@");
     if (count != 0)
         result = result + count;
     else
-        result = result + a_str + oper + _T("size()");
+        result = result + v_str + oper + _T("size()");
     return result;
 }

If you find a case where it doesn't work, please report it and provide a simple example.

p.s. patch is in the debugger branch

Update3:
ptype command can help to solve the vector issue, but the output of it is quite big and complete
Title: Re: debugging vectors
Post by: ollydbg on October 03, 2009, 09:23:04 am
I'm sorry, I failed apply this patch to the debugger_branch rev 5837. :(

TortoiseSVN said: The chunk size did not match the number of add/removed lines.

 :(

Edit
I can manually apply this patch. :D
Title: Re: debugging vectors
Post by: ollydbg on October 03, 2009, 10:02:18 am
Using this patch, the variable v still can't be shown correctly. See the screen shot.

Edit:


If I manually enter : pvector v command, the output is ok in the "Debuger(debug)" panel.
Code
> pvector v
elem[0]: $1 = {
  static npos = 4294967295,
  _M_dataplus = {
    <std::allocator<char>> = {
      <__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>},
    members of std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Alloc_hider:
    _M_p = 0x324dc "bla bla"
  }
}
Vector size = 1
Vector capacity = 1
Element type = std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>>>>>>cb_gdb:

[attachment deleted by admin]
Title: Re: debugging vectors
Post by: oBFusCATed on October 03, 2009, 10:25:57 am
The patch is not mean to fix it.
Reread my post, to find out why...
Title: Re: debugging vectors
Post by: killerbot on October 03, 2009, 10:31:11 am
I will try again later, but even showing a vector of int's does not work anymore.

I think this is something we best fix in trunk and the debug branch.

A few months we could do this : http://forums.codeblocks.org/index.php/topic,10667.msg73150.html#msg73150      (see the screenshot).

Also some other related info is in here :
http://forums.codeblocks.org/index.php/topic,10667.msg76693.html#msg76693

Can someone of the patchers tell me what to use to get it fixed.
And currently my primary concern is getting it fixed on trunk. We broke, so we should fix it ;-)

Paste your patches   here, I will manually apply them to trunk.
Title: Re: debugging vectors
Post by: oBFusCATed on October 03, 2009, 11:25:58 am
Hm, trunk works with vector<int> for me.
At the beginning it wasn't working, because the update script wasn't run at C::B was using the old gdb_types.script.

Killerbot, can you verify that src/scripts/gdb_types.script and src/deve/share/codeblocks/scripts/gdb_types.script are the same and they have "pvector" in them?
Title: Re: debugging vectors
Post by: killerbot on October 03, 2009, 11:38:23 am
I am trying in on linux. And the gdb_types.script has pvector in it (Evaluate_StlVector).

Could you show the int vector on how it looks like at your machine ??

EDIT : I just did a test on rev 5754 : it works when I add the vector as a watch variable, but when I look at the vector as part of the local variables list it doesn't work.
Gonna test in a few minutes on latest on trunk (switching to laptop ;-) ).
Title: Re: debugging vectors
Post by: oBFusCATed on October 03, 2009, 11:54:17 am
The script functions are not invoked for the locals and function paramters
Title: Re: debugging vectors
Post by: Jenna on October 03, 2009, 11:57:03 am
Works here (on linux).
Vector declared as:
Code
    std::vector<int> v;
filled with:
Code
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);

Screenshot of the watches window attached.

EDIT:
too late  :(

[attachment deleted by admin]
Title: Re: debugging vectors
Post by: killerbot on October 03, 2009, 12:03:24 pm
also work on my latest build on trunk.

But I saw another strange things, after adding some vectors, suddenly in the watch list the function arguments and local variables disappeared from the watches list ??


Why don't we invoke the script on locals ??
Title: Re: debugging vectors
Post by: oBFusCATed on October 03, 2009, 12:53:54 pm
Because we call "info locals" and "info args" which return the values ready to be put in the tree
Title: Re: debugging vectors
Post by: killerbot on October 03, 2009, 01:56:13 pm
Because we call "info locals" and "info args" which return the values ready to be put in the tree
And can we further post process them ?
For these kind of variables the use is nearly none, the only thing it shows the the user is a bad debug experience.
Are there short term possibilities to improve ?
Title: Re: debugging vectors
Post by: oBFusCATed on October 03, 2009, 02:29:24 pm
I'm not sure about trunk, probably no.
In the debugger branch locals and function args are missing at all.

There I want to add multiple watch windows + maybe locals and functions args windows. But I'm not exactly sure how to handle this.

Also we need a way to parse:
Code
struct A
{
     int a;
     string b;
     vector<int> c;
};
But implementing this will make stepping even slower...