Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A little OT. Debug a ncurses C program with eclipse

75 views
Skip to first unread message

Paulo da Silva

unread,
Jul 19, 2021, 3:15:55 PM7/19/21
to
Hi!

I have tried lots of ideas from Google search but still didn't get any
success debugging a C program with ncurses using eclipse! I think that's
mainly because the suggestions are for older eclipse versions.

This should be simple. It's only a matter of being able to insert
-tty=/dev/pts/X in the gdb command line issued by eclipse, I think. X is
obtained by tty command on a pretended terminal.

But I can't do this. Besides the command line "issued" by eclipse uses
-nx which tells eclipse to not read any command from .gdbinit file!

Does anyone here have used eclipse for such purpose that could perhaps help?

Thank you.

red floyd

unread,
Jul 19, 2021, 8:56:12 PM7/19/21
to
Have you tried starting the program in a terminal, and then attaching
the eclipse debugger to the PID of that process?

Paulo da Silva

unread,
Jul 19, 2021, 9:25:31 PM7/19/21
to
Às 01:55 de 20/07/21, red floyd escreveu:
How do I do that?
Insert some sleep at the beginning, launch it and then use "Attach to
Application" in the Debug Configurations?
I'll try that, but it's weird for a thing that should be simple.
Thanks

Paulo da Silva

unread,
Jul 19, 2021, 9:33:23 PM7/19/21
to
Às 02:25 de 20/07/21, Paulo da Silva escreveu:
> Às 01:55 de 20/07/21, red floyd escreveu:
>> On 7/19/2021 12:15 PM, Paulo da Silva wrote:
>>> Hi!
>...

>>
>> Have you tried starting the program in a terminal, and then attaching
>> the eclipse debugger to the PID of that process?
>>
> How do I do that?
> Insert some sleep at the beginning, launch it and then use "Attach to
> Application" in the Debug Configurations?
> I'll try that, but it's weird for a thing that should be simple.
> Thanks
>

It failed!
A popup message appears:

Error in final launch sequence:

Failure to attach to process: testC [56830]
Error:
Failed to execute MI command:
-target-attach 56830

Error message from debugger back end:
ptrace: Operação não permitida. (Tr. from pt: Operation not
allowed/permited)


Öö Tiib

unread,
Jul 20, 2021, 6:36:52 AM7/20/21
to

Paulo da Silva

unread,
Jul 21, 2021, 1:31:44 PM7/21/21
to
Às 02:33 de 20/07/21, Paulo da Silva escreveu:
Ok, to fix this:
Change in /etc/sysctl.d/10-ptrace.conf
kernel.yama.ptrace_scope = 1
to
kernel.yama.ptrace_scope = 0

Besides, one needs to put, for example, getchar(); at the beginning of
the program for it to wait the debugger attach. Then just hit enter and
the debugging should proceed normally.

A very weird solution, however!!

Regards

red floyd

unread,
Jul 21, 2021, 9:02:45 PM7/21/21
to
You could put "break main" in your .gdbinit file. Then it will break at
main automatically.

Paulo da Silva

unread,
Jul 22, 2021, 12:16:46 PM7/22/21
to
Às 02:02 de 22/07/21, red floyd escreveu:
> On 7/21/2021 10:31 AM, Paulo da Silva wrote:
>> Às 02:33 de 20/07/21, Paulo da Silva escreveu:
>>> Às 02:25 de 20/07/21, Paulo da Silva escreveu:
>>>> Às 01:55 de 20/07/21, red floyd escreveu:
>>>>> On 7/19/2021 12:15 PM, Paulo da Silva wrote:
>>>>>> Hi!
...

>>> Error message from debugger back end:
>>> ptrace: Operação não permitida. (Tr. from pt: Operation not
>>> allowed/permited)
>>>
>> Ok, to fix this:
>> Change in /etc/sysctl.d/10-ptrace.conf
>> kernel.yama.ptrace_scope = 1
>> to
>> kernel.yama.ptrace_scope = 0
>>
>> Besides, one needs to put, for example, getchar(); at the beginning of
>> the program for it to wait the debugger attach. Then just hit enter and
>> the debugging should proceed normally.
>>
>> A very weird solution, however!!
>>
>> Regards
>>
>
>
> You could put "break main" in your .gdbinit file.  Then it will break at
> main automatically.
>
You are missing the point that the program is launched outside
eclipse/gdb. So it runs ... Later we attach to it from eclipse. So, we
need to force it "to wait" for us to attach to it.

Besides, the eclipse issues a call to gdb using -nx. This means no
.gdbinit is executed.

Regards

red floyd

unread,
Jul 22, 2021, 1:38:54 PM7/22/21
to
Couldn't you run under gdb in the terminal, break at main, and then
detach once you've attached Eclipse?

Paulo da Silva

unread,
Jul 22, 2021, 8:19:02 PM7/22/21
to
Às 18:38 de 22/07/21, red floyd escreveu:
I didn't test, but may be. Neverthless, for repeated lauches, it may not
be wothwhile.
I'll see ...

Thanks
0 new messages