public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "kwydwuf at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug threads/12056] New: session was terminated by SIGTAP when gdbserver --attach PID to a multithreaded application. td_ta_new says application not linked with libthread
Date: Sat, 25 Sep 2010 04:48:00 -0000	[thread overview]
Message-ID: <20100925044847.12056.kwydwuf@gmail.com> (raw)

I can not debug a running multithreaded program by gdbserver --attach.
The program can be as simple as below:

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

int no_stop = 1;

void *func(void *data)
{
	int num = (int) data;
	int i = 0;
	while(no_stop) {
		sleep(1+rand()%5);
		i++;
		i%=10;
		if (i == 0)
			printf("Thread %d\n", num);
	}
}

int main(int argc, char **argv) 
{
    pthread_t id[4];
	int i;

	for (i = 0; i < 4; i++) {
		pthread_create(&id[i], NULL, func, (void*)(i+1));
	}

	for (i = 0; i < 4; i++) {
		pthread_join(id[i],NULL);
	}
	return 0;
}

build commmands are:
$ gcc -g -lpthread a.c

Then, on my linux box (Linux 2.6.35-ARCH #1 SMP PREEMPT Fri Aug 27 16:22:18 UTC
2010 i686 Intel(R) Pentium(R) 4 CPU 3.00GHz GenuineIntel GNU/Linux), I can debug
this program by below three means:
1. gdb a.out  (start program directly by gdb),
2. firstly start test program, say pid=1234, and then start gdb and attach 1234,
3. gdbserver :5555 a.out, and target remote localhost:5555 to debug.
I can get thread info (info threads) and debug with no problems in above ways.
But failed in the gdbserver --attach way:

$ gdbserver --debug :5555 --attach 1508    (my program PID is 1508)

$ gdb
GNU gdb (GDB) 7.2
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 "i686-pc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) target remote localhost:5555
Remote debugging using localhost:5555
warning: Could not load vsyscall page because no executable was specified
try using the "file" command first.
0xb77ea424 in ?? ()
Created trace state variable $trace_timestamp for target's variable 1.
(gdb) symbol-file a.out 
Reading symbols from xxx/xxx/test/a.out...done.
(gdb) i threads
* 1 Thread 1508  0xb77ea424 in ?? ()
(gdb) b 12
Breakpoint 1 at 0x8048509: file a.c, line 12.
(gdb) c
Continuing.

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
The program no longer exists.


The gdbserver log are:
my_waitpid (1516, 0x0)
my_waitpid (1516, 0x0): status(137f), 1516
my_waitpid (1516, 0x0)
my_waitpid (1516, 0x0): status(1057f), 1516
my_waitpid (1517, 0x0)
my_waitpid (1517, 0x0): status(137f), 1517
my_waitpid (1517, 0x0)
my_waitpid (1517, 0x0): status(9), 1517
my_waitpid (1516, 0x0)
my_waitpid (1516, 0x0): status(117f), 1516
my_waitpid (1516, 0x0)
my_waitpid (1516, 0x0): status(9), 1516
sigchld_handler
Attached; pid = 1508
linux_wait: [Process 1508]
linux_wait_for_lwp: <all threads>
my_waitpid (-1, 0x40000000)
my_waitpid (-1, 0x1): status(137f), 1508
Got an event from 1508 (137f)
pc is 0xb77ea424
stop pc is 0xb77ea424
linux_wait_for_lwp: pc is 0xb77ea424
Expected stop.
Hit a non-gdbserver trap event.
wait_for_sigstop: LWP 1508 already stopped
Checking whether LWP 1508 needs to move out of the jump pad...no
linux_wait ret = LWP 1508.1508, 1, 0
Listening on port 5555
handling possible accept event
Remote debugging from host 127.0.0.1
linux_async (0), previous=0
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
linux_async (0), previous=0
handling possible serial event
wait_for_sigstop: LWP 1508 already stopped
Checking whether LWP 1508 needs to move out of the jump pad...no
Writing resume reply for LWP 1508.1508:1

handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
gdbserver/tracepoint: Returning trace status as 0, stop reason tnotrun
handling possible serial event
gdbserver/tracepoint: Returning first trace state variable definition
handling possible serial event
gdbserver/tracepoint: Returning first trace state variable definition
handling possible serial event
gdbserver/tracepoint: Returning first tracepoint definition piece
handling possible serial event
symbol `gdb_agent_gdb_tp_heap_buffer' not found
symbol `gdb_agent_gdb_jump_pad_buffer' not found
symbol `gdb_agent_gdb_jump_pad_buffer_end' not found
symbol `gdb_agent_collecting' not found
symbol `gdb_agent_gdb_collect' not found
symbol `gdb_agent_stop_tracing' not found
symbol `gdb_agent_flush_trace_buffer' not found
symbol `gdb_agent_about_to_request_buffer_space' not found
symbol `gdb_agent_trace_buffer_is_full' not found
symbol `gdb_agent_stopping_tracepoint' not found
symbol `gdb_agent_expr_eval_result' not found
symbol `gdb_agent_error_tracepoint' not found
symbol `gdb_agent_tracepoints' not found
symbol `gdb_agent_tracing' not found
symbol `gdb_agent_trace_buffer_ctrl' not found
symbol `gdb_agent_trace_buffer_ctrl_curr' not found
symbol `gdb_agent_trace_buffer_lo' not found
symbol `gdb_agent_trace_buffer_hi' not found
symbol `gdb_agent_traceframe_read_count' not found
symbol `gdb_agent_traceframe_write_count' not found
symbol `gdb_agent_traceframes_created' not found
symbol `gdb_agent_trace_state_variables' not found
symbol `gdb_agent_get_raw_reg' not found
symbol `gdb_agent_get_trace_state_variable_value' not found
symbol `gdb_agent_set_trace_state_variable_value' not found
symbol `gdb_agent_ust_loaded' not found
symbol `gdb_agent_helper_thread_id' not found
symbol `gdb_agent_cmd_buf' not found
Trying host libthread_db library: libthread_db.so.1.
Host libthread_db.so.1 resolved to: /lib/libthread_db.so.1.
td_ta_new(): application not linked with libthread
thread_db_load_search returning 0
handling possible serial event
symbol `gdb_agent_gdb_tp_heap_buffer' not found
symbol `gdb_agent_gdb_jump_pad_buffer' not found
symbol `gdb_agent_gdb_jump_pad_buffer_end' not found
symbol `gdb_agent_collecting' not found
symbol `gdb_agent_gdb_collect' not found
symbol `gdb_agent_stop_tracing' not found
symbol `gdb_agent_flush_trace_buffer' not found
symbol `gdb_agent_about_to_request_buffer_space' not found
symbol `gdb_agent_trace_buffer_is_full' not found
symbol `gdb_agent_stopping_tracepoint' not found
symbol `gdb_agent_expr_eval_result' not found
symbol `gdb_agent_error_tracepoint' not found
symbol `gdb_agent_tracepoints' not found
symbol `gdb_agent_tracing' not found
symbol `gdb_agent_trace_buffer_ctrl' not found
symbol `gdb_agent_trace_buffer_ctrl_curr' not found
symbol `gdb_agent_trace_buffer_lo' not found
symbol `gdb_agent_trace_buffer_hi' not found
symbol `gdb_agent_traceframe_read_count' not found
symbol `gdb_agent_traceframe_write_count' not found
symbol `gdb_agent_traceframes_created' not found
symbol `gdb_agent_trace_state_variables' not found
symbol `gdb_agent_get_raw_reg' not found
symbol `gdb_agent_get_trace_state_variable_value' not found
symbol `gdb_agent_set_trace_state_variable_value' not found
symbol `gdb_agent_ust_loaded' not found
symbol `gdb_agent_helper_thread_id' not found
symbol `gdb_agent_cmd_buf' not found
Trying host libthread_db library: libthread_db.so.1.
Host libthread_db.so.1 resolved to: /lib/libthread_db.so.1.
td_ta_new(): application not linked with libthread
thread_db_load_search returning 0
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
handling possible serial event
Writing cc to 0x08048509
handling possible serial event
handling possible serial event
handling possible serial event
Need step over [LWP 1508]? No
pc is 0xb77ea424
Need step over [LWP 1508]? No, no breakpoint found at 0xb77ea424
Resuming, no pending status or step over needed
resuming LWP 1508
pc is 0xb77ea424
Resuming lwp 1508 (continue, signal 0, stop not expected)
  resuming from pc 0xb77ea424
linux_wait: [<all threads>]
linux_wait_for_lwp: <all threads>
my_waitpid (-1, 0x40000000)
blocking
sigchld_handler
my_waitpid (-1, 0x1): status(5), 1508
Got an event from 1508 (5)
LWP 1508 exiting
LWP 1508 is last lwp of process

Child terminated with signal = 5 

Child terminated with signal = 0x5 (SIGTRAP)
Writing resume reply for LWP 1508.1508:2

GDBserver exiting


$ gcc --version
gcc (GCC) 4.5.1
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


I'm using 7.2 gdb/gdbserver built by Arch Linux distro. But same behaviors are
observed on the 7.2 gdb/gdbserver built by myself.

PS, In gdb, if I load symbol-file before target remote, the error log of
'td_ta_new(): application not linked with libthread' was not printed by
gdbserver, but info threads still show only one thread, and SIGTRAP still break
the debug session.

-- 
           Summary: session was terminated by SIGTAP when gdbserver --attach
                    PID to a multithreaded application. td_ta_new says
                    application not linked with libthread
           Product: gdb
           Version: 7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: threads
        AssignedTo: unassigned at sourceware dot org
        ReportedBy: kwydwuf at gmail dot com
                CC: gdb-prs at sourceware dot org


http://sourceware.org/bugzilla/show_bug.cgi?id=12056

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


             reply	other threads:[~2010-09-25  4:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-25  4:48 kwydwuf at gmail dot com [this message]
2010-09-25  5:04 ` [Bug threads/12056] " kwydwuf at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100925044847.12056.kwydwuf@gmail.com \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).