From patchwork Fri Dec 9 12:52:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 18320 Received: (qmail 2142 invoked by alias); 9 Dec 2016 12:53:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 2014 invoked by uid 89); 9 Dec 2016 12:53:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=name@entry, centry, nameentry, U*name X-HELO: mail-pg0-f66.google.com Received: from mail-pg0-f66.google.com (HELO mail-pg0-f66.google.com) (74.125.83.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Dec 2016 12:52:57 +0000 Received: by mail-pg0-f66.google.com with SMTP id e9so2284861pgc.1 for ; Fri, 09 Dec 2016 04:52:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=lR5Hs5PsZeQPtvbrh8FoevNNmpzUf/UAw7wjvoS3fQY=; b=dRb/PJLB7HZ2jJKdyyqiEy0iDIVxJghjliR8ctHade/hbAewXdTYbDqKeasTgo3CKr /r5UpoUBmvW26aTtoVnBFfRhpb8MXGWT112RKyGmMETzEXQ1M3AVJENVfh17eigXDpD2 Z544mTw8YOWJ5LlSRnjI2q//HGiFNIPvB1MkzomNDk59Yogi3zMmPHg2EbUoTq3Yk/6n SDZTsjuQOxp46SlOq0Z+/PD6vzi655DJzZ0H9GZxaodHn2IW2X3sU/t9QNJstKeLu5Xl TLD89KeOR9KCBUkB5zQ1JBrXd0i+7O888XaeY+0oqkhGinYCl8A6dTZ67MEo921nRwk8 E4Tw== X-Gm-Message-State: AKaTC01AvzV0of+/FkRbFU5QFJ1cjpMG9EBZ+REYz1wgMENiuUtWLaJKz5BkmRsjIOmh6w== X-Received: by 10.98.83.193 with SMTP id h184mr81503558pfb.175.1481287975455; Fri, 09 Dec 2016 04:52:55 -0800 (PST) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id l69sm57621175pfk.34.2016.12.09.04.52.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Dec 2016 04:52:54 -0800 (PST) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH mainline/7.12.1] Create tdep->rl78_psw_type lazily Date: Fri, 9 Dec 2016 12:52:41 +0000 Message-Id: <1481287961-10631-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes I build GDB for all targets enabled. When I "set architecture rl78", GDB crashes, (gdb) set architecture rl78 Program received signal SIGSEGV, Segmentation fault. append_flags_type_flag (type=0x20cc0e0, bitpos=bitpos@entry=0, name=name@entry=0x11dba3f "CY") at ../../binutils-gdb/gdb/gdbtypes.c:4926 4926 name); (gdb) bt 10 #0 append_flags_type_flag (type=0x20cc0e0, bitpos=bitpos@entry=0, name=name@entry=0x11dba3f "CY") at ../../binutils-gdb/gdb/gdbtypes.c:4926 #1 0x00000000004aaca8 in rl78_gdbarch_init (info=..., arches=) at ../../binutils-gdb/gdb/rl78-tdep.c:1410 #2 0x00000000006b05a4 in gdbarch_find_by_info (info=...) at ../../binutils-gdb/gdb/gdbarch.c:5269 #3 0x000000000060eee4 in gdbarch_update_p (info=...) at ../../binutils-gdb/gdb/arch-utils.c:557 #4 0x000000000060f8a8 in set_architecture (ignore_args=, from_tty=1, c=) at ../../binutils-gdb/gdb/arch-utils.c:531 #5 0x0000000000593d0b in do_set_command (arg=, arg@entry=0x20be851 "rl78", from_tty=from_tty@entry=1, c=c@entry=0x20b1540) at ../../binutils-gdb/gdb/cli/cli-setshow.c:455 #6 0x00000000007665c3 in execute_command (p=, p@entry=0x20be840 "set architecture rl78", from_tty=1) at ../../binutils-gdb/gdb/top.c:666 #7 0x00000000006935f4 in command_handler (command=0x20be840 "set architecture rl78") at ../../binutils-gdb/gdb/event-top.c:577 #8 0x00000000006938d8 in command_line_handler (rl=) at ../../binutils-gdb/gdb/event-top.c:767 #9 0x0000000000692c2c in gdb_rl_callback_handler (rl=0x20be890 "") at ../../binutils-gdb/gdb/event-top.c:200 The cause is that we want to access some builtin types in gdbarch init, but it is not initialized yet. I fix it by creating the type when it is to be used. We've already done this in sparc, sparc64 and m68k. gdb: 2016-12-09 Yao Qi PR tdep/20953 * rl78-tdep.c (rl78_psw_type): New function. (rl78_register_type): Call rl78_psw_type. (rl78_gdbarch_init): Move code to rl78_psw_type. --- gdb/rl78-tdep.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c index 95a26a5..0e88fbc 100644 --- a/gdb/rl78-tdep.c +++ b/gdb/rl78-tdep.c @@ -261,6 +261,30 @@ struct rl78_prologue int reg_offset[RL78_NUM_TOTAL_REGS]; }; +/* Construct type for PSW register. */ + +static struct type * +rl78_psw_type (struct gdbarch *gdbarch) +{ + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + if (tdep->rl78_psw_type == NULL) + { + tdep->rl78_psw_type = arch_flags_type (gdbarch, + "builtin_type_rl78_psw", 1); + append_flags_type_flag (tdep->rl78_psw_type, 0, "CY"); + append_flags_type_flag (tdep->rl78_psw_type, 1, "ISP0"); + append_flags_type_flag (tdep->rl78_psw_type, 2, "ISP1"); + append_flags_type_flag (tdep->rl78_psw_type, 3, "RBS0"); + append_flags_type_flag (tdep->rl78_psw_type, 4, "AC"); + append_flags_type_flag (tdep->rl78_psw_type, 5, "RBS1"); + append_flags_type_flag (tdep->rl78_psw_type, 6, "Z"); + append_flags_type_flag (tdep->rl78_psw_type, 7, "IE"); + } + + return tdep->rl78_psw_type; +} + /* Implement the "register_type" gdbarch method. */ static struct type * @@ -273,7 +297,7 @@ rl78_register_type (struct gdbarch *gdbarch, int reg_nr) else if (reg_nr == RL78_RAW_PC_REGNUM) return tdep->rl78_uint32; else if (reg_nr == RL78_PSW_REGNUM) - return (tdep->rl78_psw_type); + return rl78_psw_type (gdbarch); else if (reg_nr <= RL78_MEM_REGNUM || (RL78_X_REGNUM <= reg_nr && reg_nr <= RL78_H_REGNUM) || (RL78_BANK0_R0_REGNUM <= reg_nr @@ -1406,16 +1430,6 @@ rl78_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) tdep->rl78_code_pointer = arch_pointer_type (gdbarch, 32, "rl78_code_addr_t", tdep->rl78_void); - tdep->rl78_psw_type = arch_flags_type (gdbarch, "builtin_type_rl78_psw", 1); - append_flags_type_flag (tdep->rl78_psw_type, 0, "CY"); - append_flags_type_flag (tdep->rl78_psw_type, 1, "ISP0"); - append_flags_type_flag (tdep->rl78_psw_type, 2, "ISP1"); - append_flags_type_flag (tdep->rl78_psw_type, 3, "RBS0"); - append_flags_type_flag (tdep->rl78_psw_type, 4, "AC"); - append_flags_type_flag (tdep->rl78_psw_type, 5, "RBS1"); - append_flags_type_flag (tdep->rl78_psw_type, 6, "Z"); - append_flags_type_flag (tdep->rl78_psw_type, 7, "IE"); - /* Registers. */ set_gdbarch_num_regs (gdbarch, RL78_NUM_REGS); set_gdbarch_num_pseudo_regs (gdbarch, RL78_NUM_PSEUDO_REGS);