I'm a C++ noob, have been using Terminal/gcc to compile and run my code, but wanted to make the switch to Xcode (v 3.2.5). I've been going through some tutorials but having problems getting the Debugger to work properly.
When I select Build and Debug, if my code has no errors, the Debugger and Debugger Console open and I get a message in the console that debugging ended normally.
When there are errors in the code, I get red error icons in the Editor, but neither the Debugger nor the console open automatically. This isn't a big deal, I can manually open the Debugger. What is a problem is that when I do open it, it's completely empty: nothing at all in the threads, vars or editor panes.
I'm using the default build configuration for the template Command Line Tool > C++ stdc++ (Generate Debug Symbols: on, Strip Debug Symbols: off, Optimization: off). I read the "Troubleshooting Debugger Display" section in the Xcode Debugging Guide and it seems like I'm doing all those things correctly, but as I said, I'm a beginner, so maybe I'm overlooking something really obvious? Appreciate any help, thanks!
Based on your statement about red error icons in the editor, it sounds like you have compile-time errors in your program.
I think you might be confused about what a debugger is for - it's used to find runtime errors with your code, not compile-time errors. The debugger won't be any use to you if your code isn't syntactically correct.
Related
so I recently got started with vscode and working with the c++ project when I noticed that some of the errors aren't displaying. Also, the program would run fine on vscode but when used it on repl.it it would show some critical errors like "signal: Aborted (core dumped)" and it would tell me at which line it encountered that problem.
Looking at vscode however it seems to me it doesn't detect subtle errors such as when I have a function that would return a string and I purposely return 0 instead of a string it still considers it a valid operation. I don't know if the issue is the IntelliSense or some error-checking aspects, but one thing for certain I know visual studio would show this with a warning sign that would appear on the number line.
I do have the squiggly lines enabled for errors and it does show errors if I have some keyword typed incorrectly. What I want to know is where the c++ would fail to run and tell me before the run, or even during runtime.
screenshot of no error when there should be
VSCode is pretty intelligent, and in theory it should be able to have all the IntelliSense that those other IDEs have. However, that does not come out of the box. What you need to do it install some extensions specific to the programming / scripting languages that you work with. For example, for C++ you can download C/C++ extension developed by Microsoft.
After installing the needed extensions please read some documentation and tweak them as needed.
Your IntelliSense issues will be solved.
I've figured out that it wasn't displaying the crash errors because my installation of msvc was flawed. I downloaded msvc again and used the Pacman commands to install all the necessary files and now my crash errors show. However, some syntax errors still don't show like int main {... without a closing curly brace. This code still runs, and the error is picked up during the run time. I would've expected the error to be highlighted before the run.
I'm using Xcode 3.0 on a PowerBook G4. I needed to test some code to see how it runs on a big endian host. I already had it set up to go so got it out to test.
I first created an empty project and added my binary as a custom executable as well as loading in some source files. This seemed to be working fine. The code is a C++ terminal application and I had already setup a Makefile with CMake.
In the beginning I set up some breakpoints and started up the debugger. And it worked well. Stopping at my breakpoints. But then something happened that I don't know what and it started ignoring them.
I setup a new project like before and started from scratch again. Loaded the debugger. And once again it ignored them!
So then I managed to get CMake (2.8.12) to generate an Xcode project file. Which didn't go too easy as it didn't know what compiler I had. Looks like I stumbled onto another bug there. I eventually got past it by going between the CMake GUI and terminal.
I then closed all windows in Xcode and quit it. I then opened up the new project to start afresh. I set up some new breakpoints and loaded up the debugger. The code fell through again but then I realised I didn't set any arguments. So I did that and tried again. It ran through again! I looked up how to reset Xcode prefs and did so. Try again and it keeps ignoring my breakpoints!
I know it's kinda bad to setup an account to ask a question. And I hate to do that. But I'm really over this and don't know what is wrong with it. I've Googled for answers, got some hits here, and tried suggestions like disabling lazy symbols, making sure strip doesn't kill debug symbols and other symbol stuff but none has any affect. I've wasted hours trying to fix it instead of testing code I need too.
What's disconcerting is that no source is loading into the [GDB] debugger either. I actually forced it to stop by doing an implicit read from location zero in my source. And even this wasn't right. It didn't even load up the source but just gave me a disassembly. Even though I had it set to show only source. There's something wrong with it. :-?
Well thanks for any help. I don't know if I'm getting old or what. But this is getting as annoying as a small hidden bug in code that brings the whole house down! ;-)
I have a program that I have written in C++ under linux (Ubuntu 10.10).
The programming and debugging worked perfectly until the moment I added the following lines to the code:
mapfile = fopen(map_filename,"wb");
fwrite(map_header,1,20,mapfile); // <-- this is the problem line
fclose(mapfile);
After I added those, the program compiles ok, but the debugger now won't start. It immediately fails with this message:
Program completed, Exit code 0x177
error while loading shared libraries: unexpected PLT reloc type 0xcc
And if I remove the line with the "fwrite", the debugger will start normally.
This problem only happends inside Netbeans.
When I debug it using the command-line "gdb" it also works ok without any problems.
Anyone have idea why its happening and how to fix it?
P.S: Those problems started recently so I assume maybe it has to do something with system updates, I'm not sure.
Found the problem:
Not long ago, I removed some old C++ projects from netbeans. It figures out that netbeans (at least v7.0) remembers all the breakpoints that I put on old projects that don't even exist in the IDE anymore.
I found this by looking at the Debugger Console (Window->Debugging->Debugging Console) and seeing that when "gdb" starts, it tries to setup all these breakpoints from other projects or from projects that do not exists (this is a bug in netbeans, btw)
The solution: I simply cleaned all the breakpoints (inside Window->Debugging->Breakpoints) and now the program can be debugged properly.
Hope this will help to anyone out there who has the similar problem.
So, I have no idea why, but breakpoints in my code::blocks project are no longer working. I'm using MinGW-W64 compiler and GDB. I used to be able to use breakpoints, but now, for some reason, when I add them to my code they do absolutely nothing - code execution goes right past them without stopping.
Why might this be happening?
You might be compiling your code in release mode. Try changing it to debug mode. Checkout http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks on how to turn on debugging symbols.
I've got a strange problem:
I use eclipse and have written a program which is quite long. Now if I compile "Debug" (so no compiler optimization) and click "Run" then everything is finde and my Program produces the expected output.
Now If I compile "Release" the program does not terminate but instead "stops" at one point...
So I've started Debugging with the dgb Debugger build into eclipse and clicked through the program. And if I let it just run through everything is fine, but If I click through every single line of code then the program "stops" at some other point.
Now I've gone one step further and clicked not only through every line but stepped into each function.
What I found very strange is that in depence on HOW I step through my program with the debugger I get the error at different positions. So I think the stopping of the debugger is related to eclipse which cannot show something in the debugger-window or so.
Additionally the error critically depends on other lines of code.
So my best guess is that the error is related to some memory problem.
Thank you very much!