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

Offline mgpensar

  • Single posting newcomer
  • *
  • Posts: 6
Re: see content of a vector in debugging
« Reply #120 on: September 21, 2009, 05:07:09 pm »
You might find this blog entry interesting. It's about STL Visualisation from one of the KDevelop developers.

Thank you for the post drac, very informative. It seems that nice visualization of STL containers is finally taking its first steps to become wide available.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: see content of a vector in debugging
« Reply #121 on: September 30, 2009, 08:52:20 am »
Thanks Jens for your hints.

Here is a workaround.
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;
}

I can only watch "v0" (see the screen shot)



hello, I found in the latest svn rev 5826, the debugger watch works badly with the test code above. see my screen shot. can someone find the bug? Thanks.



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: 13413
    • Travis build status
Re: see content of a vector in debugging
« Reply #122 on: September 30, 2009, 12:59:21 pm »
I think, this is known bug... will look at it tonight

Update: yes known bug...

Here is the output of the whatis command:
Code
> whatis v_str
type = std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >,std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >

And this line matches the regexp for std::string and so the script for std::string is used instead of the one for the vector.

Here is a patch that fixes the problem (not tested extensively)
Code

Index: src/plugins/debuggergdb/gdb_commands.h
===================================================================
--- src/plugins/debuggergdb/gdb_commands.h      (revision 5826)
+++ src/plugins/debuggergdb/gdb_commands.h      (working copy)
@@ -702,6 +702,8 @@
 
             m_watch->GetSymbol(symbol);
             m_watch->GetType(type);
+            type.Trim(true);
+            type.Trim(false);
             m_Cmd = static_cast<GDB_driver*>(m_pDriver)->GetScriptedTypeCommand(type, m_ParseFunc);
             if (m_Cmd.IsEmpty())
             {
@@ -798,7 +800,7 @@
 //            m_pWatch(watch)
             m_watch(watch)
         {
-            m_Cmd << _T("whatis ");
+            m_Cmd << _T("whatis &");
 //            m_Cmd << m_pWatch->keyword;
             wxString symbol;
             m_watch->GetSymbol(symbol);
@@ -813,6 +815,7 @@
             // type = bool
 
             wxString tmp = output.AfterFirst(_T('='));
+            tmp = tmp.substr(0, tmp.length() - 1);
             // actually add this watch with high priority
 //            m_pDriver->QueueCommand(new GdbCmd_Watch(m_pDriver, m_pDTree, m_pWatch, tmp), DebuggerDriver::High);
             wxString old_type;
@@ -850,6 +853,8 @@
             m_Type(w_type),
             m_Address(address)
         {
+            m_Type.Trim(true);
+            m_Type.Trim(false);
             m_Cmd = static_cast<GDB_driver*>(m_pDriver)->GetScriptedTypeCommand(w_type, m_ParseFunc);
             if (m_Cmd.IsEmpty())
             {
Index: src/scripts/gdb_types.script
===================================================================
--- src/scripts/gdb_types.script        (revision 5826)
+++ src/scripts/gdb_types.script        (working copy)
@@ -24,7 +24,7 @@
     // STL String
     driver.RegisterType(
         _T("STL String"),
-        _T("[^[:alnum:]_]*string[^[:alnum:]_]*"),
+        _T("^std::basic_string<.*>$"),
         _T("Evaluate_StlString"),
         _T("Parse_StlString")
     );
@@ -32,7 +32,7 @@
     // STL Vector
     driver.RegisterType(
         _T("STL Vector"),
-        _T("[^[:alnum:]_]*vector<.*"),
+        _T("^std::vector<(.*)>$"),
         _T("Evaluate_StlVector"),
         _T("Parse_StlVector")
     );

The patch includes a fix for another problem:
Code
> whatis gdb_type
Attempt to take contents of a non-pointer value.
>>>>>>cb_gdb:
> whatis &gdb_type
type = const wxString &*
>>>>>>cb_gdb:
That thing is caused by the command "source stl-views-1.0.3.script", and unfortunately, I've not reported it to gdb upstream, will do so someday...
The patch evaluates the type of the address of the watched variable and then strips the * at the end of the result.

Testing is welcome.

p.s. the patch is agains the wxpropgrid_debugger branch, if you have problems applying it, I'll produce one against trunk
« Last Edit: September 30, 2009, 07:12:35 pm 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: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: see content of a vector in debugging
« Reply #123 on: October 02, 2009, 06:26:31 am »
@oBFusCATed
Thanks, but the patch failed appling in the trunk code :(. Would you supply a patch for the trunk?
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: see content of a vector in debugging
« Reply #124 on: October 02, 2009, 06:31:06 am »
Thanks, but the patch failed appling in the trunk code :(. Would you supply a patch for the trunk?
I believe it's for the debugging 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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: see content of a vector in debugging
« Reply #125 on: October 02, 2009, 06:37:05 am »
Thanks, but the patch failed appling in the trunk code :(. Would you supply a patch for the trunk?
I believe it's for the debugging branch.

Thanks for the hint, Yes, he said:
Quote
p.s. the patch is agains the wxpropgrid_debugger branch, if you have problems applying it, I'll produce one against trunk
:D
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: see content of a vector in debugging
« Reply #126 on: October 02, 2009, 06:40:19 am »
Thanks for the hint, Yes, he said:
Quote
p.s. the patch is agains the wxpropgrid_debugger branch, if you have problems applying it, I'll produce one against trunk
:D
Nargh... it's very early in the morning here... ;-)
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