Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Threads debugging extremely slow
Threads debugging extremely slow [message #1827110] Thu, 07 May 2020 10:25 Go to next message
G O is currently offline G OFriend
Messages: 8
Registered: May 2020
Junior Member
Good morning,

I am debugging a simple program with 3 threads on CDT 9.11 with remote debugging (arm-linux-gdb 7.1, gdbserver 7.7.1).

Here is the source code:

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void *print_message_function( void *ptr );

main()
{
     pthread_t thread1, thread2, thread3;
     char *message1 = "Thread 1";
     char *message2 = "Thread 2";
     char *message3 = "Thread 3";
     int  iret1, iret2, iret3;

    /* Create independent threads each of which will execute function */

     iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1);
     iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2);
     iret3 = pthread_create( &thread3, NULL, print_message_function, (void*) message3);

     /* Wait till threads are complete before main continues. Unless we  */
     /* wait we run the risk of executing an exit which will terminate   */
     /* the process and all threads before the threads have completed.   */

     pthread_join( thread1, NULL);
     pthread_join( thread2, NULL);
     pthread_join( thread3, NULL);

     printf("Thread 1 returns: %d\n",iret1);
     printf("Thread 2 returns: %d\n",iret2);
     exit(0);
}

void *print_message_function( void *ptr )
{
	while(1){
     char *message;
     message = (char *) ptr;
     printf("%s \n", message);
     sleep(1);
	}
}


Now, say I would like to debug print_message_function, so, I set a breakpoint at its first instruction and run the program until the breakpoint is reached.
After that, I issue "set scheduler-locking on" to avoid loosing "focus" on the current thread I am debugging.
This works flawlessly with gdb from command line, however, I see a lot of overhead in the gdb traces:

100,761 (gdb) 
113,980 67-interpreter-exec console "set scheduler-locking on"
113,981 67^done
113,981 (gdb) 
125,188 68-exec-next --thread 2 1
125,247 68^running
125,247 *running,thread-id="2"
125,247 (gdb) 
125,846 69-thread-select 2
126,380 *stopped,reason="end-stepping-range",frame={addr="0x0000a534",func="print_message_function",\
args=[{name="ptr",value="0x43e34"}],file="../src/prog.c",fullname="/media/sf_VMShared/git/prog/src/prog\
.c",line="104"},thread-id="2",stopped-threads="all",core="0"
126,380 (gdb) 
126,403 70-stack-info-depth --thread 2 11
126,426 71-stack-info-depth --thread 2
126,477 69^done,new-thread-id="2",frame={level="0",addr="0x0000a534",func="print_message_function",a\
rgs=[{name="ptr",value="0x43e34"}],file="../src/prog.c",fullname="/media/sf_VMShared/git/prog/src/prog.\
c",line="104"}
126,477 (gdb) 
128,007 70^done,depth="4"
128,007 (gdb) 
128,008 71^done,depth="4"
128,008 (gdb) 
128,009 72-var-update 1 var13
128,009 73-var-update 1 var14
128,009 74-var-update 1 var15
128,009 75-var-update 1 var16
128,009 76-var-create --thread 2 --frame 0 - * i
128,009 72^done,changelist=[]
128,009 (gdb) 
128,037 73^done,changelist=[]
128,037 (gdb) 
128,043 77-var-update 1 var18
128,043 78-stack-select-frame --thread 2 0
128,055 74^done,changelist=[]
128,055 (gdb) 
128,056 79-thread-info 2
128,056 80-list-thread-groups
128,074 75^done,changelist=[]
128,074 (gdb) 
128,083 76^error,msg="mi_cmd_var_create: unable to create variable object"
128,083 (gdb) 
128,083 77^done,changelist=[]
128,083 (gdb) 
128,083 78^done
128,083 (gdb) 
128,169 81-thread-info 1
128,169 82-thread-info 3
128,169 83-thread-info 4
128,253 79^done,threads=[{id="2",target-id="Thread 14921",frame={level="0",addr="0x0000a534",func="p\
rint_message_function",args=[{name="ptr",value="0x43e34"}],file="../src/prog.c",fullname="/media/sf_V\
MShared/git/prog/src/prog.c",line="104"},state="stopped",core="0"}]
128,254 (gdb) 
128,254 84-stack-list-frames --thread 2
128,428 80^done,groups=[{id="42000",type="process",pid="42000",cores=["0"]}]
128,428 (gdb) 
129,041 81^done,threads=[{id="1",target-id="Thread 14897",frame={level="0",addr="0xb6e35308",func="c\
lone",args=[],from="../filesystem/lib/arm-linux-gnueabi/libc.so.6"},state="stopped",core="0"}]
129,041 (gdb) 
129,662 82^done,threads=[{id="3",target-id="Thread 14920",frame={level="0",addr="0x0000a52c",func="p\
rint_message_function",args=[{name="ptr",value="0x43e28"}],file="../src/prog.c",fullname="/media/sf_V\
MShared/git/prog/src/prog.c",line="103"},state="stopped"}]
129,663 (gdb) 
130,252 83^done,threads=[{id="4",target-id="Thread 14922",frame={level="0",addr="0xb6e35308",func="c\
lone",args=[],from="../filesystem/lib/arm-linux-gnueabi/libc.so.6"},state="stopped"}]
130,252 (gdb) 
131,744 84^done,stack=[frame={level="0",addr="0x0000a534",func="print_message_function",file="../src\
/prog.c",fullname="/media/sf_VMShared/git/prog/src/prog.c",line="104"},frame={level="1",addr="0xb6fad1a\
8",func="start_thread",from="../filesystem/lib/arm-linux-gnueabi/libpthread.so.0"},frame={level="2",\
addr="0xb6e3535c",func="??",from="../filesystem/lib/arm-linux-gnueabi/libc.so.6"},frame={level="3",a\
ddr="0xb6e3535c",func="??",from="../filesystem/lib/arm-linux-gnueabi/libc.so.6"}]
131,744 (gdb) 


Note that 113,980 is the time when I issued the "set scheduler-locking on" in the Debugger Console when stopped at line:

message = (char *) ptr;


At time 125,188 I hit F6, to step over the next instruction. As you can see, I get a lot of calls, which take more than 5 seconds to execute.
Is there a way to avoid some or all of these calls? What am I missing here?

Thank you in advance.
Re: Threads debugging extremely slow [message #1827261 is a reply to message #1827110] Mon, 11 May 2020 16:56 Go to previous message
G O is currently offline G OFriend
Messages: 8
Registered: May 2020
Junior Member
No Message Body

[Updated on: Tue, 12 May 2020 07:38]

Report message to a moderator

Previous Topic:Downloaded Eclipse CDT for Mac, can't compile: No Binaries, CMake not found, CMake config errors
Next Topic:GDB list-thread-groups parsing error
Goto Forum:
  


Current Time: Thu Apr 25 07:06:41 GMT 2024

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

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

Back to the top