Fix gdb.dwarf2/dwz.exp for thumb mode
Commit Message
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.
Comments
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
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 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.
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.
@@ -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}
}
}
}
@@ -20,5 +20,6 @@
int
main()
{
+ asm ("main_label: .globl main_label");
return 0;
}