views:

66

answers:

4
#include<stdio.h>
#include<string.h>

int main(void)
{
   int f;
   char duma[] = "asd char";

   f = strlen(duma);
}

So when I run it in debugger and in "watch" table type strlen(data) its getting back a message like word like strlen() does not exist or something like that, the mean is that strlen does not exist, however in locals f = strlen(duma) i mean its making the calculations and show me the number of chars in the array. In Immediate its just the same like in watch strlen does not exist ...

So any suggestions how can i fix it ???

Thanks in advance

+2  A: 

A "watch" is for variables not functions, with a few exceptions. In general, you don't want to put functions in a watch window because they can have side effects and change the state of your program every time they display.

For code like that, you should put f in the watch window, not strlen(duma).

Tim Sylvester
The VS debugger is able to evaluate many types of expressions, not just variables, in the watch, immediate, etc. windows.
Michael Burr
+1  A: 

strlen is a function and not a variable. The debugger would have to call the function every step to update the right value. This would not be very efficient. In any way, the debugger requires you to enter variable names there, not functions.

txwikinger
A: 

You might be running into the following restriction on the debugger's expression evaluator:


Edit:

I don't think I'm right about the 'intrinsic' part. I was initially testing with VS2010 (which is what I had most readily available) - VS2010 seems to be able to evaluate strlen(duma) with no problem.

When I moved to a machine that had VS2008 on it (sorry - VS2005 isn't installed right now...), the debugger was unable to evaluate strlen(duma) regardless of the settings for strlen() being intrinsic or not.


One more edit:

In VS2008 I couldn't get strlen(duma) to evaluate in the debugger watch window. However, I was able to get myStrlen(duma) to evaluate in the watch window, where myStrlen() was the obvious wrapper that did nothing but return strlen(). This may be a workaround for you (or you might want to upgrade to VS2010).

Michael Burr
A: 

If your doubt is that, you cannot step into strlen function, then the reason is strlen is from the standard library and you cannot step into that function as they are normally stripped of debugging symbols.

The user defined functions are compiled with options to retain the debugging symbols and hence you can step-into those function calls and see the execution line by line.

To have symbols from these routines available, you must satisfy two 
requirements for GDB:
     *  You must have debug versions of the libraries available.
     *  GDB must know where to find them.

And as others have indicated you cannot put a watch on functions, you can watch variables to know when their state changes.

Praveen S
strken was working 2 days ago... yesterday just stopped to work, pc was not touched and i left it working ... just a shut down the PC and next time was GONE?!?!?!
ScReYm0
@ScReYmo- What do you mean by strlen was working? How did you go about setting a watch or step-into the function.A power shutdown will not cause system libraries, compilers, executables behaviour to change. So please provide more information stepwise.
Praveen S
I mean this that when I type strlen(array) its prints me back the length of array. But now when i type on SAME CODE strlen(array) its print me back error: CXX0017: Error: symbol "strlen" not found instead of my array's length
ScReYm0
Ok paste your code.
Praveen S