public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug breakpoints/26546] New: [pie] Setting breakpoint on missing label sets breakpoint at offset 0 in NULL section
@ 2020-08-28 10:27 vries at gcc dot gnu.org
  2020-08-28 11:33 ` [Bug breakpoints/26546] " vries at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2020-08-28 10:27 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 26546
           Summary: [pie] Setting breakpoint on missing label sets
                    breakpoint at offset 0 in NULL section
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: breakpoints
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Say we modify test-case label-without-address.exp like this:
...
diff --git a/gdb/testsuite/gdb.base/label-without-address.exp b/gdb/testsuite/g
db.base/label-without-address.exp
index 0fcb1fd19a..2f05099f3a 100644
--- a/gdb/testsuite/gdb.base/label-without-address.exp
+++ b/gdb/testsuite/gdb.base/label-without-address.exp
@@ -19,6 +19,15 @@ if {[prepare_for_testing "failed to prepare" $testfile 
$srcfile debug]} {
     return -1
 }

+gdb_test "p main"
+
+if ![runto_main] then {
+    fail "can't run to main"
+    return 0
+}
+
+gdb_test "p main"
+
 set supported 0
 gdb_test_multiple "l main:L1" "" {
     -wrap -re "No label \"L1\" defined in function \"main\"\." {
...
and run with target_board unix/-fPIE/-pie, we get:
...
(gdb) break main:L1^M
Breakpoint 2 at 0x555555554000: file label-without-address.c, line 22.^M
...

Looking at the addresses of main before:
(gdb) p main^M
$1 = {int (void)} 0x63a <main>^M
...
and after relocation:
...
(gdb) p main^M
$2 = {int (void)} 0x55555555463a <main>^M
...
it becomes obvious that 0x55555555463a - 0x63a == 0x555555554000 is the
relocation base, so we're setting a breakpoint at offset 0, in the NULL
section:
...
$ readelf -S outputs/gdb.base/label-without-address/label-without-address       
There are 37 section headers, starting at offset 0x2948:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
...

Indeed, the label has no address:
...
 <2><115>: Abbrev Number: 3 (DW_TAG_label)
    <116>   DW_AT_name        : L1
    <119>   DW_AT_decl_file   : 1
    <11a>   DW_AT_decl_line   : 22
 <2><11b>: Abbrev Number: 0
...
and the line number doesn't match anything:
...
CU:
/home/vries/gdb_versions/devel/src/gdb/testsuite/gdb.base/label-without-address.c:
File name                            Line number    Starting address    View   
Stmt
label-without-address.c                       20               0x63a           
   x
label-without-address.c                       21               0x63e           
   x
label-without-address.c                       24               0x643           
   x
label-without-address.c                        -               0x645
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug breakpoints/26546] [pie] Setting breakpoint on missing label sets breakpoint at offset 0 in NULL section
  2020-08-28 10:27 [Bug breakpoints/26546] New: [pie] Setting breakpoint on missing label sets breakpoint at offset 0 in NULL section vries at gcc dot gnu.org
@ 2020-08-28 11:33 ` vries at gcc dot gnu.org
  2020-09-03 10:30 ` cvs-commit at gcc dot gnu.org
  2020-09-03 10:31 ` vries at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2020-08-28 11:33 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
Tentative patch:
...
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 0ac8533263..b37f7e7a2f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -21447,10 +21447,12 @@ new_symbol (struct die_info *die, struct type *t
ype, struct dwarf2_cu *cu,
              addr = attr->value_as_address ();
              addr = gdbarch_adjust_dwarf2_addr (gdbarch, addr + baseaddr);
              SET_SYMBOL_VALUE_ADDRESS (sym, addr);
+             SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL;
            }
+         else
+           SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
          SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
          SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
-         SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL;
          add_symbol_to_list (sym, cu->list_in_scope);
          break;
        case DW_TAG_subprogram:
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug breakpoints/26546] [pie] Setting breakpoint on missing label sets breakpoint at offset 0 in NULL section
  2020-08-28 10:27 [Bug breakpoints/26546] New: [pie] Setting breakpoint on missing label sets breakpoint at offset 0 in NULL section vries at gcc dot gnu.org
  2020-08-28 11:33 ` [Bug breakpoints/26546] " vries at gcc dot gnu.org
@ 2020-09-03 10:30 ` cvs-commit at gcc dot gnu.org
  2020-09-03 10:31 ` vries at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-03 10:30 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8f5c6526ebbd8b5749dd2f348796b53f3e2b25ee

commit 8f5c6526ebbd8b5749dd2f348796b53f3e2b25ee
Author: Tom de Vries <tdevries@suse.de>
Date:   Thu Sep 3 12:30:10 2020 +0200

    [gdb/breakpoint, PIE] Handle setting breakpoint on label without address

    When adding:
    ...
    if ![runto_main] then {
        fail "can't run to main"
        return 0
    }
    ...
    to test-case gdb.base/label-without-address.exp and running it with target
    board unix/-fPIE/-pie, we run into:
    ...
    (gdb) break main:L1^M
    Breakpoint 2 at 0x555555554000: file label-without-address.c, line 22.^M
    ...
    That is, for a label with optimized-out address, we set a breakpoint at the
    relocation base.

    The root cause is that the dwarf reader, despite finding that attribute
    DW_AT_low_pc is missing, still tags the L1 symbol as having LOC_LABEL,
which
    means it has a valid address, which defaults to 0.

    Fix this by instead tagging the L1 symbol with LOC_OPTIMIZED_OUT.

    Tested on x86_64-linux.

    gdb/ChangeLog:

    2020-09-03  Tom de Vries  <tdevries@suse.de>

            PR breakpoint/26546
            * dwarf2/read.c (new_symbol): Tag label symbol without DW_AT_low_pc
as
            LOC_OPTIMIZED_OUT instead of LOC_LABEL.

    gdb/testsuite/ChangeLog:

    2020-09-03  Tom de Vries  <tdevries@suse.de>

            PR breakpoint/26546
            * gdb.base/label-without-address.exp: Runto main first.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug breakpoints/26546] [pie] Setting breakpoint on missing label sets breakpoint at offset 0 in NULL section
  2020-08-28 10:27 [Bug breakpoints/26546] New: [pie] Setting breakpoint on missing label sets breakpoint at offset 0 in NULL section vries at gcc dot gnu.org
  2020-08-28 11:33 ` [Bug breakpoints/26546] " vries at gcc dot gnu.org
  2020-09-03 10:30 ` cvs-commit at gcc dot gnu.org
@ 2020-09-03 10:31 ` vries at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2020-09-03 10:31 UTC (permalink / raw)
  To: gdb-prs

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

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |10.1
             Status|NEW                         |RESOLVED

--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
Patch committed, testsuite update included, marking resolved-fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2020-09-03 10:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-28 10:27 [Bug breakpoints/26546] New: [pie] Setting breakpoint on missing label sets breakpoint at offset 0 in NULL section vries at gcc dot gnu.org
2020-08-28 11:33 ` [Bug breakpoints/26546] " vries at gcc dot gnu.org
2020-09-03 10:30 ` cvs-commit at gcc dot gnu.org
2020-09-03 10:31 ` vries at gcc dot gnu.org

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