|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
|
#1 |
|
Check in xcode where is the value of a variable in memory
Hi developers.
I am using xcode to build some simples command line programs, and now i want to check where is the value that i insert to a variable, i am writing in C language. Exemple: scanf("%d", &Var); well, i run the program and insert the value, then i pause the program executation and go to Product -> Debug -> View memory and then i dont know what address i need to choose to see my value of the variable, anyone can give me some help with that? Thanks people. |
|
|
|
0
|
|
|
#2 |
|
You should just set a breakpoint at that line, step over it, and in the debugger you will see the new value for 'Var'.
You could obviously printf out the variable, and its address (&Var) too. |
|
|
|
0
|
|
|
#3 | |
|
Quote:
How can i get the right address of my variable? Thanks for the answer |
||
|
|
0
|
|
|
#4 |
|
Is your variable on the variable list? If so, select it. Right click. One of the options is View Memory of "Var". It will bring up the memory viewer at the correct location.
Otherwise, you can print it out with printf. Code:
printf("%p\n", &Var);
|
|
|
|
0
|
|
|
#5 | |
|
Quote:
i am using this program... Code:
#include <stdio.h>
int seconds_from_time(int h, int m, int d)
{
return( h * 3600 + m * 60 + d);
}
void exercise_1_1 (void)
{
int h;
int m;
int d;
while (scanf ("%d%d%d", &h, &m, &d) != EOF)
{
int z = seconds_from_time (h, m, d);
printf ("%d\n", z);
}
}
int main()
{
exercise_1_1();
return 0;
}
Last edited by grapes911; Nov 14, 2012 at 06:26 PM. Reason: added code tags to make it more readable |
||
|
|
0
|
|
|
#6 | |
|
Quote:
"Pause" isn't very helpful because by the time you press "Pause" your program has been running on executing about 2 billion instructions per second, so you can probably see on the left side in the call stack that it is in the middle of the scanf function, waiting for your input. Use a breakpoint. |
||
|
|
0
|
|
|
#7 |
|
Which versions of Mac OS and Xcode are you running?
|
|
|
|
0
|
|
|
#8 |
|
I am using the last version of OSX and Xcode.
i am using the lldb debugger. i am using the breakpoint at the line of scanf, using the code that i posted above, when i run the the code and it stop at the breakpoint i have 3 things in the debugger navigation, exercise_1_1, main and start. What i am doing wrong? |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 04:20 AM.








Hybrid Mode
