public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
@ 2014-09-14 11:31 Andreas Schwab
  2014-09-14 14:37 ` Yao Qi
  0 siblings, 1 reply; 14+ messages in thread
From: Andreas Schwab @ 2014-09-14 11:31 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

Yao Qi <yao@codesourcery.com> writes:

> @@ -59,9 +60,17 @@ gdb_test_multiple $test $test {
>      }
>  }
>  
> -if { $main_length == "" } {
> +set main_label_offset ""
> +set test "p main_label"
> +gdb_test_multiple $test $test {
> +    -re ".* = {.*} $hex <main\\+($decimal)>.*\r\n$gdb_prompt $" {
> +	set main_label_offset $expect_out(1,string)
> +    }
> +}

This will also fail to match if assembler labels are prefixed.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
  2014-09-14 11:31 [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode Andreas Schwab
@ 2014-09-14 14:37 ` Yao Qi
  2014-09-14 15:24   ` Andreas Schwab
  0 siblings, 1 reply; 14+ messages in thread
From: Yao Qi @ 2014-09-14 14:37 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: gdb-patches

Andreas Schwab <schwab@linux-m68k.org> writes:

>> -if { $main_length == "" } {
>> +set main_label_offset ""
>> +set test "p main_label"
>> +gdb_test_multiple $test $test {
>> +    -re ".* = {.*} $hex <main\\+($decimal)>.*\r\n$gdb_prompt $" {
>> +	set main_label_offset $expect_out(1,string)
>> +    }
>> +}
>
> This will also fail to match if assembler labels are prefixed.

If you meant 'main' could be prefixed to '_main' for example, then GDB
can get rid of the prefix on display.  On mingw target, function 'foo'
is prefixed to '_foo', but GDB still shows 'foo' rather than '_foo'.

$ i686-w64-mingw32-objdump -t 2.exe | grep foo
[ 64](sec  1)(fl 0x00)(ty  20)(scl   3) (nx 1) 0x00000560 _foo

Dump of assembler code from 0x401560 to 0x401565:
   0x00401560 <foo+0>:  push   %ebp
   0x00401561 <foo+1>:  mov    %esp,%ebp
-- 
Yao (齐尧)

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

* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
  2014-09-14 14:37 ` Yao Qi
@ 2014-09-14 15:24   ` Andreas Schwab
  2014-09-15  2:09     ` Yao Qi
  0 siblings, 1 reply; 14+ messages in thread
From: Andreas Schwab @ 2014-09-14 15:24 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

Yao Qi <yao@codesourcery.com> writes:

> Andreas Schwab <schwab@linux-m68k.org> writes:
>
>>> -if { $main_length == "" } {
>>> +set main_label_offset ""
>>> +set test "p main_label"
>>> +gdb_test_multiple $test $test {
>>> +    -re ".* = {.*} $hex <main\\+($decimal)>.*\r\n$gdb_prompt $" {
>>> +	set main_label_offset $expect_out(1,string)
>>> +    }
>>> +}
>>
>> This will also fail to match if assembler labels are prefixed.
>
> If you meant 'main' could be prefixed to '_main' for example, then GDB
> can get rid of the prefix on display.  On mingw target, function 'foo'
> is prefixed to '_foo', but GDB still shows 'foo' rather than '_foo'.

(gdb) p main_label 
$1 = {<text variable, no debug info>} 0x100004e0 <.main+12>

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
  2014-09-14 15:24   ` Andreas Schwab
@ 2014-09-15  2:09     ` Yao Qi
  2014-09-15  8:57       ` Andreas Schwab
  0 siblings, 1 reply; 14+ messages in thread
From: Yao Qi @ 2014-09-15  2:09 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: gdb-patches

Andreas Schwab <schwab@linux-m68k.org> writes:

> (gdb) p main_label 
> $1 = {<text variable, no debug info>} 0x100004e0 <.main+12>

How about getting the offset by 'p main_label - main'?  It also fixes the
zero-offset problem you pointed out in another mail.

-- 
Yao (齐尧)

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

* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
  2014-09-15  2:09     ` Yao Qi
@ 2014-09-15  8:57       ` Andreas Schwab
  0 siblings, 0 replies; 14+ messages in thread
From: Andreas Schwab @ 2014-09-15  8:57 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

Yao Qi <yao@codesourcery.com> writes:

> Andreas Schwab <schwab@linux-m68k.org> writes:
>
>> (gdb) p main_label 
>> $1 = {<text variable, no debug info>} 0x100004e0 <.main+12>
>
> How about getting the offset by 'p main_label - main'?  It also fixes the
> zero-offset problem you pointed out in another mail.

That would work.

(gdb) p main_label - main
$1 = 12

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
  2014-09-15 12:29   ` Yao Qi
  2014-09-22 13:52     ` Yao Qi
@ 2014-10-08 15:21     ` Doug Evans
  1 sibling, 0 replies; 14+ messages in thread
From: Doug Evans @ 2014-10-08 15:21 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On Mon, Sep 15, 2014 at 8:25 AM, Yao Qi <yao@codesourcery.com> wrote:
> Yao Qi <yao@codesourcery.com> writes:
>
>> -if { $main_length == "" } {
>> +set main_label_offset ""
>> +set test "p main_label"
>> +gdb_test_multiple $test $test {
>> +    -re ".* = {.*} $hex <main\\+($decimal)>.*\r\n$gdb_prompt $" {
>> +     set main_label_offset $expect_out(1,string)
>> +    }
>> +}
>
> Here is the V3 of this patch, to address Andreas's comments about
> getting the offset of main_label to main.
>
> --
> Yao (齐尧)
> From: Yao Qi <yao@codesourcery.com>
> Date: Sat, 13 Sep 2014 14:51:04 +0800
> Subject: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
>
> We see the fail in gdb.dwarf2/dwz.exp in thumb mode,
>
> p the_int^M
> $2 = 99^M
> (gdb) FAIL: gdb.dwarf2/dwz.exp: p the_int
>
> In thumb mode, the lsb of references to 'main' in the assembly
> (produced by dwarf assember) is set, so the generated debug
> information is incorrect.
>
> in this patch, we add a label main_label inside function main.  Linker
> doesn't set its lsb in thumb mode, and we can get function main's
> address by 'main_label - $main_label_offset'.  This label isn't moved
> out of function main in both gcc and clang.
>
> gdb/testsuite:
>
> 2014-09-15  Yao Qi  <yao@codesourcery.com>
>
>         * gdb.dwarf2/main.c (main): New lable main_label.

Typo: label

>         * gdb.dwarf2/dwz.exp: Get the offset of main_label to main.
>         Return early if $main_label_offset is unknown.  Get address
>         of main by "main_label - $main_label_offset".
>
> diff --git a/gdb/testsuite/gdb.dwarf2/dwz.exp b/gdb/testsuite/gdb.dwarf2/dwz.exp
> index 9175f9e..3cf4e4f 100644
> --- a/gdb/testsuite/gdb.dwarf2/dwz.exp
> +++ b/gdb/testsuite/gdb.dwarf2/dwz.exp
> @@ -27,8 +27,9 @@ if  {[gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
>      return -1
>  }
>
> -# Start GDB and load object file, compute the function length which is
> -# needed in the Dwarf Assembler below.
> +# Start GDB and load object file, compute the function length and the
> +# offset from main to main_label which are needed in the Dwarf Assembler
> +# below.
>  clean_restart ${testfile}1.o
>
>  set main_length ""
> @@ -59,9 +60,17 @@ gdb_test_multiple $test $test {
>      }
>  }
>
> -if { $main_length == "" } {
> +set main_label_offset ""
> +set test "p main_label - main"
> +gdb_test_multiple $test $test {
> +    -re ".* = ($decimal)\r\n$gdb_prompt $" {
> +       set main_label_offset $expect_out(1,string)
> +    }
> +}
> +
> +if { $main_length == "" || $main_label_offset == "" } {
>      # Bail out here, because we can't do the following tests if
> -    # $main_length is unknown.
> +    # $main_length or $main_label_offset is unknown.
>      return -1
>  }
>
> @@ -71,7 +80,7 @@ gdb_exit
>  set asm_file [standard_output_file $srcfile2]
>  Dwarf::assemble $asm_file {
>      declare_labels partial_label int_label int_label2
> -    global main_length
> +    global main_length main_label_offset
>
>      extern main
>
> @@ -79,8 +88,8 @@ Dwarf::assemble $asm_file {
>         partial_label: partial_unit {} {
>             subprogram {
>                 {name main}
> -               {low_pc main addr}
> -               {high_pc "main + $main_length" addr}
> +               {low_pc "main_label - $main_label_offset" addr}
> +               {high_pc "main_label - $main_label_offset + $main_length" addr}
>             }
>         }
>      }
> diff --git a/gdb/testsuite/gdb.dwarf2/main.c b/gdb/testsuite/gdb.dwarf2/main.c
> index 3ddd194..e6d4715 100644
> --- a/gdb/testsuite/gdb.dwarf2/main.c
> +++ b/gdb/testsuite/gdb.dwarf2/main.c
> @@ -20,5 +20,6 @@
>  int
>  main()
>  {
> +  asm ("main_label: .globl main_label");
>    return 0;
>  }

Hi.
I'd like to see comments in the code explaining why main_label exists
(thumb) and why we can't put labels outside the function (clang).

I shouldn't have to grind through commit logs or emails to answer
these questions.

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

* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
  2014-09-30 14:04       ` Yao Qi
@ 2014-10-07 14:03         ` Yao Qi
  0 siblings, 0 replies; 14+ messages in thread
From: Yao Qi @ 2014-10-07 14:03 UTC (permalink / raw)
  To: gdb-patches

Yao Qi <yao@codesourcery.com> writes:

> On 09/22/2014 09:47 PM, Yao Qi wrote:
>> On 09/15/2014 08:25 PM, Yao Qi wrote:
>>> Subject: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
>>>
>>> We see the fail in gdb.dwarf2/dwz.exp in thumb mode,
>>>
>>> p the_int^M
>>> $2 = 99^M
>>> (gdb) FAIL: gdb.dwarf2/dwz.exp: p the_int
>>>
>>> In thumb mode, the lsb of references to 'main' in the assembly
>>> (produced by dwarf assember) is set, so the generated debug
>>> information is incorrect.
>>>
>>> in this patch, we add a label main_label inside function main.  Linker
>>> doesn't set its lsb in thumb mode, and we can get function main's
>>> address by 'main_label - $main_label_offset'.  This label isn't moved
>>> out of function main in both gcc and clang.
>>>
>>> gdb/testsuite:
>>>
>>> 2014-09-15  Yao Qi  <yao@codesourcery.com>
>>>
>>> 	* gdb.dwarf2/main.c (main): New lable main_label.
>>> 	* gdb.dwarf2/dwz.exp: Get the offset of main_label to main.
>>> 	Return early if $main_label_offset is unknown.  Get address
>>> 	of main by "main_label - $main_label_offset".
>> 
>> Ping.  https://sourceware.org/ml/gdb-patches/2014-09/msg00497.html
>> 
>
> Ping.

Ping.

-- 
Yao (齐尧)

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

* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
  2014-09-22 13:52     ` Yao Qi
@ 2014-09-30 14:04       ` Yao Qi
  2014-10-07 14:03         ` Yao Qi
  0 siblings, 1 reply; 14+ messages in thread
From: Yao Qi @ 2014-09-30 14:04 UTC (permalink / raw)
  To: gdb-patches

On 09/22/2014 09:47 PM, Yao Qi wrote:
> On 09/15/2014 08:25 PM, Yao Qi wrote:
>> Subject: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
>>
>> We see the fail in gdb.dwarf2/dwz.exp in thumb mode,
>>
>> p the_int^M
>> $2 = 99^M
>> (gdb) FAIL: gdb.dwarf2/dwz.exp: p the_int
>>
>> In thumb mode, the lsb of references to 'main' in the assembly
>> (produced by dwarf assember) is set, so the generated debug
>> information is incorrect.
>>
>> in this patch, we add a label main_label inside function main.  Linker
>> doesn't set its lsb in thumb mode, and we can get function main's
>> address by 'main_label - $main_label_offset'.  This label isn't moved
>> out of function main in both gcc and clang.
>>
>> gdb/testsuite:
>>
>> 2014-09-15  Yao Qi  <yao@codesourcery.com>
>>
>> 	* gdb.dwarf2/main.c (main): New lable main_label.
>> 	* gdb.dwarf2/dwz.exp: Get the offset of main_label to main.
>> 	Return early if $main_label_offset is unknown.  Get address
>> 	of main by "main_label - $main_label_offset".
> 
> Ping.  https://sourceware.org/ml/gdb-patches/2014-09/msg00497.html
> 

Ping.

-- 
Yao (齐尧)

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

* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
  2014-09-15 12:29   ` Yao Qi
@ 2014-09-22 13:52     ` Yao Qi
  2014-09-30 14:04       ` Yao Qi
  2014-10-08 15:21     ` Doug Evans
  1 sibling, 1 reply; 14+ messages in thread
From: Yao Qi @ 2014-09-22 13:52 UTC (permalink / raw)
  To: gdb-patches

On 09/15/2014 08:25 PM, Yao Qi wrote:
> Subject: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
> 
> We see the fail in gdb.dwarf2/dwz.exp in thumb mode,
> 
> p the_int^M
> $2 = 99^M
> (gdb) FAIL: gdb.dwarf2/dwz.exp: p the_int
> 
> In thumb mode, the lsb of references to 'main' in the assembly
> (produced by dwarf assember) is set, so the generated debug
> information is incorrect.
> 
> in this patch, we add a label main_label inside function main.  Linker
> doesn't set its lsb in thumb mode, and we can get function main's
> address by 'main_label - $main_label_offset'.  This label isn't moved
> out of function main in both gcc and clang.
> 
> gdb/testsuite:
> 
> 2014-09-15  Yao Qi  <yao@codesourcery.com>
> 
> 	* gdb.dwarf2/main.c (main): New lable main_label.
> 	* gdb.dwarf2/dwz.exp: Get the offset of main_label to main.
> 	Return early if $main_label_offset is unknown.  Get address
> 	of main by "main_label - $main_label_offset".

Ping.  https://sourceware.org/ml/gdb-patches/2014-09/msg00497.html

-- 
Yao (齐尧)

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

* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
  2014-09-14  9:35 ` Yao Qi
@ 2014-09-15 12:29   ` Yao Qi
  2014-09-22 13:52     ` Yao Qi
  2014-10-08 15:21     ` Doug Evans
  0 siblings, 2 replies; 14+ messages in thread
From: Yao Qi @ 2014-09-15 12:29 UTC (permalink / raw)
  To: gdb-patches

Yao Qi <yao@codesourcery.com> writes:

> -if { $main_length == "" } {
> +set main_label_offset ""
> +set test "p main_label"
> +gdb_test_multiple $test $test {
> +    -re ".* = {.*} $hex <main\\+($decimal)>.*\r\n$gdb_prompt $" {
> +	set main_label_offset $expect_out(1,string)
> +    }
> +}

Here is the V3 of this patch, to address Andreas's comments about
getting the offset of main_label to main.

-- 
Yao (齐尧)
From: Yao Qi <yao@codesourcery.com>
Date: Sat, 13 Sep 2014 14:51:04 +0800
Subject: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode

We see the fail in gdb.dwarf2/dwz.exp in thumb mode,

p the_int^M
$2 = 99^M
(gdb) FAIL: gdb.dwarf2/dwz.exp: p the_int

In thumb mode, the lsb of references to 'main' in the assembly
(produced by dwarf assember) is set, so the generated debug
information is incorrect.

in this patch, we add a label main_label inside function main.  Linker
doesn't set its lsb in thumb mode, and we can get function main's
address by 'main_label - $main_label_offset'.  This label isn't moved
out of function main in both gcc and clang.

gdb/testsuite:

2014-09-15  Yao Qi  <yao@codesourcery.com>

	* gdb.dwarf2/main.c (main): New lable main_label.
	* gdb.dwarf2/dwz.exp: Get the offset of main_label to main.
	Return early if $main_label_offset is unknown.  Get address
	of main by "main_label - $main_label_offset".

diff --git a/gdb/testsuite/gdb.dwarf2/dwz.exp b/gdb/testsuite/gdb.dwarf2/dwz.exp
index 9175f9e..3cf4e4f 100644
--- a/gdb/testsuite/gdb.dwarf2/dwz.exp
+++ b/gdb/testsuite/gdb.dwarf2/dwz.exp
@@ -27,8 +27,9 @@ if  {[gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
     return -1
 }
 
-# Start GDB and load object file, compute the function length which is
-# needed in the Dwarf Assembler below.
+# Start GDB and load object file, compute the function length and the
+# offset from main to main_label which are needed in the Dwarf Assembler
+# below.
 clean_restart ${testfile}1.o
 
 set main_length ""
@@ -59,9 +60,17 @@ gdb_test_multiple $test $test {
     }
 }
 
-if { $main_length == "" } {
+set main_label_offset ""
+set test "p main_label - main"
+gdb_test_multiple $test $test {
+    -re ".* = ($decimal)\r\n$gdb_prompt $" {
+	set main_label_offset $expect_out(1,string)
+    }
+}
+
+if { $main_length == "" || $main_label_offset == "" } {
     # Bail out here, because we can't do the following tests if
-    # $main_length is unknown.
+    # $main_length or $main_label_offset is unknown.
     return -1
 }
 
@@ -71,7 +80,7 @@ gdb_exit
 set asm_file [standard_output_file $srcfile2]
 Dwarf::assemble $asm_file {
     declare_labels partial_label int_label int_label2
-    global main_length
+    global main_length main_label_offset
 
     extern main
 
@@ -79,8 +88,8 @@ Dwarf::assemble $asm_file {
 	partial_label: partial_unit {} {
 	    subprogram {
 		{name main}
-		{low_pc main addr}
-		{high_pc "main + $main_length" addr}
+		{low_pc "main_label - $main_label_offset" addr}
+		{high_pc "main_label - $main_label_offset + $main_length" addr}
 	    }
 	}
     }
diff --git a/gdb/testsuite/gdb.dwarf2/main.c b/gdb/testsuite/gdb.dwarf2/main.c
index 3ddd194..e6d4715 100644
--- a/gdb/testsuite/gdb.dwarf2/main.c
+++ b/gdb/testsuite/gdb.dwarf2/main.c
@@ -20,5 +20,6 @@
 int
 main()
 {
+  asm ("main_label: .globl main_label");
   return 0;
 }

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

* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
  2014-09-03  1:23 Yao Qi
  2014-09-03 17:51 ` Doug Evans
@ 2014-09-14  9:35 ` Yao Qi
  2014-09-15 12:29   ` Yao Qi
  1 sibling, 1 reply; 14+ messages in thread
From: Yao Qi @ 2014-09-14  9:35 UTC (permalink / raw)
  To: gdb-patches

Yao Qi <yao@codesourcery.com> writes:

> +asm (".section	\".text\"");
> +asm (".balign 8");
> +asm ("main_start: .globl main_start");
> +
>  int
>  main()

Doug expressed the concern that this approach is fragile to clang,
because clang will move the label after function main.  After some
experiments, I find a reliable approach: define a label main_label
inside function main, so neither gcc or clang moves it out of
function.  We can get the address of main by main_label minus the offset
of main_label to main.

In this updated patch, we compile main.c to object, and gets
main_label's offset to main.  Then, we can produce the correct address
of main in the debug information.

-- 
Yao (齐尧)

From: Yao Qi <yao@codesourcery.com>
Subject: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode

We see the fail in gdb.dwarf2/dwz.exp in thumb mode,

p the_int^M
$2 = 99^M
(gdb) FAIL: gdb.dwarf2/dwz.exp: p the_int

In thumb mode, the lsb of references to 'main' in the assembly
(produced by dwarf assember) is set, so the generated debug
information is incorrect.

in this patch, we add a label main_label inside function main.  Linker
doesn't set its lsb in thumb mode, and we can get function main's
address by 'main_label - $main_label_offset'.  This label isn't moved
out of function main in both gcc and clang.

gdb/testsuite:

2014-09-13  Yao Qi  <yao@codesourcery.com>

	* gdb.dwarf2/main.c (main): New lable main_label.
	* gdb.dwarf2/dwz.exp: Get the offset of main_label to main.
	Return early if $main_label_offset is unknown.  Get address
	of main by "main_label - $main_label_offset".

diff --git a/gdb/testsuite/gdb.dwarf2/dwz.exp b/gdb/testsuite/gdb.dwarf2/dwz.exp
index 9175f9e..229f512 100644
--- a/gdb/testsuite/gdb.dwarf2/dwz.exp
+++ b/gdb/testsuite/gdb.dwarf2/dwz.exp
@@ -27,8 +27,9 @@ if  {[gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
     return -1
 }
 
-# Start GDB and load object file, compute the function length which is
-# needed in the Dwarf Assembler below.
+# Start GDB and load object file, compute the function length and the
+# offset from main to main_label which are needed in the Dwarf Assembler
+# below.
 clean_restart ${testfile}1.o
 
 set main_length ""
@@ -59,9 +60,17 @@ gdb_test_multiple $test $test {
     }
 }
 
-if { $main_length == "" } {
+set main_label_offset ""
+set test "p main_label"
+gdb_test_multiple $test $test {
+    -re ".* = {.*} $hex <main\\+($decimal)>.*\r\n$gdb_prompt $" {
+	set main_label_offset $expect_out(1,string)
+    }
+}
+
+if { $main_length == "" || $main_label_offset == "" } {
     # Bail out here, because we can't do the following tests if
-    # $main_length is unknown.
+    # $main_length or $main_label_offset is unknown.
     return -1
 }
 
@@ -71,7 +80,7 @@ gdb_exit
 set asm_file [standard_output_file $srcfile2]
 Dwarf::assemble $asm_file {
     declare_labels partial_label int_label int_label2
-    global main_length
+    global main_length main_label_offset
 
     extern main
 
@@ -79,8 +88,8 @@ Dwarf::assemble $asm_file {
 	partial_label: partial_unit {} {
 	    subprogram {
 		{name main}
-		{low_pc main addr}
-		{high_pc "main + $main_length" addr}
+		{low_pc "main_label - $main_label_offset" addr}
+		{high_pc "main_label - $main_label_offset + $main_length" addr}
 	    }
 	}
     }
diff --git a/gdb/testsuite/gdb.dwarf2/main.c b/gdb/testsuite/gdb.dwarf2/main.c
index 3ddd194..e6d4715 100644
--- a/gdb/testsuite/gdb.dwarf2/main.c
+++ b/gdb/testsuite/gdb.dwarf2/main.c
@@ -20,5 +20,6 @@
 int
 main()
 {
+  asm ("main_label: .globl main_label");
   return 0;
 }

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

* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
  2014-09-03 17:51 ` Doug Evans
@ 2014-09-05 11:08   ` Yao Qi
  0 siblings, 0 replies; 14+ messages in thread
From: Yao Qi @ 2014-09-05 11:08 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

Doug Evans <dje@google.com> writes:

> This approach is fragile w.r.t. clang.
> IIUC, Clang makes no guarantees about the ordering of global asms and
> other objects, or even other objects w.r.t. each other (even at -O0).

Doug, how about compile main.c to execution first, get the address of
main, write this address down to dwz.S, and recompile main.c with dwz.S
again.  I assume that debug information changes doesn't affect the
location of .text section and main's address.

-- 
Yao (齐尧)

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

* Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
  2014-09-03  1:23 Yao Qi
@ 2014-09-03 17:51 ` Doug Evans
  2014-09-05 11:08   ` Yao Qi
  2014-09-14  9:35 ` Yao Qi
  1 sibling, 1 reply; 14+ messages in thread
From: Doug Evans @ 2014-09-03 17:51 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On Tue, Sep 2, 2014 at 6:15 PM, Yao Qi <yao@codesourcery.com> wrote:
> Hi,
> We see the fail in gdb.dwarf2/dwz.exp in thumb mode,
>
> p the_int^M
> $2 = 99^M
> (gdb) FAIL: gdb.dwarf2/dwz.exp: p the_int
>
> In thumb mode, the lsb of references to 'main' in the assembly
> (produced by dwarf assember) is set, so the generated debug
> information is incorrect.
>
> This patch copies the approach from
>
>   [PATCH 4/4] Fix gdb.trace/entry-values.exp for thumb mode
>   https://sourceware.org/ml/gdb-patches/2014-07/msg00041.html
>
> introduce new label 'main_start' which is the correct
> function address (without lsb set).  This patch fixes these
> fails we've seen.
>
> Regression tested on arm-none-eabi and x86_64-linux.
>
> gdb/testsuite:
>
> 2014-09-03  Yao Qi  <yao@codesourcery.com>
>
>         * gdb.dwarf2/dwz.exp: Use main_start instead of main.
>         * gdb.dwarf2/main.c: Define label 'main_start' at the beginning
>         function 'main'.
> ---
>  gdb/testsuite/gdb.dwarf2/dwz.exp | 4 ++--
>  gdb/testsuite/gdb.dwarf2/main.c  | 4 ++++
>  2 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/gdb/testsuite/gdb.dwarf2/dwz.exp b/gdb/testsuite/gdb.dwarf2/dwz.exp
> index 9175f9e..ef19631 100644
> --- a/gdb/testsuite/gdb.dwarf2/dwz.exp
> +++ b/gdb/testsuite/gdb.dwarf2/dwz.exp
> @@ -79,8 +79,8 @@ Dwarf::assemble $asm_file {
>         partial_label: partial_unit {} {
>             subprogram {
>                 {name main}
> -               {low_pc main addr}
> -               {high_pc "main + $main_length" addr}
> +               {low_pc main_start addr}
> +               {high_pc "main_start + $main_length" addr}
>             }
>         }
>      }
> diff --git a/gdb/testsuite/gdb.dwarf2/main.c b/gdb/testsuite/gdb.dwarf2/main.c
> index 3ddd194..5a4cbc3 100644
> --- a/gdb/testsuite/gdb.dwarf2/main.c
> +++ b/gdb/testsuite/gdb.dwarf2/main.c
> @@ -17,6 +17,10 @@
>
>  /* Dummy main function.  */
>
> +asm (".section \".text\"");
> +asm (".balign 8");
> +asm ("main_start: .globl main_start");
> +
>  int
>  main()
>  {

This approach is fragile w.r.t. clang.
IIUC, Clang makes no guarantees about the ordering of global asms and
other objects, or even other objects w.r.t. each other (even at -O0).

The email you refer to above refers to another email,
https://sourceware.org/ml/gdb-patches/2014-03/msg00202.html
and that email does a similar thing to fix dw2-ifort-parameter.exp
(not for thumb, but for similar reasons).

dw2-ifort-parameter.exp currently fails with clang on amd64-linux because
func gets moved after main, but the asms that wrap func stay put.

Loosely speaking,

asm ("func_start:");
void func () {}
asm ("func_end:");
int main () { return 0; }

gets emitted as:

asm ("func_start:");
asm ("func_end:");
int main () { return 0; }
void func () {}

I don't have a solution yet, I'm just giving a "heads up".

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

* [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
@ 2014-09-03  1:23 Yao Qi
  2014-09-03 17:51 ` Doug Evans
  2014-09-14  9:35 ` Yao Qi
  0 siblings, 2 replies; 14+ messages in thread
From: Yao Qi @ 2014-09-03  1:23 UTC (permalink / raw)
  To: gdb-patches

Hi,
We see the fail in gdb.dwarf2/dwz.exp in thumb mode,

p the_int^M
$2 = 99^M
(gdb) FAIL: gdb.dwarf2/dwz.exp: p the_int

In thumb mode, the lsb of references to 'main' in the assembly
(produced by dwarf assember) is set, so the generated debug
information is incorrect.

This patch copies the approach from

  [PATCH 4/4] Fix gdb.trace/entry-values.exp for thumb mode
  https://sourceware.org/ml/gdb-patches/2014-07/msg00041.html

introduce new label 'main_start' which is the correct
function address (without lsb set).  This patch fixes these
fails we've seen.

Regression tested on arm-none-eabi and x86_64-linux.

gdb/testsuite:

2014-09-03  Yao Qi  <yao@codesourcery.com>

	* gdb.dwarf2/dwz.exp: Use main_start instead of main.
	* gdb.dwarf2/main.c: Define label 'main_start' at the beginning
	function 'main'.
---
 gdb/testsuite/gdb.dwarf2/dwz.exp | 4 ++--
 gdb/testsuite/gdb.dwarf2/main.c  | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.dwarf2/dwz.exp b/gdb/testsuite/gdb.dwarf2/dwz.exp
index 9175f9e..ef19631 100644
--- a/gdb/testsuite/gdb.dwarf2/dwz.exp
+++ b/gdb/testsuite/gdb.dwarf2/dwz.exp
@@ -79,8 +79,8 @@ Dwarf::assemble $asm_file {
 	partial_label: partial_unit {} {
 	    subprogram {
 		{name main}
-		{low_pc main addr}
-		{high_pc "main + $main_length" addr}
+		{low_pc main_start addr}
+		{high_pc "main_start + $main_length" addr}
 	    }
 	}
     }
diff --git a/gdb/testsuite/gdb.dwarf2/main.c b/gdb/testsuite/gdb.dwarf2/main.c
index 3ddd194..5a4cbc3 100644
--- a/gdb/testsuite/gdb.dwarf2/main.c
+++ b/gdb/testsuite/gdb.dwarf2/main.c
@@ -17,6 +17,10 @@
 
 /* Dummy main function.  */
 
+asm (".section	\".text\"");
+asm (".balign 8");
+asm ("main_start: .globl main_start");
+
 int
 main()
 {
-- 
1.9.3

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

end of thread, other threads:[~2014-10-08 15:21 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-14 11:31 [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode Andreas Schwab
2014-09-14 14:37 ` Yao Qi
2014-09-14 15:24   ` Andreas Schwab
2014-09-15  2:09     ` Yao Qi
2014-09-15  8:57       ` Andreas Schwab
  -- strict thread matches above, loose matches on Subject: below --
2014-09-03  1:23 Yao Qi
2014-09-03 17:51 ` Doug Evans
2014-09-05 11:08   ` Yao Qi
2014-09-14  9:35 ` Yao Qi
2014-09-15 12:29   ` Yao Qi
2014-09-22 13:52     ` Yao Qi
2014-09-30 14:04       ` Yao Qi
2014-10-07 14:03         ` Yao Qi
2014-10-08 15:21     ` Doug Evans

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