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

Message ID 20190503104352.GA7789@delia
State New, archived
Headers

Commit Message

Tom de Vries May 3, 2019, 10:43 a.m. UTC
  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(+)
  

Comments

Simon Marchi May 3, 2019, 9:17 p.m. UTC | #1
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
  

Patch

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