From patchwork Sun Dec 15 04:09:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 36883 Received: (qmail 28788 invoked by alias); 15 Dec 2019 04:09:46 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 28779 invoked by uid 89); 15 Dec 2019 04:09:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=March, absence, Shouldnt, Shouldn't X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 15 Dec 2019 04:09:42 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id xBF49WVP025600 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 14 Dec 2019 23:09:37 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca xBF49WVP025600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1576382978; bh=hGNVMLfsvWz16wQeQHS8DkLsxHwLoArxw1E+Q0vHkW4=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=dhBWO0RPZvW3+K7LOVQ3tbmAhvL2kWfgziMRyjFPuZBVf7fW2LYBqsOsx/e85uZNj 31HFsT3vexoAYJzD2Rzx99xyMEN7+N73AnhLlRoJqzIG3eJMwBaM4nbVO1AC4yur3O OPaV8Nc4u9pYp7P/rQo2mczJ/os9Nd+mBxMTmQX8= Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 21ABE1E50B; Sat, 14 Dec 2019 23:09:32 -0500 (EST) Subject: Re: Question for Ada people, debugging gdb.ada/ptype_tagged_param.exp To: Joel Brobecker Cc: GDB patches References: <070fa9d7-a4bc-e9e3-4f8d-bb2959846251@polymtl.ca> <20191208005143.GA21428@adacore.com> <763a224e-8f53-4c8b-5880-03991fbb49b2@polymtl.ca> <20191212224820.GB13716@adacore.com> From: Simon Marchi Message-ID: <81337265-2508-4e7a-1acc-4bf09b664f42@polymtl.ca> Date: Sat, 14 Dec 2019 23:09:31 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: <20191212224820.GB13716@adacore.com> X-IsSubscribed: yes On 2019-12-12 5:48 p.m., Joel Brobecker wrote: > FWIW, this is really about the runtime, so I would mention it > in the name of the function. Noted. > The other thing you might want to be careful of is that, on some > platforms, the gnat runtime used for linking by default is the > shared libgnat. So, if you want to check for the presence of > a given symbol, you would have to start the program first. > Shouldn't be a big issue, I believe; you just have to run until > reaching a known subprogram in the inferior. I did that, it doesn't seem to be a problem. > The approach of checking for a given symbol to infer whether > the runtime as a whole has the necessary debug info for a given > test should work in practice -- as I do not a situation where > only part of the units that need debugging info have debug info, > but not others, is worth worrying about. > > Probably one good function to look for is the following: > > __gnat_debug_raise_exception Great, thanks. > The thing with these internal functions is that they are subject > to change. We try not to, but this has happened as you can see > from the various declarations of struct exception_support_info > objects in ada-lang.c (search for default_exception_support_info). > Luckily, I think this one has been quite stable (unchanged since > March 2007 according to one of the comments0, and I am hoping > will remain the same for a veeeery long time. And even if it changes, we can adapt the test easily. Here's a patch. It works on a runtime without debug info, but I'll need your help to test it on a runtime with debug info, as I didn't find a configuration that worked. I tried to install the libgnat-7-dbg package on Ubuntu 18.04, but it didn't help. From 431f8d1d6ff7dd343a4c35ab67318a44690abd4b Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 14 Dec 2019 22:16:05 -0500 Subject: [PATCH] Adjust test gdb.ada/ptype_tagged_param.exp for when GNAT runtime does not have debug info This test verifies that GDB correctly identifies the run-time type of "s" as being the type "Circle". However, that can only be done correctly if the GNAT runtime has been compiled and shipped with debug information, so that GDB can poke in its internal data structures. Currently the test fails when when running against a GNAT runtime without debug info. This is the case, for example, on Arch Linux using the distribution package. This patch adds a helper in lib/ada.exp to check whether the GNAT runtime has debug info or not. It then uses it in gdb.ada/ptype_tagged_param.exp to expect a different result, depending on whether we have debug info or not in the runtime. At first, I made it so we would XFAIL the test, in the absence of debug info, but then I thought that we might as well test for the output we expect in the absence of debug info instead. gdb/testsuite/ChangeLog: * lib/ada.exp (gnat_runtime_has_debug_info): New proc. * lib/gnat-debug-info-test.adb: New file. * gdb.ada/ptype_tagged_param.exp: Use gnat_runtime_has_debug_info, expect a different output if runtime does not have debug info. --- gdb/testsuite/gdb.ada/ptype_tagged_param.exp | 22 +++++++++--- gdb/testsuite/lib/ada.exp | 36 ++++++++++++++++++++ gdb/testsuite/lib/gnat-debug-info-test.adb | 6 ++++ 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/lib/gnat-debug-info-test.adb diff --git a/gdb/testsuite/gdb.ada/ptype_tagged_param.exp b/gdb/testsuite/gdb.ada/ptype_tagged_param.exp index 567ef8251d9f..87a676c9ca24 100644 --- a/gdb/testsuite/gdb.ada/ptype_tagged_param.exp +++ b/gdb/testsuite/gdb.ada/ptype_tagged_param.exp @@ -21,14 +21,28 @@ if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } return -1 } +set has_runtime_debug_info [gnat_runtime_has_debug_info] + clean_restart ${testfile} if ![runto "position_x" ] then { return -1 } -set eol "\[\r\n\]+" -set sp "\[ \t\]*" +if { $has_runtime_debug_info } { + gdb_test "ptype s" \ + [multi_line \ + "type = new pck.shape with record" \ + " r: integer;" \ + "end record"] \ + "ptype s, with debug info" +} else { + gdb_test "ptype s" \ + [multi_line \ + "type = tagged record" \ + " x: integer;" \ + " y: integer;" \ + "end record" ] \ + "ptype s, without debug info" +} -gdb_test "ptype s" \ - "type = new pck.shape with record${eol}${sp}r: integer;${eol}end record" diff --git a/gdb/testsuite/lib/ada.exp b/gdb/testsuite/lib/ada.exp index 45c41806a648..378c0db610e4 100644 --- a/gdb/testsuite/lib/ada.exp +++ b/gdb/testsuite/lib/ada.exp @@ -149,3 +149,39 @@ proc gnatmake_version_at_least { major } { # Unknown, return 1 return 1 } + +# Return 1 if the GNAT runtime appears to have debug info. + +gdb_caching_proc gnat_runtime_has_debug_info { + global srcdir + + set src "$srcdir/lib/gnat-debug-info-test.adb" + set dst [standard_output_file "gnat-debug-info-test"] + + if { [gdb_compile_ada $src $dst executable {debug}] != "" } { + fail "failed to compile gnat-debug-info test binary" + return 0 + } + + clean_restart $dst + + if { ! [runto "Hello"] } { + fail "failed to run to Hello" + return 0 + } + + set has_debug_info 0 + + gdb_test_multiple "whatis __gnat_debug_raise_exception" "" { + -re "type = " { } + -re "type = void" { + set has_debug_info 1 + } + default { + # Some other unexpected output... + fail $gdb_test_name + } + } + + return 0 +} diff --git a/gdb/testsuite/lib/gnat-debug-info-test.adb b/gdb/testsuite/lib/gnat-debug-info-test.adb new file mode 100644 index 000000000000..f1831ad86991 --- /dev/null +++ b/gdb/testsuite/lib/gnat-debug-info-test.adb @@ -0,0 +1,6 @@ +with Ada.Text_IO; + +procedure Hello is +begin + Ada.Text_IO.Put_Line("Hello, world!"); +end Hello;