public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "andrew.burgess at embecosm dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug backtrace/27147] [GNU/Linux, sparc64] GDB is unable to print full stack trace (got "previous frame inner to this frame" errors)
Date: Wed, 24 Feb 2021 09:50:17 +0000	[thread overview]
Message-ID: <bug-27147-4717-Mq1mcKw8Tm@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-27147-4717@http.sourceware.org/bugzilla/>

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

--- Comment #11 from Andrew Burgess <andrew.burgess at embecosm dot com> ---
The problem is that the registers that "go wrong" are part of frame #0, which
are fetched when GDB first stops.  As such they end up being fetched in a call
tree that originates from the ::wait, like this:

#0  sparc_supply_rwindow (regcache=0x10001187fa0, sp=8791798050576, regnum=-1)
at ../../src/gdb/sparc-tdep.c:1967
#1  0x000001000076171c in sparc64_supply_gregset (gregmap=0x10000be0b5c
<sparc64_linux_ptrace_gregmap>, 
    regcache=0x10001187fa0, regnum=-1, gregs=0x7feffffd260) at
../../src/gdb/sparc64-tdep.c:1974
#2  0x0000010000751094 in sparc_fetch_inferior_registers
(regcache=0x10001187fa0, regnum=80)
    at ../../src/gdb/sparc-nat.c:170
#3  0x00000100007593f8 in sparc64_linux_nat_target::fetch_registers (
    this=0x10000fa0c40 <the_sparc64_linux_nat_target>, regcache=0x10001187fa0,
regnum=80)
    at ../../src/gdb/sparc64-linux-nat.c:38
#4  0x0000010000813d30 in target_fetch_registers (regcache=0x10001187fa0,
regno=80) at ../../src/gdb/target.c:3281
#5  0x00000100006a8194 in regcache::raw_update (this=0x10001187fa0, regnum=80)
at ../../src/gdb/regcache.c:584
#6  0x00000100006a82cc in readable_regcache::raw_read (this=0x10001187fa0,
regnum=80, buf=0x7feffffd7f0 "")
    at ../../src/gdb/regcache.c:598
#7  0x00000100006a88f0 in readable_regcache::cooked_read (this=0x10001187fa0,
regnum=80, buf=0x7feffffd7f0 "")
    at ../../src/gdb/regcache.c:690
#8  0x00000100006b1dc4 in readable_regcache::cooked_read<unsigned long, void>
(this=0x10001187fa0, regnum=80, 
    val=0x7feffffd978) at ../../src/gdb/regcache.c:777
#9  0x00000100006a907c in regcache_cooked_read_unsigned
(regcache=0x10001187fa0, regnum=80, val=0x7feffffd978)
    at ../../src/gdb/regcache.c:791
#10 0x00000100006ab474 in regcache_read_pc (regcache=0x10001187fa0) at
../../src/gdb/regcache.c:1295
#11 0x0000010000507218 in save_stop_reason (lp=0x1000121f190) at
../../src/gdb/linux-nat.c:2612
#12 0x0000010000508ee0 in linux_nat_filter_event (lwpid=3400064, status=1407)
at ../../src/gdb/linux-nat.c:3049
#13 0x00000100005098ac in linux_nat_wait_1 (ptid=..., ourstatus=0x7feffffe920,
target_options=...)
    at ../../src/gdb/linux-nat.c:3194
#14 0x000001000050aae0 in linux_nat_target::wait (this=0x10000fa0c40
<the_sparc64_linux_nat_target>, ptid=..., 
    ourstatus=0x7feffffe920, target_options=...) at
../../src/gdb/linux-nat.c:3432
#15 0x00000100007f810c in target_wait (ptid=..., status=0x7feffffe920,
options=...) at ../../src/gdb/target.c:1994
#16 0x00000100004aba74 in do_target_wait_1 (inf=0x1000116b140, ptid=...,
status=0x7feffffe920, options=...)
    at ../../src/gdb/infrun.c:3464
#17 0x00000100004abcb0 in operator() (__closure=0x7feffffe6a8,
inf=0x1000116b140) at ../../src/gdb/infrun.c:3527
#18 0x00000100004ac0c4 in do_target_wait (wait_ptid=..., ecs=0x7feffffe8f8,
options=...)
    at ../../src/gdb/infrun.c:3540
#19 0x00000100004ad1bc in fetch_inferior_event () at
../../src/gdb/infrun.c:3880
#20 0x0000010000484e60 in inferior_event_handler (event_type=INF_REG_EVENT) at
../../src/gdb/inf-loop.c:42
#21 0x00000100004be90c in infrun_async_inferior_event_handler (data=0x0) at
../../src/gdb/infrun.c:9216
#22 0x000001000012e9bc in check_async_event_handlers () at
../../src/gdb/async-event.c:327
#23 0x0000010000ab3ed4 in gdb_do_one_event () at
../../src/gdbsupport/event-loop.cc:216
#24 0x0000010000541f78 in start_event_loop () at ../../src/gdb/main.c:348
#25 0x000001000054218c in captured_command_loop () at ../../src/gdb/main.c:408
#26 0x0000010000544794 in captured_main (data=0x7fefffff0a8) at
../../src/gdb/main.c:1242
#27 0x000001000054483c in gdb_main (args=0x7fefffff0a8) at
../../src/gdb/main.c:1257
#28 0x00000100000c1f14 in main (argc=4, argv=0x7fefffff468) at
../../src/gdb/gdb.c:32

When we go into the wait inferior_ptid is always set to null_ptid, which makes
sense, as we don't know which inferior will be giving us an event.  It appears
that everything called from the wait, once we do know which inferior has
stopped, still has inferior_ptid set to null_ptid.

Having thought about my fix a little more I do wonder if we should move the
setting of inferior_ptid further up the call stack.  Given that inferior_ptid
does need to be set when making target_* calls, I'm tempted to say we should
really set inferior_ptid possibly as early as the ::wait, once we have figured
out which inferior the event is for.

Have reviewed the test results, and it looks pretty good.  Failures on sparc64
dropped from 7k+ to ~1.5k.

One further note, placing the error where I did (after the target read) has an
unfortunate effect that it prevents the target from stopping, here's a broken
session:

 (gdb) b puts
 Breakpoint 1 at 0x108de4
 (gdb) r
 Starting program: /home/aburgess/project/binutils-gdb/test/gdb-test.static 
 failed to read target memory at 0x000007feffffeef0
 (gdb) bt
 Selected thread is running.
 (gdb) 

Obviously this isn't a problem once we fix the setting of inferior_ptid, but it
still feels kind of rubbish.  I think a much better solution is:

diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index 4f9c679b55c..78f93b121c8 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -1957,7 +1962,14 @@ sparc_supply_rwindow (struct regcache *regcache,
CORE_ADDR sp, int regnum)
        {
          if (regnum == i || regnum == -1)
            {
-             target_read_memory (sp + ((i - SPARC_L0_REGNUM) * 8), buf, 8);
+             if (target_read_memory (sp + ((i - SPARC_L0_REGNUM) * 8), buf, 8)
== -1)
+               {
+                 warning (_("failed to read 8 bytes of target memory at %s for
register %s"),
+                          core_addr_to_string (sp + ((i - SPARC_L0_REGNUM) *
8)),
+                          gdbarch_register_name (gdbarch, i));
+                 regcache->raw_supply (i, nullptr);
+                 continue;
+               }

              /* Handle StackGhost.  */
              if (i == SPARC_I7_REGNUM)

Now the register are just marked as unavailable.

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

  parent reply	other threads:[~2021-02-24  9:50 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-04 12:57 [Bug backtrace/27147] New: " koachan+sourceware at protonmail dot com
2021-01-04 15:58 ` [Bug backtrace/27147] " simark at simark dot ca
2021-01-04 16:26 ` simark at simark dot ca
2021-01-04 18:58 ` simark at simark dot ca
2021-01-04 23:41 ` koachan+sourceware at protonmail dot com
2021-01-04 23:42 ` koachan+sourceware at protonmail dot com
2021-02-18 17:35 ` simark at simark dot ca
2021-02-23 17:48 ` andrew.burgess at embecosm dot com
2021-02-23 18:23 ` andrew.burgess at embecosm dot com
2021-02-23 18:32 ` simark at simark dot ca
2021-02-23 18:33 ` simark at simark dot ca
2021-02-24  9:50 ` andrew.burgess at embecosm dot com [this message]
2021-02-24 21:34 ` simark at simark dot ca
2021-02-24 23:39 ` simark at simark dot ca
2021-03-04  0:49 ` simark at simark dot ca
2021-03-04 12:27 ` koachan+sourceware at protonmail dot com
2021-03-04 16:07 ` cvs-commit at gcc dot gnu.org
2021-03-04 17:08 ` cvs-commit at gcc dot gnu.org
2021-03-04 17:09 ` simark at simark dot ca
2021-03-04 17:09 ` simark at simark dot ca
2021-06-27 17:46 ` ahmedsayeed1982 at yahoo dot com
2021-08-10 11:45 ` ucelsanicin at yahoo dot com
2021-08-27 17:52 ` ribevi6798 at enamelme dot com
2021-08-28 18:31 ` buranlevent at yahoo dot com
2021-09-06  9:10 ` focixujo at livinginsurance dot co.uk
2021-09-10 19:40 ` mehmetgelisin at aol dot com
2021-09-14 17:29 ` johnb6174 at gmail dot com
2021-09-14 18:48 ` mark at klomp dot org
2021-09-26 13:31 ` tes.vik1986 at gmail dot com
2021-10-09 11:00 ` gulsenenginar at aol dot com
2021-10-10 16:10 ` oficaj3 at gmail dot com
2021-10-19  7:14 ` progonsaytu at gmail dot com
2021-10-23 13:46 ` fiteva5725 at bomoads dot com
2021-10-24 10:02 ` glassmtech at ukr dot net
2021-10-29 10:57 ` kimolsun2020 at outlook dot com
2021-10-29 12:07 ` huracantili20 at gmail dot com
2021-11-02 15:21 ` gepaw63633 at dukeoo dot com
2021-11-06 21:12 ` paneki8601 at dukeoo dot com
2021-11-16 19:05 ` xecana8007 at funboxcn dot com
2021-11-16 19:08 ` xecana8007 at funboxcn dot com
2021-11-22  7:37 ` gexed96894 at keagenan dot com

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=bug-27147-4717-Mq1mcKw8Tm@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).