From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 62957 invoked by alias); 7 Dec 2017 21:22:27 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 62943 invoked by uid 89); 7 Dec 2017 21:22:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-19.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=H*F:U*tim, H*r:sk:gdb@sou, H*c:alternative X-HELO: mail-ot0-f172.google.com Received: from mail-ot0-f172.google.com (HELO mail-ot0-f172.google.com) (74.125.82.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Dec 2017 21:22:24 +0000 Received: by mail-ot0-f172.google.com with SMTP id d27so7572866ote.11 for ; Thu, 07 Dec 2017 13:22:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=d8JdFZfW1aMtWP6s4ugFQ5AUg8s5ASb/2TQoYFUdZE4=; b=AErqowdeW/TQaWKYV0fr47n8hIq0oC8toO0vAorSS55iKquMtzF1tz8d7NQ7psWbrn J4kf9Vn4GPsMgUhE1rlenLIHvE7pkbdySJBCjXBShu/Jlz33o+WcT0JLxvOYrA7jvGk9 HIXEbDoxMIQw1bdGppXu79jzlH+YZlw89IHOEcsWCXunc3AzS+KVZANTJ0WCyZHKiq2B ZHycO5vzR/pnGwulnOdGvH2nREKHUbIQmvRketxz3u07yh1VzGOWjkETehSoCrgfgi3T OtIuZavroyS8gH0j5VXHaO9osmY9bYCZKDTBqwb2azdzfXq3fXoxOeJ6R9eOBFD/JXen lhag== X-Gm-Message-State: AKGB3mI4l1bNL/uS0BtRTckbKIyNooyO7hruGFpRtNBz1XTAcUrrJps2 uNkz7rjOZK/b58kAS+cxw40Vu173qu/en4sphwnKkxC03uc= X-Google-Smtp-Source: ACJfBoshddg/1oOua4ezy9yzEEKCliaIN19PgopweUUs2c6E2ifSTbfU6pvmPYn67GiLsV1FvvpkykWpIHbgvBySbIo= X-Received: by 10.157.56.75 with SMTP id r11mr397717otd.166.1512681742870; Thu, 07 Dec 2017 13:22:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.168.66.197 with HTTP; Thu, 7 Dec 2017 13:22:22 -0800 (PST) In-Reply-To: References: From: Tim Newsome Date: Thu, 07 Dec 2017 21:22:00 -0000 Message-ID: Subject: Re: gdbarch_init, ABI, and registers To: gdb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg00007.txt.bz2 I=E2=80=99ve made some progress here. gdb does keep track of the description for the current target, and it can be retrieved by calling target_current_description(). My problems stemmed from the fact that sometimes riscv_gdbarch_init() was called with an info structure that did not have the current target description filled out. I tracked this down to gdbarch_from_bfd(), which doesn=E2=80=99t set info.target_desc. set_gdbarch_from_file() does do so (since 2008), and the following patch makes everything work for me: diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 2ae3413087..6c84f100af 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -600,6 +600,7 @@ gdbarch_from_bfd (bfd *abfd) gdbarch_info_init (&info); info.abfd =3D abfd; + info.target_desc =3D target_current_description (); return gdbarch_find_by_info (info); } Does this seem like the right solution? A better one might be to put this assignment in gdbarch_info_init(). Or I could just call target_current_description() in riscv_arch_init() when no target description is passed in. The latter goes against the comment accompanying target_current_description(), but it would only be a target-dependent change. Tim =E2=80=8B On Wed, Dec 6, 2017 at 12:20 PM, Tim Newsome wrote: > Still working on RISC-V support=E2=80=A6 > > I=E2=80=99ve taught OpenOCD to provide a target description, so now when > connecting to a target that doesn=E2=80=99t have an FPU, the FPU register= s don=E2=80=99t > show up. Obviously I want this reflected in gdb, and I=E2=80=99ve managed= to make > that work in some cases. However, it doesn=E2=80=99t always work. Sometim= es my > target appears to revert to the case where it just uses the built-in list > of registers, despite being connected to an OpenOCD that I know provides > the target description. > > My confusion comes from when riscv_gdbarch_init() is called, and how. With > a bit of instrumenting, I get this output: > > + /opt/riscv/bin/riscv64-unknown-elf-gdb > >>> riscv_gdbarch_init() > >>> bits_per_word=3D64 > >>> tdesc_has_register() -> 0 > >>> info.abfd=3D(nil) > >>> abi=3D1073741824 > GNU gdb (GDB) 8.0.50.20170724-git > ... > (gdb) target extended-remote localhost:38295 > > target extended-remote localhost:38295 > Remote debugging using localhost:38295 > >>> riscv_gdbarch_init() > >>> bits_per_word=3D64 > >>> tdesc_has_register() -> 1 > >>> info.abfd=3D(nil) > >>> abi=3D1073741824 > warning: No executable has been specified and target does not support > determining executable automatically. Try using the "file" command. > 0x00000000800009f0 in ?? () > (gdb) file HiFive1_debug-32 > >>> riscv_gdbarch_init() > > >>> bits_per_word=3D32 > >>> tdesc_has_register() -> 1 > >>> info.abfd=3D0x55a8a1f4e7f0 > >>> flavour=3D5 > >>> abi=3D0 > >>> riscv_gdbarch_init() > >>> bits_per_word=3D32 > >>> tdesc_has_register() -> 0 > >>> info.abfd=3D0x55a8a1f4e7f0 > >>> flavour=3D5 > >>> abi=3D0 > Reading symbols from HiFive1_debug-32...done. > (gdb) set arch riscv:rv32 > >>> riscv_gdbarch_init() > >>> bits_per_word=3D32 > >>> tdesc_has_register() -> 1 > >>> info.abfd=3D0x55a8a1f4e7f0 > >>> flavour=3D5 > >>> abi=3D0 > The target architecture is assumed to be riscv:rv32 > > It almost feels like I=E2=80=99m on completely the wrong track by initial= izing > registers in riscv_gdbarch_init(), but that=E2=80=99s what the ARM and MI= PS targets > do. A lot of code in their gdbarch_init() is dedicated to figuring out the > ABI in use. How are ABIs and registers related? In my world view the > hardware has certain registers, and how the software chooses to use those > registers is the ABI. But changing the ABI doesn=E2=80=99t change what re= gisters > exist. > > Are there callbacks I can use that are called when we connect > to/disconnect from a remote server like OpenOCD? > > Thank you, > Tim > =E2=80=8B >