Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <yao@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Fix gdb.dwarf2/dwz.exp for thumb mode
Date: Sun, 14 Sep 2014 09:35:00 -0000	[thread overview]
Message-ID: <87k356lfa8.fsf@codesourcery.com> (raw)
In-Reply-To: <1409706936-11220-1-git-send-email-yao@codesourcery.com> (Yao	Qi's message of "Wed, 3 Sep 2014 09:15:36 +0800")

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;
 }


  parent reply	other threads:[~2014-09-14  9:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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-09-14 11:31 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k356lfa8.fsf@codesourcery.com \
    --to=yao@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox