|
|||||||
![]() |
|
|
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
|
|
|
#9 |
|
Do you see a pane with the debugger variables below the program source?
|
|
|
|
0
|
|
|
#10 |
|
|
0
|
|
|
#11 |
|
That's the "stack trace" pane off to the left side of the "source" pane.
So that's a big "no" on my question. At the top right of the window above the "source" pane is a collection of buttons. One of which is called "View". Select the center button. A "debug" pane should appear "BELOW" your projects source. All the above is accurate assuming you haven't done any custom setup. |
|
|
|
0
|
|
|
#12 |
|
To find the address of variable foo, you can just type:
Code:
print &foo Code:
me r -b <start_address> <end_address> |
|
|
|
0
|
|
|
#13 | |
|
Quote:
Can you tell us what the "Show Toolbar" or "Hide Toolbar" menu does? That's the first step. Next, what do the three icons with "View" under them do? That's the next step. What do the three little icons to the right of the "Clear" button do? |
||
|
|
0
|
|
|
#14 | |
|
Quote:
Thanks |
||
|
|
0
|
|
|
#15 |
|
Why Skype when there a native solutions already a part of your "last version of OSX" - Messages.
What you haven't clearly made apparent yet is if you've got it figured out yet or not! |
|
|
|
0
|
|
|
#16 |
|
|
0
|
|
|
#17 |
|
About printing the variable address, other than printf you can do it with gdb: "print &Var".
|
|
|
|
0
|
|
|
#18 |
|
Have you tried to help yourself based on my previous post above?
|
|
|
|
0
|
|
|
#19 | |
|
Quote:
i want to see the values of my variables in "stack trace", i already know how to go to stack trace using the address, but i cant find the right address of a variable, if i have this: http://bencollier.net/wp-content/upl...t-22.36.27.png it will be very easy. |
||
|
|
0
|
|
|
#20 |
|
Are we both speaking english or is it just me.
I see your variables "below" the "source pane" in that image. Perhaps you could say explicitly what it is you need to see that isn't in that image. If you're looking for the addresses of 'argc', 'argv' and 'retVal' then 'argc' and 'argv' will most likely be in 'registers', which don't have an address and 'retVal' may've been mapped directly to the 'register' in which function results are returned bypassing the stack altogether. |
|
|
|
0
|
|
|
#21 |
|
n/m, that may not even be the OPs code.
|
|
|
|
0
|
|
|
#22 | |
|
Quote:
I posted a simple code above, and i want to share a simple image to show you, what i have in my xcode. Can i send you a image via email, or other way? |
||
|
|
0
|
|
|
#23 | |
|
Quote:
http://forums.macrumors.com/showpost.php?p=15977842 |
||
|
|
0
|
|
|
#24 | |
|
Quote:
Now i need to check in the stack trace, the values of my variables...before and after the breakpoint. |
||
|
|
0
|
|
|
#25 |
|
The picture helps.
In the "debug pane" you're only displaying the "console". See the "clear" button in the "debug pane"? Their's a group of three buttons next to it. Press the center button and your variables sub pane will display what you're wanting to see. |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 10:42 PM.








Linear Mode
