[Solved] Debugging CEGUI 0.8.X strings in Visual Studio

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

joeludwig
Just popping in
Just popping in
Posts: 2
Joined: Tue Oct 14, 2008 18:54

[Solved] Debugging CEGUI 0.8.X strings in Visual Studio

Postby joeludwig » Tue Oct 14, 2008 18:58

It is difficult for me to see the contents of a CEGUI::String in visual studio. I basically have to add something like this to the watch window and then expand it and ignore every other letter:
(wchar_t *)(stringVar).d_quickbuff,50

There must be an easier way. Is there some way to get Visual Studio to recognize a UTF-32 string?


Joe

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Sun Oct 26, 2008 09:35

Hi,

Apologies for the lateness of this response; I have been unwell.

I agree dedbugging without seeing the strings can be a pain. It is possible to extend Visual C++ to display the string "normally". The way you do this is dependent upon the version of VC++ in use. Way back in the distant past a guy here on the forum provided such a thing for VC++ 2003.

As I understand it, the process is much easier in VC++ 2005 and higher. I don't think anyone has done a data visualizer for this already, though my memory could be fuzzy.

The following video on MSDN might be useful, it shows how to create a visualizer: http://msdn.microsoft.com/en-us/visualc/bb684927.aspx

HTH

CE.

User avatar
gring
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Tue Mar 18, 2008 09:26
Location: Sweden

Postby gring » Mon Oct 27, 2008 12:37

Nice CE,

That eeaddin sample was a bit tricky, when i did as follows I got it working.

This is how i did it in VS2008.

Create an empty win32 (.dll) project. I called it CEGUIDbg.
Remove unicode setting for the project in properties.
Add the preprocessor define CEGUI_STATIC.
Add CEGUIString.h and CEGUIString.cpp to the project.
Remove precompiled header usage on CEGUIString.cpp.
Add the search path to CEGUI\inc directory, CEGUIBase.h needs to be in that search path.
add this postbuild event

Code: Select all

copy $(TargetPath) "$(DevEnvDir)"
, this will copy ceguidbg.dll to the same folder as devenv.exe, usually C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE
(There might be security issue with this copy in Windows Vista, can be done manually.)

This is the file: CEGUIDbg.cpp

Code: Select all

// CEGUIDbg.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "tchar.h"

#include "ceguistring.h"

#define ADDIN_API    __declspec(dllexport)

typedef struct tagDEBUGHELPER

{

    DWORD dwVersion;

    HRESULT (WINAPI *ReadDebuggeeMemory)( struct tagDEBUGHELPER *pThis, DWORD dwAddr,
                              DWORD nWant, VOID* pWhere, DWORD *nGot );

    // from here only when dwVersion >= 0x20000

    DWORDLONG (WINAPI *GetRealAddress)( struct tagDEBUGHELPER *pThis );

    HRESULT (WINAPI *ReadDebuggeeMemoryEx)( struct tagDEBUGHELPER *pThis, DWORDLONG qwAddr,
                                 DWORD nWant, VOID* pWhere, DWORD *nGot );

    int (WINAPI *GetProcessorType)( struct tagDEBUGHELPER *pThis );

} DEBUGHELPER;



static void CEGUI_print(char *pResult, int max, int len, const char *pbuf)
{
   try
   {
      sprintf_s(pResult, max, "%d,\"%s\"", len, pbuf);
   }
   catch(...)
   {
      sprintf_s(pResult, max, "%d,\"%10s<Err>", len, pbuf);
   }
}

ADDIN_API HRESULT WINAPI CEGUIDbg_String(DWORD dwAddress, DEBUGHELPER *pHelper,
                              int nBase, BOOL bUniStrings, char *pResult,
                              size_t max, DWORD reserved )
{
   CEGUI::String s;
   DWORD nGot;

   if (pHelper->ReadDebuggeeMemory(pHelper,dwAddress,sizeof(s),&s,&nGot) != S_OK)
      return E_FAIL;

   int len = s.length();
   
   if (!len)
   {
      CEGUI_print(pResult, max, len, "");
   }
   else if (s.capacity() < STR_QUICKBUFF_SIZE)
   {
      CEGUI_print(pResult, max, len, s.c_str());
   }
   else
   {
      UINT32 *buf = new UINT32[len + 1];
      CEGUI::String s1;

      if (pHelper->ReadDebuggeeMemory(pHelper, (DWORD)s.ptr(), sizeof(UINT32) * len, buf, &nGot) != S_OK)
      {
         delete [] buf;
         return E_FAIL;
      }
      for (int i = 0; i < len; i++)
         s1 += buf[i];

      delete[] buf;
      CEGUI_print(pResult, max, len, s1.c_str());
   }
   return S_OK;
}



Find the file autoexp.dat, usually in this path
C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger

Add this line under the section [AutoExpand]

Code: Select all

CEGUI::String=$ADDIN(ceguidbg.dll,?CEGUIDbg_String@@YGJKPAUtagDEBUGHELPER@@HHPADIK@Z)


Now build and you will see the strings as utf8 encoded strings in VStudio.

HTH,

Gring

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Wed Oct 29, 2008 09:25

Wow! Thanks for the effort :)

I did not try it out yet, but definitely will at the weekend.

CE.

jbl4ir
Just popping in
Just popping in
Posts: 1
Joined: Sun Sep 09, 2012 20:02

Re: Debugging CEGUI strings in Visual Studio

Postby jbl4ir » Sun Sep 09, 2012 20:22

Just wanted to mention I followed these instructions using Visual Studio 2010 on Windows 7 and it worked great. A couple notes - as mentioned in the instructions, running VS with standard user permissions caused copying the dll as a post build step to fail. I just copied via Windows Explorer and confirmed admin permissions in the process. The directory was "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE" in my case, as indicated by the failure warning in the VS output window when trying to execute the post build step. I assume running VS as administrator would allow the copy to succeed, but I didn't bother trying.

I also didn't need to change any unicode settings in the project properties as instructed. Also, that step is pretty vague, so I'm not exactly sure what was meant anyway.

Thanks a ton @gring for the instructions. Not being able to see assert text in the debugger was driving me particularly crazy. :D

MorbidAngel
Just popping in
Just popping in
Posts: 18
Joined: Sat Aug 04, 2012 16:35

Re: Debugging CEGUI strings in Visual Studio

Postby MorbidAngel » Mon Sep 10, 2012 18:41

Thanks for bumping this thread, was exactly what i was looking for (and it works wonderfully) but couldn't find a way to do it :) Was bugging the hell out of me i couldn't see strings under debugging.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Debugging CEGUI strings in Visual Studio

Postby CrazyEddie » Tue Sep 11, 2012 08:08

Guys, just a heads up that the above code has a bug in it ;) I draw your attention to another forum topic where I've posted a fixed version of the function: viewtopic.php?p=22009#p22009

I'm not sure why or how we ended up with two separate topics each with a bit of the solution, but still, at least now I have finally back linked this topic to the other one :D

I can confirm my fixed code also does work in MSVC++ 2010, since I had cause to provide a running version to somebody a few weeks ago.

CE.

MorbidAngel
Just popping in
Just popping in
Posts: 18
Joined: Sat Aug 04, 2012 16:35

Re: Debugging CEGUI strings in Visual Studio

Postby MorbidAngel » Tue Sep 11, 2012 16:35

Thanks.

I updated it to your code and works fine.

thorlak
Just popping in
Just popping in
Posts: 1
Joined: Wed Oct 17, 2012 20:37

Re: Debugging CEGUI strings in Visual Studio

Postby thorlak » Wed Oct 17, 2012 20:41

What I usually do is to drag and drop the variable that contains the string into the watch window and then edit the variable ariable name adding ".c_str()" which gives me the string content as if it was a normal C string.

kiske1
Just popping in
Just popping in
Posts: 17
Joined: Fri May 20, 2016 11:53

Re: Debugging CEGUI strings in Visual Studio

Postby kiske1 » Mon May 23, 2016 08:00

Hello!

Sorry if I bump this old thread, but is this dll working with newer visuals studio (2015) / CEGUI 0.8.7?

As a newbie I really can't understand how to come up with those:

1) Add CEGUIString.h and CEGUIString.cpp to the project.
2) Remove precompiled header usage on CEGUIString.cpp.
3) Add the search path to CEGUI\inc directory, CEGUIBase.h needs to be in that search path.

Could someone please point me out in the right direction?

Many thanks in advance!

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Debugging CEGUI strings in Visual Studio

Postby Ident » Sat May 28, 2016 12:54

Try this: https://bitbucket.org/cegui/cegui/downl ... _0-8-X.zip
Description is in the readme
CrazyEddie: "I don't like GUIs"

kiske1
Just popping in
Just popping in
Posts: 17
Joined: Fri May 20, 2016 11:53

Re: Debugging CEGUI strings in Visual Studio

Postby kiske1 » Thu Jul 07, 2016 07:36

Thank you,

Worked pefectly in VS 2015!

User avatar
FluXy
Just popping in
Just popping in
Posts: 14
Joined: Mon Aug 22, 2005 03:34
Location: Germany
Contact:

Re: [Solved] Debugging CEGUI 0.8.X strings in Visual Studio

Postby FluXy » Tue Aug 29, 2017 13:17

Hey,

Lubens String debugger is unstable for me on VS2015, but after some fiddling i managed to create a simpler natvis for VS2015.
Please also report back if this works for you :)

https://bitbucket.org/snippets/Flonor/ojpLAX

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: [Solved] Debugging CEGUI 0.8.X strings in Visual Studio

Postby Ident » Sat Feb 17, 2018 18:35

FluXy wrote:Hey,

Lubens String debugger is unstable for me on VS2015, but after some fiddling i managed to create a simpler natvis for VS2015.
Please also report back if this works for you :)

https://bitbucket.org/snippets/Flonor/ojpLAX

I tested the natvis file and added it to the downloads: https://bitbucket.org/cegui/cegui/downloads/
CrazyEddie: "I don't like GUIs"


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 4 guests