Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Debugging ncurses application in Eclipse CDT (Linux)
Debugging ncurses application in Eclipse CDT (Linux) [message #1821141] Thu, 06 February 2020 09:47 Go to next message
Ksawery Wieczorkowski-Rettinger is currently offline Ksawery Wieczorkowski-RettingerFriend
Messages: 6
Registered: February 2020
Junior Member
I'm creating an ncurses application in the Eclipse IDE (for C/C++ developers), running on Linux Mint. I'm able to successfully launch the application in the gnome terminal from Eclipse, using the following Run configuration, recommended in a Stack Exchange forum:

Quote:

C/C++ Application: /usr/bin/gnome-terminal

Arguments tab:

Program arguments: -e ./nameofproject*

** you can add --window-with-profile=PROFILENAME gnome-terminal setting to run it with other profiles.

Working directory:

Here set the exactly file location directory:

${workspace_loc:nameofproject/Debug}

And deselect 'Use default'

Environment tab:

No changes

Common tab:

Deselect Allocate Console (necessary for input) in Standard Input and Output frame.

Apply and run.



However, the same configuration does not work for debugging. I'm seeing the following message when launching the debugger:

index.php/fa/37295/0/

So far I've been unable to run the Eclipse debugger alongside the gnome terminal. Running the debugger within Eclipse doesn't work either, since i'm seeing the "Error opening terminal: unknown." message, after which the application is terminated. The "Attach to Application" option doesn't seem to work either, I'm only seeing "failure to attach to process" errors when trying to attach the debugger to the application running in a separate terminal (launched separately from the terminal).

Any suggestions?

Many thanks,

Ksawery
Re: Debugging ncurses application in Eclipse CDT (Linux) [message #1821186 is a reply to message #1821141] Thu, 06 February 2020 18:22 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Please do not start multiple threads for the same issue.
Edit the initial post instead.

Eclispe Run is like typing the command in a terminal (more or less).

The message you got is from gbd.
It says that the command is not an executable.
Maybe it's a script.

[Updated on: Thu, 06 February 2020 18:28]

Report message to a moderator

Re: Debugging ncurses application in Eclipse CDT (Linux) [message #1821235 is a reply to message #1821186] Fri, 07 February 2020 15:17 Go to previous messageGo to next message
Ksawery Wieczorkowski-Rettinger is currently offline Ksawery Wieczorkowski-RettingerFriend
Messages: 6
Registered: February 2020
Junior Member
Apologies for starting another thread, I didn't realize that the first one was being moderated. I assumed I didn't post it correctly. I'll reply on this (original) thread from now on.

In response to your previous message - I've been unable to debug via the "C/C++ Attach to Application" debug configuration. I tried to initially launch my application outside of Eclipse, in the gnome terminal, and then attach to that process via Eclipse.

After starting my ncurses application it pauses, waiting for user input, so I should be able to attach the debugger to it. I'm not sure what I'm doing wrong.

I believe that your recommended solution (link below) works outside of Eclipse? How can I launch and attach gdb correctly from within Eclipse?

https://stackoverflow.com/questions/11965328/debugging-ncurses-application-with-gdb

Here is the error that I'm seeing in Eclipse:

index.php/fa/37319/0/

Regards,
Ksawery

[Updated on: Fri, 07 February 2020 15:29]

Report message to a moderator

Re: Debugging ncurses application in Eclipse CDT (Linux) [message #1821236 is a reply to message #1821235] Fri, 07 February 2020 15:49 Go to previous messageGo to next message
Ksawery Wieczorkowski-Rettinger is currently offline Ksawery Wieczorkowski-RettingerFriend
Messages: 6
Registered: February 2020
Junior Member
Ok, I've been able to attach to the process after launching Eclipse with root privileges, however the Eclipse debugger starts to behave erratically - the Variables tab keeps flashing and displaying various errors. My application freezes and the debugger doesn't stop at any breakpoints. I'm still not sure what I'm doing wrong, and why exactly gdb needed root privileges to go past the aforementioned error.

Regards,
Ksawery
Re: Debugging ncurses application in Eclipse CDT (Linux) [message #1821257 is a reply to message #1821236] Sat, 08 February 2020 14:31 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Not sure why you need root privilege to debug an ncurses app.

Eclipse however is merely running gdb and sends it commands as any user might.
It would seem your issue is more related to debugging your app than using gdb through Eclipse.

Try debugging it by running gdb outside of Eclipse to separate issues with your app and those related to Eclipse.

UPDATE:
I came across this post about debugging ncurses with gdb.
It's example is written in python but it may prove helpful anyway.
http://www.brendangregg.com/blog/2016-08-09/gdb-example-ncurses.html

GDB also has a TUI mode you can use:
https://undo.io/resources/cppcon-2015-greg-law-give-me-15-minutes-ill-change/
This was referenced in the first link.


[Updated on: Sat, 08 February 2020 15:24]

Report message to a moderator

Re: Debugging ncurses application in Eclipse CDT (Linux) [message #1821753 is a reply to message #1821257] Wed, 19 February 2020 14:55 Go to previous messageGo to next message
Ksawery Wieczorkowski-Rettinger is currently offline Ksawery Wieczorkowski-RettingerFriend
Messages: 6
Registered: February 2020
Junior Member
Thanks for your message and apologies for the late reply. I'm still trying to solve the gdb issue, with some progress.

I'm able to run my application with gdb directly - it responds to some basic commands, such as start, run, break and continue (i'm a complete beginner when it comes to command line gdb). However, the terminal window quickly becomes cluttered as both the ncurses app and gdb attempt to print to the terminal window.

As the next possible solution I tried to redirect the output of gdb to another terminal window using the tty command. That ended up printing both the gdb and the ncurses outputs to the second terminal, but the ncurses stopped responding to user input. This issue was raised in the forum post that you suggested:

https://stackoverflow.com/questions/11965328/debugging-ncurses-application-with-gdb

Finally, I tried to run the ncurses application separately from a terminal window and attach gdb to the running process, using gdb -p [pid]. Initially I ran into the same gdb error as seen in Eclipse, related to "ptrace operation not permitted". Apparently, this issue is caused by "Linux kernel hardening". The suggested solutions were to run the gdb command as root (and that's why I could attach the Eclipse debugger when running Eclipse as root), or to change the kernel.yama.ptrace_scope variable in /etc/sysctl.d/10-ptrace.conf from 1 to 0.

After changing the suggested variable, I'm able to attach gdb to the process, either from a terminal or from Eclipse. However, gdb behaves in an unexpected manner, printing the following output after attaching to the process:

[New LWP 23653]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007f5c4c59e384 in __libc_read (fd=0, buf=0x7fff83008fdf, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
27 ../sysdeps/unix/sysv/linux/read.c: No such file or directory.

I'm assuming it's becuase I'm using multithreading in my application, and debugging a multithreaded application in gdb is a bit more complicated:

https://www.cs.swarthmore.edu/~newhall/unixhelp/gdb_pthreads.php

I'm also not sure what the ../sysdeps/unix/sysv/linux/read.c: No such file or directory. error means.

When I type the continue command, the application works, and gdb prints out information related to stopping/starting threads (as I navigate through my application). I'm sure there's a way I can debug the application from the terminal (I haven't read through the tutorial yet).

(gdb) continue
Continuing.
[New Thread 0x7ff70e934700 (LWP 23784)]
[Thread 0x7ff70e934700 (LWP 23784) exited]
[New Thread 0x7ff70e934700 (LWP 23787)]
[Thread 0x7ff70e934700 (LWP 23787) exited]
[New Thread 0x7ff70e934700 (LWP 23788)]
[Thread 0x7ff70e934700 (LWP 23788) exited]
[New Thread 0x7ff70e934700 (LWP 23789)]

Unfortunately, Eclipse still behaves erratically after attaching to the process (unresponsive, flashing windows etc). Is there any way to configure Eclipse to support debugging the multithreaded ncurses application? I've previously been successful in debugging a multithreaded wxWidgets application in Eclipse. The debugger worked without any issues (however I didn't have to attach to a separate process then).

Many thanks,
Ksawery

[Updated on: Wed, 19 February 2020 15:09]

Report message to a moderator

Re: Debugging ncurses application in Eclipse CDT (Linux) [message #1821794 is a reply to message #1821753] Thu, 20 February 2020 09:55 Go to previous message
Ksawery Wieczorkowski-Rettinger is currently offline Ksawery Wieczorkowski-RettingerFriend
Messages: 6
Registered: February 2020
Junior Member
Ok so I went into the Debug Configuration in Eclipse and selected all available options under the Debugger tab. Something worked, since I can finally debug my application by attaching to the running process! I'm not sure which setting it was exactly, here's my configuration:

index.php/fa/37409/0/

I also selected 'Automatic' in Tracepoint mode, and deselected the 'Allocate console' option under the Common tab.

I'm now able to set all breakpoints, see all running threads in the Debug tab, and access the Variables tab at any time.

Regards,
Ksawery

[Updated on: Thu, 20 February 2020 10:22]

Report message to a moderator

Previous Topic:When Debug tabbed view is selected, this results in Build Project menu disabled
Next Topic:CDT Indexer not parsing some files
Goto Forum:
  


Current Time: Fri Apr 26 08:32:59 GMT 2024

Powered by FUDForum. Page generated in 0.03284 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top