From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 15/15] Fix resolving GNU ifunc bp locations when inferior runs resolver
Date: Sun, 25 Mar 2018 19:19:00 -0000 [thread overview]
Message-ID: <20180325191943.8246-16-palves@redhat.com> (raw)
In-Reply-To: <20180325191943.8246-1-palves@redhat.com>
I noticed that if you set a breakpoint on an ifunc before the ifunc is
resolved, and then let the program call the ifunc, thus resolving it,
GDB end up with a location for that original breakpoint that is
pointing to the ifunc target, but it is left pointing to the first
address of the function, instead of after its prologue. After
prologue is what you get if you create a new breakpoint at that point.
1) With no debug info for the target function:
1.a) Set before resolving, and then program continued passed resolving:
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000400753 <final>
1.b) Breakpoint set after inferior resolved ifunc:
Num Type Disp Enb Address What
2 breakpoint keep y 0x0000000000400757 <final+4>
2) With debug info for the target function:
1.a) Set before resolving, and then program continued passed resolving:
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000400753 in final at gdb/testsuite/gdb.base/gnu-ifunc-final.c:20
1.b) Breakpoint set after inferior resolved ifunc:
Num Type Disp Enb Address What
2 breakpoint keep y 0x000000000040075a in final at gdb/testsuite/gdb.base/gnu-ifunc-final.c:21
The problem is that elf_gnu_ifunc_resolver_return_stop (called by the
internal breakpoint that traps the resolver returning) does not agree
with linespec.c:minsym_found. It does not skip to the function's
start line (i.e., past the prologue). We can now use the
find_function_start_sal overload added by the previous commmit to fix
this.
New tests included, which fail before the patch, and pass afterwards.
gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* elfread.c (elf_gnu_ifunc_resolver_return_stop): Use
find_function_start_sal instead of find_pc_line.
gdb/testsuite/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* gdb.base/gnu-ifunc.exp (set-break): Test that GDB resolves
ifunc breakpoint locations correctly of ifunc breakpoints set
while the program resolves the ifunc.
---
gdb/elfread.c | 3 ++-
gdb/testsuite/gdb.base/gnu-ifunc.exp | 18 ++++++++++++++----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 2a876e1bcc4..b50a283bea1 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1033,7 +1033,8 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
b->type = bp_breakpoint;
update_breakpoint_locations (b, current_program_space,
- find_pc_line (resolved_pc, 0), {});
+ find_function_start_sal (resolved_pc, NULL, true),
+ {});
}
/* A helper function for elf_symfile_read that reads the minimal
diff --git a/gdb/testsuite/gdb.base/gnu-ifunc.exp b/gdb/testsuite/gdb.base/gnu-ifunc.exp
index 827ac1202d2..d6ec6988a7d 100644
--- a/gdb/testsuite/gdb.base/gnu-ifunc.exp
+++ b/gdb/testsuite/gdb.base/gnu-ifunc.exp
@@ -106,6 +106,9 @@ proc_with_prefix set-break {resolver_attr resolver_debug final_debug} {
return 1
}
+ gdb_breakpoint [gdb_get_line_number "break-at-call"]
+ gdb_continue_to_breakpoint "break-at-call" ".*break-at-call.*"
+
set ws "\[ \t\]+"
set dot "\\.?"
@@ -131,19 +134,21 @@ proc_with_prefix set-break {resolver_attr resolver_debug final_debug} {
"Breakpoint $decimal at gnu-indirect-function resolver at $hex"
gdb_test "info breakpoints" \
"$decimal${ws}STT_GNU_IFUNC resolver${ws}keep${ws}y${ws}$hex <${gnu_ifunc_resolver}>"
+
+ # Make the breakpoint conditional on a condition that always
+ # fails. This is so that when the ifunc-resolver breakpoint
+ # triggers, GDB resumes the program immediately.
+ gdb_test_no_output "condition \$bpnum 0"
}
global final_src
with_test_prefix "resolve" {
- delete_breakpoints
gdb_breakpoint [gdb_get_line_number "break-at-exit"]
gdb_continue_to_breakpoint "break-at-exit" ".*break-at-exit.*"
}
with_test_prefix "after resolving" {
- delete_breakpoints
-
if {!$final_debug} {
# Set a breakpoint both at the ifunc, and at the ifunc's
# target. GDB should resolve both to the same address.
@@ -176,7 +181,12 @@ proc_with_prefix set-break {resolver_attr resolver_debug final_debug} {
gdb_test "break gnu_ifunc" "Breakpoint .* at $hex: file .*$final_src, line $lineno\\."
set location "$decimal${ws}breakpoint${ws}keep${ws}y${ws}$hex in final at .*$final_src:$lineno"
}
- gdb_test "info breakpoints" "$location\r\n$location"
+
+ # The first location here is for the breakpoint that was set
+ # before the ifunc was resolved. It should be resolved by
+ # now, and it should have the exact same address/line as the
+ # other two locations.
+ gdb_test "info breakpoints" "$location\r\n.*$location\r\n$location"
}
}
--
2.14.3
next prev parent reply other threads:[~2018-03-25 19:19 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-25 19:19 [PATCH v2 00/15] Fixing GNU ifunc support Pedro Alves
2018-03-25 19:19 ` [PATCH v2 01/15] Fix breakpoints in ifunc after inferior resolved it (@got.plt symbol creation) Pedro Alves
2018-04-01 3:35 ` Simon Marchi
2018-04-10 21:20 ` Pedro Alves
2018-04-14 16:36 ` Simon Marchi
2018-03-25 19:19 ` [PATCH v2 11/15] Fix stepping past GNU ifunc resolvers (introduce lookup_msym_prefer) Pedro Alves
2018-06-18 20:26 ` [PATCH] Silence GCC "uninitialized" warning on minsyms.c:lookup_minimal_symbol_by_pc_section Sergio Durigan Junior
2018-06-19 15:22 ` Pedro Alves
2018-06-19 16:55 ` Sergio Durigan Junior
2018-06-19 18:47 ` Tom Tromey
2018-03-25 19:19 ` [PATCH v2 03/15] Calling ifunc functions when target has no debug info but resolver has Pedro Alves
2018-04-01 4:22 ` Simon Marchi
2018-04-10 21:48 ` Pedro Alves
2018-04-10 21:54 ` Pedro Alves
2018-03-25 19:19 ` [PATCH v2 05/15] Fix elf_gnu_ifunc_resolve_by_got buglet Pedro Alves
2018-04-01 4:32 ` Simon Marchi
2018-04-10 21:52 ` Pedro Alves
2018-03-25 19:19 ` [PATCH v2 08/15] Eliminate find_pc_partial_function_gnu_ifunc Pedro Alves
2018-03-25 19:19 ` [PATCH v2 02/15] Fix calling ifunc functions when resolver has debug info and different name Pedro Alves
2018-04-01 3:44 ` Simon Marchi
2018-04-10 21:20 ` Pedro Alves
2018-03-25 19:19 ` [PATCH v2 07/15] Breakpoints, don't skip prologue of ifunc resolvers with debug info Pedro Alves
2018-03-25 19:19 ` [PATCH v2 12/15] For PPC64/ELFv1: Introduce mst_data_gnu_ifunc Pedro Alves
2018-03-25 19:19 ` Pedro Alves [this message]
2018-03-25 19:25 ` [PATCH v2 09/15] Factor out minsym_found/find_function_start_sal overload Pedro Alves
2018-03-25 19:25 ` [PATCH v2 04/15] Calling ifunc functions when resolver has debug info, user symbol same name Pedro Alves
2018-03-25 19:28 ` [PATCH v2 14/15] Extend GNU ifunc testcases Pedro Alves
2018-03-25 19:29 ` [PATCH v2 10/15] For PPC64: elf_gnu_ifunc_record_cache: handle plt symbols in .text section Pedro Alves
2018-03-25 19:29 ` [PATCH v2 13/15] PPC64: always make synthetic .text symbols for GNU ifunc symbols Pedro Alves
2018-03-25 19:33 ` Pedro Alves
2018-03-26 7:54 ` Alan Modra
2018-03-25 19:29 ` [PATCH v2 06/15] Fix setting breakpoints on ifunc functions after they're already resolved Pedro Alves
2018-04-26 12:23 ` [PATCH v2 00/15] Fixing GNU ifunc support Pedro Alves
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=20180325191943.8246-16-palves@redhat.com \
--to=palves@redhat.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