0

I keep coming across this type of problem again and again so am asking now. I am an eletronic engineer and thus used to writing low leve code. I am using pointers in C++.

I have a function that takes char* msg. When I stop execution using breakpoint in function I am able to see only the first byte of the char* parameter. How do I get the rest? The char* may not be null terminated and will not be of fixed size. Assuming that I can know how long it is, I am not sure how to tell the locals window about it.

Visual Studio has these things called Immediate and Debug windows. I have not used them before? Can they be used to print arbitrary characters from this msg? During break mode? How?

quantum231
  • 2,420
  • 3
  • 31
  • 53
  • 1
    Assuming that `the char* may not be null terminated and will not be of fixed size`, I suggest to check the address in pointer and use the [_Memory_](https://msdn.microsoft.com/en-us/library/s3aw423e.aspx) tab, where you can go to that adress and see what are the contents from the start and till you find what you what (or not find). If not mistaken you can do that before the function, and see how the content at that address is modified (changed bytes should be highlighted) while debugging. – Mikhail Churbanov Oct 31 '16 at 00:19
  • I see, I did not know about this memory viewer. However, doesn't this only show things in hex. Is it really not possible to use one of them immediate or debug window here? I am perplexed what these Windows are used for. – quantum231 Oct 31 '16 at 08:46
  • @quantum231, would you please share the latest information about this issue? – Jack Zhai Nov 07 '16 at 01:08
  • My program heavily relied on pointers as I am from electronic engineering background. After looking into all options I have and still being stuck with elusive bugs and/or increased complexity, I rewrote my program using OOP methodology. I read about how to write program OOP techniques in c++ into book a few months ago. Now the program is working. I only used dynamic memory allocation if I really really had to. Otherwise, I just accessed the private variables inside the class for everything. One class is passed to another class in functions as reference. This solved many other issues too. – quantum231 Nov 07 '16 at 21:51
  • Regardless, I am really impressed by this memory contents viewer tool. Thanks. – quantum231 Nov 07 '16 at 22:06

2 Answers2

1

We couldn't debug it directly in the debug window, other members also asked this kind of issue before and shared the reason why it just showed the first byte of the char* parameter:

http://www.cplusplus.com/forum/general/23205/

vs2010 c++ view pointers content by debug

In Memory Viewer you can choose how you want to view the data, but if you want to print the address, one workaround is that you can cast it to other type of pointer like casting as a pointer to void or others.

Community
  • 1
  • 1
Jack Zhai
  • 6,230
  • 1
  • 12
  • 20
1

Try adding a watch to msg and then try watching msg,10.

You should be watching the 10 next characters.

Something like the screenshot below:

enter image description here

Pingolin
  • 3,161
  • 6
  • 25
  • 40
Shash
  • 19
  • 2