Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
To: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Subject: [PATCH][gdb/testsuite] Don't leave gdb instance running after function_range
Date: Fri, 24 Sep 2021 14:34:39 +0200	[thread overview]
Message-ID: <c14984f7-526d-7d27-a0f0-5e7f46632fb9@suse.de> (raw)
In-Reply-To: <13a04bcb-6842-a5ce-5457-ed4510a0a79b@suse.de>

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

[ Re: [PATCH][gdb/testsuite] Replace prepare_for_testing with
build_executable ]

On 9/23/21 11:43 PM, Tom de Vries wrote:
> I found a problem in cpp-linkage-name.exp.  The test passes, but the gdb
> commands execute on a lingering gdb instance started by function_range,
> so I had to fix that first (by adding gdb_exit at the end of
> function_range) to trigger the FAIL introduced by the script.  I've
> removed the change in that test-case, and similar cases, and am
> currently retesting.

I've factored this out as a separate patch.

Any comments?

Thanks,
- Tom


[-- Attachment #2: 0001-gdb-testsuite-Don-t-leave-gdb-instance-running-after-function_range.patch --]
[-- Type: text/x-patch, Size: 3277 bytes --]

[gdb/testsuite] Don't leave gdb instance running after function_range

A typical dwarf assembly test-case start like this:
...
standard_testfile .c -debug.S

set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
  ...
}

if { [prepare_for_testing "failed to prepare" ${testfile} \
	  [list $srcfile $asm_file] {nodebug}] } {
    return -1
}
...

When accidentally using build_for_executable instead of
prepare_for_testing (or intentionally using it but forgetting to add
clean_restart $binfile or some such) the mistake may not be caught, because
another gdb instance is still running, and we may silently end up testing
compiler-generated DWARF.

This can be caused by something relatively obvious, like an earlier
prepare_for_testing or clean_restart, but also by something more obscure like
function_range, which may even be triggered by dwarf assembly like this:
...
  {MACRO_AT_func {main}}
...

Fix this by calling gdb_exit at the end of function_range.

Also fix the fallout of that in test-case gdb.dwarf2/dw2-bad-elf.exp, where a
get_sizeof call used the gdb instance left lingering by function_range.

[ A better and more complete fix would add a new proc get_exec_info, that would
be called at the start of the dwarf:
...
Dwarf::assemble $asm_file {
  get_exec_info {main foo} {int void*}
...
that would:
- do a prepare_for_testing with $srcfile (roughtly equivalent to what
  MACRO_AT_func does,
- call function_range for all functions main and foo, without starting a
  new gdb instance
- set corresponding variables at the call-site: main_start, main_len,
  main_end, foo_start, foo_len, foo_end.
- get size for types int and void*
- set corresponding variable at the call-site: int_size, void_ptr_size. ]

Tested on x86_64-linux.

---
 gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp | 11 ++++++++---
 gdb/testsuite/lib/dwarf.exp              |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp b/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp
index 5ab08c18f77..d276bf8f0d4 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-bad-elf.exp
@@ -36,10 +36,17 @@ if {![dwarf2_support]} {
 
 standard_testfile main.c -other.S -dwarf.S
 
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
+    untested "failed to compile"
+    return -1
+}
+
+set int_size [get_sizeof "int" 4]
+
 # Make some DWARF for the test.
 set asm_file [standard_output_file $srcfile3]
 Dwarf::assemble $asm_file {
-    global srcdir subdir srcfile srcfile2
+    global srcdir subdir srcfile srcfile2 int_size
 
     declare_labels ranges_label_1 ranges_label_2 L1 L2
 
@@ -47,8 +54,6 @@ Dwarf::assemble $asm_file {
     set main_start [lindex $main_result 0]
     set main_length [lindex $main_result 1]
 
-    set int_size [get_sizeof "int" 4]
-
     cu {} {
 	DW_TAG_compile_unit {
 	    {DW_AT_language @DW_LANG_C}
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 87bb6c152d1..c248296aa8d 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -271,6 +271,7 @@ proc function_range { func src {options {debug}} } {
 	}
     }
 
+    gdb_exit
     return [list "${func}_label - $func_label_offset" $func_length]
 }
 

  reply	other threads:[~2021-09-24 12:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-17 22:49 [PATCH][gdb/testsuite] Replace prepare_for_testing with build_executable Tom de Vries via Gdb-patches
2021-09-23 15:12 ` Simon Marchi via Gdb-patches
2021-09-23 21:43   ` Tom de Vries via Gdb-patches
2021-09-24 12:34     ` Tom de Vries via Gdb-patches [this message]
2021-09-24 13:56       ` [PATCH][gdb/testsuite] Don't leave gdb instance running after function_range Simon Marchi via Gdb-patches
2021-09-24 14:10 ` [PATCH][gdb/testsuite] Replace prepare_for_testing with build_executable Pedro Alves
2021-09-24 19:40   ` Tom de Vries via Gdb-patches

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=c14984f7-526d-7d27-a0f0-5e7f46632fb9@suse.de \
    --to=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    --cc=tdevries@suse.de \
    /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