CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Sep 2003
    Posts
    815

    std:string & debugging

    Hi,

    When I debug my code containing std:string, many times I see garbage in the std:string in the debuuger but is I call to c_str I see the correct value

    I mean

    If I have string smyString
    I see smyString at the debugger as garbage

    then I do (for example)
    char szMyString[100]
    strcpy(szMyString,sMyString.c_str())

    I see szMyString just fine in the debugger

    that mostly happens when I have chars like & { at the debbuger } but not only

    Any explanation?
    Do I have to worry about that?

    Thanks
    avi123

  2. #2
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    std::string is a class that has its own representation for the underlying string somewhere, but you debugger doesn't necessarily know about it. So, no you should not worrry about this "garbage".

    Unfortunately, this makes debugging a bit harder, but it's rather a question of the debugger, not std::string. Also, different environments deal differently with this. For example in my VC6 STLPort configuration, it's quite ugly (and a hack is to watch s._M_start), but in VC.NET 2002 std::strings show up correctly under the debugger. So your mileage may vary.
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  3. #3
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    What garbage??? show an example in code, the expansion is controlled by the autoexp.dat in your <install dir>\common\msdev98\bin

  4. #4
    Join Date
    Feb 2003
    Posts
    377
    I added:

    std::basic_string<*> =Ptr=<_Bx._Ptr,s> Buf=<_Bx._Buf,s>

    to my autoexp.dat for the Dinkumware's upgraded STL for MSVC++ 6.0. It works well for me. Sometimes the data is in the _Ptr variable, other times in the _Buf. It can be a hassle expanding it always in the watch or variables windows.

  5. #5
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    Originally posted by Mick
    What garbage??? show an example in code, the expansion is controlled by the autoexp.dat in your <install dir>\common\msdev98\bin
    Now there is something I didn't know. Thanks, that will come in handy
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  6. #6
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by Yves M
    Now there is something I didn't know. Thanks, that will come in handy
    Yea they don't come out and tell you those types of things...bad boys....

    But I've posted a couple of times on it, and so have a couple of other people....

    You can also ignore things like stepping over std::string or CString code....

    like adding:

    Code:
    [ExecutionControl]
    CString::* =NoStepInto

  7. #7
    Join Date
    Sep 2003
    Posts
    815
    jlou


    Is there a specail location that should I add this :
    std::basic_string<*> =Ptr=<_Bx._Ptr,s> Buf=<_Bx._Buf,s>

    Should I do something else or just add it?

    Thanks

  8. #8
    Join Date
    Sep 2003
    Posts
    815
    when I want to save this file (autoexp.dat) I get this error meesage:

    "You are about to save the doucument in a Text - Only format, which will remove all formatting. Are you sure you want to to this?"

    I opened this file with notepad IS that the right way?

    Thanks

  9. #9
    Join Date
    Feb 2003
    Posts
    377
    I just added that line to the end of the file. And yes, it is perfectly fine to use Notepad or Wordpad and save in text-only format.

    Note that this may not work for you if you have a different STL than I do.
    Last edited by jlou; October 15th, 2003 at 11:53 AM.

  10. #10
    Join Date
    Sep 2003
    Posts
    815
    Hi,

    std::basic_string<*> =Ptr=<_Bx._Ptr,s> Buf=<_Bx._Buf,s>
    It doesn't work for me

    I have no idea what stl am I using, how can I know that
    anyway I have added this at the end of the file and still I see ??? when the data is in the _ptr and not in the _Buf

    thanks

  11. #11
    Join Date
    Feb 2003
    Posts
    377
    What compiler/platform do you have? Maybe somebody with the same implementation can give you their version. Also, you said that it doesn't work when it is in _ptr, mine uses _Ptr, make sure the case matches in your autoexp.dat and in the watch window. Does it work when the string is in _Buf?

    If you wanted to just figure out what to put, expand a string variable in the watch window when you are debugging. When I expand mine, I have to expand the string first, and then expand the _Bx member. The string is then either in _Ptr or _Buf. If you just find the location of the string when it's not working for you, that would help in creating the right line in the autoexp.dat.

  12. #12
    Join Date
    Sep 2003
    Posts
    815
    I'm using VS.NET platform,

    Thanks for your advice I'll check it when I'll get back to work

    Thanks
    avi

  13. #13
    Join Date
    Aug 2000
    Location
    New Jersey
    Posts
    968
    Originally posted by avi123
    I'm using VS.NET platform,

    Thanks for your advice I'll check it when I'll get back to work

    Thanks
    avi
    Which version?

    Are you using VC++ 7.0(2002) or VC++ 7.1 (2003)?
    David Maisonave
    Author of Policy Based Synchronized Smart Pointer
    http://axter.com/smartptr


    Top ten member of C++ Expert Exchange.
    C++ Topic Area

  14. #14
    Join Date
    Sep 2003
    Posts
    815
    VS.NET 2003

  15. #15
    Join Date
    Aug 2000
    Location
    New Jersey
    Posts
    968
    Originally posted by avi123
    VS.NET 2003
    I just tested it out, and I have no problems watching the data in std::string with .Net 2003.

    Are you using the STL library that comes with .Net?
    David Maisonave
    Author of Policy Based Synchronized Smart Pointer
    http://axter.com/smartptr


    Top ten member of C++ Expert Exchange.
    C++ Topic Area

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured