public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][gdb/testsuite] Fix index-cache.exp with CC_WITH_TWEAKS_FLAGS=-i
@ 2019-05-03 10:44 Tom de Vries
  2019-05-03 21:17 ` Simon Marchi
  0 siblings, 1 reply; 6+ messages in thread
From: Tom de Vries @ 2019-05-03 10:44 UTC (permalink / raw)
  To: gdb-patches

Hi,

When running gdb.base/index-cache.exp with target board cc-with-tweaks with
CC_WITH_TWEAKS_FLAGS set to "-i", we run into:
...
FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: at least one file \
      was created
FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: expected file is there
FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: check index-cache stats
FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats
...

The problem is that the target board makes sure that the generated executable
contains a .gdb_index section, while the test assumes that the executable
doesn't contain this section.

Fix this by removing the .gdb_index section from the generated executable.

Tested on x86_64-linux with native and CC_WITH_TWEAKS_FLAGS=-i config.

OK for trunk?

Thanks,
- Tom

[gdb/testsuite] Fix index-cache.exp with CC_WITH_TWEAKS_FLAGS=-i

gdb/testsuite/ChangeLog:

2019-05-03  Tom de Vries  <tdevries@suse.de>

	* gdb.base/index-cache.exp: Remove .gdb_index section from generated
	executable.

---
 gdb/testsuite/gdb.base/index-cache.exp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gdb/testsuite/gdb.base/index-cache.exp b/gdb/testsuite/gdb.base/index-cache.exp
index 4e583abf01..a97252cee4 100644
--- a/gdb/testsuite/gdb.base/index-cache.exp
+++ b/gdb/testsuite/gdb.base/index-cache.exp
@@ -22,6 +22,12 @@ if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
     return
 }
 
+# If a .gdb_index section was already added during compilation, remove it.
+if {[run_on_host "objcopy" [gdb_find_objcopy] \
+	 "--remove-section .gdb_index $binfile"]} {
+    return
+}
+
 # List the files in DIR on the host (where GDB-under-test runs).
 # Return a list of two elements:
 #   - 0 on success, -1 on failure

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][gdb/testsuite] Fix index-cache.exp with CC_WITH_TWEAKS_FLAGS=-i
  2019-05-03 10:44 [PATCH][gdb/testsuite] Fix index-cache.exp with CC_WITH_TWEAKS_FLAGS=-i Tom de Vries
@ 2019-05-03 21:17 ` Simon Marchi
  2019-05-04  8:20   ` [committed][gdb/testsuite] Add cc-with-debug-names.exp Tom de Vries
  2019-05-04  8:35   ` [gdb/testsuite] Fix index-cache.exp with cc-with-{gdb-index,debug-names} Tom de Vries
  0 siblings, 2 replies; 6+ messages in thread
From: Simon Marchi @ 2019-05-03 21:17 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

On 2019-05-03 6:43 a.m., Tom de Vries wrote:
> Hi,
> 
> When running gdb.base/index-cache.exp with target board cc-with-tweaks with
> CC_WITH_TWEAKS_FLAGS set to "-i", we run into:
> ...
> FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: at least one file \
>       was created
> FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: expected file is there
> FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: check index-cache stats
> FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats
> ...
> 
> The problem is that the target board makes sure that the generated executable
> contains a .gdb_index section, while the test assumes that the executable
> doesn't contain this section.
> 
> Fix this by removing the .gdb_index section from the generated executable.
> 
> Tested on x86_64-linux with native and CC_WITH_TWEAKS_FLAGS=-i config.
> 
> OK for trunk?
> 
> Thanks,
> - Tom

Hi Tom,

I would slightly prefer that instead of doing this, we would notice that that file
already has an index (in the form of .gdb_index or .debug_names), and adjust our
expectations in the test.

In other words, we currently assert that loading the file in GDB will produce some
files in the cache.  However, if we know that the file already has an index, we
should verify that no file was produced, as this is the behavior we expect when
loading a file which already has an index.

Stripping the index makes the test pass, but it just goes back to testing the same
thing as with the default board file.  Adjusting our expectation to the presence
of an index makes the test cover a different use case.

Simon

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [committed][gdb/testsuite] Add cc-with-debug-names.exp
  2019-05-03 21:17 ` Simon Marchi
@ 2019-05-04  8:20   ` Tom de Vries
  2019-05-04  8:35   ` [gdb/testsuite] Fix index-cache.exp with cc-with-{gdb-index,debug-names} Tom de Vries
  1 sibling, 0 replies; 6+ messages in thread
From: Tom de Vries @ 2019-05-04  8:20 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

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

[ was: Re: [PATCH][gdb/testsuite] Fix index-cache.exp with
CC_WITH_TWEAKS_FLAGS=-i ]

On 03-05-19 23:17, Simon Marchi wrote:
> I would slightly prefer that instead of doing this, we would notice that that file
> already has an index (in the form of .gdb_index or .debug_names), and adjust our
> expectations in the test.
> 

Added cc-with-debug-names target board for .debug_names. Filed PR24522 -
"Asserts with cc-with-debug-names".

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-testsuite-Add-cc-with-debug-names.exp.patch --]
[-- Type: text/x-patch, Size: 3248 bytes --]

[gdb/testsuite] Add cc-with-debug-names.exp

Add a target board that makes it easy to run the test suite with a
.debug_names section added to executables.

gdb/ChangeLog:

2019-05-04  Tom de Vries  <tdevries@suse.de>

	* contrib/cc-with-tweaks.sh: Support -n arg.

gdb/testsuite/ChangeLog:

2019-05-04  Tom de Vries  <tdevries@suse.de>

	* boards/cc-with-debug-names.exp: New file.

---
 gdb/contrib/cc-with-tweaks.sh                |  8 ++++++--
 gdb/testsuite/boards/cc-with-debug-names.exp | 26 ++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/gdb/contrib/cc-with-tweaks.sh b/gdb/contrib/cc-with-tweaks.sh
index 33c6322138..47379cc158 100755
--- a/gdb/contrib/cc-with-tweaks.sh
+++ b/gdb/contrib/cc-with-tweaks.sh
@@ -42,7 +42,8 @@
 # -Z invoke objcopy --compress-debug-sections
 # -z compress using dwz
 # -m compress using dwz -m
-# -i make an index
+# -i make an index (.gdb_index)
+# -n make a dwarf5 index (.debug_names)
 # -p create .dwp files (Fission), you need to also use gcc option -gsplit-dwarf
 # If nothing is given, no changes are made
 
@@ -77,6 +78,7 @@ next_is_output_file=no
 output_file=a.out
 
 want_index=false
+index_options=""
 want_dwz=false
 want_multi=false
 want_dwp=false
@@ -87,6 +89,7 @@ while [ $# -gt 0 ]; do
 	-Z) want_objcopy_compress=true ;;
 	-z) want_dwz=true ;;
 	-i) want_index=true ;;
+	-n) want_index=true; index_options=-dwarf-5;;
 	-m) want_multi=true ;;
 	-p) want_dwp=true ;;
 	*) break ;;
@@ -170,7 +173,8 @@ if [ "$want_index" = true ]; then
     # Filter out these messages which would stop dejagnu testcase run:
     # echo "$myname: No index was created for $file" 1>&2
     # echo "$myname: [Was there no debuginfo? Was there already an index?]" 1>&2
-    GDB=$GDB $GDB_ADD_INDEX "$output_file" 2>&1|grep -v "^${GDB_ADD_INDEX##*/}: " >&2
+    GDB=$GDB $GDB_ADD_INDEX $index_options "$output_file" 2>&1 \
+	| grep -v "^${GDB_ADD_INDEX##*/}: " >&2
     rc=${PIPESTATUS[0]}
     [ $rc != 0 ] && exit $rc
 fi
diff --git a/gdb/testsuite/boards/cc-with-debug-names.exp b/gdb/testsuite/boards/cc-with-debug-names.exp
new file mode 100644
index 0000000000..0acf46ca95
--- /dev/null
+++ b/gdb/testsuite/boards/cc-with-debug-names.exp
@@ -0,0 +1,26 @@
+# Copyright 2019 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This file is a dejagnu "board file" and is used to run the testsuite
+# with contrib/cc-with-tweaks.sh -n.
+#
+# Example usage:
+# bash$ cd $objdir
+# bash$ make check-gdb \
+#   RUNTESTFLAGS='--target_board=cc-with-debug-names'
+#
+
+set CC_WITH_TWEAKS_FLAGS "-n"
+load_board_description "cc-with-tweaks"

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gdb/testsuite] Fix index-cache.exp with cc-with-{gdb-index,debug-names}
  2019-05-03 21:17 ` Simon Marchi
  2019-05-04  8:20   ` [committed][gdb/testsuite] Add cc-with-debug-names.exp Tom de Vries
@ 2019-05-04  8:35   ` Tom de Vries
  2019-05-04 16:28     ` Simon Marchi
  1 sibling, 1 reply; 6+ messages in thread
From: Tom de Vries @ 2019-05-04  8:35 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

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

[ was: Re: [PATCH][gdb/testsuite] Fix index-cache.exp with
CC_WITH_TWEAKS_FLAGS=-i ]

On 03-05-19 23:17, Simon Marchi wrote:
> On 2019-05-03 6:43 a.m., Tom de Vries wrote:
>> Hi,
>>
>> When running gdb.base/index-cache.exp with target board cc-with-tweaks with
>> CC_WITH_TWEAKS_FLAGS set to "-i", we run into:
>> ...
>> FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: at least one file \
>>       was created
>> FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: expected file is there
>> FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: check index-cache stats
>> FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats
>> ...
>>
>> The problem is that the target board makes sure that the generated executable
>> contains a .gdb_index section, while the test assumes that the executable
>> doesn't contain this section.
>>
>> Fix this by removing the .gdb_index section from the generated executable.
>>
>> Tested on x86_64-linux with native and CC_WITH_TWEAKS_FLAGS=-i config.
>>
>> OK for trunk?
>>
>> Thanks,
>> - Tom
> 
> Hi Tom,
> 
> I would slightly prefer that instead of doing this, we would notice that that file
> already has an index (in the form of .gdb_index or .debug_names), and adjust our
> expectations in the test.
> 
> In other words, we currently assert that loading the file in GDB will produce some
> files in the cache.  However, if we know that the file already has an index, we
> should verify that no file was produced, as this is the behavior we expect when
> loading a file which already has an index.
> 
> Stripping the index makes the test pass, but it just goes back to testing the same
> thing as with the default board file.  Adjusting our expectation to the presence
> of an index makes the test cover a different use case.

I've implemented this approach, attached below.

OK for trunk?

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-testsuite-Fix-index-cache.exp-with-cc-with-gdb-index-debug-names.patch --]
[-- Type: text/x-patch, Size: 3989 bytes --]

[gdb/testsuite] Fix index-cache.exp with cc-with-{gdb-index,debug-names}

In gdb.base/index-cache.exp, handle the case that binfile contains either a
.gdb_index or .debug_names index section.

Tested on x86_64-linux with native, cc-with-gdb-index and cc-with-debug-names.

gdb/testsuite/ChangeLog:

2019-05-04  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (exec_has_index_section): New proc.
	* gdb.base/index-cache.exp: Handle case that binfile contains an index
	section.

---
 gdb/testsuite/gdb.base/index-cache.exp | 30 +++++++++++++++++++++++++-----
 gdb/testsuite/lib/gdb.exp              | 11 +++++++++++
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/gdb/testsuite/gdb.base/index-cache.exp b/gdb/testsuite/gdb.base/index-cache.exp
index 4e583abf01..f5e1e4a850 100644
--- a/gdb/testsuite/gdb.base/index-cache.exp
+++ b/gdb/testsuite/gdb.base/index-cache.exp
@@ -22,6 +22,8 @@ if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
     return
 }
 
+set has_index_section [exec_has_index_section $binfile]
+
 # List the files in DIR on the host (where GDB-under-test runs).
 # Return a list of two elements:
 #   - 0 on success, -1 on failure
@@ -125,7 +127,7 @@ proc_with_prefix test_cache_disabled { cache_dir } {
 # Test with the cache enabled, we expect to have exactly one file created.
 
 proc_with_prefix test_cache_enabled_miss { cache_dir } {
-    global testfile
+    global testfile has_index_section
 
     lassign [ls_host $cache_dir] ret files_before
 
@@ -133,7 +135,11 @@ proc_with_prefix test_cache_enabled_miss { cache_dir } {
 
 	lassign [ls_host $cache_dir] ret files_after
 	set nfiles_created [expr [llength $files_after] - [llength $files_before]]
-	gdb_assert "$nfiles_created > 0" "at least one file was created"
+	if { $has_index_section } {
+	    gdb_assert "$nfiles_created == 0" "no file was created"
+	} else {
+	    gdb_assert "$nfiles_created > 0" "at least one file was created"
+	}
 
 	set build_id [get_build_id  [standard_output_file ${testfile}]]
 	if { $build_id == "" } {
@@ -143,11 +149,19 @@ proc_with_prefix test_cache_enabled_miss { cache_dir } {
 
 	set expected_created_file [list "${build_id}.gdb-index"]
 	set found_idx [lsearch -exact $files_after $expected_created_file]
-	gdb_assert "$found_idx >= 0" "expected file is there"
+	if { $has_index_section } {
+	    gdb_assert "$found_idx == -1" "no index cache file generated"
+	} else {
+	    gdb_assert "$found_idx >= 0" "expected file is there"
+	}
 
 	remote_exec host rm "-f $cache_dir/$expected_created_file"
 
-	check_cache_stats 0 1
+	if { $has_index_section } {
+	    check_cache_stats 0 0
+	} else {
+	    check_cache_stats 0 1
+	}
     }
 }
 
@@ -156,6 +170,8 @@ proc_with_prefix test_cache_enabled_miss { cache_dir } {
 # same), but one cache read hit.
 
 proc_with_prefix test_cache_enabled_hit { cache_dir } {
+    global has_index_section
+
     # Just to populate the cache.
     run_test_with_flags $cache_dir on {}
 
@@ -166,7 +182,11 @@ proc_with_prefix test_cache_enabled_hit { cache_dir } {
 	set nfiles_created [expr [llength $files_after] - [llength $files_before]]
 	gdb_assert "$nfiles_created == 0" "no files were created"
 
-	check_cache_stats 1 0
+	if { $has_index_section } {
+	    check_cache_stats 0 0
+	} else {
+	    check_cache_stats 1 0
+	}
     }
 }
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 57866daa11..84c54062c8 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5107,6 +5107,17 @@ proc rerun_to_main {} {
   }
 }
 
+# Return true if EXECUTABLE contains a .gdb_index or .debug_names index section.
+
+proc exec_has_index_section { executable } {
+    set res [catch {exec readelf -S $executable \
+			| grep -E "\.gdb_index|\.debug_names" }]
+    if { $res == 0 } {
+	return 1
+    }
+    return 0
+}
+
 # Return true if a test should be skipped due to lack of floating
 # point support or GDB can't fetch the contents from floating point
 # registers.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gdb/testsuite] Fix index-cache.exp with cc-with-{gdb-index,debug-names}
  2019-05-04  8:35   ` [gdb/testsuite] Fix index-cache.exp with cc-with-{gdb-index,debug-names} Tom de Vries
@ 2019-05-04 16:28     ` Simon Marchi
  2019-05-06  6:43       ` Tom de Vries
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2019-05-04 16:28 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

On 2019-05-04 4:35 a.m., Tom de Vries wrote:
> [ was: Re: [PATCH][gdb/testsuite] Fix index-cache.exp with
> CC_WITH_TWEAKS_FLAGS=-i ]
> 
> On 03-05-19 23:17, Simon Marchi wrote:
>> On 2019-05-03 6:43 a.m., Tom de Vries wrote:
>>> Hi,
>>>
>>> When running gdb.base/index-cache.exp with target board cc-with-tweaks with
>>> CC_WITH_TWEAKS_FLAGS set to "-i", we run into:
>>> ...
>>> FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: at least one file \
>>>       was created
>>> FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: expected file is there
>>> FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: check index-cache stats
>>> FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats
>>> ...
>>>
>>> The problem is that the target board makes sure that the generated executable
>>> contains a .gdb_index section, while the test assumes that the executable
>>> doesn't contain this section.
>>>
>>> Fix this by removing the .gdb_index section from the generated executable.
>>>
>>> Tested on x86_64-linux with native and CC_WITH_TWEAKS_FLAGS=-i config.
>>>
>>> OK for trunk?
>>>
>>> Thanks,
>>> - Tom
>>
>> Hi Tom,
>>
>> I would slightly prefer that instead of doing this, we would notice that that file
>> already has an index (in the form of .gdb_index or .debug_names), and adjust our
>> expectations in the test.
>>
>> In other words, we currently assert that loading the file in GDB will produce some
>> files in the cache.  However, if we know that the file already has an index, we
>> should verify that no file was produced, as this is the behavior we expect when
>> loading a file which already has an index.
>>
>> Stripping the index makes the test pass, but it just goes back to testing the same
>> thing as with the default board file.  Adjusting our expectation to the presence
>> of an index makes the test cover a different use case.
> 
> I've implemented this approach, attached below.
> 
> OK for trunk?
> 
> Thanks,
> - Tom
> 

Thanks Tom, this LGTM.

Before pushing, could you just adjust the comments above each proc?  They describe
what the test expects (at a high level), so maybe just add a precision about what is
expected when the binary already has an index.

Simon

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gdb/testsuite] Fix index-cache.exp with cc-with-{gdb-index,debug-names}
  2019-05-04 16:28     ` Simon Marchi
@ 2019-05-06  6:43       ` Tom de Vries
  0 siblings, 0 replies; 6+ messages in thread
From: Tom de Vries @ 2019-05-06  6:43 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

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

On 04-05-19 18:28, Simon Marchi wrote:
> On 2019-05-04 4:35 a.m., Tom de Vries wrote:
>> [ was: Re: [PATCH][gdb/testsuite] Fix index-cache.exp with
>> CC_WITH_TWEAKS_FLAGS=-i ]
>>
>> On 03-05-19 23:17, Simon Marchi wrote:
>>> On 2019-05-03 6:43 a.m., Tom de Vries wrote:
>>>> Hi,
>>>>
>>>> When running gdb.base/index-cache.exp with target board cc-with-tweaks with
>>>> CC_WITH_TWEAKS_FLAGS set to "-i", we run into:
>>>> ...
>>>> FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: at least one file \
>>>>       was created
>>>> FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: expected file is there
>>>> FAIL: gdb.base/index-cache.exp: test_cache_enabled_miss: check index-cache stats
>>>> FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats
>>>> ...
>>>>
>>>> The problem is that the target board makes sure that the generated executable
>>>> contains a .gdb_index section, while the test assumes that the executable
>>>> doesn't contain this section.
>>>>
>>>> Fix this by removing the .gdb_index section from the generated executable.
>>>>
>>>> Tested on x86_64-linux with native and CC_WITH_TWEAKS_FLAGS=-i config.
>>>>
>>>> OK for trunk?
>>>>
>>>> Thanks,
>>>> - Tom
>>>
>>> Hi Tom,
>>>
>>> I would slightly prefer that instead of doing this, we would notice that that file
>>> already has an index (in the form of .gdb_index or .debug_names), and adjust our
>>> expectations in the test.
>>>
>>> In other words, we currently assert that loading the file in GDB will produce some
>>> files in the cache.  However, if we know that the file already has an index, we
>>> should verify that no file was produced, as this is the behavior we expect when
>>> loading a file which already has an index.
>>>
>>> Stripping the index makes the test pass, but it just goes back to testing the same
>>> thing as with the default board file.  Adjusting our expectation to the presence
>>> of an index makes the test cover a different use case.
>>
>> I've implemented this approach, attached below.
>>
>> OK for trunk?
>>
>> Thanks,
>> - Tom
>>
> 
> Thanks Tom, this LGTM.
> 
> Before pushing, could you just adjust the comments above each proc?  They describe
> what the test expects (at a high level), so maybe just add a precision about what is
> expected when the binary already has an index.
> 

Done.

Also replaced use of hardcoded "readelf" with result of gdb_find_readelf.

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-testsuite-Fix-index-cache.exp-with-cc-with-gdb-index-debug-names.patch --]
[-- Type: text/x-patch, Size: 4408 bytes --]

[gdb/testsuite] Fix index-cache.exp with cc-with-{gdb-index,debug-names}

In gdb.base/index-cache.exp, handle the case that binfile contains either a
.gdb_index or .debug_names index section.

Tested on x86_64-linux with native, cc-with-gdb-index and cc-with-debug-names.

gdb/testsuite/ChangeLog:

2019-05-04  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (exec_has_index_section): New proc.
	* gdb.base/index-cache.exp: Handle case that binfile contains an index
	section.

---
 gdb/testsuite/gdb.base/index-cache.exp | 39 +++++++++++++++++++++++++++-------
 gdb/testsuite/lib/gdb.exp              | 12 +++++++++++
 2 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/gdb/testsuite/gdb.base/index-cache.exp b/gdb/testsuite/gdb.base/index-cache.exp
index 4e583abf01..5baba84360 100644
--- a/gdb/testsuite/gdb.base/index-cache.exp
+++ b/gdb/testsuite/gdb.base/index-cache.exp
@@ -22,6 +22,8 @@ if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
     return
 }
 
+set has_index_section [exec_has_index_section $binfile]
+
 # List the files in DIR on the host (where GDB-under-test runs).
 # Return a list of two elements:
 #   - 0 on success, -1 on failure
@@ -122,10 +124,12 @@ proc_with_prefix test_cache_disabled { cache_dir } {
     }
 }
 
-# Test with the cache enabled, we expect to have exactly one file created.
+# Test with the cache enabled, we expect to have:
+# - exactly one file created, in case of no index section
+# - no file created, in case of an index section
 
 proc_with_prefix test_cache_enabled_miss { cache_dir } {
-    global testfile
+    global testfile has_index_section
 
     lassign [ls_host $cache_dir] ret files_before
 
@@ -133,7 +137,11 @@ proc_with_prefix test_cache_enabled_miss { cache_dir } {
 
 	lassign [ls_host $cache_dir] ret files_after
 	set nfiles_created [expr [llength $files_after] - [llength $files_before]]
-	gdb_assert "$nfiles_created > 0" "at least one file was created"
+	if { $has_index_section } {
+	    gdb_assert "$nfiles_created == 0" "no file was created"
+	} else {
+	    gdb_assert "$nfiles_created > 0" "at least one file was created"
+	}
 
 	set build_id [get_build_id  [standard_output_file ${testfile}]]
 	if { $build_id == "" } {
@@ -143,19 +151,30 @@ proc_with_prefix test_cache_enabled_miss { cache_dir } {
 
 	set expected_created_file [list "${build_id}.gdb-index"]
 	set found_idx [lsearch -exact $files_after $expected_created_file]
-	gdb_assert "$found_idx >= 0" "expected file is there"
+	if { $has_index_section } {
+	    gdb_assert "$found_idx == -1" "no index cache file generated"
+	} else {
+	    gdb_assert "$found_idx >= 0" "expected file is there"
+	}
 
 	remote_exec host rm "-f $cache_dir/$expected_created_file"
 
-	check_cache_stats 0 1
+	if { $has_index_section } {
+	    check_cache_stats 0 0
+	} else {
+	    check_cache_stats 0 1
+	}
     }
 }
 
 
-# Test with the cache enabled, this time we should have one file (the
-# same), but one cache read hit.
+# Test with the cache enabled, this time we should have:
+# - one file (the same), but one cache read hit, in case of no index section
+# - no file, no cache hit, in case an an index section
 
 proc_with_prefix test_cache_enabled_hit { cache_dir } {
+    global has_index_section
+
     # Just to populate the cache.
     run_test_with_flags $cache_dir on {}
 
@@ -166,7 +185,11 @@ proc_with_prefix test_cache_enabled_hit { cache_dir } {
 	set nfiles_created [expr [llength $files_after] - [llength $files_before]]
 	gdb_assert "$nfiles_created == 0" "no files were created"
 
-	check_cache_stats 1 0
+	if { $has_index_section } {
+	    check_cache_stats 0 0
+	} else {
+	    check_cache_stats 1 0
+	}
     }
 }
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 57866daa11..8dea857d5e 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5107,6 +5107,18 @@ proc rerun_to_main {} {
   }
 }
 
+# Return true if EXECUTABLE contains a .gdb_index or .debug_names index section.
+
+proc exec_has_index_section { executable } {
+    set readelf_program [gdb_find_readelf]
+    set res [catch {exec $readelf_program -S $executable \
+			| grep -E "\.gdb_index|\.debug_names" }]
+    if { $res == 0 } {
+	return 1
+    }
+    return 0
+}
+
 # Return true if a test should be skipped due to lack of floating
 # point support or GDB can't fetch the contents from floating point
 # registers.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-05-06  6:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-03 10:44 [PATCH][gdb/testsuite] Fix index-cache.exp with CC_WITH_TWEAKS_FLAGS=-i Tom de Vries
2019-05-03 21:17 ` Simon Marchi
2019-05-04  8:20   ` [committed][gdb/testsuite] Add cc-with-debug-names.exp Tom de Vries
2019-05-04  8:35   ` [gdb/testsuite] Fix index-cache.exp with cc-with-{gdb-index,debug-names} Tom de Vries
2019-05-04 16:28     ` Simon Marchi
2019-05-06  6:43       ` Tom de Vries

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).