1

I can only post this as I have a new account Hey if there is anyone who uses Xcode for CPP PLEASE HELP ME I have searched everywhere and can not figure out what I am doing wrong. I want to debug but while debugging I want to be able to input values into a variable and I can not figure out how. Please if anyone can help me. Thank you!

I have tried looking everywhere and cannot find the solution anywhere. If needed I can provide a screen shot of my xcode.

Navire
  • 21
  • 3
  • Your debugger should enable you to change variable values/memory content, while you're stepping through the code. That's not done via `std::cin` – πάντα ῥεῖ Dec 13 '22 at 20:05
  • oh okay so I would have to do that manually within lldb? – Navire Dec 13 '22 at 20:06
  • Debugging from an IDE usually gives you access to a console or terminal where the programs output is written, and the normal input is read from. I'm sure that Xcode have it too, you just need to look around for it. – Some programmer dude Dec 13 '22 at 20:07
  • I've looked everywhere and cannot find it at all i've searched far and wide on the internet as well. I am pretty new to programming so that is probably a huge factor as well. – Navire Dec 13 '22 at 20:08
  • yep, xcode definitely has a terminal, don't have it in front of my now but it definitely is there – Alan Birtles Dec 13 '22 at 20:09
  • @Navire it's pretty unclear what you're actually asking about. – πάντα ῥεῖ Dec 13 '22 at 20:10
  • lets say I am doing simple like std::cin >> helloWorld;. When I debug I want to be able to input a string into that variable lets say "Hello there". But when I do input to the console nothing happens and the debug ends – Navire Dec 13 '22 at 20:13
  • Which is why I am asking stack overflow and have said that I am fairly new to C++. If you aren't helping with the question asked, why do you feel the need to provide some condescending response? Do you need to feel validated? – Navire Dec 13 '22 at 20:14
  • the question is unclear. The comments are trying to help clarifying the question. Well, my comments was rather editorial, because I think the wording could be improved. You can [edit](https://stackoverflow.com/posts/74790300/edit) the question to add more details, some code and explain what variables value you want to change – 463035818_is_not_an_ai Dec 13 '22 at 20:17
  • Alan I was seeing that online and I do believe that it is using a terminal. When I debug it is saying (lldb) – Navire Dec 13 '22 at 20:17
  • e.g. area on the bottom right in this screenshot https://stackoverflow.com/questions/32425625/xcode-6-to-xcode-11-detach-the-console-log-window – Alan Birtles Dec 13 '22 at 20:19
  • yes I do have that. If I don't have any breakpoints I am able to type into the console but as soon as I add any breakpoints all I see is (lldb) and when I step to the std::cin>>helloWorld; it just stops the code and I am not able to type anything into the console. – Navire Dec 13 '22 at 20:21
  • I appreciate everyone trying to help. This is my first post on stack overflow. – Navire Dec 13 '22 at 20:24
  • @Navire Show your code, show where you set breakpoints, show where your program doesn't stop at them, or where you're missing a terminal prompt to input something. Your question is vague at best. – πάντα ῥεῖ Dec 13 '22 at 20:36
  • I was only able to add one photo – Navire Dec 13 '22 at 21:02
  • Use the "debugger output" drop down to change back to the terminal – Alan Birtles Dec 14 '22 at 07:30

2 Answers2

1

It seems your question is: How do I change a variable while debugging with Xcode?

For simple types like int and double, it's very straightforward. Option-click on the variable and select Edit Value.... Then the value turns into an editable text field.

enter image description here

For variable of type string, it's more difficult as they are actually complex C++ classes. The easiest approach is to do it in the console and call the string object's assign() function:

call str.assign("xyz")

Note that the debugger doesn't immediately realize that the value has changed. So it keeps displaying the old value until you continue to run the code.

enter image description here

Codo
  • 75,595
  • 17
  • 168
  • 206
  • Okay I see thank you so much! When I do the method of changing value it is not stepping through the rest of the code. – Navire Dec 13 '22 at 20:40
  • I don't understand your last sentence. Are you saying that – after you have modified a variable and continued to run the code – it doesn't take the path you expect? If so, you would need to show your code to get help. – Codo Dec 13 '22 at 20:45
  • I was only able to add one photo, I hope that helps. – Navire Dec 13 '22 at 21:02
0

To enable input through std::cin switch debug output window mode from "All Output" to "Target Output".

Sergei Krivonos
  • 4,217
  • 3
  • 39
  • 54