public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 4/6] gdb/testsuite: add "macros" option to gdb_compile
Date: Wed,  6 Apr 2022 21:51:57 -0400	[thread overview]
Message-ID: <20220407015159.1734834-5-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20220407015159.1734834-1-simon.marchi@polymtl.ca>

From: Simon Marchi <simon.marchi@efficios.com>

Make gdb_compile handle a new "macros" option, which makes it pass the
appropriate flag to make the compiler include macro information in the
debug info.  This will help simplify tests using macros, reduce
redundant code, and make it easier to add support for a new compiler.

Right now it only handles clang specially (using -fdebug-macro) and
falls back to -g3 otherwise (which works for gcc).  Other compilers can
be added as needed.

Change-Id: I50cd6ab1bfbb478c1005486408e214b551364c9b
---
 gdb/testsuite/gdb.base/info-macros.exp        | 14 +----------
 gdb/testsuite/gdb.base/macscp.exp             | 11 ++-------
 gdb/testsuite/gdb.base/style.exp              | 23 ++++---------------
 gdb/testsuite/gdb.linespec/macro-relative.exp |  9 +-------
 gdb/testsuite/lib/gdb.exp                     | 13 +++++++++++
 5 files changed, 22 insertions(+), 48 deletions(-)

diff --git a/gdb/testsuite/gdb.base/info-macros.exp b/gdb/testsuite/gdb.base/info-macros.exp
index b3e1032d76f9..39c9bc696ccf 100644
--- a/gdb/testsuite/gdb.base/info-macros.exp
+++ b/gdb/testsuite/gdb.base/info-macros.exp
@@ -21,19 +21,7 @@ if [using_fission] {
     return -1
 }
 
-set options {debug}
-
-get_compiler_info
-if { [test_compiler_info gcc*] } {
-    lappend options "additional_flags=-g3"
-} elseif { [test_compiler_info clang*] } {
-    lappend options "additional_flags=-fdebug-macro"
-} else {
-    untested "no compiler info"
-    return -1
-}
-
-if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $options] } {
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug macros}] } {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.base/macscp.exp b/gdb/testsuite/gdb.base/macscp.exp
index 4c06423e6d50..be9bd5312ff2 100644
--- a/gdb/testsuite/gdb.base/macscp.exp
+++ b/gdb/testsuite/gdb.base/macscp.exp
@@ -18,19 +18,12 @@
 standard_testfile macscp1.c
 set objfile [standard_output_file ${testfile}.o]
 
-set options { debug additional_flags=-DFROM_COMMANDLINE=ARG}
-
-get_compiler_info
-if { [test_compiler_info "gcc-*"] } {
-    lappend options additional_flags=-g3
-} elseif { [test_compiler_info "clang-*"] } {
-    lappend options additional_flags=-fdebug-macro
-}
+set options {debug macros additional_flags=-DFROM_COMMANDLINE=ARG}
 
 # Generate the intermediate object file.  This is required by Darwin to
 # have access to the .debug_macinfo section.
 if  {[gdb_compile "${srcdir}/${subdir}/macscp1.c" "${objfile}" \
-	  object $options] != "" 
+	  object $options] != ""
      || [gdb_compile "${objfile}" "${binfile}" executable $options] != "" } {
     untested "failed to compile"
     return -1
diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp
index 611b8ae52ba0..6bb5e1c9ac06 100644
--- a/gdb/testsuite/gdb.base/style.exp
+++ b/gdb/testsuite/gdb.base/style.exp
@@ -20,18 +20,7 @@ load_lib gdb-python.exp
 standard_testfile
 
 # Compile the test executable.
-set test_macros 0
-set options debug
-get_compiler_info
-if { [test_compiler_info "gcc-*"] } {
-    lappend options additional_flags=-g3
-    set test_macros 1
-} elseif { [test_compiler_info "clang-*"] } {
-    lappend options additional_flags=-fdebug-macro
-    set test_macros 1
-}
-
-if {[build_executable "failed to build" $testfile $srcfile $options]} {
+if {[build_executable "failed to build" $testfile $srcfile {debug macros}]} {
     return -1
 }
 
@@ -75,7 +64,7 @@ proc clean_restart_and_disable { args } {
 # CLEAN_RESTART_AND_DISABLE instead of CLEAN_RESTART, this ensures
 # that the test operates as expected as styles are disabled.
 proc run_style_tests { } {
-    global testfile srcfile hex binfile test_macros
+    global testfile srcfile hex binfile
     global currently_disabled_style decimal hex
 
     save_vars { env(TERM) } {
@@ -181,11 +170,9 @@ proc run_style_tests { } {
 	    gdb_test_no_output "set width 0" ""
 	}
 
-	if {$test_macros} {
-	    set macro_line [gdb_get_line_number "\#define SOME_MACRO"]
-	    gdb_test "info macro SOME_MACRO" \
-		"Defined at $base_file_expr:$macro_line\r\n#define SOME_MACRO 23"
-	}
+	set macro_line [gdb_get_line_number "\#define SOME_MACRO"]
+	gdb_test "info macro SOME_MACRO" \
+	    "Defined at $base_file_expr:$macro_line\r\n#define SOME_MACRO 23"
 
 	gdb_test_no_output "set width 0"
 
diff --git a/gdb/testsuite/gdb.linespec/macro-relative.exp b/gdb/testsuite/gdb.linespec/macro-relative.exp
index f827420eb3cf..609f290d8fbe 100644
--- a/gdb/testsuite/gdb.linespec/macro-relative.exp
+++ b/gdb/testsuite/gdb.linespec/macro-relative.exp
@@ -26,14 +26,7 @@ if [is_remote host] {
     return 0
 }
 
-set opts {debug additional_flags=-I.}
-
-get_compiler_info
-if [test_compiler_info gcc*] {
-    lappend opts additional_flags=-g3
-} elseif [test_compiler_info clang*] {
-    lappend opts additional_flags=-fdebug-macro
-}
+set opts {debug additional_flags=-I. macros}
 
 if { [file pathtype $objdir] == "relative" } {
     untested "objdir $objdir should be absolute"
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 0b242b649929..8db41154e428 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -4347,6 +4347,8 @@ set gdb_saved_set_unbuffered_mode_obj ""
 #   - nowarnings:  Inhibit all compiler warnings.
 #   - pie: Force creation of PIE executables.
 #   - nopie: Prevent creation of PIE executables.
+#   - macros: Add the required compiler flag to include macro information in
+#     debug information
 #
 # And here are some of the not too obscure options understood by DejaGnu that
 # influence the compilation:
@@ -4574,6 +4576,17 @@ proc gdb_compile {source dest type options} {
 	lappend options "$flag"
     }
 
+  set macros [lsearch -exact $options macros]
+  if {$macros != -1} {
+      if { [test_compiler_info "clang-*"] } {
+	  set flag "additional_flags=-fdebug-macro"
+      } else {
+	  set flag "additional_flags=-g3"
+      }
+
+      set options [lreplace $options $macros $macros $flag]
+  }
+
     if { $type == "executable" } {
 	if { ([istarget "*-*-mingw*"]
 	      || [istarget "*-*-*djgpp"]
-- 
2.35.1


  parent reply	other threads:[~2022-04-07  1:52 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-07  1:51 [PATCH 0/6] Fix printing macros Simon Marchi
2022-04-07  1:51 ` [PATCH 1/6] gdb/testsuite/dwarf: remove two unused variables Simon Marchi
2022-04-07 13:51   ` Tom Tromey
2022-04-07  1:51 ` [PATCH 2/6] gdb/testsuite/dwarf: simplify line number program syntax Simon Marchi
2022-04-07 13:52   ` Tom Tromey
2022-04-07 17:10     ` Simon Marchi
2022-04-07  1:51 ` [PATCH 3/6] gdb/testsuite/dwarf: don't automatically add directory and file entry for DWARF 5 Simon Marchi
2022-04-18 16:28   ` Tom Tromey
2022-04-18 17:32     ` Simon Marchi
2022-04-18 19:28       ` Tom Tromey
2022-04-18 20:58         ` Simon Marchi
2022-04-07  1:51 ` Simon Marchi [this message]
2022-04-07 14:01   ` [PATCH 4/6] gdb/testsuite: add "macros" option to gdb_compile Tom Tromey
2022-04-07 17:22     ` Simon Marchi
2022-04-07 18:31       ` Tom Tromey
2022-04-07 18:41         ` Simon Marchi
2022-04-07  1:51 ` [PATCH 5/6] gdb: prepend comp_dir to symtab name in buildsym_compunit Simon Marchi
2022-04-07  6:09   ` Eli Zaretskii
2022-04-07 16:44     ` Simon Marchi
2022-04-07 17:04       ` Eli Zaretskii
2022-04-07 17:26         ` Simon Marchi
2022-04-07 19:15           ` Eli Zaretskii
2022-04-07 19:45             ` Simon Marchi
2022-04-08  4:07               ` Eli Zaretskii
2022-04-08 13:54                 ` Simon Marchi
2022-04-09  6:59                   ` Eli Zaretskii
2022-04-18 16:35         ` Tom Tromey
2022-04-18 17:36           ` Simon Marchi
2022-04-18 17:59             ` Pedro Alves
2022-04-18 18:19               ` Simon Marchi
2022-04-18 18:25                 ` Pedro Alves
2022-04-18 20:33                   ` Samuel Thibault
2022-04-18 20:56                     ` Simon Marchi
2022-04-07 15:19   ` Hannes Domani
2022-04-07 18:01     ` Simon Marchi
2022-04-21 10:56       ` Hannes Domani
2022-04-21 20:26         ` Simon Marchi
2022-04-18 16:36   ` Tom Tromey
2022-04-18 20:18     ` Simon Marchi
2022-04-07  1:51 ` [PATCH 6/6] gdb/testsuite: add macros test for source files compiled in various ways Simon Marchi
2022-04-18 16:53   ` Tom Tromey
2022-04-21 18:36     ` Simon Marchi
2022-04-21 18:45       ` Pedro Alves
2022-04-21 18:47         ` Pedro Alves

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=20220407015159.1734834-5-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.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).