Author Topic: gdb with custom makefiles: unabled to interrupt while running  (Read 13857 times)

Offline pasdVn

  • Multiple posting newcomer
  • *
  • Posts: 15
gdb with custom makefiles: unabled to interrupt while running
« on: February 13, 2011, 09:16:24 pm »
Hey guys,

I'm new to your forum and have - what a suprise - a (small) question. I'm currently trying to use C::B as a confortable IDE for a quite big project, that supports the build with the GNU autotools at unix systems. I'm using the auto-generated Makefiles in C::B witch works quite good for now.

The problem is the Debugging process (using gdb): I can start debugging without problems. It is also possible to add breakpoints before starting the Debug-session or when you reached a breakpoint while debugging (so the programm is interrupted currently). What does NOT work is to interrupt the programm while it is running (via "Stop Debugger", the red button with the white cross :-P) and thus not adding any new breakpoints. So in fact it is the "Ctrl-C" what you would use to interrupt the running programm if you start a gdb debug-session at the bash.

I also tried to create an own hello-world programm with a custom makefile. For any reaso this worked perfectly when I tried to debug it via C::B.

Tried to find any hints in this forum, but was not sucessfully until now. Maybe anyone of you has an idea how I can make it work?


My system:
Ubuntu 10.10 (x86_64)
GNU gdb (GDB) 7.2-ubuntu
C::B 10.05 rev6282 (From Jens' deb-repo, a big thx for that, btw :-) )

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #1 on: February 13, 2011, 10:42:16 pm »
Try a nightly from the debuggers branch, this is the latest one: http://forums.codeblocks.org/index.php/topic,14207.0.html

I think there the problem should be fixed, if it is not please provide a minimal test case project.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pasdVn

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #2 on: February 14, 2011, 11:35:50 am »
Thanks for your answer.

I just noticed, that I used a quite old version of c::b on my dektop-pc (the one, that shipps with the distribution, the nightly build was on another machine, where I did not try to debug this project). Nevertheless I tried the actual nightly build of the debug branch, but there occures the same problem: No "communication" to gdb, while it the programm is running.

I'll see what I can do to provide an example. As I mentioned it worked with a very small programm using custom makefiles. Also possible, that the problem is not connected to the custom makefiles, but to anything else :-/ Debugging from the shell via gdb works like a charm.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #3 on: February 14, 2011, 12:37:50 pm »
So the pause button doesn't work?
Have you tried  to interrupt  hello world project with something like "while(1) sleep(1);" ?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pasdVn

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #4 on: February 14, 2011, 03:58:01 pm »
Also tried this now, but everything works fine with my hello-world.

I also tried to reproduce this behaviour of the big project by starting gdb from the console with all custom initialisation commands codeblocks uses (as they get printed in the "Debugger (debug)"-window), but in this case it is still possible to break with Ctrl-C.

Edit: Just treid to send the gdb-session (started via codeblocks) a SIGINT (via htop or similar). In this case it really gets interrupted an I can control gdb again out of the codeblocks IDE.
« Last Edit: February 14, 2011, 04:15:05 pm by pasdVn »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #5 on: February 14, 2011, 06:24:12 pm »
Does your app interrupts SIGINT?
I think C::B is sending SIGINT to your app first and then tries to send it to gdb.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pasdVn

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #6 on: February 14, 2011, 09:31:58 pm »
Tried this now with sending to the app. It also works in this case (so does not matter if I send it to gdb or the app). What is also interesting (or maybe you can expect that) is, that all the breakpoints I try to set while the application is running are like in a waitqueue: with every SIGINT I send to the application (or gdb) manually, cb sets a breakpoint and resumes the app.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #7 on: February 14, 2011, 10:21:39 pm »
Can you paste the debugger's debug log? (in code tags)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pasdVn

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #8 on: February 14, 2011, 10:34:34 pm »
Here it is:

Code
LD_LIBRARY_PATH=.:
Command-line: /usr/bin/gdb -nx -fullname  -quiet -args ../mangos-server/bin/mangosd
Working dir : /home/tobias/Entwicklung/mangos/origin/builddir/
Reading symbols from /home/tobias/Entwicklung/mangos/origin/mangos-server/bin/mangosd...
> set prompt >>>>>>cb_gdb:
Queued:[tty /dev/pts/4]
done.
(gdb) >>>>>>cb_gdb:
> show version
GNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
>>>>>>cb_gdb:
> set confirm off
>>>>>>cb_gdb:
> set width 0
>>>>>>cb_gdb:
> set height 0
>>>>>>cb_gdb:
> set breakpoint pending on
>>>>>>cb_gdb:
> set print asm-demangle on
>>>>>>cb_gdb:
> set unwindonsignal on
>>>>>>cb_gdb:
> set print elements -1
>>>>>>cb_gdb:
> set disassembly-flavor intel
>>>>>>cb_gdb:
> catch throw
Catchpoint 1 (throw)
>>>>>>cb_gdb:
> source /usr/share/codeblocks/scripts/stl-views-1.0.3.gdb
>>>>>>cb_gdb:
> cd ../mangos-server/bin
>>>>>>cb_gdb:
> directory /home/tobias/Entwicklung/mangos/origin/builddir/
>>>>>>cb_gdb:
> directory /home/tobias/Entwicklung/mangos/origin/
>>>>>>cb_gdb:
> tty /dev/pts/4
>>>>>>cb_gdb:
> run
[Thread debugging using libthread_db enabled]
[New Thread 0x7ffff541b700 (LWP 25750)]
[Thread 0x7ffff541b700 (LWP 25750) exited]

Afterwards there is silence.. as long as I don't start to send SIGINTs manually.

Tried it on my other x86 machine btw. Same problem here, so really seems to be some specific problem with this application :-/
« Last Edit: February 14, 2011, 10:38:15 pm by pasdVn »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #9 on: February 14, 2011, 11:27:41 pm »
Is your application a daemon?
Does it fork?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pasdVn

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #10 on: February 15, 2011, 03:09:33 pm »
It does not run as a daemon.

I'm not that familiar with the unix fork, but if you want to know that: It is a multithreaded application, running under several PIDs. It does not use fork(), as much as I know.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #11 on: February 15, 2011, 03:43:10 pm »
It does not run as a daemon.
To be a daemon doesn't mean to be run with &, there a few things an app should do to be a daemon and it should be explicit.

I'm not that familiar with the unix fork, but if you want to know that: It is a multithreaded application, running under several PIDs. It does not use fork(), as much as I know.
Can you try:
1. printf("start pid: %d\n", getpid()); after int main(....) {
2. printf("work pid: %d\n", getpid()); at the point where you want to interrupt your program (make sure it is on the main thread).

C::B can debug multi-threadeds apps
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pasdVn

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #12 on: February 15, 2011, 09:18:50 pm »
Quote
To be a daemon doesn't mean to be run with &, there a few things an app should do to be a daemon and it should be explicit.

Ok :-)

Quote
start pid: 14836
work pid: 14836

Additionally I'm really sure now,. that it does not fork, after reading a bit about that topic (and stepping through the code, what works already really nice <3).

Thank you for patience with me, btw!

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #13 on: February 15, 2011, 09:43:26 pm »
Can you try to rebuild C::B debugger's branch with this patch applied:

Code
Index: src/plugins/debuggergdb/debuggergdb.cpp
===================================================================
--- src/plugins/debuggergdb/debuggergdb.cpp     (revision 6974)
+++ src/plugins/debuggergdb/debuggergdb.cpp     (working copy)
@@ -1570,7 +1570,8 @@
     // m_Process is PipedProcess I/O; m_Pid is debugger pid
     if (m_pProcess && m_Pid && !IsStopped())
     {
-        long pid = m_State.GetDriver()->GetChildPID();
+        long childPid = m_State.GetDriver()->GetChildPID();
+        long pid = childPid;
     #ifndef __WXMSW__
         if (pid <= 0)
             pid = m_Pid; // try poking gdb directly
@@ -1578,7 +1579,11 @@
         if (pid <= 0) // look out for the "fake" PIDs (killall)
             cbMessageBox(_("Unable to stop the debug process!"), _("Error"), wxOK | wxICON_WARNING);
         else
+        {
+            DebugLog(wxString::Format(_("Code::Blocks is trying to interrupt process with pid: %ld; child pid: %ld gdb pid: %ld"),
+                                      pid, childPid, m_Pid));
             wxKill(pid, wxSIGINT);
+        }
     #else
         // windows gdb can interrupt the running process too. yay!
         if (   (pid <=0)
After you've applied the patch and recompiled (remember to execute ./update).
You should see info in the debugger's debug log what C::B is trying to interrupt.

Another option is to build C::B with debug info (install -dbg package if there is such) and debug C::B itself with gdb.
You should put breakpoint in DebuggerGDB::DoBreak.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pasdVn

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #14 on: February 16, 2011, 04:50:06 pm »
After trying to Debug the Version of the packet-manager, which gave me only a <value optimized out> here my result with your patch:

Code
Code::Blocks is trying to interrupt process with pid: 13748; child pid: 13748 gdb pid: 13736

Edit: Hmm ok. This seems to be the Problem: There is no process with this pid running :-/
Edit 2: Hmm Ok, strange. I started my app and breaked at main. The main thread has PID 14386. But later, if I want to set a breakpoint in main he want's to interrupt PID 14389 wich is not exsisting. Those things are too high for me, I guess :-/. Probably it really has to do with the mechanism you mentioned. All other threads in this example have 14392-14398, so probably there has been anything in between.
« Last Edit: February 16, 2011, 05:05:09 pm by pasdVn »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #15 on: February 16, 2011, 06:29:02 pm »
Can you add these two commands in the Debugger initialization commands in the Settings -> Compiler & Debugger -> Debugger?

Code
catch fork
catch vfork
If there is fork, gdb should stop... or print something in the log

Here is some info on the matter: http://sourceware.org/gdb/onlinedocs/gdb/Forks.html

I'll do some tests and probably will give you a better patch to test...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pasdVn

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #16 on: February 16, 2011, 06:59:37 pm »
Ok, I'll try that.

I tried to get it work in Eclipse CDT in the meantime. The suprising thing: Same Problem there O.o I start to believe that it really has not to  with codeblocks but with the architecture of this application...

Edit:
Code
>>>>>>cb_gdb:
> catch fork
catch vfork
Catchpoint 2 (fork)
>>>>>>cb_gdb:Catchpoint 3 (vfork)

Oh no, sry. This is just the initialisation. No breaks or other logs occured. Tried it also with DDD in the meanwhile, where it works.
« Last Edit: February 16, 2011, 07:33:36 pm by pasdVn »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #17 on: February 16, 2011, 07:54:43 pm »
Can you paste full log with the patch attached?

p.s. Eclipse has two debugger implementations, as far as I know, so you could try both
p.s.s. Can you past a log from DDD?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pasdVn

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #18 on: February 16, 2011, 08:21:06 pm »
GDB Log from cb:

Code
LD_LIBRARY_PATH=.:
Command-line: /usr/bin/gdb -nx -fullname  -quiet -args ../mangos-server/bin/mangosd
Working dir : /home/tobias/Entwicklung/mangos/origin/builddir/
Reading symbols from /home/tobias/Entwicklung/mangos/origin/mangos-server/bin/mangosd...
> set prompt >>>>>>cb_gdb:
Queued:[tty /dev/pts/11]
done.
(gdb) >>>>>>cb_gdb:
> show version
GNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
>>>>>>cb_gdb:
> set confirm off
>>>>>>cb_gdb:
> set width 0
>>>>>>cb_gdb:
> set height 0
>>>>>>cb_gdb:
> set breakpoint pending on
>>>>>>cb_gdb:
> set print asm-demangle on
>>>>>>cb_gdb:
> set unwindonsignal on
>>>>>>cb_gdb:
> set print elements -1
>>>>>>cb_gdb:
> set disassembly-flavor intel
>>>>>>cb_gdb:
> catch throw
Catchpoint 1 (throw)
>>>>>>cb_gdb:
> source /home/tobias/Entwicklung/codeblocks/branches/wxpropgrid_debugger/binbin/share/codeblocks/scripts/stl-views-1.0.3.gdb
>>>>>>cb_gdb:
> catch fork
catch vfork
Catchpoint 2 (fork)
>>>>>>cb_gdb:Catchpoint 3 (vfork)
> cd ../mangos-server/bin
>>>>>>cb_gdb:
> directory /home/tobias/Entwicklung/mangos/origin/builddir/
>>>>>>cb_gdb:
> directory /home/tobias/Entwicklung/mangos/origin/
>>>>>>cb_gdb:
> tty /dev/pts/11
>>>>>>cb_gdb:>>>>>>cb_gdb:
> run
[Thread debugging using libthread_db enabled]
[New Thread 0x7ffff541b700 (LWP 31862)]
[Thread 0x7ffff541b700 (LWP 31862) exited]
Code::Blocks is trying to interrupt process with pid: 31862; child pid: 31862 gdb pid: 31853


GDB-log from DDD:
Code
GNU DDD 3.3.12 (x86_64-pc-linux-gnu), by Dorothea Lütkehaus and Andreas Zeller.
Copyright © 1995-1999 Technische Universität Braunschweig, Germany.
Copyright © 1999-2001 Universität Passau, Germany.
Copyright © 2001 Universität des Saarlandes, Germany.
Copyright © 2001-2004 Free Software Foundation, Inc.
(gdb) file /home/tobias/Entwicklung/mangos/origin/mangos-server/bin/mangosd
(gdb) run
[Thread debugging using libthread_db enabled]
^C[New Thread 0x7ffff541b700 (LWP 32194)]
[Thread 0x7ffff541b700 (LWP 32194) exited]
[New Thread 0x7ffff541b700 (LWP 32195)]
[New Thread 0x7ffff4a0d700 (LWP 32196)]
[New Thread 0x7ffff420c700 (LWP 32197)]
[New Thread 0x7fffefc64700 (LWP 32198)]
[New Thread 0x7fffef463700 (LWP 32199)]
[New Thread 0x7fffeec62700 (LWP 32200)]
[New Thread 0x7fffee461700 (LWP 32201)]

Program received signal SIGINT, Interrupt.
0x00007ffff5e02285 in pthread_join () from /lib/libpthread.so.0
(gdb)

Offline pasdVn

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: gdb with custom makefiles: unabled to interrupt while running
« Reply #19 on: March 08, 2011, 02:00:28 pm »
It suddenly works!! :)

Just updated to a new nightly build of the debugger branch (rev 7040). Who ever fixed this:
Thanks a lot!