Debugging in Visual Studio : Breakpoint moves and inserts a new line - c++

I am a beginner with Visual Studio and I am encounting a problem when I am in the Debug Mode.
I did not have this problem at first, and now it happens more and more.
This is what happens :
I am debugging my project and I hit a breakpoint. So I press F5 to continue debugging, and then a new line is inserted just before the line with the breakpoint, and the program continues debugging. Problem is it modifies my code...
The problem does not occur when I press F10 or F11 (but it still happens later when I press F5). And it does not occur everywhere in the code, just with some lines, especially the new ones.
I have tried many things like :
restart VS, clean solution, delete .pdb, make sure I have the good type of linefeed.
Please help me !
:)

Check your Keyboard settings at Tools -> Options -> Environment -> Keyboard.
Try press F5 in Press shortcut keys input and see at "Shortcut currently used by".
In my case there is only "Debug.Start (F5 (Global))".
If you have other commands, try to remove it.

Related

Can you easily debug your code again while the last debugger/console still is open? (Visual studio 2019)

Is there a way/option to always press f5 to "re-run" your code with the console after you've made some changes to it. As for now, you have to close the console/debugger and run again to start your program instead of just pressing f5 to close old console and run the new one.
In the IDLE environment, you could do that and I kind of miss it since it made coding/programming a little faster.
Edit: To clarify, I do some changes, save the code and press f5. But the old console is still running. Which means I have to close it first.
I suggest we could try to click the Restart button in the Debug Toolbar (Ctrl + Shift + F5). When you press Restart, it saves time versus stopping the app and restarting the debugger.

Automatic Code completion in Eclipse 8.4?

I recently installed Eclipse Luna(for win7) for developing C++ programs. The problem is the code completion only shows suggestions when I press Ctrl + Space button. I searched on the internet, but the only solution I was able to find is for old Eclipse(Java) version 3.4 or something. In that you have some text feilds in which you can enter the characters for auto-completion. But in 8.4 there are no such text-fields. Do they have a plugin for this? Please Help me
Yes they've changed the behavior a bit. The auto completion list pops up at entering ., -> or ::, and as you mentioned with CTRL + Space
If the list popped up, press TAB once to get inside the popup selection list, and go up down with the arrow keys. Press enter to select one.
If the entered symbol is specified enough, to select a proposal, hitting Space after the dialog popped up, will autocomplete though.

Xcode 4: why "Continue to current line" is grayed out?

When I am debugging my program, I often want to make it run from where it is paused to a specific line.
In Xcode 3, I was able to do that by clicking on the button appearing next to the line number when hovering it.
In Xcode 4, it seems to be possible to do that either by right clicking on the line number and select Continue to here, either by using the Debug menu and choose Continue To Current Line item.
However these options are always grayed out when I want to use them.
Note, I don't know if this is relevant but I am using c++
Is there something I am doing wrong?
Thanks in advance,
Kevin
It seems that this is because you are using the LLDB debugger. As the same thing happens to me, whilst using the LLDB debugger and debugging C++ code, as you can see here:
I tested this with Objective-C code, and this feature works perfectly fine whilst debugging Objective-C.
The green button you mentioned, for Xcode 3, also pops-up with Objective-C code (using Xcode 4). As you can see here:
Perhaps it's a bug in Xcode, or Apple just wants you to program in Objective-C. It seems to be only an issue whilst using LLDB, and debugging C++ code (I am unsure of C code). On the other hand, debugging with GDB works fine with both: C++ and Obj-C code.
The only real options you have at the current time is:
Option 1:
Use the GDB debugger instead, as the GDB debugger with Xcode supports this.
To change the debugger:
Step 1:
Click your project name under the Scheme Menu, in the top left.
Step 2:
Click "Edit Scheme..."
Step 3:
Once the Edit Scheme menu comes up, click the pop-up menu next to the "Debugger" option.
Step 4:
Click the option "GDB" to use the GDB debugger.
NOTE:
Once you click GDB, the "Debug Process As" option will be greyed out.
Step 5:
Click OK.
NOTE:
I'm not sure about the limitations whilst using the GDB debugger, over LLDB (I think Xcode does not support any recent versions of GDB, as they have switched to LLDB and clang).
Option 2:
Create a breakpoint to where you wish to continue, and then continue to it. It really isn't that hard compared to right clicking and pressing "Continue Here" or the green button. This also provides the same functionality. With the use of keyboard shortcuts it could be just as fast (see below).
For example:
Say you want to continue until you hit line 39.
Set a breakpoint at line 39.
Click "Continue program execution" button, which is the button that likes some-what like a media-play button. Alternatively you can continue using the keyboard shortcut: Command + Ctrl + Y, or use the Menu (Product->Debug->Continue)
NOTE:
You need the Debug area shown (Shift-Command-Y), in order to see the "Continue program execution" button.

Unable to reach breakpoint in Visual Studio

I am facing a odd behavior of Breakpoints in Visual Studio 2010 Express. Below is the code with breakpoints.
I am able to break at the first breakpoint (Line 159), but stepping after line 160, the cursor vanishes, i.e after this image of code pressing F10/F11 the application is displayed.
The problem is,
Why isn't line 162 executing (Without this statement, asserts fail elsewhere) or breaking at it?
Note : The line 166 Refresh(); is being executed, because the application displayed is updated.
EDIT : On suggestions in comments, I stepped through disassembly, and I found this line (from wxWidgets library) is causing the debug to fail 00D5AF7C call wxCharBuffer::~wxCharBuffer (0D207AAh)
Have you tried stepping through disassembly? With combined assembly-source view you can tell what exactly is going on.
To do that once you hit a breakpoint go to Debug->Windows->Disassembly. Or just click RMB and then "Go to disassembly".

C++ on Windows - the console window just flashes and disappears. What's going on? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Visual Studio Console App - Prevent window from closing.
I'm starting to learn C++ on Windows and I'm trying a few different development environments:
1. Netbeans with Cygwin compiler
2. MS Visual Studio 2010
For either of them, when I write a very simple Hello World program, I build it and it's fine. But when I try to run the program, the command prompt window pops up really quick and then disappears right away.
This happens whether it's in Debug or Release config. Please help with this - I can't see my program output! :(
Thanks.
EDIT1:
Thanks for the replies. This is my code:
#include <iostream>
int main()
{
std::cout << "This is a test." << std::endl;
return 0;
}
I tried Ctrl+F5 for "Start without Debugging" and that doesn't work. It still flashes the black console screen then disappears right away.
I also tried adding in std::cin.get(); and this works with Ctrl+F5, but isn't that a really... inelegant workaround solution? I'd rather have my program in the final form.
The breakpoint works, but then I have to run with debugging and the console window flashes and disappears, but then it stays in the background. Any way to get the console to stay in the foreground so I can see program output right away? Seems like that's how it should work.
Any more ideas? Why wouldn't Ctrl+F5 work?
After you are done with your program, press Ctrl + F5 ( Run without debugging). This will prompt before closing the window and this is what you want.
Write cin.get() at the end of the program.
use Ctrl+F5 to run your program or set a break point in the last line or write cin>> to any vraiable at the end....etc
I think your program just prints Hello World and then exits. That's the reason the console closes immediately. You can run the executable from Command Prompt (Start Menu > Run and type cmd.exe). Otherwise, you can put std::cin.get() in your code so that program waits for user's input and hence the console window remains open until a key is pressed.
Your application is probably working. Make the last command in your console application wait for user input: e.g int i;
string i;
cout<<"Hello";
cin<<i;
Issue a getchar() before returning or run from cmd.exe