From f66713d24ad2c0a2e3d0e480119716f6d75a837e Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Thu, 26 Jul 2012 19:09:35 +0000 Subject: [PATCH] gdb/ * python/py-inferior.c (infpy_threads): Call update_thread_list (). gdb/testsuite/ * gdb.python/py-inferior.c (thread): New function. (check_threads): New function. (test_threads): New function. * gdb.python/py-inferior.exp: Added test. Replaced runto with continue to breakpoint. --- gdb/ChangeLog | 4 +++ gdb/python/py-inferior.c | 5 +++ gdb/testsuite/ChangeLog | 8 +++++ gdb/testsuite/gdb.python/py-inferior.c | 41 ++++++++++++++++++++++++ gdb/testsuite/gdb.python/py-inferior.exp | 15 +++++++-- 5 files changed, 70 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 80fb57ede27..9ff2a653e27 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2012-07-26 Markus Metzger + + * python/py-inferior.c (infpy_threads): Call update_thread_list (). + 2012-07-26 Jan Kratochvil * auto-load.c (auto_load_info_scripts): Remove immediate_quit increment diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 2b229beeda6..907b73e8da8 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -300,9 +300,14 @@ infpy_threads (PyObject *self, PyObject *args) struct threadlist_entry *entry; inferior_object *inf_obj = (inferior_object *) self; PyObject *tuple; + volatile struct gdb_exception except; INFPY_REQUIRE_VALID (inf_obj); + TRY_CATCH (except, RETURN_MASK_ALL) + update_thread_list (); + GDB_PY_HANDLE_EXCEPTION (except); + tuple = PyTuple_New (inf_obj->nthreads); if (!tuple) return NULL; diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 0c11c2b4a36..ba48b8df8ad 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2012-07-26 Markus Metzger + + * gdb.python/py-inferior.c (thread): New function. + (check_threads): New function. + (test_threads): New function. + * gdb.python/py-inferior.exp: Added test. + Replaced runto with continue to breakpoint. + 2012-07-26 Tom Tromey * lib/ada.exp (standard_ada_testfile): New proc. diff --git a/gdb/testsuite/gdb.python/py-inferior.c b/gdb/testsuite/gdb.python/py-inferior.c index 04ec4769263..3ee9a462060 100644 --- a/gdb/testsuite/gdb.python/py-inferior.c +++ b/gdb/testsuite/gdb.python/py-inferior.c @@ -2,9 +2,11 @@ #include #include #include +#include #define CHUNK_SIZE 16000 /* same as findcmd.c's */ #define BUF_SIZE (2 * CHUNK_SIZE) /* at least two chunks */ +#define NUMTH 8 int8_t int8_search_buf[100]; int16_t int16_search_buf[100]; @@ -43,8 +45,47 @@ init_bufs () memset (search_buf, 'x', search_buf_size); } +static void * +thread (void *param) +{ + pthread_barrier_t *barrier = (pthread_barrier_t *) param; + + pthread_barrier_wait (barrier); + + return param; +} + +static void +check_threads (pthread_barrier_t *barrier) +{ + pthread_barrier_wait (barrier); +} + +extern int +test_threads (void) +{ + pthread_t threads[NUMTH]; + pthread_barrier_t barrier; + int i; + + pthread_barrier_init (&barrier, NULL, NUMTH + 1); + + for (i = 0; i < NUMTH; ++i) + pthread_create (&threads[i], NULL, thread, &barrier); + + check_threads (&barrier); + + for (i = 0; i < NUMTH; ++i) + pthread_join (threads[i], NULL); + + pthread_barrier_destroy (&barrier); + + return 0; +} + int main (int argc, char *argv[]) { + test_threads (); init_bufs (); return f1 (1, 2); diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index b40a5143965..15e684aa226 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -20,7 +20,7 @@ load_lib gdb-python.exp standard_testfile -if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { +if { [gdb_compile_pthreads ${srcdir}/${subdir}/${srcfile} ${binfile} executable {debug}] != "" } { return -1 } @@ -48,8 +48,6 @@ if ![runto_main] then { return 0 } -runto [gdb_get_line_number "Break here."] - # Test basic gdb.Inferior attributes and methods. gdb_py_test_silent_cmd "python inferiors = gdb.inferiors ()" "get inferiors list" 1 @@ -62,6 +60,17 @@ gdb_test "python print 'result =', i0.pid" " = \[0-9\]+" "test Inferior.pid" gdb_test "python print 'result =', i0.was_attached" " = False" "test Inferior.was_attached" gdb_test "python print i0.threads ()" "\\(,\\)" "test Inferior.threads" +# Test the number of inferior threads. + +gdb_breakpoint check_threads +gdb_continue_to_breakpoint "cont to check_threads" ".*pthread_barrier_wait.*" +gdb_test "python print len (i0.threads ())" "\r\n9" "test Inferior.threads 2" + +# Proceed to the next test. + +gdb_breakpoint [gdb_get_line_number "Break here."] +gdb_continue_to_breakpoint "cont to Break here." ".*Break here\..*" + # Test memory read and write operations. gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \ -- 2.30.2