public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Pedro Alves <palves@redhat.com>,
	"Aktemur, Tankut Baris" <tankut.baris.aktemur@intel.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH v8 6/6] gdb/infrun: handle already-exited threads when attempting to stop
Date: Fri, 15 May 2020 16:16:43 +0200	[thread overview]
Message-ID: <b28cfdfe-b4f5-7b7e-89ce-00773db64d2c@suse.de> (raw)
In-Reply-To: <7d7a056c-63cb-1865-b8ab-027840ac15bc@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1019 bytes --]

On 15-05-2020 14:02, Pedro Alves wrote:
> On 5/15/20 12:53 PM, Tom de Vries wrote:
> 
>> It occurred to me that we can find leaked global arrays using a
>> runtest.exp patch. I've filed a testsuite cleanup PR ( PR25996 - "wrap
>> global arrays in namespace",
>> https://sourceware.org/bugzilla/show_bug.cgi?id=25996 ).
> 
> Wouldn't it work to do this in gdb_init / gdb_finish ?
> 

Indeed, thanks for the pointer.

With attached patch, we have:
...
Running src/gdb/testsuite/gdb.ada/info_auto_lang.exp ...
WARNING: info_auto_lang.exp defined global array type_in_c
WARNING: info_auto_lang.exp defined global array rbreak_func_in_ada
WARNING: info_auto_lang.exp defined global array var_in_c
WARNING: info_auto_lang.exp defined global array func_in_c
WARNING: info_auto_lang.exp defined global array func_in_ada
WARNING: info_auto_lang.exp defined global array type_in_ada
WARNING: info_auto_lang.exp defined global array var_in_ada
WARNING: info_auto_lang.exp defined global array rbreak_func_in_c
...

Thanks,
- Tom


[-- Attachment #2: 0001-gdb-testsuite-Warn-about-leaked-global-array.patch --]
[-- Type: text/x-patch, Size: 2154 bytes --]

[gdb/testsuite] Warn about leaked global array

---
 gdb/testsuite/lib/gdb.exp | 54 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index f7d20bd94f..91491a1f0f 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5048,6 +5048,58 @@ proc standard_testfile {args} {
     }
 }
 
+# Returns 1 if __VAR is a global array.
+
+proc global_array_exists { __var } {
+    global $__var
+    return [array exists $__var]
+}
+
+# Unset global variable __VAR.
+
+proc global_unset { __var } {
+    global $__var
+    unset $__var
+}
+
+# Save global vars to variable gdb_global_vars.
+
+proc save_global_vars { test_file_name } {
+    global gdb_test_file_name
+    set gdb_test_file_name $test_file_name
+
+    global gdb_global_vars
+    set gdb_global_vars [list]
+
+    set gdb_global_vars [info globals]
+}
+
+# Check global variables not in gdb_global_vars.
+
+proc check_global_vars { } {
+    global gdb_global_vars
+    set vars [info globals]
+    set skip [list "expect_out" "spawn_out"]
+    foreach var $vars {
+        set found [lsearch -exact $gdb_global_vars $var]
+        if { $found != -1 } {
+            # Already present
+            continue
+        }
+        set found [lsearch -exact $skip $var]
+        if { $found != -1 } {
+            continue
+        }
+        if { ![global_array_exists $var] } {
+	    continue
+        }
+
+	global gdb_test_file_name
+        warning "$gdb_test_file_name.exp defined global array $var"
+        global_unset $var
+    }
+}
+
 # The default timeout used when testing GDB commands.  We want to use
 # the same timeout as the default dejagnu timeout, unless the user has
 # already provided a specific value (probably through a site.exp file).
@@ -5177,10 +5229,12 @@ proc gdb_init { test_file_name } {
     global gdb_instances
     set gdb_instances 0
 
+    save_global_vars $test_file_name
     return [default_gdb_init $test_file_name]
 }
 
 proc gdb_finish { } {
+    check_global_vars
     global gdbserver_reconnect_p
     global gdb_prompt
     global cleanfiles

  reply	other threads:[~2020-05-15 14:16 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-13 20:53 [PATCH v8 0/6] Handle already-exited threads in 'stop_all_threads' Pedro Alves
2020-05-13 20:53 ` [PATCH v8 1/6] gdb: protect some 'regcache_read_pc' calls Pedro Alves
2020-05-13 20:53 ` [PATCH v8 2/6] gdb/infrun: move a 'regcache_read_pc' call down to first use Pedro Alves
2020-05-13 20:53 ` [PATCH v8 3/6] gdb/infrun: extract out a code piece into 'mark_non_executing_threads' function Pedro Alves
2020-05-13 20:53 ` [PATCH v8 4/6] gdb: introduce 'all_non_exited_process_targets' and 'switch_to_target_no_thread' Pedro Alves
2020-05-14  8:44   ` Aktemur, Tankut Baris
2020-05-14 11:12     ` Pedro Alves
2020-05-14 11:23       ` Aktemur, Tankut Baris
2020-05-13 20:53 ` [PATCH v8 5/6] gdb/infrun: enable/disable thread events of all targets in stop_all_threads Pedro Alves
2020-05-14  8:44   ` Aktemur, Tankut Baris
2020-05-14 11:16     ` Pedro Alves
2020-05-14 11:30       ` Aktemur, Tankut Baris
2020-05-13 20:53 ` [PATCH v8 6/6] gdb/infrun: handle already-exited threads when attempting to stop Pedro Alves
2020-05-14  8:47   ` Aktemur, Tankut Baris
2020-05-14 11:16     ` Pedro Alves
2020-05-14 11:40       ` Aktemur, Tankut Baris
2020-05-14 18:00   ` Tom de Vries
2020-05-14 18:54     ` Aktemur, Tankut Baris
2020-05-14 18:58       ` Pedro Alves
2020-05-15  7:53         ` Aktemur, Tankut Baris
2020-05-15 10:14           ` Pedro Alves
2020-05-15 10:17         ` Tom de Vries
2020-05-15 10:35           ` Pedro Alves
2020-05-15 11:53         ` Tom de Vries
2020-05-15 12:02           ` Pedro Alves
2020-05-15 14:16             ` Tom de Vries [this message]
2020-05-15 15:46               ` Pedro Alves
2020-05-15 17:17                 ` Tom de Vries
2020-05-18  6:18                   ` [PATCH][gdb/testsuite] Warn about leaked global array Tom de Vries
2020-05-18 10:41                     ` Pedro Alves
2020-05-19 16:34                       ` Tom de Vries

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=b28cfdfe-b4f5-7b7e-89ce-00773db64d2c@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=tankut.baris.aktemur@intel.com \
    /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).