From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3077 invoked by alias); 6 Mar 2018 11:06:04 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 3066 invoked by uid 89); 6 Mar 2018 11:06:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=alessandro, Todd, todd, HX-Received:10.223.169.4 X-HELO: mail-wr0-f193.google.com Received: from mail-wr0-f193.google.com (HELO mail-wr0-f193.google.com) (209.85.128.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 06 Mar 2018 11:06:00 +0000 Received: by mail-wr0-f193.google.com with SMTP id o76so20478947wrb.7 for ; Tue, 06 Mar 2018 03:06:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=1BfP78QQ1yzdxn0IYh0DmgI87ue7gg/0HnnQGvOX6zs=; b=QnOqiuD3HUEz9mj6SVgxSdjUAn5s3sghwCxbGh8JOnlByeyN+5GZMcHHmBJMFM0U1x Xo8nwrzvvsCzRmPgm1gKf0iQVeleCFohT1E1Z/7JnCQ4BkM7mo8ZkCyhZiKjLFYuRPnb ZjzlK1W/8hoRBYj9nNsQuiQzms0zYZuGpaDP3azU47T5hW2z29ogNiIxKV+FhqqRIlsL 72YTV4kin0ikuMSHh2Zy1ppjYqnUyCS1j17RYX4ZR4Ufa4gIl9Pdy4aiV6SESDWE3xvE UvE4TRC97NbXU1eNbSVr0aqQq8AEkUgoZE5dPDoLp0Q9iEnQLU/WohXP6vDkbO0s5TG/ rFtQ== X-Gm-Message-State: APf1xPBsZ9vFiOEKqI81hi1uuSgfd3aeEjO6hUw2Kc9LyjsFPknffQFt ASRwbkQr3wZTlPKcv8AgEx8VSgNY X-Google-Smtp-Source: AG47ELtPIq0u5FG3RvLJIDce2jXxqEMXPjeIIl+H5lA+7vqhRykA0Lr8AGBIiS718lMx/VAHqAuPbQ== X-Received: by 10.223.169.4 with SMTP id u4mr14380520wrc.170.1520334358342; Tue, 06 Mar 2018 03:05:58 -0800 (PST) Received: from E107787-LIN (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id p60sm16311712wrc.88.2018.03.06.03.05.57 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 06 Mar 2018 03:05:57 -0800 (PST) From: Yao Qi To: Andrew Burgess Cc: Simon Marchi , gdb-patches@sourceware.org, Eli Zaretskii Subject: Re: [PATCHv4 2/2] gdb: Initial baremetal riscv support References: <430dd07a2ed6520ad17108eb156935ec86cec826.1520021226.git.andrew.burgess@embecosm.com> <3e083125-4a39-04ee-45cc-0152ced1e259@simark.ca> <20180305104543.GA2612@embecosm.com> Date: Tue, 06 Mar 2018 11:06:00 -0000 In-Reply-To: <20180305104543.GA2612@embecosm.com> (Andrew Burgess's message of "Mon, 5 Mar 2018 10:45:44 +0000") Message-ID: <86fu5d31ma.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2018-03/txt/msg00133.txt.bz2 Andrew Burgess writes: Hi Andrew, Did you see the GDB internal error in gdb selftests. I build my gdb with all targets enabled (--enable-targets=3Dall --enable-64-bit-bfd), and type command "maintenance selftest" ../../binutils-gdb/gdb/regcache.c:371: internal-error: void reg_buffer::ass= ert_regnum(int) const: Assertion `regnum < gdbarch_num_regs (arch ())' fail= ed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) n (gdb) bt 10 #0 internal_error (file=3Dfile@entry=3D0xeb4630 "../../binutils-gdb/gdb/re= gcache.c", line=3Dline@entry=3D371, fmt=3D0xd91f23 "%s: Assertion `%s' fail= ed.") at ../../binutils-gdb/gdb/common/errors.c:51 #1 0x0000000000768691 in reg_buffer::assert_regnum (this=3D= , regnum=3D4162) at ../../binutils-gdb/gdb/regcache.c:371 #2 0x0000000000768802 in regcache::raw_update (this=3D0x7fffffffd0f0, regn= um=3D4162) at ../../binutils-gdb/gdb/regcache.c:521 #3 0x000000000076903a in readable_regcache::raw_read (this=3D0x7fffffffd0f= 0, regnum=3D4162, buf=3D0x34adc30 "\230k)\366\377\177") at ../../binutils-g= db/gdb/regcache.c:550 #4 0x00000000007695af in selftests::cooked_read_test (gdbarch=3D0x29e4a00)= at ../../binutils-gdb/gdb/regcache.c:1659 #5 0x00000000005d6403 in selftests::gdbarch_selftest::operator() (this=3D0= x2840aa0) at ../../binutils-gdb/gdb/selftest-arch.c:73 #6 0x00000000005d57c2 in selftests::run_tests (filter=3D0x0) at ../../binutils-gdb/gdb/common/selftest.c:88 (gdb) p gdbarch->bfd_arch_info $3 =3D (const bfd_arch_info *) 0x1969d80 Looks it is from riscv port. Some other comments on this patch below, > + Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU > + and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin > + and by Todd Snyder > + and by Mike Frysinger . > + Please don't use "Contributed by" see https://sourceware.org/gdb/wiki/ContributionChecklist#Attribution > + > +/* Implement the unwind_pc gdbarch method. */ > + > +static CORE_ADDR > +riscv_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) > +{ > + return frame_unwind_register_unsigned (next_frame, RISCV_PC_REGNUM); > +} > + unwind_pc has some duplication across all gdb ports. Can we define a default implementation of this method like this, static CORE_ADDR default_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) { return frame_unwind_register_unsigned (next_frame, gdbarch_pc_regnum (gdbarch)); }=20 so many ports, including riscv, don't need to define its own unwind_pc at all. > +/* Implement the unwind_sp gdbarch method. */ > + > +static CORE_ADDR > +riscv_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) > +{ > + return frame_unwind_register_unsigned (next_frame, RISCV_SP_REGNUM); > +} > + > +/* Initialize the current architecture based on INFO. If possible, > + re-use an architecture from ARCHES, which is a list of > + architectures already created during this debugging session. > + > + Called e.g. at program startup, when reading a core file, and when > + reading a binary file. */ > + > +static struct gdbarch * > +riscv_gdbarch_init (struct gdbarch_info info, > + struct gdbarch_list *arches) > +{ > + struct gdbarch *gdbarch; > + struct gdbarch_tdep *tdep; > + struct gdbarch_tdep tmp_tdep; > + bool has_compressed_isa =3D false; > + int i; > + > + /* Ideally, we'd like to get as much information from the target for > + things like register size, and whether the target has floating point > + hardware. However, there are some things that the target can't tell > + us, like, what ABI is being used. > + > + So, for now, we take as much information as possible from the ELF, > + including things like register size, and FP hardware support, along > + with information about the ABI. > + > + Information about this target is built up in TMP_TDEP, and then we > + look for an existing gdbarch in ARCHES that matches TMP_TDEP. If no > + match is found we'll create a new gdbarch and copy TMP_TDEP over. = */ > + memset (&tmp_tdep, 0, sizeof (tmp_tdep)); > + > + if (info.abfd !=3D NULL > + && bfd_get_flavour (info.abfd) =3D=3D bfd_target_elf_flavour) > + { > + unsigned char eclass =3D elf_elfheader (info.abfd)->e_ident[EI_CLA= SS]; > + int e_flags =3D elf_elfheader (info.abfd)->e_flags; > + > + if (eclass =3D=3D ELFCLASS32) > + tmp_tdep.abi.fields.base_len =3D 1; > + else if (eclass =3D=3D ELFCLASS64) > + tmp_tdep.abi.fields.base_len =3D 2; > + else > + internal_error (__FILE__, __LINE__, > + _("unknown ELF header class %d"), eclass); > + > + if (e_flags & EF_RISCV_RVC) > + { > + has_compressed_isa =3D true; > + tmp_tdep.core_features |=3D (1 << ('C' - 'A')); > + } > + > + if (e_flags & EF_RISCV_FLOAT_ABI_DOUBLE) > + { > + tmp_tdep.abi.fields.float_abi =3D 2; > + tmp_tdep.core_features |=3D (1 << ('D' - 'A')); > + tmp_tdep.core_features |=3D (1 << ('F' - 'A')); > + } > + else if (e_flags & EF_RISCV_FLOAT_ABI_SINGLE) > + { > + tmp_tdep.abi.fields.float_abi =3D 1; > + tmp_tdep.core_features |=3D (1 << ('F' - 'A')); > + } > + } > + else > + { > + const struct bfd_arch_info *binfo =3D info.bfd_arch_info; > + > + if (binfo->bits_per_word =3D=3D 32) > + tmp_tdep.abi.fields.base_len =3D 1; > + else if (binfo->bits_per_word =3D=3D 64) > + tmp_tdep.abi.fields.base_len =3D 2; > + else > + internal_error (__FILE__, __LINE__, _("unknown bits_per_word %d"= ), > + binfo->bits_per_word); > + } > + > + /* Find a candidate among the list of pre-declared architectures. */ > + for (arches =3D gdbarch_list_lookup_by_info (arches, &info); > + arches !=3D NULL; > + arches =3D gdbarch_list_lookup_by_info (arches->next, &info)) > + if (gdbarch_tdep (arches->gdbarch)->abi.value =3D=3D tmp_tdep.abi.va= lue) > + return arches->gdbarch; > + > + /* None found, so create a new architecture from the information provi= ded. */ > + tdep =3D (struct gdbarch_tdep *) xmalloc (sizeof *tdep); > + gdbarch =3D gdbarch_alloc (&info, tdep); > + memcpy (tdep, &tmp_tdep, sizeof (tmp_tdep)); > + > + /* Target data types. */ > + set_gdbarch_short_bit (gdbarch, 16); > + set_gdbarch_int_bit (gdbarch, 32); > + set_gdbarch_long_bit (gdbarch, riscv_isa_xlen (gdbarch) * 8); > + set_gdbarch_long_long_bit (gdbarch, 64); > + set_gdbarch_float_bit (gdbarch, 32); > + set_gdbarch_double_bit (gdbarch, 64); > + set_gdbarch_long_double_bit (gdbarch, 128); > + set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad); > + set_gdbarch_ptr_bit (gdbarch, riscv_isa_xlen (gdbarch) * 8); > + set_gdbarch_char_signed (gdbarch, 0); > + > + /* Information about the target architecture. */ > + set_gdbarch_return_value (gdbarch, riscv_return_value); > + set_gdbarch_breakpoint_kind_from_pc (gdbarch, riscv_breakpoint_kind_fr= om_pc); > + set_gdbarch_sw_breakpoint_from_kind (gdbarch, riscv_sw_breakpoint_from= _kind); > + > + /* Register architecture. */ > + set_gdbarch_pseudo_register_read (gdbarch, riscv_pseudo_register_read); > + set_gdbarch_pseudo_register_write (gdbarch, riscv_pseudo_register_writ= e); > + set_gdbarch_num_regs (gdbarch, RISCV_LAST_REGNUM + 1); > + set_gdbarch_num_pseudo_regs (gdbarch, RISCV_LAST_REGNUM + 1); > + set_gdbarch_sp_regnum (gdbarch, RISCV_SP_REGNUM); > + set_gdbarch_pc_regnum (gdbarch, RISCV_PC_REGNUM); > + set_gdbarch_ps_regnum (gdbarch, RISCV_FP_REGNUM); > + set_gdbarch_deprecated_fp_regnum (gdbarch, RISCV_FP_REGNUM); > + > + /* Functions to supply register information. */ > + set_gdbarch_register_name (gdbarch, riscv_register_name); > + set_gdbarch_register_type (gdbarch, riscv_register_type); > + set_gdbarch_print_registers_info (gdbarch, riscv_print_registers_info); > + set_gdbarch_register_reggroup_p (gdbarch, riscv_register_reggroup_p); > + > + /* Functions to analyze frames. */ > + set_gdbarch_decr_pc_after_break (gdbarch, (has_compressed_isa ? 2 : 4)= ); > + set_gdbarch_skip_prologue (gdbarch, riscv_skip_prologue); > + set_gdbarch_inner_than (gdbarch, core_addr_lessthan); > + set_gdbarch_frame_align (gdbarch, riscv_frame_align); > + > + /* Functions to access frame data. */ > + set_gdbarch_unwind_pc (gdbarch, riscv_unwind_pc); > + set_gdbarch_unwind_sp (gdbarch, riscv_unwind_sp); > + > + /* Functions handling dummy frames. */ > + set_gdbarch_call_dummy_location (gdbarch, ON_STACK); > + set_gdbarch_push_dummy_code (gdbarch, riscv_push_dummy_code); > + set_gdbarch_push_dummy_call (gdbarch, riscv_push_dummy_call); > + set_gdbarch_dummy_id (gdbarch, riscv_dummy_id); > + > + /* Frame unwinders. Use DWARF debug info if available, otherwise use = our own > + unwinder. */ > + dwarf2_append_unwinders (gdbarch); > + frame_unwind_append_unwinder (gdbarch, &riscv_frame_unwind); > + > + /* Check any target description for validity. */ Target description is not added yet. Can we remove it? > + if (tdesc_has_registers (info.target_desc)) > + { > + const struct tdesc_feature *feature; > + struct tdesc_arch_data *tdesc_data; > + int valid_p; > + > + feature =3D tdesc_find_feature (info.target_desc, "org.gnu.gdb.ris= cv.cpu"); > + if (feature =3D=3D NULL) > + goto no_tdata; > + > + tdesc_data =3D tdesc_data_alloc (); > + > + valid_p =3D 1; > + for (i =3D RISCV_ZERO_REGNUM; i <=3D RISCV_LAST_FP_REGNUM; ++i) > + valid_p &=3D tdesc_numbered_register (feature, tdesc_data, i, > + riscv_gdb_reg_names[i]); > + for (i =3D RISCV_FIRST_CSR_REGNUM; i <=3D RISCV_LAST_CSR_REGNUM; += +i) > + { > + char buf[20]; > + > + sprintf (buf, "csr%d", i - RISCV_FIRST_CSR_REGNUM); > + valid_p &=3D tdesc_numbered_register (feature, tdesc_data, i, = buf); > + } > + > + valid_p &=3D tdesc_numbered_register (feature, tdesc_data, i++, "p= riv"); > + > + if (!valid_p) > + tdesc_data_cleanup (tdesc_data); > + else > + tdesc_use_registers (gdbarch, info.target_desc, tdesc_data); > + } > + no_tdata: > + > + for (i =3D 0; i < ARRAY_SIZE (riscv_register_aliases); ++i) > + user_reg_add (gdbarch, riscv_register_aliases[i].name, > + value_of_riscv_user_reg, &riscv_register_aliases[i].regnum); > + > + return gdbarch; > +} > + > + --=20 Yao (=E9=BD=90=E5=B0=A7)