Author Topic: debugging vectors  (Read 12221 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
debugging vectors
« 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 ?
« Last Edit: October 01, 2009, 11:07:46 pm by killerbot »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: debugging vectors
« Reply #1 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?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: debugging vectors
« Reply #2 on: October 01, 2009, 11:07:19 pm »
no I am using trunk.

And I think these things have worked in the past.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: debugging vectors
« Reply #3 on: October 01, 2009, 11:34:49 pm »
Test code please?
Works here with the debugger branch, not tested trunk in a while
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: debugging vectors
« Reply #4 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.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: debugging vectors
« Reply #5 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
« Last Edit: October 03, 2009, 12:44:37 am by oBFusCATed »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: debugging vectors
« Reply #6 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
« Last Edit: October 03, 2009, 09:35:38 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: debugging vectors
« Reply #7 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]
« Last Edit: October 03, 2009, 10:05:59 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: debugging vectors
« Reply #8 on: October 03, 2009, 10:25:57 am »
The patch is not mean to fix it.
Reread my post, to find out why...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: debugging vectors
« Reply #9 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.
« Last Edit: October 03, 2009, 10:33:22 am by killerbot »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: debugging vectors
« Reply #10 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?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: debugging vectors
« Reply #11 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 ;-) ).
« Last Edit: October 03, 2009, 11:52:19 am by killerbot »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: debugging vectors
« Reply #12 on: October 03, 2009, 11:54:17 am »
The script functions are not invoked for the locals and function paramters
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: debugging vectors
« Reply #13 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]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: debugging vectors
« Reply #14 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 ??

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: debugging vectors
« Reply #15 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
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: debugging vectors
« Reply #16 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 ?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: debugging vectors
« Reply #17 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...

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]