Author Topic: see content of a vector in debugging  (Read 69517 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5291
Re: see content of a vector in debugging
« Reply #105 on: June 17, 2009, 08:06:12 am »
I found out what my issue of yesterday was, the original CB gdb_types.script was back instead of the patched one  :oops:

Just tested the latest script : everything show fines now, though it still says type is "int*"

Online ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5349
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: see content of a vector in debugging
« Reply #106 on: June 17, 2009, 08:20:21 am »
I found out what my issue of yesterday was, the original CB gdb_types.script was back instead of the patched one  :oops:

Just tested the latest script : everything show fines now, though it still says type is "int*"


Did you change
line 94:      whatis $arg0._M_impl._M_start 
to whatis *$arg0._M_impl._M_start 

in stl-views-1.0.3.gdb.

Works fine here in TDM-GCC

By ollydbg at 2009-06-16
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 killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5291
Re: see content of a vector in debugging
« Reply #107 on: June 17, 2009, 08:29:14 am »
ok, I thought it was a line in our script :-)

EDIT : confirmed it works
« Last Edit: June 17, 2009, 08:47:58 am by killerbot »

Online ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5349
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: see content of a vector in debugging
« Reply #108 on: June 17, 2009, 08:35:31 am »
ok, I thought it was a line in our script :-)
At first, I also thought it was in "gdb_types.script"   :D, but didn't find "Line 94" there. So...
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 killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5291
Re: see content of a vector in debugging
« Reply #109 on: June 17, 2009, 11:24:06 pm »
alright ..................  THANKS to everyone who helped out in writing, testing , commenting the improvements resulting in the ability to see the contents of a vector :-)

I have committed to svn : revision 5653.


But this is just the start ... ;-)

Much much more to think of : vector of vector, list, map, showing std::string / wxString in all cases (I think now there's a difference between member variable, local variable or program argument but  I forgot why ...)

Once more : good job and cheers to all who helped out.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13326
    • Travis build status
Re: see content of a vector in debugging
« Reply #110 on: June 17, 2009, 11:38:53 pm »
Great, thank you for the time too :)

Next step in my TODO (not a real todo list thought) for the debugger is  to find why it is so slow.
I've some clues and I've found some hot spots (fixed one in a previous post in this thread).
Should I start a new thread or to post here?

p.s. I'll test it myself when it reaches the wxaui branch
(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!]

Online ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5349
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: see content of a vector in debugging
« Reply #111 on: June 19, 2009, 03:41:06 am »
Hi all.

Seems there is a bug, a function name will be recognized as a vector name. See the screen shot:


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: 13326
    • Travis build status
Re: see content of a vector in debugging
« Reply #112 on: August 30, 2009, 05:41:55 pm »
OK, here is a little patch

Code
Index: src/scripts/gdb_types.script
===================================================================
--- src/scripts/gdb_types.script        (revision 5731)
+++ src/scripts/gdb_types.script        (working copy)
@@ -164,9 +164,12 @@
     local element_type_value = vector_info_str.Mid(capacity_end_pos + 15,
                                                    vector_info_str.length() - capacity_end_pos - 15);
 
-    local result = _T("[size] = ") + size_value + _T("\n");
-    result += _T("[capacity] = ") + capacity_value + _T("\n");
-    result += _T("[element type] = ") + element_type_value + _T("\n");
+    local result = _T("[size] = ") + size_value + _T(",\n");
+    result += _T("[capacity] = ") + capacity_value + _T(",\n");
+    result += _T("[element type] = ") + element_type_value;
+
+    if(size > 0)
+        result += _T(",\n");
 
     local value_str = a_str;
     for(local item = 0; item < size; item += 1)
@@ -185,8 +188,12 @@
             local equal_pos = elem_value.Find(_T(" = "));
             if(equal_pos >= 0)
                 elem_value.Remove(0, equal_pos + 3);
+            if(item > 0)
+                result += _T(",");
             result += _T("[") + item + _T("] = ") + elem_value + _T("\n");
         }
+        else
+            break;
 
         value_str.Remove(0, elem_end);
     }


It does two things:
1. Add , at the end of every item/line, so the output more like the one emitted from GDB (not readly needed in trunk, but in my local patch)
2. Fixes an almost infinite loop if the vector is not initialized.

Code

     std::vector<int> v; // <- if you break here and add v to the watches, C::B freezes, because vector.size is very big number (in my case, but it could be anything)
     v.push_back(1);


Best regards...
(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: 5291
Re: see content of a vector in debugging
« Reply #113 on: August 30, 2009, 06:32:06 pm »
Quote
std::vector<int> v; // <- if you break here and add v to the watches, C::B freezes, because vector.size is very big number (in my case, but it could be anything)

the vector size should be 0, according to the standard, right ?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13326
    • Travis build status
Re: see content of a vector in debugging
« Reply #114 on: August 30, 2009, 07:12:39 pm »
If you break on the next line, yes, the size should be 0...
But on the first line the c-tor have not run and the pvector command calculates the size incorrectly... don't know exactly why... 8)
(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 mgpensar

  • Single posting newcomer
  • *
  • Posts: 6
Re: see content of a vector in debugging
« Reply #115 on: September 03, 2009, 10:05:02 pm »
Hi,

I cannot even see v[0] in debugger. I keep getting a "kernel event / debug exception message". Please see attached image.

I am using:
Windows Vista (not by my choice)
C::B 8.02
mingw 5.1.4
gdb 5.2.1-1

Any suggestions ?

Thank you in advance for your attention !

I test your code, found it is even bad in my system(MinGW, WindowsXP), I can't view "v[0]".
See my screenshot

You have to use the []-operator in your program, otherwise it gets not compiled in and therefore cannot be used by gdb.

@taram:
watching the variable as array does not work here.

[attachment deleted by admin]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5291
Re: see content of a vector in debugging
« Reply #116 on: September 03, 2009, 11:06:54 pm »
your gdb is way too old. Try to upgrade to for example GDB 6.8

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: see content of a vector in debugging
« Reply #117 on: September 03, 2009, 11:24:23 pm »
your gdb is way too old. Try to upgrade to for example GDB 6.8

And the changesdiscussed in this thread are in trunk and not in the 8.02 release.
If you need them, you should download a recent nighly build, or you have to wait for the next release.

Offline mgpensar

  • Single posting newcomer
  • *
  • Posts: 6
Re: see content of a vector in debugging
« Reply #118 on: September 04, 2009, 12:05:13 am »
I will download gdb and trunk and give it a try.
Thank you very much !

your gdb is way too old. Try to upgrade to for example GDB 6.8

And the changesdiscussed in this thread are in trunk and not in the 8.02 release.
If you need them, you should download a recent nighly build, or you have to wait for the next release.

Offline drac

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: see content of a vector in debugging
« Reply #119 on: September 21, 2009, 09:29:18 am »
You might find this blog entry interesting. It's about STL Visualisation from one of the KDevelop developers.