Page 1 of 1

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

Posted: Tue Oct 14, 2008 18:58
by joeludwig
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

Posted: Sun Oct 26, 2008 09:35
by CrazyEddie
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.

Posted: Mon Oct 27, 2008 12:37
by gring
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

Posted: Wed Oct 29, 2008 09:25
by CrazyEddie
Wow! Thanks for the effort :)

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

CE.

Re: Debugging CEGUI strings in Visual Studio

Posted: Sun Sep 09, 2012 20:22
by jbl4ir
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

Re: Debugging CEGUI strings in Visual Studio

Posted: Mon Sep 10, 2012 18:41
by MorbidAngel
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.

Re: Debugging CEGUI strings in Visual Studio

Posted: Tue Sep 11, 2012 08:08
by CrazyEddie
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.

Re: Debugging CEGUI strings in Visual Studio

Posted: Tue Sep 11, 2012 16:35
by MorbidAngel
Thanks.

I updated it to your code and works fine.

Re: Debugging CEGUI strings in Visual Studio

Posted: Wed Oct 17, 2012 20:41
by thorlak
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.

Re: Debugging CEGUI strings in Visual Studio

Posted: Mon May 23, 2016 08:00
by kiske1
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!

Re: Debugging CEGUI strings in Visual Studio

Posted: Sat May 28, 2016 12:54
by Ident
Try this: https://bitbucket.org/cegui/cegui/downl ... _0-8-X.zip
Description is in the readme

Re: Debugging CEGUI strings in Visual Studio

Posted: Thu Jul 07, 2016 07:36
by kiske1
Thank you,

Worked pefectly in VS 2015!

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

Posted: Tue Aug 29, 2017 13:17
by FluXy
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

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

Posted: Sat Feb 17, 2018 18:35
by Ident
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/