Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary
@ 2020-08-17 15:17 Sharma, Alok Kumar
  2020-08-17 20:51 ` Tom Tromey
  2020-08-18 10:29 ` Andrew Burgess
  0 siblings, 2 replies; 8+ messages in thread
From: Sharma, Alok Kumar @ 2020-08-17 15:17 UTC (permalink / raw)
  To: gdb-patches; +Cc: George, Jini Susan, Achra, Nitika

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

Hi All,

I request you all to please review this patch. Below are the details.

Problem Description:
Currently, GDB is not able to set a breakpoint at subprogram post
prologue for flang generated binaries. This is due to clang having
two line notes one before and another after the prologue.
Resolution:
 Now the end of prologue is determined using symbol table, which was
the way for clang generated binaries already. Since clang and flang
both share same back-end it is true for flang as well.

gdb/ChangeLog

      * amd64-tdep.c (amd64_skip_prologue): Using symbol table
      to find the end of prologue for flang compiled binaries.
      * arm-tdep.c (arm_skip_prologue): Likewise.
      * i386-tdep.c (i386_skip_prologue): Likewise.

gdb/testsuite/ChangeLog

      * gdb.fortran/vla-type.exp: Skip commands not required for
      the Flang compiled binaries after prologue fix.

Regards,
Alok

[-- Attachment #2: 0001-Fix-for-incorrect-breakpoint-set-in-case-of-flang-co.patch --]
[-- Type: application/octet-stream, Size: 5558 bytes --]

From 6f578b992c789196478742b71af6b75fb76573f3 Mon Sep 17 00:00:00 2001
From: Alok Kumar Sharma <AlokKumar.Sharma@amd.com>
Date: Mon, 17 Aug 2020 17:04:11 +0530
Subject: [PATCH] Fix for incorrect breakpoint set in case of flang compiled
 binary

  Currently, GDB is not able to set a breakpoint at subprogram post
prologue for flang generated binaries. This is due to clang having
two line notes one before and another after the prologue.
  Now the end of prologue is determined using symbol table, which was
the way for clang generated binaries already. Since clang and flang
both share same back-end it is true for flang as well.

gdb/ChangeLog

      * amd64-tdep.c (amd64_skip_prologue): Using symbol table
      to find the end of prologue for flang compiled binaries.
      * arm-tdep.c (arm_skip_prologue): Likewise.
      * i386-tdep.c (i386_skip_prologue): Likewise.

gdb/testsuite/ChangeLog

      * gdb.fortran/vla-type.exp: Skip commands not required for
      the Flang compiled binaries after prologue fix.

Change-Id: I5609f979315effc213feeb6dde6a01a024e0c487
---
 gdb/ChangeLog                          | 7 +++++++
 gdb/amd64-tdep.c                       | 5 +++--
 gdb/arm-tdep.c                         | 3 ++-
 gdb/i386-tdep.c                        | 5 +++--
 gdb/testsuite/ChangeLog                | 5 +++++
 gdb/testsuite/gdb.fortran/vla-type.exp | 8 ++++++--
 6 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3e733a73f0..3eb07cb5d0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2020-08-14  Alok Kumar Sharma  <AlokKumar.Sharma@amd.com>
+
+	* amd64-tdep.c (amd64_skip_prologue): Using symbol table
+	to find the end of prologue for flang compiled binaries.
+	* arm-tdep.c (arm_skip_prologue): Likewise.
+	* i386-tdep.c (i386_skip_prologue): Likewise.
+
 2020-08-17  Tom de Vries  <tdevries@suse.de>
 
 	PR gdb/26393
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 768fe63bdd..6f05f60548 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2547,12 +2547,13 @@ amd64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 	= skip_prologue_using_sal (gdbarch, func_addr);
       struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
 
-      /* Clang always emits a line note before the prologue and another
+      /* Clang/Flang always emit a line note before the prologue and another
 	 one after.  We trust clang to emit usable line notes.  */
       if (post_prologue_pc
 	  && (cust != NULL
 	      && COMPUNIT_PRODUCER (cust) != NULL
-	      && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
+	      && (startswith (COMPUNIT_PRODUCER (cust), "clang ")
+	          || startswith(COMPUNIT_PRODUCER(cust), " F90 Flang"))))
         return std::max (start_pc, post_prologue_pc);
     }
 
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 9cedcc8575..27a8b519ed 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -1351,7 +1351,8 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 	  && (cust == NULL
 	      || COMPUNIT_PRODUCER (cust) == NULL
 	      || startswith (COMPUNIT_PRODUCER (cust), "GNU ")
-	      || startswith (COMPUNIT_PRODUCER (cust), "clang ")))
+	      || startswith (COMPUNIT_PRODUCER (cust), "clang ")
+	      || startswith (COMPUNIT_PRODUCER (cust), " F90 Flang")))
 	return post_prologue_pc;
 
       if (post_prologue_pc != 0)
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 9b905c1996..4c1cf3acd7 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -1847,12 +1847,13 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 	= skip_prologue_using_sal (gdbarch, func_addr);
       struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
 
-      /* Clang always emits a line note before the prologue and another
+      /* Clang/Flang always emit a line note before the prologue and another
 	 one after.  We trust clang to emit usable line notes.  */
       if (post_prologue_pc
 	  && (cust != NULL
 	      && COMPUNIT_PRODUCER (cust) != NULL
-	      && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
+	      && (startswith (COMPUNIT_PRODUCER (cust), "clang ")
+                  || startswith (COMPUNIT_PRODUCER (cust), " F90 Flang"))))
         return std::max (start_pc, post_prologue_pc);
     }
  
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index f0b7949fd6..9d6e42ad39 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-08-14  Alok Kumar Sharma  <AlokKumar.Sharma@amd.com>
+
+	* gdb.fortran/vla-type.exp: Skip commands not required for
+	the Flang compiled binaries after prologue fix.
+
 2020-08-16  Tom de Vries  <tdevries@suse.de>
 
 	PR gdb/25350
diff --git a/gdb/testsuite/gdb.fortran/vla-type.exp b/gdb/testsuite/gdb.fortran/vla-type.exp
index 925c583edc..e2b8d71b4c 100755
--- a/gdb/testsuite/gdb.fortran/vla-type.exp
+++ b/gdb/testsuite/gdb.fortran/vla-type.exp
@@ -33,8 +33,12 @@ set int [fortran_int4]
 
 # Check if not allocated VLA in type does not break
 # the debugger when accessing it.
-gdb_breakpoint [gdb_get_line_number "before-allocated"]
-gdb_continue_to_breakpoint "before-allocated"
+# break main for Flang compiler already breaks here
+if ![test_compiler_info "clang-*"] {
+    gdb_breakpoint [gdb_get_line_number "before-allocated"]
+    gdb_continue_to_breakpoint "before-allocated"
+}
+
 gdb_test "print twov" " = \\\( ivla1 = <not allocated>, ivla2 = <not allocated> \\\)" \
   "print twov before allocated"
 gdb_test "print twov%ivla1" " = <not allocated>" \
-- 
2.17.1


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

* Re: [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary
  2020-08-17 15:17 [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary Sharma, Alok Kumar
@ 2020-08-17 20:51 ` Tom Tromey
  2020-08-19 13:05   ` Andrew Burgess
  2020-08-18 10:29 ` Andrew Burgess
  1 sibling, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2020-08-17 20:51 UTC (permalink / raw)
  To: Sharma, Alok Kumar; +Cc: gdb-patches, George, Jini Susan, Achra, Nitika

>>>>> ">" == Sharma, Alok Kumar <AlokKumar.Sharma@amd.com> writes:

>> +	          || startswith(COMPUNIT_PRODUCER(cust), " F90 Flang"))))

Space before "(".

Does it really start with a space?  That seems weird.

>>  # Check if not allocated VLA in type does not break
>>  # the debugger when accessing it.
>> -gdb_breakpoint [gdb_get_line_number "before-allocated"]
>> -gdb_continue_to_breakpoint "before-allocated"
>> +# break main for Flang compiler already breaks here

Do you know why?

Tom


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

* Re: [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary
  2020-08-17 15:17 [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary Sharma, Alok Kumar
  2020-08-17 20:51 ` Tom Tromey
@ 2020-08-18 10:29 ` Andrew Burgess
  2020-08-18 12:53   ` Sharma, Alok Kumar
  2020-08-18 19:21   ` Tom Tromey
  1 sibling, 2 replies; 8+ messages in thread
From: Andrew Burgess @ 2020-08-18 10:29 UTC (permalink / raw)
  To: Sharma, Alok Kumar; +Cc: gdb-patches, George, Jini Susan, Achra, Nitika

* Sharma, Alok Kumar <AlokKumar.Sharma@amd.com> [2020-08-17 15:17:02 +0000]:

> Hi All,
> 
> I request you all to please review this patch. Below are the details.
> 
> Problem Description:
> Currently, GDB is not able to set a breakpoint at subprogram post
> prologue for flang generated binaries. This is due to clang having
> two line notes one before and another after the prologue.
> Resolution:
>  Now the end of prologue is determined using symbol table, which was
> the way for clang generated binaries already. Since clang and flang
> both share same back-end it is true for flang as well.
> 
> gdb/ChangeLog
> 
>       * amd64-tdep.c (amd64_skip_prologue): Using symbol table
>       to find the end of prologue for flang compiled binaries.
>       * arm-tdep.c (arm_skip_prologue): Likewise.
>       * i386-tdep.c (i386_skip_prologue): Likewise.
> 
> gdb/testsuite/ChangeLog
> 
>       * gdb.fortran/vla-type.exp: Skip commands not required for
>       the Flang compiled binaries after prologue fix.
> 
> Regards,
> Alok
>
>
> From 6f578b992c789196478742b71af6b75fb76573f3 Mon Sep 17 00:00:00 2001
> From: Alok Kumar Sharma <AlokKumar.Sharma@amd.com>
> Date: Mon, 17 Aug 2020 17:04:11 +0530
> Subject: [PATCH] Fix for incorrect breakpoint set in case of flang compiled
>  binary
> 
>   Currently, GDB is not able to set a breakpoint at subprogram post
> prologue for flang generated binaries. This is due to clang having
> two line notes one before and another after the prologue.
>   Now the end of prologue is determined using symbol table, which was
> the way for clang generated binaries already. Since clang and flang
> both share same back-end it is true for flang as well.
> 
> gdb/ChangeLog
> 
>       * amd64-tdep.c (amd64_skip_prologue): Using symbol table
>       to find the end of prologue for flang compiled binaries.
>       * arm-tdep.c (arm_skip_prologue): Likewise.
>       * i386-tdep.c (i386_skip_prologue): Likewise.
> 
> gdb/testsuite/ChangeLog
> 
>       * gdb.fortran/vla-type.exp: Skip commands not required for
>       the Flang compiled binaries after prologue fix.
> 
> Change-Id: I5609f979315effc213feeb6dde6a01a024e0c487
> ---
>  gdb/ChangeLog                          | 7 +++++++
>  gdb/amd64-tdep.c                       | 5 +++--
>  gdb/arm-tdep.c                         | 3 ++-
>  gdb/i386-tdep.c                        | 5 +++--
>  gdb/testsuite/ChangeLog                | 5 +++++
>  gdb/testsuite/gdb.fortran/vla-type.exp | 8 ++++++--
>  6 files changed, 26 insertions(+), 7 deletions(-)
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 3e733a73f0..3eb07cb5d0 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,10 @@
> +2020-08-14  Alok Kumar Sharma  <AlokKumar.Sharma@amd.com>
> +
> +	* amd64-tdep.c (amd64_skip_prologue): Using symbol table
> +	to find the end of prologue for flang compiled binaries.
> +	* arm-tdep.c (arm_skip_prologue): Likewise.
> +	* i386-tdep.c (i386_skip_prologue): Likewise.
> +
>  2020-08-17  Tom de Vries  <tdevries@suse.de>
>  
>  	PR gdb/26393
> diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
> index 768fe63bdd..6f05f60548 100644
> --- a/gdb/amd64-tdep.c
> +++ b/gdb/amd64-tdep.c
> @@ -2547,12 +2547,13 @@ amd64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
>  	= skip_prologue_using_sal (gdbarch, func_addr);
>        struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
>  
> -      /* Clang always emits a line note before the prologue and another
> +      /* Clang/Flang always emit a line note before the prologue and another
>  	 one after.  We trust clang to emit usable line notes.  */
>        if (post_prologue_pc
>  	  && (cust != NULL
>  	      && COMPUNIT_PRODUCER (cust) != NULL
> -	      && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
> +	      && (startswith (COMPUNIT_PRODUCER (cust), "clang ")
> +	          || startswith(COMPUNIT_PRODUCER(cust), " F90 Flang"))))
>          return std::max (start_pc, post_prologue_pc);

We have the files producer.{c,h} that wrap up tests just like this
one.  If feels like we should add a new test to those files that
matches all clang backend based compilers, then make use of this new
test throughout.

I'd keep the name of the test fairly generic, the important thing here
is the backend technology right, not the frontend language?  So if I
added a new language with a clang backend I'd likely run into the same
issues.

Thanks,
Andrew

>      }
>  
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index 9cedcc8575..27a8b519ed 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -1351,7 +1351,8 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
>  	  && (cust == NULL
>  	      || COMPUNIT_PRODUCER (cust) == NULL
>  	      || startswith (COMPUNIT_PRODUCER (cust), "GNU ")
> -	      || startswith (COMPUNIT_PRODUCER (cust), "clang ")))
> +	      || startswith (COMPUNIT_PRODUCER (cust), "clang ")
> +	      || startswith (COMPUNIT_PRODUCER (cust), " F90 Flang")))
>  	return post_prologue_pc;
>  
>        if (post_prologue_pc != 0)
> diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
> index 9b905c1996..4c1cf3acd7 100644
> --- a/gdb/i386-tdep.c
> +++ b/gdb/i386-tdep.c
> @@ -1847,12 +1847,13 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
>  	= skip_prologue_using_sal (gdbarch, func_addr);
>        struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
>  
> -      /* Clang always emits a line note before the prologue and another
> +      /* Clang/Flang always emit a line note before the prologue and another
>  	 one after.  We trust clang to emit usable line notes.  */
>        if (post_prologue_pc
>  	  && (cust != NULL
>  	      && COMPUNIT_PRODUCER (cust) != NULL
> -	      && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
> +	      && (startswith (COMPUNIT_PRODUCER (cust), "clang ")
> +                  || startswith (COMPUNIT_PRODUCER (cust), " F90 Flang"))))
>          return std::max (start_pc, post_prologue_pc);
>      }
>   
> diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
> index f0b7949fd6..9d6e42ad39 100644
> --- a/gdb/testsuite/ChangeLog
> +++ b/gdb/testsuite/ChangeLog
> @@ -1,3 +1,8 @@
> +2020-08-14  Alok Kumar Sharma  <AlokKumar.Sharma@amd.com>
> +
> +	* gdb.fortran/vla-type.exp: Skip commands not required for
> +	the Flang compiled binaries after prologue fix.
> +
>  2020-08-16  Tom de Vries  <tdevries@suse.de>
>  
>  	PR gdb/25350
> diff --git a/gdb/testsuite/gdb.fortran/vla-type.exp b/gdb/testsuite/gdb.fortran/vla-type.exp
> index 925c583edc..e2b8d71b4c 100755
> --- a/gdb/testsuite/gdb.fortran/vla-type.exp
> +++ b/gdb/testsuite/gdb.fortran/vla-type.exp
> @@ -33,8 +33,12 @@ set int [fortran_int4]
>  
>  # Check if not allocated VLA in type does not break
>  # the debugger when accessing it.
> -gdb_breakpoint [gdb_get_line_number "before-allocated"]
> -gdb_continue_to_breakpoint "before-allocated"
> +# break main for Flang compiler already breaks here
> +if ![test_compiler_info "clang-*"] {
> +    gdb_breakpoint [gdb_get_line_number "before-allocated"]
> +    gdb_continue_to_breakpoint "before-allocated"
> +}
> +
>  gdb_test "print twov" " = \\\( ivla1 = <not allocated>, ivla2 = <not allocated> \\\)" \
>    "print twov before allocated"
>  gdb_test "print twov%ivla1" " = <not allocated>" \
> -- 
> 2.17.1



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

* RE: [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary
  2020-08-18 10:29 ` Andrew Burgess
@ 2020-08-18 12:53   ` Sharma, Alok Kumar
  2020-08-19 13:09     ` Andrew Burgess
  2020-08-18 19:21   ` Tom Tromey
  1 sibling, 1 reply; 8+ messages in thread
From: Sharma, Alok Kumar @ 2020-08-18 12:53 UTC (permalink / raw)
  To: Andrew Burgess, Tom Tromey; +Cc: gdb-patches, George, Jini Susan, Achra, Nitika

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

Thanks Tom and Andrew for your comments. Hopefully addressed in the attached updated patch.

Please find my below answers for your queries.

> We have the files producer.{c,h} that wrap up tests just like this one.  If feels like we should add a new test to those files that matches all clang backend based compilers, then make use of this new test throughout.
> I'd keep the name of the test fairly generic, the important thing here is the backend technology right, not the frontend language?  So if I added a new language with a clang backend I'd likely run into the same issues.
Thanks for your suggestion. I have updated the patch for same.

> Space before "(".
Though the code is moved, I have taken care of the comment in general.

> Does it really start with a space?  That seems weird.
Agreed but it has space at the start.

>> +# break main for Flang compiler already breaks here
> Do you know why?
Line number 46 is the place where breakpoint to main is hit for Flang compiled binary and that looks Okey.
Below is the snippet from gdb.fortran/
------------------------------------------
    16  program vla_struct
    17    type :: one
    18      integer, allocatable :: ivla (:, :, :)
    19    end type one
    20    type :: two
    21      integer, allocatable :: ivla1 (:, :, :)
    22      integer, allocatable :: ivla2 (:, :)
    23    end type two
    24    type :: three
    25      integer :: ivar
    26      integer, allocatable :: ivla (:)
    27    end type three
    28    type :: four
    29      integer, allocatable :: ivla (:)
    30      integer :: ivar
    31    end type four
    32    type :: five
    33      type(one) :: tone
    34    end type five
    35
    36    type(one), target        :: onev
    37    type(two)                :: twov
    38    type(three)              :: threev
    39    type(four)               :: fourv
    40    type(five)               :: fivev
    41    type(five)               :: fivearr (2)
    42    type(five), allocatable  :: fivedynarr (:)
    43    logical                  :: l
    44    integer                  :: i, j
    45
    46    allocate (onev%ivla (11,22,33))         ! before-allocated
    47    l = allocated(onev%ivla)
    48
------------------------------------------ 

    gdb/ChangeLog

          * amd64-tdep.c (amd64_skip_prologue): Using symbol table
          to find the end of prologue for flang compiled binaries.
          * arm-tdep.c (arm_skip_prologue): Likewise.
          * i386-tdep.c (i386_skip_prologue): Likewise.
          * producer.c (producer_is_llvm): New function.
          (producer_parsing_tests): Added new tests for clang/flang.
          * producer.h (producer_is_llvm): New declaration.

    gdb/testsuite/ChangeLog

          * gdb.fortran/vla-type.exp: Skip commands not required for
          the Flang compiled binaries after prologue fix.

Regards,
Alok

-----Original Message-----
From: Andrew Burgess <andrew.burgess@embecosm.com> 
Sent: Tuesday, August 18, 2020 3:59 PM
To: Sharma, Alok Kumar <AlokKumar.Sharma@amd.com>
Cc: gdb-patches@sourceware.org; George, Jini Susan <JiniSusan.George@amd.com>; Achra, Nitika <Nitika.Achra@amd.com>
Subject: Re: [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary

[CAUTION: External Email]

* Sharma, Alok Kumar <AlokKumar.Sharma@amd.com> [2020-08-17 15:17:02 +0000]:

> Hi All,
>
> I request you all to please review this patch. Below are the details.
>
> Problem Description:
> Currently, GDB is not able to set a breakpoint at subprogram post 
> prologue for flang generated binaries. This is due to clang having two 
> line notes one before and another after the prologue.
> Resolution:
>  Now the end of prologue is determined using symbol table, which was 
> the way for clang generated binaries already. Since clang and flang 
> both share same back-end it is true for flang as well.
>
> gdb/ChangeLog
>
>       * amd64-tdep.c (amd64_skip_prologue): Using symbol table
>       to find the end of prologue for flang compiled binaries.
>       * arm-tdep.c (arm_skip_prologue): Likewise.
>       * i386-tdep.c (i386_skip_prologue): Likewise.
>
> gdb/testsuite/ChangeLog
>
>       * gdb.fortran/vla-type.exp: Skip commands not required for
>       the Flang compiled binaries after prologue fix.
>
> Regards,
> Alok
>
>
> From 6f578b992c789196478742b71af6b75fb76573f3 Mon Sep 17 00:00:00 2001
> From: Alok Kumar Sharma <AlokKumar.Sharma@amd.com>
> Date: Mon, 17 Aug 2020 17:04:11 +0530
> Subject: [PATCH] Fix for incorrect breakpoint set in case of flang 
> compiled  binary
>
>   Currently, GDB is not able to set a breakpoint at subprogram post 
> prologue for flang generated binaries. This is due to clang having two 
> line notes one before and another after the prologue.
>   Now the end of prologue is determined using symbol table, which was 
> the way for clang generated binaries already. Since clang and flang 
> both share same back-end it is true for flang as well.
>
> gdb/ChangeLog
>
>       * amd64-tdep.c (amd64_skip_prologue): Using symbol table
>       to find the end of prologue for flang compiled binaries.
>       * arm-tdep.c (arm_skip_prologue): Likewise.
>       * i386-tdep.c (i386_skip_prologue): Likewise.
>
> gdb/testsuite/ChangeLog
>
>       * gdb.fortran/vla-type.exp: Skip commands not required for
>       the Flang compiled binaries after prologue fix.
>
> Change-Id: I5609f979315effc213feeb6dde6a01a024e0c487
> ---
>  gdb/ChangeLog                          | 7 +++++++
>  gdb/amd64-tdep.c                       | 5 +++--
>  gdb/arm-tdep.c                         | 3 ++-
>  gdb/i386-tdep.c                        | 5 +++--
>  gdb/testsuite/ChangeLog                | 5 +++++
>  gdb/testsuite/gdb.fortran/vla-type.exp | 8 ++++++--
>  6 files changed, 26 insertions(+), 7 deletions(-)
>
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 
> 3e733a73f0..3eb07cb5d0 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,10 @@
> +2020-08-14  Alok Kumar Sharma  <AlokKumar.Sharma@amd.com>
> +
> +     * amd64-tdep.c (amd64_skip_prologue): Using symbol table
> +     to find the end of prologue for flang compiled binaries.
> +     * arm-tdep.c (arm_skip_prologue): Likewise.
> +     * i386-tdep.c (i386_skip_prologue): Likewise.
> +
>  2020-08-17  Tom de Vries  <tdevries@suse.de>
>
>       PR gdb/26393
> diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index 
> 768fe63bdd..6f05f60548 100644
> --- a/gdb/amd64-tdep.c
> +++ b/gdb/amd64-tdep.c
> @@ -2547,12 +2547,13 @@ amd64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
>       = skip_prologue_using_sal (gdbarch, func_addr);
>        struct compunit_symtab *cust = find_pc_compunit_symtab 
> (func_addr);
>
> -      /* Clang always emits a line note before the prologue and another
> +      /* Clang/Flang always emit a line note before the prologue and 
> + another
>        one after.  We trust clang to emit usable line notes.  */
>        if (post_prologue_pc
>         && (cust != NULL
>             && COMPUNIT_PRODUCER (cust) != NULL
> -           && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
> +           && (startswith (COMPUNIT_PRODUCER (cust), "clang ")
> +               || startswith(COMPUNIT_PRODUCER(cust), " F90 
> + Flang"))))
>          return std::max (start_pc, post_prologue_pc);

We have the files producer.{c,h} that wrap up tests just like this one.  If feels like we should add a new test to those files that matches all clang backend based compilers, then make use of this new test throughout.

I'd keep the name of the test fairly generic, the important thing here is the backend technology right, not the frontend language?  So if I added a new language with a clang backend I'd likely run into the same issues.

Thanks,
Andrew

>      }
>
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 
> 9cedcc8575..27a8b519ed 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -1351,7 +1351,8 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
>         && (cust == NULL
>             || COMPUNIT_PRODUCER (cust) == NULL
>             || startswith (COMPUNIT_PRODUCER (cust), "GNU ")
> -           || startswith (COMPUNIT_PRODUCER (cust), "clang ")))
> +           || startswith (COMPUNIT_PRODUCER (cust), "clang ")
> +           || startswith (COMPUNIT_PRODUCER (cust), " F90 Flang")))
>       return post_prologue_pc;
>
>        if (post_prologue_pc != 0)
> diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 
> 9b905c1996..4c1cf3acd7 100644
> --- a/gdb/i386-tdep.c
> +++ b/gdb/i386-tdep.c
> @@ -1847,12 +1847,13 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
>       = skip_prologue_using_sal (gdbarch, func_addr);
>        struct compunit_symtab *cust = find_pc_compunit_symtab 
> (func_addr);
>
> -      /* Clang always emits a line note before the prologue and another
> +      /* Clang/Flang always emit a line note before the prologue and 
> + another
>        one after.  We trust clang to emit usable line notes.  */
>        if (post_prologue_pc
>         && (cust != NULL
>             && COMPUNIT_PRODUCER (cust) != NULL
> -           && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
> +           && (startswith (COMPUNIT_PRODUCER (cust), "clang ")
> +                  || startswith (COMPUNIT_PRODUCER (cust), " F90 
> + Flang"))))
>          return std::max (start_pc, post_prologue_pc);
>      }
>
> diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 
> f0b7949fd6..9d6e42ad39 100644
> --- a/gdb/testsuite/ChangeLog
> +++ b/gdb/testsuite/ChangeLog
> @@ -1,3 +1,8 @@
> +2020-08-14  Alok Kumar Sharma  <AlokKumar.Sharma@amd.com>
> +
> +     * gdb.fortran/vla-type.exp: Skip commands not required for
> +     the Flang compiled binaries after prologue fix.
> +
>  2020-08-16  Tom de Vries  <tdevries@suse.de>
>
>       PR gdb/25350
> diff --git a/gdb/testsuite/gdb.fortran/vla-type.exp 
> b/gdb/testsuite/gdb.fortran/vla-type.exp
> index 925c583edc..e2b8d71b4c 100755
> --- a/gdb/testsuite/gdb.fortran/vla-type.exp
> +++ b/gdb/testsuite/gdb.fortran/vla-type.exp
> @@ -33,8 +33,12 @@ set int [fortran_int4]
>
>  # Check if not allocated VLA in type does not break  # the debugger 
> when accessing it.
> -gdb_breakpoint [gdb_get_line_number "before-allocated"] 
> -gdb_continue_to_breakpoint "before-allocated"
> +# break main for Flang compiler already breaks here if 
> +![test_compiler_info "clang-*"] {
> +    gdb_breakpoint [gdb_get_line_number "before-allocated"]
> +    gdb_continue_to_breakpoint "before-allocated"
> +}
> +
>  gdb_test "print twov" " = \\\( ivla1 = <not allocated>, ivla2 = <not allocated> \\\)" \
>    "print twov before allocated"
>  gdb_test "print twov%ivla1" " = <not allocated>" \
> --
> 2.17.1


[-- Attachment #2: 0001-Fix-for-incorrect-breakpoint-set-in-case-of-flang-co.patch --]
[-- Type: application/octet-stream, Size: 8117 bytes --]

From 580656516e649e133bd2dca291ea12c9680acbad Mon Sep 17 00:00:00 2001
From: Alok Kumar Sharma <AlokKumar.Sharma@amd.com>
Date: Mon, 17 Aug 2020 17:04:11 +0530
Subject: [PATCH] Fix for incorrect breakpoint set in case of flang compiled
 binary

  Currently, GDB is not able to set a breakpoint at subprogram post
prologue for flang generated binaries. This is due to clang having
two line notes one before and another after the prologue.
  Now the end of prologue is determined using symbol table, which was
the way for clang generated binaries already. Since clang and flang
both share same back-end it is true for flang as well.

gdb/ChangeLog

      * amd64-tdep.c (amd64_skip_prologue): Using symbol table
      to find the end of prologue for flang compiled binaries.
      * arm-tdep.c (arm_skip_prologue): Likewise.
      * i386-tdep.c (i386_skip_prologue): Likewise.
      * producer.c (producer_is_llvm): New function.
      (producer_parsing_tests): Added new tests for clang/flang.
      * producer.h (producer_is_llvm): New declaration.

gdb/testsuite/ChangeLog

      * gdb.fortran/vla-type.exp: Skip commands not required for
      the Flang compiled binaries after prologue fix.

Change-Id: I5609f979315effc213feeb6dde6a01a024e0c487
---
 gdb/ChangeLog                          | 10 +++++++++
 gdb/amd64-tdep.c                       |  7 ++++---
 gdb/arm-tdep.c                         |  4 +++-
 gdb/i386-tdep.c                        |  8 +++++---
 gdb/producer.c                         | 28 ++++++++++++++++++++++++++
 gdb/producer.h                         |  4 ++++
 gdb/testsuite/ChangeLog                |  5 +++++
 gdb/testsuite/gdb.fortran/vla-type.exp |  8 ++++++--
 8 files changed, 65 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3e733a73f0..63c97f4c50 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2020-08-14  Alok Kumar Sharma  <AlokKumar.Sharma@amd.com>
+
+	* amd64-tdep.c (amd64_skip_prologue): Using symbol table
+	to find the end of prologue for flang compiled binaries.
+	* arm-tdep.c (arm_skip_prologue): Likewise.
+	* i386-tdep.c (i386_skip_prologue): Likewise.
+	* producer.c (producer_is_llvm): New function.
+	(producer_parsing_tests): Added new tests for clang/flang.
+	* producer.h (producer_is_llvm): New declaration.
+
 2020-08-17  Tom de Vries  <tdevries@suse.de>
 
 	PR gdb/26393
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 768fe63bdd..59f7c9f885 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2547,12 +2547,13 @@ amd64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 	= skip_prologue_using_sal (gdbarch, func_addr);
       struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
 
-      /* Clang always emits a line note before the prologue and another
-	 one after.  We trust clang to emit usable line notes.  */
+      /* LLVM backend (Clang/Flang) always emits a line note before the
+         prologue and another one after.  We trust clang to emit usable
+         line notes.  */
       if (post_prologue_pc
 	  && (cust != NULL
 	      && COMPUNIT_PRODUCER (cust) != NULL
-	      && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
+	      && producer_is_llvm (COMPUNIT_PRODUCER (cust))))
         return std::max (start_pc, post_prologue_pc);
     }
 
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 9cedcc8575..074eedb480 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -60,6 +60,8 @@
 #include "record-full.h"
 #include <algorithm>
 
+#include "producer.h"
+
 #if GDB_SELF_TEST
 #include "gdbsupport/selftest.h"
 #endif
@@ -1351,7 +1353,7 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 	  && (cust == NULL
 	      || COMPUNIT_PRODUCER (cust) == NULL
 	      || startswith (COMPUNIT_PRODUCER (cust), "GNU ")
-	      || startswith (COMPUNIT_PRODUCER (cust), "clang ")))
+	      || producer_is_llvm (COMPUNIT_PRODUCER (cust))))
 	return post_prologue_pc;
 
       if (post_prologue_pc != 0)
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 9b905c1996..d9fa2b9264 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -65,6 +65,7 @@
 #include <ctype.h>
 #include <algorithm>
 #include <unordered_set>
+#include "producer.h"
 
 /* Register names.  */
 
@@ -1847,12 +1848,13 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 	= skip_prologue_using_sal (gdbarch, func_addr);
       struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
 
-      /* Clang always emits a line note before the prologue and another
-	 one after.  We trust clang to emit usable line notes.  */
+      /* LLVM backend (Clang/Flang) always emits a line note before the
+         prologue and another one after.  We trust clang to emit usable
+         line notes.  */
       if (post_prologue_pc
 	  && (cust != NULL
 	      && COMPUNIT_PRODUCER (cust) != NULL
-	      && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
+	      && producer_is_llvm (COMPUNIT_PRODUCER (cust))))
         return std::max (start_pc, post_prologue_pc);
     }
  
diff --git a/gdb/producer.c b/gdb/producer.c
index 735a928f33..fe89e7d536 100644
--- a/gdb/producer.c
+++ b/gdb/producer.c
@@ -125,6 +125,18 @@ producer_is_icc (const char *producer, int *major, int *minor)
   return false;
 }
 
+/* See producer.h.  */
+
+bool
+producer_is_llvm (const char *producer)
+{
+  if (producer == NULL || !(startswith (producer, "clang ")
+                            || startswith (producer, " F90 Flang ")))
+    return false;
+
+  return true;
+}
+
 #if defined GDB_SELF_TEST
 namespace selftests {
 namespace producer {
@@ -203,6 +215,22 @@ Version 18.0 Beta";
     SELF_CHECK (producer_is_gcc (gnu_exp, &major, &minor)
 		&& major == 5 && minor == 0);
   }
+
+  {
+    static const char clang_llvm_exp[] = "clang version 12.0.0 (CLANG: bld#8)";
+    int major = 0, minor = 0;
+    SELF_CHECK (!producer_is_icc (clang_llvm_exp, NULL, NULL));
+    SELF_CHECK (!producer_is_gcc (clang_llvm_exp, &major, &minor));
+    SELF_CHECK (producer_is_llvm (clang_llvm_exp));
+  }
+
+  {
+    static const char flang_llvm_exp[] = " F90 Flang - 1.5 2017-05-01";
+    int major = 0, minor = 0;
+    SELF_CHECK (!producer_is_icc (flang_llvm_exp, NULL, NULL));
+    SELF_CHECK (!producer_is_gcc (flang_llvm_exp, &major, &minor));
+    SELF_CHECK (producer_is_llvm (flang_llvm_exp));
+  }
 }
 }
 }
diff --git a/gdb/producer.h b/gdb/producer.h
index d8974d3814..e9bc309b0c 100644
--- a/gdb/producer.h
+++ b/gdb/producer.h
@@ -52,4 +52,8 @@ extern int producer_is_gcc (const char *producer, int *major, int *minor);
        running on Intel(R) 64, Version 18.0 Beta ....".  */
 extern bool producer_is_icc (const char *producer, int *major, int *minor);
 
+/* Returns true if the given PRODUCER string is LLVM (clang/flang) or
+   false otherwise.*/
+extern bool producer_is_llvm (const char *producer);
+
 #endif
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index f0b7949fd6..9d6e42ad39 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-08-14  Alok Kumar Sharma  <AlokKumar.Sharma@amd.com>
+
+	* gdb.fortran/vla-type.exp: Skip commands not required for
+	the Flang compiled binaries after prologue fix.
+
 2020-08-16  Tom de Vries  <tdevries@suse.de>
 
 	PR gdb/25350
diff --git a/gdb/testsuite/gdb.fortran/vla-type.exp b/gdb/testsuite/gdb.fortran/vla-type.exp
index 925c583edc..e2b8d71b4c 100755
--- a/gdb/testsuite/gdb.fortran/vla-type.exp
+++ b/gdb/testsuite/gdb.fortran/vla-type.exp
@@ -33,8 +33,12 @@ set int [fortran_int4]
 
 # Check if not allocated VLA in type does not break
 # the debugger when accessing it.
-gdb_breakpoint [gdb_get_line_number "before-allocated"]
-gdb_continue_to_breakpoint "before-allocated"
+# break main for Flang compiler already breaks here
+if ![test_compiler_info "clang-*"] {
+    gdb_breakpoint [gdb_get_line_number "before-allocated"]
+    gdb_continue_to_breakpoint "before-allocated"
+}
+
 gdb_test "print twov" " = \\\( ivla1 = <not allocated>, ivla2 = <not allocated> \\\)" \
   "print twov before allocated"
 gdb_test "print twov%ivla1" " = <not allocated>" \
-- 
2.17.1


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

* Re: [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary
  2020-08-18 10:29 ` Andrew Burgess
  2020-08-18 12:53   ` Sharma, Alok Kumar
@ 2020-08-18 19:21   ` Tom Tromey
  1 sibling, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2020-08-18 19:21 UTC (permalink / raw)
  To: Andrew Burgess
  Cc: Sharma, Alok Kumar, George, Jini Susan, Achra, Nitika, gdb-patches

Andrew> We have the files producer.{c,h} that wrap up tests just like this
Andrew> one.  If feels like we should add a new test to those files that
Andrew> matches all clang backend based compilers, then make use of this new
Andrew> test throughout.

Andrew> I'd keep the name of the test fairly generic, the important thing here
Andrew> is the backend technology right, not the frontend language?  So if I
Andrew> added a new language with a clang backend I'd likely run into the same
Andrew> issues.

See also the hilarious

https://github.com/rust-lang/rust/issues/41252#issuecomment-293676579

Also

https://sourceware.org/bugzilla/show_bug.cgi?id=21470

Whenever this comes up, I think to myself that gdb should assume correct
DWARF by default, and have to sniff for the compilers that break the
rules -- mostly GCC I suppose :-( 

Tom


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

* Re: [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary
  2020-08-17 20:51 ` Tom Tromey
@ 2020-08-19 13:05   ` Andrew Burgess
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Burgess @ 2020-08-19 13:05 UTC (permalink / raw)
  To: Tom Tromey
  Cc: Sharma, Alok Kumar, George, Jini Susan, Achra, Nitika, gdb-patches

* Tom Tromey <tom@tromey.com> [2020-08-17 14:51:19 -0600]:

> >>>>> ">" == Sharma, Alok Kumar <AlokKumar.Sharma@amd.com> writes:
> 
> >> +	          || startswith(COMPUNIT_PRODUCER(cust), " F90 Flang"))))
> 
> Space before "(".
> 
> Does it really start with a space?  That seems weird.
> 
> >>  # Check if not allocated VLA in type does not break
> >>  # the debugger when accessing it.
> >> -gdb_breakpoint [gdb_get_line_number "before-allocated"]
> >> -gdb_continue_to_breakpoint "before-allocated"
> >> +# break main for Flang compiler already breaks here
> 
> Do you know why?

The line marked 'before-allocated' is the first line that should be
considered after the prologue.

Due to GCC not really marking the end of prologue correctly we rely on
the prologue scanner for GCC, while for Flang we can use the line
table to spot the end of prologue.

On Flang this leaves us in the correct place, the 'before-allocated'
line.

On GCC the prologue scanner aborts early because the prologue contains
a small control flow loop  to initialise some of the local variables.
As a result on GCC we stop part way through the prologue.

We could improve the prologue scanner to handle this case on GCC, but
that's obviously a separate issue.

... or GCC could start marking the end of prologue.

Thanks,
Andrew


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

* Re: [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary
  2020-08-18 12:53   ` Sharma, Alok Kumar
@ 2020-08-19 13:09     ` Andrew Burgess
  2020-08-19 15:25       ` Sharma, Alok Kumar
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Burgess @ 2020-08-19 13:09 UTC (permalink / raw)
  To: Sharma, Alok Kumar
  Cc: Tom Tromey, gdb-patches, George, Jini Susan, Achra, Nitika

* Sharma, Alok Kumar <AlokKumar.Sharma@amd.com> [2020-08-18 12:53:10 +0000]:

> Thanks Tom and Andrew for your comments. Hopefully addressed in the attached updated patch.
> 
> Please find my below answers for your queries.
> 
> > We have the files producer.{c,h} that wrap up tests just like this one.  If feels like we should add a new test to those files that matches all clang backend based compilers, then make use of this new test throughout.
> > I'd keep the name of the test fairly generic, the important thing here is the backend technology right, not the frontend language?  So if I added a new language with a clang backend I'd likely run into the same issues.
> Thanks for your suggestion. I have updated the patch for same.
> 
> > Space before "(".
> Though the code is moved, I have taken care of the comment in general.
> 
> > Does it really start with a space?  That seems weird.
> Agreed but it has space at the start.
> 
> >> +# break main for Flang compiler already breaks here
> > Do you know why?
> Line number 46 is the place where breakpoint to main is hit for Flang compiled binary and that looks Okey.
> Below is the snippet from gdb.fortran/
> ------------------------------------------
>     16  program vla_struct
>     17    type :: one
>     18      integer, allocatable :: ivla (:, :, :)
>     19    end type one
>     20    type :: two
>     21      integer, allocatable :: ivla1 (:, :, :)
>     22      integer, allocatable :: ivla2 (:, :)
>     23    end type two
>     24    type :: three
>     25      integer :: ivar
>     26      integer, allocatable :: ivla (:)
>     27    end type three
>     28    type :: four
>     29      integer, allocatable :: ivla (:)
>     30      integer :: ivar
>     31    end type four
>     32    type :: five
>     33      type(one) :: tone
>     34    end type five
>     35
>     36    type(one), target        :: onev
>     37    type(two)                :: twov
>     38    type(three)              :: threev
>     39    type(four)               :: fourv
>     40    type(five)               :: fivev
>     41    type(five)               :: fivearr (2)
>     42    type(five), allocatable  :: fivedynarr (:)
>     43    logical                  :: l
>     44    integer                  :: i, j
>     45
>     46    allocate (onev%ivla (11,22,33))         ! before-allocated
>     47    l = allocated(onev%ivla)
>     48
> ------------------------------------------ 
> 
>     gdb/ChangeLog
> 
>           * amd64-tdep.c (amd64_skip_prologue): Using symbol table
>           to find the end of prologue for flang compiled binaries.
>           * arm-tdep.c (arm_skip_prologue): Likewise.
>           * i386-tdep.c (i386_skip_prologue): Likewise.
>           * producer.c (producer_is_llvm): New function.
>           (producer_parsing_tests): Added new tests for clang/flang.
>           * producer.h (producer_is_llvm): New declaration.
> 
>     gdb/testsuite/ChangeLog
> 
>           * gdb.fortran/vla-type.exp: Skip commands not required for
>           the Flang compiled binaries after prologue fix.

This looks good to me with two minor nits fixed.

> diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
> index 768fe63bdd..59f7c9f885 100644
> --- a/gdb/amd64-tdep.c
> +++ b/gdb/amd64-tdep.c
> @@ -2547,12 +2547,13 @@ amd64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
>         = skip_prologue_using_sal (gdbarch, func_addr);
>        struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
> 
> -      /* Clang always emits a line note before the prologue and another
> -	 one after.  We trust clang to emit usable line notes.  */
> +      /* LLVM backend (Clang/Flang) always emits a line note before the
> +         prologue and another one after.  We trust clang to emit usable
> +         line notes.  */
>        if (post_prologue_pc
>           && (cust != NULL
>               && COMPUNIT_PRODUCER (cust) != NULL
> -	      && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
> +	      && producer_is_llvm (COMPUNIT_PRODUCER (cust))))
>          return std::max (start_pc, post_prologue_pc);
>      }
> 
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index 9cedcc8575..074eedb480 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -60,6 +60,8 @@
>  #include "record-full.h"
>  #include <algorithm>
> 
> +#include "producer.h"
> +
>  #if GDB_SELF_TEST
>  #include "gdbsupport/selftest.h"
>  #endif
> @@ -1351,7 +1353,7 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
>           && (cust == NULL
>               || COMPUNIT_PRODUCER (cust) == NULL
>               || startswith (COMPUNIT_PRODUCER (cust), "GNU ")
> -	      || startswith (COMPUNIT_PRODUCER (cust), "clang ")))
> +	      || producer_is_llvm (COMPUNIT_PRODUCER (cust))))
>         return post_prologue_pc;
> 
>        if (post_prologue_pc != 0)
> diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
> index 9b905c1996..d9fa2b9264 100644
> --- a/gdb/i386-tdep.c
> +++ b/gdb/i386-tdep.c
> @@ -65,6 +65,7 @@
>  #include <ctype.h>
>  #include <algorithm>
>  #include <unordered_set>
> +#include "producer.h"
> 
>  /* Register names.  */
> 
> @@ -1847,12 +1848,13 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
>         = skip_prologue_using_sal (gdbarch, func_addr);
>        struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
> 
> -      /* Clang always emits a line note before the prologue and another
> -	 one after.  We trust clang to emit usable line notes.  */
> +      /* LLVM backend (Clang/Flang) always emits a line note before the
> +         prologue and another one after.  We trust clang to emit usable
> +         line notes.  */
>        if (post_prologue_pc
>           && (cust != NULL
>               && COMPUNIT_PRODUCER (cust) != NULL
> -	      && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
> +	      && producer_is_llvm (COMPUNIT_PRODUCER (cust))))
>          return std::max (start_pc, post_prologue_pc);
>      }
> 
> diff --git a/gdb/producer.c b/gdb/producer.c
> index 735a928f33..fe89e7d536 100644
> --- a/gdb/producer.c
> +++ b/gdb/producer.c
> @@ -125,6 +125,18 @@ producer_is_icc (const char *producer, int *major, int *minor)
>    return false;
>  }
> 
> +/* See producer.h.  */
> +
> +bool
> +producer_is_llvm (const char *producer)
> +{
> +  if (producer == NULL || !(startswith (producer, "clang ")
> +                            || startswith (producer, " F90 Flang ")))
> +    return false;
> +
> +  return true;

I'm really not a fan of 'if (condition) return condition' type code,
I'd rather see just:

  return !(producer == NULL || !(startswith (producer, "clang ")
				 || startswith (producer, " F90 Flang ")));

> +}
> +
>  #if defined GDB_SELF_TEST
>  namespace selftests {
>  namespace producer {
> @@ -203,6 +215,22 @@ Version 18.0 Beta";
>      SELF_CHECK (producer_is_gcc (gnu_exp, &major, &minor)
>                 && major == 5 && minor == 0);
>    }
> +
> +  {
> +    static const char clang_llvm_exp[] = "clang version 12.0.0 (CLANG: bld#8)";
> +    int major = 0, minor = 0;
> +    SELF_CHECK (!producer_is_icc (clang_llvm_exp, NULL, NULL));
> +    SELF_CHECK (!producer_is_gcc (clang_llvm_exp, &major, &minor));
> +    SELF_CHECK (producer_is_llvm (clang_llvm_exp));
> +  }
> +
> +  {
> +    static const char flang_llvm_exp[] = " F90 Flang - 1.5 2017-05-01";
> +    int major = 0, minor = 0;
> +    SELF_CHECK (!producer_is_icc (flang_llvm_exp, NULL, NULL));
> +    SELF_CHECK (!producer_is_gcc (flang_llvm_exp, &major, &minor));
> +    SELF_CHECK (producer_is_llvm (flang_llvm_exp));
> +  }
>  }
>  }
>  }
> diff --git a/gdb/producer.h b/gdb/producer.h
> index d8974d3814..e9bc309b0c 100644
> --- a/gdb/producer.h
> +++ b/gdb/producer.h
> @@ -52,4 +52,8 @@ extern int producer_is_gcc (const char *producer, int *major, int *minor);
>         running on Intel(R) 64, Version 18.0 Beta ....".  */
>  extern bool producer_is_icc (const char *producer, int *major, int *minor);
> 
> +/* Returns true if the given PRODUCER string is LLVM (clang/flang) or
> +   false otherwise.*/

Two whitespace after the final '.' here.

Thanks,
Andrew


> +extern bool producer_is_llvm (const char *producer);
> +
>  #endif
> diff --git a/gdb/testsuite/gdb.fortran/vla-type.exp b/gdb/testsuite/gdb.fortran/vla-type.exp
> index 925c583edc..e2b8d71b4c 100755
> --- a/gdb/testsuite/gdb.fortran/vla-type.exp
> +++ b/gdb/testsuite/gdb.fortran/vla-type.exp
> @@ -33,8 +33,12 @@ set int [fortran_int4]
> 
>  # Check if not allocated VLA in type does not break
>  # the debugger when accessing it.
> -gdb_breakpoint [gdb_get_line_number "before-allocated"]
> -gdb_continue_to_breakpoint "before-allocated"
> +# break main for Flang compiler already breaks here
> +if ![test_compiler_info "clang-*"] {
> +    gdb_breakpoint [gdb_get_line_number "before-allocated"]
> +    gdb_continue_to_breakpoint "before-allocated"
> +}
> +
>  gdb_test "print twov" " = \\\( ivla1 = <not allocated>, ivla2 = <not allocated> \\\)" \
>    "print twov before allocated"
>  gdb_test "print twov%ivla1" " = <not allocated>" \
> -- 
> 2.17.1



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

* RE: [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary
  2020-08-19 13:09     ` Andrew Burgess
@ 2020-08-19 15:25       ` Sharma, Alok Kumar
  0 siblings, 0 replies; 8+ messages in thread
From: Sharma, Alok Kumar @ 2020-08-19 15:25 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Tom Tromey, gdb-patches, George, Jini Susan, Achra, Nitika

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

Thanks Andrew. Please find the updated patch. I shall be committing this.

    gdb/ChangeLog

          * amd64-tdep.c (amd64_skip_prologue): Using symbol table
          to find the end of prologue for flang compiled binaries.
          * arm-tdep.c (arm_skip_prologue): Likewise.
          * i386-tdep.c (i386_skip_prologue): Likewise.
          * producer.c (producer_is_llvm): New function.
          (producer_parsing_tests): Added new tests for clang/flang.
          * producer.h (producer_is_llvm): New declaration.

    gdb/testsuite/ChangeLog

          * gdb.fortran/vla-type.exp: Skip commands not required for
          the Flang compiled binaries after prologue fix.

Regards,
Alok

-----Original Message-----
From: Andrew Burgess <andrew.burgess@embecosm.com> 
Sent: Wednesday, August 19, 2020 6:40 PM
To: Sharma, Alok Kumar <AlokKumar.Sharma@amd.com>
Cc: Tom Tromey <tom@tromey.com>; gdb-patches@sourceware.org; George, Jini Susan <JiniSusan.George@amd.com>; Achra, Nitika <Nitika.Achra@amd.com>
Subject: Re: [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary

[CAUTION: External Email]

* Sharma, Alok Kumar <AlokKumar.Sharma@amd.com> [2020-08-18 12:53:10 +0000]:

> Thanks Tom and Andrew for your comments. Hopefully addressed in the attached updated patch.
>
> Please find my below answers for your queries.
>
> > We have the files producer.{c,h} that wrap up tests just like this one.  If feels like we should add a new test to those files that matches all clang backend based compilers, then make use of this new test throughout.
> > I'd keep the name of the test fairly generic, the important thing here is the backend technology right, not the frontend language?  So if I added a new language with a clang backend I'd likely run into the same issues.
> Thanks for your suggestion. I have updated the patch for same.
>
> > Space before "(".
> Though the code is moved, I have taken care of the comment in general.
>
> > Does it really start with a space?  That seems weird.
> Agreed but it has space at the start.
>
> >> +# break main for Flang compiler already breaks here
> > Do you know why?
> Line number 46 is the place where breakpoint to main is hit for Flang compiled binary and that looks Okey.
> Below is the snippet from gdb.fortran/
> ------------------------------------------
>     16  program vla_struct
>     17    type :: one
>     18      integer, allocatable :: ivla (:, :, :)
>     19    end type one
>     20    type :: two
>     21      integer, allocatable :: ivla1 (:, :, :)
>     22      integer, allocatable :: ivla2 (:, :)
>     23    end type two
>     24    type :: three
>     25      integer :: ivar
>     26      integer, allocatable :: ivla (:)
>     27    end type three
>     28    type :: four
>     29      integer, allocatable :: ivla (:)
>     30      integer :: ivar
>     31    end type four
>     32    type :: five
>     33      type(one) :: tone
>     34    end type five
>     35
>     36    type(one), target        :: onev
>     37    type(two)                :: twov
>     38    type(three)              :: threev
>     39    type(four)               :: fourv
>     40    type(five)               :: fivev
>     41    type(five)               :: fivearr (2)
>     42    type(five), allocatable  :: fivedynarr (:)
>     43    logical                  :: l
>     44    integer                  :: i, j
>     45
>     46    allocate (onev%ivla (11,22,33))         ! before-allocated
>     47    l = allocated(onev%ivla)
>     48
> ------------------------------------------
>
>     gdb/ChangeLog
>
>           * amd64-tdep.c (amd64_skip_prologue): Using symbol table
>           to find the end of prologue for flang compiled binaries.
>           * arm-tdep.c (arm_skip_prologue): Likewise.
>           * i386-tdep.c (i386_skip_prologue): Likewise.
>           * producer.c (producer_is_llvm): New function.
>           (producer_parsing_tests): Added new tests for clang/flang.
>           * producer.h (producer_is_llvm): New declaration.
>
>     gdb/testsuite/ChangeLog
>
>           * gdb.fortran/vla-type.exp: Skip commands not required for
>           the Flang compiled binaries after prologue fix.

This looks good to me with two minor nits fixed.

> diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index 
> 768fe63bdd..59f7c9f885 100644
> --- a/gdb/amd64-tdep.c
> +++ b/gdb/amd64-tdep.c
> @@ -2547,12 +2547,13 @@ amd64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
>         = skip_prologue_using_sal (gdbarch, func_addr);
>        struct compunit_symtab *cust = find_pc_compunit_symtab 
> (func_addr);
>
> -      /* Clang always emits a line note before the prologue and another
> -      one after.  We trust clang to emit usable line notes.  */
> +      /* LLVM backend (Clang/Flang) always emits a line note before the
> +         prologue and another one after.  We trust clang to emit usable
> +         line notes.  */
>        if (post_prologue_pc
>           && (cust != NULL
>               && COMPUNIT_PRODUCER (cust) != NULL
> -           && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
> +           && producer_is_llvm (COMPUNIT_PRODUCER (cust))))
>          return std::max (start_pc, post_prologue_pc);
>      }
>
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 
> 9cedcc8575..074eedb480 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -60,6 +60,8 @@
>  #include "record-full.h"
>  #include <algorithm>
>
> +#include "producer.h"
> +
>  #if GDB_SELF_TEST
>  #include "gdbsupport/selftest.h"
>  #endif
> @@ -1351,7 +1353,7 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
>           && (cust == NULL
>               || COMPUNIT_PRODUCER (cust) == NULL
>               || startswith (COMPUNIT_PRODUCER (cust), "GNU ")
> -           || startswith (COMPUNIT_PRODUCER (cust), "clang ")))
> +           || producer_is_llvm (COMPUNIT_PRODUCER (cust))))
>         return post_prologue_pc;
>
>        if (post_prologue_pc != 0)
> diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 
> 9b905c1996..d9fa2b9264 100644
> --- a/gdb/i386-tdep.c
> +++ b/gdb/i386-tdep.c
> @@ -65,6 +65,7 @@
>  #include <ctype.h>
>  #include <algorithm>
>  #include <unordered_set>
> +#include "producer.h"
>
>  /* Register names.  */
>
> @@ -1847,12 +1848,13 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
>         = skip_prologue_using_sal (gdbarch, func_addr);
>        struct compunit_symtab *cust = find_pc_compunit_symtab 
> (func_addr);
>
> -      /* Clang always emits a line note before the prologue and another
> -      one after.  We trust clang to emit usable line notes.  */
> +      /* LLVM backend (Clang/Flang) always emits a line note before the
> +         prologue and another one after.  We trust clang to emit usable
> +         line notes.  */
>        if (post_prologue_pc
>           && (cust != NULL
>               && COMPUNIT_PRODUCER (cust) != NULL
> -           && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
> +           && producer_is_llvm (COMPUNIT_PRODUCER (cust))))
>          return std::max (start_pc, post_prologue_pc);
>      }
>
> diff --git a/gdb/producer.c b/gdb/producer.c index 
> 735a928f33..fe89e7d536 100644
> --- a/gdb/producer.c
> +++ b/gdb/producer.c
> @@ -125,6 +125,18 @@ producer_is_icc (const char *producer, int *major, int *minor)
>    return false;
>  }
>
> +/* See producer.h.  */
> +
> +bool
> +producer_is_llvm (const char *producer) {
> +  if (producer == NULL || !(startswith (producer, "clang ")
> +                            || startswith (producer, " F90 Flang ")))
> +    return false;
> +
> +  return true;

I'm really not a fan of 'if (condition) return condition' type code, I'd rather see just:

  return !(producer == NULL || !(startswith (producer, "clang ")
                                 || startswith (producer, " F90 Flang ")));

> +}
> +
>  #if defined GDB_SELF_TEST
>  namespace selftests {
>  namespace producer {
> @@ -203,6 +215,22 @@ Version 18.0 Beta";
>      SELF_CHECK (producer_is_gcc (gnu_exp, &major, &minor)
>                 && major == 5 && minor == 0);
>    }
> +
> +  {
> +    static const char clang_llvm_exp[] = "clang version 12.0.0 (CLANG: bld#8)";
> +    int major = 0, minor = 0;
> +    SELF_CHECK (!producer_is_icc (clang_llvm_exp, NULL, NULL));
> +    SELF_CHECK (!producer_is_gcc (clang_llvm_exp, &major, &minor));
> +    SELF_CHECK (producer_is_llvm (clang_llvm_exp));  }
> +
> +  {
> +    static const char flang_llvm_exp[] = " F90 Flang - 1.5 2017-05-01";
> +    int major = 0, minor = 0;
> +    SELF_CHECK (!producer_is_icc (flang_llvm_exp, NULL, NULL));
> +    SELF_CHECK (!producer_is_gcc (flang_llvm_exp, &major, &minor));
> +    SELF_CHECK (producer_is_llvm (flang_llvm_exp));  }
>  }
>  }
>  }
> diff --git a/gdb/producer.h b/gdb/producer.h index 
> d8974d3814..e9bc309b0c 100644
> --- a/gdb/producer.h
> +++ b/gdb/producer.h
> @@ -52,4 +52,8 @@ extern int producer_is_gcc (const char *producer, int *major, int *minor);
>         running on Intel(R) 64, Version 18.0 Beta ....".  */  extern 
> bool producer_is_icc (const char *producer, int *major, int *minor);
>
> +/* Returns true if the given PRODUCER string is LLVM (clang/flang) or
> +   false otherwise.*/

Two whitespace after the final '.' here.

Thanks,
Andrew


> +extern bool producer_is_llvm (const char *producer);
> +
>  #endif
> diff --git a/gdb/testsuite/gdb.fortran/vla-type.exp 
> b/gdb/testsuite/gdb.fortran/vla-type.exp
> index 925c583edc..e2b8d71b4c 100755
> --- a/gdb/testsuite/gdb.fortran/vla-type.exp
> +++ b/gdb/testsuite/gdb.fortran/vla-type.exp
> @@ -33,8 +33,12 @@ set int [fortran_int4]
>
>  # Check if not allocated VLA in type does not break  # the debugger 
> when accessing it.
> -gdb_breakpoint [gdb_get_line_number "before-allocated"] 
> -gdb_continue_to_breakpoint "before-allocated"
> +# break main for Flang compiler already breaks here if 
> +![test_compiler_info "clang-*"] {
> +    gdb_breakpoint [gdb_get_line_number "before-allocated"]
> +    gdb_continue_to_breakpoint "before-allocated"
> +}
> +
>  gdb_test "print twov" " = \\\( ivla1 = <not allocated>, ivla2 = <not allocated> \\\)" \
>    "print twov before allocated"
>  gdb_test "print twov%ivla1" " = <not allocated>" \
> --
> 2.17.1


[-- Attachment #2: 0001-Fix-for-incorrect-breakpoint-set-in-case-of-flang-co.patch --]
[-- Type: application/octet-stream, Size: 8165 bytes --]

From a9be5b9f2322b17a74554828ea37c39c6e544265 Mon Sep 17 00:00:00 2001
From: Alok Kumar Sharma <AlokKumar.Sharma@amd.com>
Date: Mon, 17 Aug 2020 17:04:11 +0530
Subject: [PATCH] Fix for incorrect breakpoint set in case of flang compiled
 binary

  Currently, GDB is not able to set a breakpoint at subprogram post
prologue for flang generated binaries. This is due to clang having
two line notes one before and another after the prologue.
  Now the end of prologue is determined using symbol table, which was
the way for clang generated binaries already. Since clang and flang
both share same back-end it is true for flang as well.

gdb/ChangeLog

      * amd64-tdep.c (amd64_skip_prologue): Using symbol table
      to find the end of prologue for flang compiled binaries.
      * arm-tdep.c (arm_skip_prologue): Likewise.
      * i386-tdep.c (i386_skip_prologue): Likewise.
      * producer.c (producer_is_llvm): New function.
      (producer_parsing_tests): Added new tests for clang/flang.
      * producer.h (producer_is_llvm): New declaration.

gdb/testsuite/ChangeLog

      * gdb.fortran/vla-type.exp: Skip commands not required for
      the Flang compiled binaries after prologue fix.

Change-Id: I5609f979315effc213feeb6dde6a01a024e0c487
---
 gdb/ChangeLog                          | 10 ++++++++++
 gdb/amd64-tdep.c                       |  7 ++++---
 gdb/arm-tdep.c                         |  4 +++-
 gdb/i386-tdep.c                        |  8 +++++---
 gdb/producer.c                         | 25 +++++++++++++++++++++++++
 gdb/producer.h                         |  4 ++++
 gdb/testsuite/ChangeLog                |  5 +++++
 gdb/testsuite/gdb.fortran/vla-type.exp |  8 ++++++--
 8 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index cd950287ec..aee25787b0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2020-08-19  Alok Kumar Sharma  <AlokKumar.Sharma@amd.com>
+
+	* amd64-tdep.c (amd64_skip_prologue): Using symbol table
+	to find the end of prologue for flang compiled binaries.
+	* arm-tdep.c (arm_skip_prologue): Likewise.
+	* i386-tdep.c (i386_skip_prologue): Likewise.
+	* producer.c (producer_is_llvm): New function.
+	(producer_parsing_tests): Added new tests for clang/flang.
+	* producer.h (producer_is_llvm): New declaration.
+
 2020-08-18  Simon Marchi  <simon.marchi@efficios.com>
 
 	* linux-nat.c (linux_nat_debug_printf): New function.
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 768fe63bdd..59f7c9f885 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2547,12 +2547,13 @@ amd64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 	= skip_prologue_using_sal (gdbarch, func_addr);
       struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
 
-      /* Clang always emits a line note before the prologue and another
-	 one after.  We trust clang to emit usable line notes.  */
+      /* LLVM backend (Clang/Flang) always emits a line note before the
+         prologue and another one after.  We trust clang to emit usable
+         line notes.  */
       if (post_prologue_pc
 	  && (cust != NULL
 	      && COMPUNIT_PRODUCER (cust) != NULL
-	      && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
+	      && producer_is_llvm (COMPUNIT_PRODUCER (cust))))
         return std::max (start_pc, post_prologue_pc);
     }
 
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 9cedcc8575..074eedb480 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -60,6 +60,8 @@
 #include "record-full.h"
 #include <algorithm>
 
+#include "producer.h"
+
 #if GDB_SELF_TEST
 #include "gdbsupport/selftest.h"
 #endif
@@ -1351,7 +1353,7 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 	  && (cust == NULL
 	      || COMPUNIT_PRODUCER (cust) == NULL
 	      || startswith (COMPUNIT_PRODUCER (cust), "GNU ")
-	      || startswith (COMPUNIT_PRODUCER (cust), "clang ")))
+	      || producer_is_llvm (COMPUNIT_PRODUCER (cust))))
 	return post_prologue_pc;
 
       if (post_prologue_pc != 0)
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 9b905c1996..d9fa2b9264 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -65,6 +65,7 @@
 #include <ctype.h>
 #include <algorithm>
 #include <unordered_set>
+#include "producer.h"
 
 /* Register names.  */
 
@@ -1847,12 +1848,13 @@ i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 	= skip_prologue_using_sal (gdbarch, func_addr);
       struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
 
-      /* Clang always emits a line note before the prologue and another
-	 one after.  We trust clang to emit usable line notes.  */
+      /* LLVM backend (Clang/Flang) always emits a line note before the
+         prologue and another one after.  We trust clang to emit usable
+         line notes.  */
       if (post_prologue_pc
 	  && (cust != NULL
 	      && COMPUNIT_PRODUCER (cust) != NULL
-	      && startswith (COMPUNIT_PRODUCER (cust), "clang ")))
+	      && producer_is_llvm (COMPUNIT_PRODUCER (cust))))
         return std::max (start_pc, post_prologue_pc);
     }
  
diff --git a/gdb/producer.c b/gdb/producer.c
index 735a928f33..d25d93fcce 100644
--- a/gdb/producer.c
+++ b/gdb/producer.c
@@ -125,6 +125,15 @@ producer_is_icc (const char *producer, int *major, int *minor)
   return false;
 }
 
+/* See producer.h.  */
+
+bool
+producer_is_llvm (const char *producer)
+{
+  return ((producer != NULL) && (startswith (producer, "clang ")
+                                 || startswith (producer, " F90 Flang ")));
+}
+
 #if defined GDB_SELF_TEST
 namespace selftests {
 namespace producer {
@@ -203,6 +212,22 @@ Version 18.0 Beta";
     SELF_CHECK (producer_is_gcc (gnu_exp, &major, &minor)
 		&& major == 5 && minor == 0);
   }
+
+  {
+    static const char clang_llvm_exp[] = "clang version 12.0.0 (CLANG: bld#8)";
+    int major = 0, minor = 0;
+    SELF_CHECK (!producer_is_icc (clang_llvm_exp, NULL, NULL));
+    SELF_CHECK (!producer_is_gcc (clang_llvm_exp, &major, &minor));
+    SELF_CHECK (producer_is_llvm (clang_llvm_exp));
+  }
+
+  {
+    static const char flang_llvm_exp[] = " F90 Flang - 1.5 2017-05-01";
+    int major = 0, minor = 0;
+    SELF_CHECK (!producer_is_icc (flang_llvm_exp, NULL, NULL));
+    SELF_CHECK (!producer_is_gcc (flang_llvm_exp, &major, &minor));
+    SELF_CHECK (producer_is_llvm (flang_llvm_exp));
+  }
 }
 }
 }
diff --git a/gdb/producer.h b/gdb/producer.h
index d8974d3814..e9bc309b0c 100644
--- a/gdb/producer.h
+++ b/gdb/producer.h
@@ -52,4 +52,8 @@ extern int producer_is_gcc (const char *producer, int *major, int *minor);
        running on Intel(R) 64, Version 18.0 Beta ....".  */
 extern bool producer_is_icc (const char *producer, int *major, int *minor);
 
+/* Returns true if the given PRODUCER string is LLVM (clang/flang) or
+   false otherwise.*/
+extern bool producer_is_llvm (const char *producer);
+
 #endif
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 7c624589de..0e4f6a5ce9 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-08-19  Alok Kumar Sharma  <AlokKumar.Sharma@amd.com>
+
+	* gdb.fortran/vla-type.exp: Skip commands not required for
+	the Flang compiled binaries after prologue fix.
+
 2020-08-17  Tom de Vries  <tdevries@suse.de>
 	    Tom Tromey  <tromey@adacore.com>
 
diff --git a/gdb/testsuite/gdb.fortran/vla-type.exp b/gdb/testsuite/gdb.fortran/vla-type.exp
index 925c583edc..e2b8d71b4c 100755
--- a/gdb/testsuite/gdb.fortran/vla-type.exp
+++ b/gdb/testsuite/gdb.fortran/vla-type.exp
@@ -33,8 +33,12 @@ set int [fortran_int4]
 
 # Check if not allocated VLA in type does not break
 # the debugger when accessing it.
-gdb_breakpoint [gdb_get_line_number "before-allocated"]
-gdb_continue_to_breakpoint "before-allocated"
+# break main for Flang compiler already breaks here
+if ![test_compiler_info "clang-*"] {
+    gdb_breakpoint [gdb_get_line_number "before-allocated"]
+    gdb_continue_to_breakpoint "before-allocated"
+}
+
 gdb_test "print twov" " = \\\( ivla1 = <not allocated>, ivla2 = <not allocated> \\\)" \
   "print twov before allocated"
 gdb_test "print twov%ivla1" " = <not allocated>" \
-- 
2.17.1


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

end of thread, other threads:[~2020-08-19 15:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-17 15:17 [PATCH] Fix for incorrect breakpoint set in case of flang compiled binary Sharma, Alok Kumar
2020-08-17 20:51 ` Tom Tromey
2020-08-19 13:05   ` Andrew Burgess
2020-08-18 10:29 ` Andrew Burgess
2020-08-18 12:53   ` Sharma, Alok Kumar
2020-08-19 13:09     ` Andrew Burgess
2020-08-19 15:25       ` Sharma, Alok Kumar
2020-08-18 19:21   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox