Author Topic: Strange behaviour in memory window while debugging  (Read 6230 times)

Offline gygabyte017

  • Multiple posting newcomer
  • *
  • Posts: 10
Strange behaviour in memory window while debugging
« on: May 17, 2008, 03:05:52 pm »
Hi, I'm trying to debug a simple C program with Code::Blocks. In memory window, while debugging (I see correctly the disasm window with yellow arrow at the line debugged), if I write an incorrect address (e.g. 0x0) in output I see "Cannot access memory at address 0x0", but if I put a correct address (e.g. &i), the output is blank. Not really blank, it's filled by X blank spaces (the X is the number of bytes set in combobox).
So it seems that there is a problem in showing memory dump. Is there a bug? Or I'm doing something wrong?

I post an image to show what happens: [img=http://img516.imageshack.us/img516/2005/schermataep9.th.png]

Thanks

Offline gygabyte017

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Strange behaviour in memory window while debugging
« Reply #1 on: May 18, 2008, 08:32:32 pm »
I've noticed that in windows version of Code::Blocks, this error does not happen... So it seems to be a unix problem?!
Is there any ubuntu user that has some data in memory dump window ??

Thanks again

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Strange behaviour in memory window while debugging
« Reply #2 on: May 18, 2008, 10:37:19 pm »
After your first post I tested it on debian and had the same problem.

Today I wanted to debug C::B to look for a possible bug and ...
... it works as expected.

I'm a little bit confused, because I did not update any relevant files since yesterday afaik.

debian sid/experimental, 64 bit, C::B svn r5074
gdb 6.8-3, gcc 4.2.3-6, g++ 4.2.3-9, libstdc++6 4.3.0-4, libc6 2.7-11

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Strange behaviour in memory window while debugging
« Reply #3 on: May 20, 2008, 09:56:38 am »
It's definitely a bug in C::B's debugger plugin, due to incorrect/insecure use of wxString::Format with format-string "%s" and a wxChar-Array.
Quote
On (some) linux systems the memory dump randomly shows nothing but blanks.
The problem is using of wxString::Format with format-string "%s" to show the wxChar[] m_LineText in ExamineMemoryDlg::AddHexByte.

The Format-function for char-arrays needs either a null-terminated string or an explicitely given precision to know the end of the string.

In some cases the last byte after m_LineText is not 0 and the function tries to read more what leads to the following error-message in the console (if C::B is started from commandline):
"(codeblocks:890): Gtk-CRITICAL **: gtk_text_buffer_emit_insert: assertion `g_utf8_validate (text, len, NULL)' failed".

It was not so easy to track it down, because it only happens randomly.

I described the bug here and posted a patch.

There seems to be no other place where Format is used in this way. In all other places a ".c_str" is used and that returns a null-terminated string I guess.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Strange behaviour in memory window while debugging
« Reply #4 on: May 20, 2008, 10:10:51 am »
@gygabyte017

Can you test the patch yourself ?

I will upload patched debian packages to my repository during this day.

EDIT:

It's in my repo now.
« Last Edit: May 20, 2008, 12:30:24 pm by jens »

Offline gygabyte017

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Strange behaviour in memory window while debugging
« Reply #5 on: May 21, 2008, 06:19:27 pm »
@jens

ok, now it works, thanks!

But there are still problems with addresses shown at the left of dump window... Randomly, all rows have address '0x7fffffff' instead of the address written on textbox... Sometimes addresses are correct, sometimes they aren't..

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Strange behaviour in memory window while debugging
« Reply #6 on: May 22, 2008, 06:07:23 pm »
But there are still problems with addresses shown at the left of dump window... Randomly, all rows have address '0x7fffffff' instead of the address written on textbox... Sometimes addresses are correct, sometimes they aren't..

Fixed in revision 5077. :)
Be a part of the solution, not a part of the problem.

Offline gygabyte017

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Strange behaviour in memory window while debugging
« Reply #7 on: May 22, 2008, 08:13:54 pm »
Perfect! Thanks! :D