I was debugging in terminal using gdb, and I typed inlayout src,then I entered the UI mode.
Most of the time, it worked fine, but sometimes, the whole terminal text code got mixed.(I post the picture below.).
what's more, sometimes I typed in some shell command in gdb like !pmap <pid>, its output's format was also strange.
I tried to set TERM to screen-256color but it doesn't work.
I solved it in some sense.
I redirect the output of my program to another tty.
Related
program ss
I tried to debug this program but when I open the terminal window to give inputs, it doesn't take any inputs. It is like the keyboard doesn't work but the window takes inputs just fine when I execute a program normally, this only happens when I try debug a program. Please, help me out!
Edit: my IDE doesn't crash, everything is fine except the terminal window doesn't display or take any of my inputs.
eg: 'Input an integer:' and when i try to input an integer, it doesn't take it or display it on the screen. I have noticed that also it takes longer to close the terminal window when I try to close it.
So for some reason when I run my script and have it output to the terminal just as it would, I get my intended output. Yet when I redirect the output to a file, I don't receive full output.
Let's say I have an executable named "filename" and run it "./filename", the output on the terminal is, let's say :
a
b
c
Yet if I do "./filename > output.txt" or "./filename |& tee output.txt", the output on the terminal AND the output.txt text file is just, let's say:
a
b
I know this isn't very specific, but my output is huge. I was thinking this would be general enough to provide general solutions/ possible problems.
I'm using a program someone else made, so I don't know where this additional output is called. Yet, it shouldn't matter since the functionality of the program doesn't change, just what's being output.
Without a minimal code sample to reproduce, it's very hard to guess what's going on.
But some things you could try:
Redirect all output streams to your file, i.e. your-script &> output.txt
Run it through strace and look for write and open calls to see what's going on
Read and debug the source code to figure out what's going on
I am debugging a C program with gdb. I have used the tty command to send the output to a new terminal window but am unable to enter input while the program is running.
If I debug in the same window it works fine, but when using a separate terminal window, input doesn't do anything.
I can still kill the process with ctr-c but once I hit the input line, it waits for input and doesn't do anything when I press return.
I have looked around but am haven't found the same problem online. Any ideas?
Start your program in one window. While your program is waiting for input, start gdb in another window. Use the gdb attach command to attach to and debug your program.
I'm running GNU Screen and gdb with TUI, and I'm having some issues relating to scrollback, so I want to send the output to a different screen window. What's the best way to do this?
Ideally i'd want the tui input and output (i.e. anything I do like 'print ' from gdb) to be on one window, and the output from printf's, etc to be on a different screen window.
Does anyone know how to do this?
(I'm actually doing remote debugging over gdb + serial, so it's connecting via target remote /dev/ttyS0 in my ~/.gbdinit).
There are maybe a few ways to do this. I think the simplest is the "tty" command though. See "help tty".
Another approach is that taken by "screenify" -- use gdb's inferior call functionality to change the controlling tty (and various std* file descriptors) of the program.
Another approach is to just run your program in another tty and then use "attach".
I've written a tiny program in Ansi C on Windows first, and I compiled it on Ubuntu with the built-in GCC now.
The program is simple:
read the line from console with scanf().
Analyze the string and calculate.
But something weird happens. When I try to move the cursor, it prints four characters:
pressing Up prints "^[[A"
pressing Dn prints "^[[B"
pressing Rt prints "^[[C"
pressing Lt prints "^[[D"
How can this be avoided?
Why does it print these 4 characters instead of moving the cursor?
Because that's what the keyboard actually sends to the PC (more precisely, what the terminal prints for what it actually receives from the keyboard). bash for example gets those values, deciphers them and understands that you want to move around, so it will either move the cursor (in case of left/right) or use its history to fetch previous commands (up/down). So you can't expect your program to magically support arrow keys.
However, reading from standard input from the terminal already supports left/right arrow keys (I believe, but I'm not in Linux right now to test and make sure). So my guess is that there is another issue interfering. One possible cause could be that one of your modifier keys is stuck? Perhaps ALT, CTRL or SUPER?
For those who are coming from the osx (mac) try changing the shells to bash
Terminal -> Preferences -> Shells open with -> [select] Command (complete path)
then paste
/bin/bash
This might be because the user account is created in shell. You can change it to bash by two ways.
Permament solution is -
sudo chsh -s /bin/bash ${username}
To get this solution working you will have to logout and login
Temporary solution is everytime when you login into the ubuntu server type bash and hit return.
If it's under a docker container, run /bin/bash . This helped me solve the problem.
Additionally to what Shahbaz mentioned, I realized that pressing enter (thus sending an empty command) can fix the problem. This is usually necessary after using CTRLC to cancel a command.
On MacOS Terminal for me was enough to uncheck "Scroll alternate screen" for the issue to disappear. See screenshot of the preferences below.
You can (re)bind keys. Add this at the bottom of your .profile, .zshrc or whatever shell config you have.
bindkey -e
bindkey '\e\e[C' forward-word
bindkey '\e\e[D' backward-word
i think simple way is we can just do
kill %%
because this sometimes happen because of background processes.