I'm trying to debug a simple program of several line with gdb from the command line.
The problem is that whenever I run the program it runs the program and then automatically assume that I wanted to quit and quit gdb for me.
I'm using gcc compiler and I've updated the version (which solved another problem that I had).
to clarify the problem is that it is not me who entered the quit command after the run command, gdb generates it automatically without asking me and then assumes yes.
I fixed this problem by running gdb in a cygwin window rather than a Windows command window. I get the cygwin window by running (i.e., double-clicking on) mintty.exe, which on my machine is at
C:\cygwin64\bin\mintty.exe
Related
I have made a c program with codeBlocks on windows 10, but the exe crashes as soon as I open it, actually it does not matter the program all exe produced by codeblocks won't run, maybe there are some problems with the settings? Cause if I run the program from inside codeBlocks it runs without problems, any suggestion?
You are compiling "command line programs", which don't open a window on their own. Since they apparently don't expect any user input they run to the end quite happily and quit.
If you want to run this type of programs, you need a shell, which provides a window.
This is a simple way to get one: Open a file explorer window and navigate to the directory containing your program. Click into the address bar so that it changes into a textual representation of the path. Replace all of it with the word cmd and press enter. Now the shell's window opens, commonly with white text on a black background. Enter the name of the program, and it will run.
There's this bug with the placement of certain characters in the embedded terminal in CLion (the Run tab that pops up when you click the Run button), and I figured out that if I changed the terminal in CLion, that wouldn't happen. I changed the terminal to cmder, and it is all working now, except one thing: I can't figure out how to make CLion run the program to that terminal.
I tried changing the configuration, but all it did on run was open cmder but not execute the program (I had to run it manually, by writing the file name).
I wonder, what's the way to fix this, and make CLion directly run C programs on the terminal, instead of the Run tab?
Thank you.
The CLion run configuration always runs in the integreted run window. That is not a terminal emulator, and it cannot be changed so that it runs in an actual terminal emulator (like cmder).
Your best bet is to try to fix the "character placement" in the run window. Maybe ask a different question where you explain the issue, or if it's a clear bug, file a bug report for it.
I am using eclipse cdt oxygen with mingw64 7.2.0 on windows 10 to write programs in c. Whenever I write programs that only outputs like:
printf("x\n");
The output got printed into the console. However when I write programs that asks for inputs, like:
c = getchar();
rather than going to the console, eclipse instead opens a terminal. I believe that is where you will type the input. This doesn't usually bother me, however my eyes are destroyed, I am using a screen reader and this terminal is somewhat inaccessible. It is usable, but can be very hard to use sometimes (E.G. my screen reader JAWS does not speak what I'm typing).
Is there a way for eclipse cdt to put all inputs and outputs directly to the console?
Unfortunately in this case eclipse console is read only. Better once compile and build your code go to the folder where it created your exe file and run that exe in command prompt and test.
open command prompt window (type cmd)
cd C:\path_to_your_exe\
yourexe
This will also help you in case your program takes command line parameters.
I had to write code in C and run it for an assignment. Since this is the first time that I'm using C, I downloaded MinGW as a compiler and Code Blocks as an IDE. I had no problem compiling the code given by my professor but it never runs (this is a simulation for an M/M/1 queue). When I say it never runs, I mean that a command prompt like window pops up and nothing happens after that. Every time I close that window and try to compile the SAME program again, I get an error that says that permission to access the file has been denied.
I then deleted Code Blocks and tried running the program through command prompt but I have the same problem. I've now tried doing it using LCC-Win but nothing has changed. Another weird thing that happens when I run any program is that three instances of the .exe file of that particular program are in my processes under task manager. I then need to restart my computer to try compiling that same program.
I even tried running a simple Hello World program and I have the same problem!
I am currently using a Windows 7 32-bit system.
Any help would be greatly appreciated!
I'm trying to debug my ncurses application, using gdb. I use tty command to redirect program's I/O to another terminal. Output works like a charm, but I'm having problems with input. I'm using getch() function to retrieve symbols in my app. So, for instance, if I do in my gdb session:
tty /dev/pts/5
I get my output in another tab of my terminal window (gnome-terminal). My gdb sessions is getting stuck, waiting for input, but when I press any key within my /dev/pts/5 I get it printed out, but the app itself does not except it as an input symbol. When running without gdb everything works fine, I'm also using noecho(), so symbols should not be displayed.
So, what's the problem? Is it possible to somehow handle input from redirected terminal?
You can attach to your process to debug from a different terminal instead of trying to run the application from within gdb.
Run your process as normal. When it is blocked for user input, find its process ID, and then attach to it with gdb from a different window:
gdb -p <PID>
Your problem is due to the program still expecting its interactive input to be coming from your gdb session.
Maybe it's a bit late to answer, but hope this helps:
It took some time to figure out how to debug ncurses applications,
finally i made a very comfy way with the help of gdbserver and tmux.
This way I/O of gdb and the application are completely separated:
debug.sh (the script that starts debugging):
#!/bin/bash
tmux splitw -h -p 50 "gdbserver :12345 ./yourapplication"
tmux selectp -t 0
gdb -x debug.gdb
debug.gdb (one-liner gdb scriptfile for comfort):
target remote localhost:12345
So this way, application starts up on right side, gdb on left waiting to hit continue or any other usual gdb stuff :)
Once you exit, tmux automatically closes the gdbserver (therefore right panel as well) and that's all :)