From patchwork Mon Mar 6 22:02:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Steve Ellcey X-Patchwork-Id: 19441 Received: (qmail 17123 invoked by alias); 6 Mar 2017 22:03:04 -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 17107 invoked by uid 89); 6 Mar 2017 22:03:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=qi, Qi, PC, 5197 X-HELO: NAM03-DM3-obe.outbound.protection.outlook.com Received: from mail-dm3nam03on0088.outbound.protection.outlook.com (HELO NAM03-DM3-obe.outbound.protection.outlook.com) (104.47.41.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 06 Mar 2017 22:03:00 +0000 Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=caviumnetworks.com; Received: from sellcey-dt.caveonetworks.com (50.233.148.156) by CY1PR07MB2443.namprd07.prod.outlook.com (10.166.195.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.947.12; Mon, 6 Mar 2017 22:02:55 +0000 Message-ID: <1488837762.2866.268.camel@caviumnetworks.com> Subject: [Patch v2 1/2] Enable ILP32 mode in gdb on aarch64 From: Steve Ellcey To: gdb-patches Date: Mon, 06 Mar 2017 14:02:42 -0800 Mime-Version: 1.0 X-ClientProxiedBy: BN6PR11CA0012.namprd11.prod.outlook.com (10.172.17.22) To CY1PR07MB2443.namprd07.prod.outlook.com (10.166.195.20) X-MS-Office365-Filtering-Correlation-Id: cd674696-c8ea-4cda-3829-08d464dc8b50 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:CY1PR07MB2443; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2443; 3:d62ZVyfMl62SYxgHJqtaU8zMltMGrXZC3LgCW953h/CxCiMWtpbJgVM5C+F3nomopNB4DISWn7VfF/I76S3AZ7KlDPwmtzyEbJ93yKXAkP6LJGgo3Tvjn191iWOZ3LsriOJLe4Qmu8Y/31t/GgZXy0Lz/xpH/bPLuyxdpY284UG34Xu2COoVPto44g9V9yVRWUPNS6vQn+zyxq92gw+1sxHvqkzxWbU6+uKv4WxVumfX3ptqm+9r0UcYS7DM/fHwHXk/cI5XB4/QeEtxKmjN5g==; 25:acOnrPZsvmK9wXNYGD7fh/+eV0LeSrO8gZ5eFoq5uUGTiK1GYBfVeUeEBtYzxuepvLm7p/Q+M1TJdqYHBJ8wXV2qn6AkMTaLPrC76zIts6GBTk2TBdub5Holw/6Jy+7ZkMOM+nBu3XOFZ7oHw7zSToesQGWno0zIECod9nf6Wd1oezVPNuXxjyuzuyZsbCr9p6DluPjt1kjQ4SLRWL5ViNqmf4yeGyr19Lg57SntAWCgLWKpYmImBZm5xqqT2dOrTfxjCLI8NsFF5H4yQts0zKU7mQSopKWf6E2rBdHlBt9ASEgvDubZqs4XJNpEItw4VYjXHZzJmIpVB0RoM06z9HfzH1s3/D3I74mQqaRRvx/riRW7LMRA8pZzfMG/NZFpMHNQBQdEEe8KB17yGUlIml/8ydxFgLXjJa0ZfMPhLDD09AFFFXmkwXAo0E3co1/1g6REBLNGFvAbS0kkZvtqJSn0f3ELDwUfuIkmJlFokr5/pAsF1AVhXy8RNhhqw78i X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2443; 31:LyziYFzwvf/mSwtaNmAWjxQ6qJpe2zIE8E/4TY5kfuVCK4q27wEEwvxun+XQ53EKalpXKTTnhTD9VKarPJqXCxBjEqQ6YeZTqDKGPiJ4UjyxiIgQuDtvj82VsMYExpTPGnSiycvSErZNYAk899bhq22OJCRMcVaNTVWNvT4B4N8CVQ/gOyKIUCaksCXgefZJHsgSFNqzZ0McNcMupYRvAKIkiQm8cSqUPpxj+v8T/BSVP1J3MAI0hNsitt0kWHXzO5ELDWqX3f99MvkVmmagcQKMzem0vwSRWWWt7kKoYh/NihjqHZ3zH34qQA7VmVdQ; 20:iMuIm8NIqnwdUFj4EJ3xh1ycH5tEsCHDNRYf3eW356G24Tkygu1WNJbbOcZRIBm16Piq/0VcbAiA3lvT16vQeYa6cHISdQsMPmS/pTjK888BasjDe8kxLwRz/2OlH07eq96m4iJc5Y0YDBh3CUCtsYNzZ8GYMZIfey1KbnP6RJW673G+Ij1eUP2+L5J38cWd3k86oRZ3Zb7iFuka+6/YFzGXYrPpGPA1e2w/1UkIy8mkkg8CVHsSOhEQp7nIpqZQrywAK2ERu2xOt6UdyFxD7f05JcSDYp+cBHdzgxDphtZDWCdJpNAZ9sPeLzS7orUbpC71oyvRmDFLZIV4TzoDsDGcDsiQ6ZiSsRrJpIA0KDo2MXQceiqgk0ThXbCf+WbBeFjU9LCIWMS9KKr8AHQl54JTdpZM4leTxVvfVPYZ1oScEvnlgY5NSk0KvDYzkAFV43I3h/ZkUrC8FLTCOnuiDRvWj1KCUTfjqrfqXkuUSD5Zs+UFxGBn00hiXhXI7ktBtrH9nyBBi0tU/E4+5KunBlKq6j+cnSwotSVG7UxL/7/z8CZw1WwsAXVe6Slkiq8qdznz+3bcm4baoGG/2i+tx2LtqBjO4o+26CMol84dRgE= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(102415395)(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123562025)(20161123555025)(20161123558025)(20161123564025)(20161123560025)(6072148); SRVR:CY1PR07MB2443; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2443; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2443; 4:UKo7hHVg4pagsLhFgusGy0PTIywPnCd38EGd2sUKom5/Z0iXY/lpM5+zTVdFvXVkkN+nJiC1riSK5U3b83XlyM5hzQjE0ckMBwx7pOlDxrH2igo65u39BJ3YcHeU5SHZW8AUmfSkdOIgoU8NGMpN5kJP50USlp7rkS7cmMpQbhfk9bIVkKv3cZX4uFmqJpoxQ2tAE9nt83XaGy9qXem0tXObf8tMtMJhE+HRXaFFI+VQFvIsdWV6MoHzRal0MblglX1asFFio3ugPJYVA3CGX/0T8734/Im7jWW5sxTLHXT4weL/peicIgx+J5I/VL+JCCkFQkJfcfkGUKgP5vPPuaVvUfjBYRCXIRajpdzd2vGDoZFQ5aPaJ/B8LCg947TLu+NhirvHdPnNPpLKWVNxQjYpyP5wDcJQAT6CjC+Y3P4YssJjGj3UIuhCpeOqvk/XRAOgzVe/wNm6Ji3VLM0watCs4rnEqg9uEUubKC+zFRr4S2E7XwjSRAckINo66trmIjPEK9Id28Icarjd3Rpu22ajv6CB7Uu5IXyi9zSMPwzNKCdaf1HlVLU+70kL9Tnuqx0fWN9zcbZbqtaQJVrfR4tU94rUztBqAVYokgPMXKUZqYLHMu9If5KsetP+G6j0 X-Forefront-PRVS: 0238AEEDB0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(39450400003)(377424004)(54534003)(4610100001)(36756003)(38730400002)(110136004)(512874002)(6506006)(6512007)(81166006)(103116003)(8676002)(5890100001)(3846002)(568964002)(50226002)(6116002)(53936002)(6486002)(189998001)(25786008)(84326002)(66066001)(305945005)(7736002)(42882006)(6666003)(33646002)(6916009)(50986999)(92566002)(5660300001)(53416004)(42186005)(2906002)(450100001)(2476003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR07MB2443; H:sellcey-dt.caveonetworks.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR07MB2443; 23:V/zQW13C9swo5bKNq4iXszXQ281GaQDwJvbiEImta?= =?us-ascii?Q?4+/13CAYbguqX01kHQpC2j4lDXOc7+iSFz/ervADZiyRRpdCiNk6UxvmqCqb?= =?us-ascii?Q?5mQSt9n2orQ9eG4t3JOCUUTXwzAWKaWYVM3tRGnqMhfTitHVfoahZnC83nzp?= =?us-ascii?Q?ILIKOAWgJRCdGF2vBS7GhZ4czIt3DHgi9O0GFmfThLaCtslNwdVhMR/yf9n0?= =?us-ascii?Q?aIza5l5FLc+9BUsBw6uvDXx4TEXZo28PzCQJFqFKs/U6HSg7P/EkdMz1qW7N?= =?us-ascii?Q?0cMoxjVnKY9TyWBWFTWbscIx9AS3SdtJ6kySWn6/hRmAbwR9L6ZpCkC6csDZ?= =?us-ascii?Q?Zi3X3D47/H/wxOZLx38/V0AUw5lJ6rqe0eNJ07EvpfS2dQCAHJTWjB2dAIme?= =?us-ascii?Q?9c0Pih6ccm2k5KOF6xa37/84tl9cS/OR+rCGNuVs981s9/Y8bAExU/FOpKc9?= =?us-ascii?Q?L1myQbrPwXmf648fQasjcn6tui5VRiNEavd1seUV9k9uedKAkQGajssUsCfK?= =?us-ascii?Q?2mcscb7AuDrauKYjulbtSFf9PWTPg8XlZerI+DB+GJSmk/cHiVhHnMrkPKSE?= =?us-ascii?Q?LUSbJgPq1K9SEL01UlNgckMBK7FvZgvAizsIQ5fANbPf8P6E7W8e1bJHpQm5?= =?us-ascii?Q?oze/Mg2y8DsO4ho7xUUz+hUy+YXlAfSpGx6upAOE78Um+ud11BEw5PSiQLzx?= =?us-ascii?Q?YYOL6v3TyeSp2adCjhTMPtlJNnAZbze/WHbwxVs/lMw/Oam8R2iGf+MOqq2S?= =?us-ascii?Q?9HqwiWXOs1oxPFyWpPskPHF+mKTMAOYSLyptJwUF6w/fHdIskQLgoXOvqH1D?= =?us-ascii?Q?iQP+mNSwCIsNRa5+x1jk9LTS7kOvGYzSNLhz38vDbT6PgKtBMlYPV20Prih0?= =?us-ascii?Q?76vB+uAGRH+Fo50z4gbLSRU759lilx5cu1BY1a8JC63Bm7UxIozsYwSMWOmY?= =?us-ascii?Q?Qggu4qkGmPrH3HdZFL/pdqF7pvgfbXjN2EbwN6zU9YlKpKgdcpnziUFGkbFb?= =?us-ascii?Q?u3eEVBZw4LhVHavm5FvcATAmOkylwGVvjQFyHuqRtkGwQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2443; 6:LpeTuarbzLi4viCtQjQr4G0T00zS+vSwNY7fsrBvPogcmIxgz4OdSj6Y9a/VL/EHdK3qkcmvSp+evxBqrHZiza1oEwxost44wjJYgu7GzKEsfU3+iuLdjaLTyXjcOlf1CwDD3bZkvSjJHFHxKMXoMi8og+1lyfBllcySZrWeiDtQWgA9cS+t+pLjEYrZS3t/M/daHsggYOkaDK45bpMWKHfccLTKu8G9ddJ7E3Co3n58ZBq7+J9YisOn4ZGyKcj1Ap5xn0qTVuGJOAPxa44Yvqp6Yaj5IXSVRjCxYmgTEdwr9S9NGSFt6pXmI1t2UsUTTIda0j/7zFpqzviv0L5nni1wW+rRaSXyjiMvlZ1tC/YtwfUFjwbD83xn7Hv1ii4ECdHpJrPevGfzyWC1MEkPzw==; 5:q5C8xV6g/6QRNNgNT1gz55Tw7oP50QoFv+X/LUTb8k7ylsDYA8IJQds30yQklcTziyTq28NxELwqGAnh6CWBrNrPVl9wZ9I1rNUtfu92ZyNH6vNoPUkWV6Gbje0+gZqejwENWKnVqpC/uZwEt5hxYg==; 24:nHdfR00QgIyzQxmrccAveZiz79lACxjfBMV4xCo/PXaKgnYQ/CYM97ne3TTgqrTsEOis6rga0NiL5uqavrMibcAIwKxkSyaHcGdVLtRUJxo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2443; 7:LO+TJIeyJYOLWuORTZBA0kmhTkn5mGv+zfoSuVYZwDcnUlpGIEOgXiIoMgGdKnsXrV3Bq6VkFCLSwbMb3O++0SMLxw3ROwf9sunB2w0XVcsvPNTRxp8zuGRHVB9IvyKtypMH63zxOr0OWfI7mauAMbwclPuQGDrbxTCsG2j08APiEpjyS/orJtqBQPLSgf24oGQ876OseevsHXaXDiTeKoCPNVXwGt7PBT7/vtDCGtb5zhq7JBqknXZq8/zQIh4KlZrKwSYg7yx+vMi7XO8cJr47Eb4JuzQND9OSiRdw2r7oQzlcOCj5ME0jjKOVkqyLVpHlG6zRi3P10/TtDvTIXg== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2017 22:02:55.3871 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2443 This is the first of two new patches for ILP32 support on aarch64. This one is the gdb changes, the next will be the bfd changes. The standard gdb testsuite run on 64 bit aarch64 executables results in 65 failures (30627 passes), running it on 32 bit aarch64 executables results in 213 failures (30354 passes). I believe most of the new failures are due to two problems.  One is unwinding through signal handlers and the other is accessing thread local data.  I think the thread problem may be due to a version mismatch between the thread_db library that gdb (a 64 bit process) is using and a newer thread_db library that the 32 bit executables being debugged are using and not a problem with the code. I am working on the signal unwinding problem but I was hoping that the part that is already working is sufficiently useful to check in while I work on fixing this problem.  The current code handles the usual gdb functionality of breakpoints, stepping, printing variables, etc. Steve Ellcey sellcey@cavium.com gdb ChangeLog: 2017-03-06  Andrew Pinski       Steve Ellcey       Yao Qi   * aarch64-linux-nat.c (IS_ARM32): New macro. (fetch_gregs_from_thread): Use IS_ARM32 macro. (store_gregs_to_thread): Ditto. (fetch_fpregs_from_thread): Ditto. (store_fpregs_to_thread): Ditto. (ps_get_thread_area): Ditto. (aarch64_linux_siginfo_fixup): Ditto. * aarch64-linux-tdep.c (aarch64_linux_init_abi): Set link map offsets to 32 or 64 bits. * aarch64-tdep.c (aarch64_ilp32_register_type): New function. (aarch64_gdbarch_init): Setup ILP32 support. Make sure the gdbarches have compatible ilp32 flags. Set long and ptr sizes correctly for ilp32. * aarch64-tdep.h (gdbarch_tdep) : New field. gdbserver ChangeLog: 2017-03-06  Andrew Pinski       Steve Ellcey   * linux-aarch64-low.c (aarch64_linux_read_description): Use machine instead of is_elf64 to determine architecture.  Give an error when using 32 bit gdbserver on 64 bit program. diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 0d472e2..0caac7f 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -49,6 +49,9 @@ #define TRAP_HWBKPT 0x0004 #endif +/* Check if we are on arm (as opposed to aarch64). */ +#define IS_ARM32(gdbarch) (gdbarch_bfd_arch_info(gdbarch)->arch == bfd_arch_arm) + /* Per-process data. We don't bind this to a per-inferior registry because of targets like x86 GNU/Linux that need to keep track of processes that aren't bound to any inferior (e.g., fork children, @@ -166,7 +169,7 @@ fetch_gregs_from_thread (struct regcache *regcache) tid = ptid_get_lwp (inferior_ptid); iovec.iov_base = ®s; - if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32) + if (IS_ARM32 (gdbarch)) iovec.iov_len = 18 * 4; else iovec.iov_len = sizeof (regs); @@ -175,7 +178,7 @@ fetch_gregs_from_thread (struct regcache *regcache) if (ret < 0) perror_with_name (_("Unable to fetch general registers.")); - if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32) + if (IS_ARM32 (gdbarch)) aarch32_gp_regcache_supply (regcache, (uint32_t *) regs, 1); else { @@ -203,7 +206,7 @@ store_gregs_to_thread (const struct regcache *regcache) tid = ptid_get_lwp (inferior_ptid); iovec.iov_base = ®s; - if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32) + if (IS_ARM32 (gdbarch)) iovec.iov_len = 18 * 4; else iovec.iov_len = sizeof (regs); @@ -212,7 +215,7 @@ store_gregs_to_thread (const struct regcache *regcache) if (ret < 0) perror_with_name (_("Unable to fetch general registers.")); - if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32) + if (IS_ARM32 (gdbarch)) aarch32_gp_regcache_collect (regcache, (uint32_t *) regs, 1); else { @@ -248,7 +251,7 @@ fetch_fpregs_from_thread (struct regcache *regcache) iovec.iov_base = ®s; - if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32) + if (IS_ARM32 (gdbarch)) { iovec.iov_len = VFP_REGS_SIZE; @@ -295,7 +298,7 @@ store_fpregs_to_thread (const struct regcache *regcache) iovec.iov_base = ®s; - if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32) + if (IS_ARM32 (gdbarch)) { iovec.iov_len = VFP_REGS_SIZE; @@ -328,7 +331,7 @@ store_fpregs_to_thread (const struct regcache *regcache) (char *) ®s.fpcr); } - if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32) + if (IS_ARM32 (gdbarch)) { ret = ptrace (PTRACE_SETREGSET, tid, NT_ARM_VFP, &iovec); if (ret < 0) @@ -460,8 +463,7 @@ ps_err_e ps_get_thread_area (struct ps_prochandle *ph, lwpid_t lwpid, int idx, void **base) { - int is_64bit_p - = (gdbarch_bfd_arch_info (target_gdbarch ())->bits_per_word == 64); + int is_64bit_p = !IS_ARM32 (target_gdbarch ()); return aarch64_ps_get_thread_area (ph, lwpid, idx, base, is_64bit_p); } @@ -517,7 +519,7 @@ aarch64_linux_siginfo_fixup (siginfo_t *native, gdb_byte *inf, int direction) /* Is the inferior 32-bit? If so, then do fixup the siginfo object. */ - if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32) + if (IS_ARM32 (gdbarch)) { if (direction == 0) aarch64_compat_siginfo_from_siginfo ((struct compat_siginfo *) inf, diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index b94ccb2..6d0c3bd 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -1000,8 +1000,12 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) linux_init_abi (info, gdbarch); - set_solib_svr4_fetch_link_map_offsets (gdbarch, - svr4_lp64_fetch_link_map_offsets); + if (tdep->ilp32) + set_solib_svr4_fetch_link_map_offsets (gdbarch, + svr4_ilp32_fetch_link_map_offsets); + else + set_solib_svr4_fetch_link_map_offsets (gdbarch, + svr4_lp64_fetch_link_map_offsets); /* Enable TLS support. */ set_gdbarch_fetch_tls_load_module_address (gdbarch, diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 801c03d..67f1a2e 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -2091,6 +2091,22 @@ aarch64_gen_return_address (struct gdbarch *gdbarch, } +/* Implement the "register_type" gdbarch method. + Adjust the register type of $PC and $SP on ILP32. */ + +static struct type * +aarch64_ilp32_register_type (struct gdbarch *gdbarch, int regnum) +{ + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + gdb_assert (tdep->ilp32); + + if (regnum == AARCH64_SP_REGNUM || regnum == AARCH64_PC_REGNUM) + return builtin_type (gdbarch)->builtin_uint64; + else + return tdesc_register_type (gdbarch, regnum); +} + /* Return the pseudo register name corresponding to register regnum. */ static const char * @@ -2851,6 +2867,10 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) const struct tdesc_feature *feature; int num_regs = 0; int num_pseudo_regs = 0; + bool ilp32 = false; + + if (info.bfd_arch_info->mach == bfd_mach_aarch64_ilp32) + ilp32 = true; /* Ensure we always have a target descriptor. */ if (!tdesc_has_registers (tdesc)) @@ -2908,6 +2928,9 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) best_arch != NULL; best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info)) { + /* ILP32 and LP64 are incompatible. */ + if (gdbarch_tdep (arches->gdbarch)->ilp32 != ilp32) + continue; /* Found a match. */ break; } @@ -2926,6 +2949,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) tdep->lowest_pc = 0x20; tdep->jb_pc = -1; /* Longjump support not enabled by default. */ tdep->jb_elt_size = 8; + tdep->ilp32 = ilp32; set_gdbarch_push_dummy_call (gdbarch, aarch64_push_dummy_call); set_gdbarch_frame_align (gdbarch, aarch64_frame_align); @@ -2968,9 +2992,9 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_float_bit (gdbarch, 32); set_gdbarch_double_bit (gdbarch, 64); set_gdbarch_long_double_bit (gdbarch, 128); - set_gdbarch_long_bit (gdbarch, 64); + set_gdbarch_long_bit (gdbarch, ilp32 ? 32 : 64); set_gdbarch_long_long_bit (gdbarch, 64); - set_gdbarch_ptr_bit (gdbarch, 64); + set_gdbarch_ptr_bit (gdbarch, ilp32 ? 32 : 64); set_gdbarch_char_signed (gdbarch, 0); set_gdbarch_float_format (gdbarch, floatformats_ieee_single); set_gdbarch_double_format (gdbarch, floatformats_ieee_double); @@ -3012,6 +3036,13 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) tdesc_use_registers (gdbarch, tdesc, tdesc_data); + if (ilp32) + { + /* Override tdesc_register_type to adjust the types of $PC and + $SP in ILP32. */ + set_gdbarch_register_type (gdbarch, aarch64_ilp32_register_type); + } + /* Add standard register aliases. */ for (i = 0; i < ARRAY_SIZE (aarch64_register_aliases); i++) user_reg_add (gdbarch, aarch64_register_aliases[i].name, diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h index 85c6a97..87d36b6 100644 --- a/gdb/aarch64-tdep.h +++ b/gdb/aarch64-tdep.h @@ -97,6 +97,9 @@ struct gdbarch_tdep /* syscall record. */ int (*aarch64_syscall_record) (struct regcache *regcache, unsigned long svc_number); + /* If this is ILP32 or LP64. */ + bool ilp32; + }; extern struct target_desc *tdesc_aarch64; diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c index 334310b..e31d5c5 100644 --- a/gdb/gdbserver/linux-aarch64-low.c +++ b/gdb/gdbserver/linux-aarch64-low.c @@ -484,7 +484,12 @@ aarch64_linux_read_description (void) is_elf64 = linux_pid_exe_is_elf_64_file (tid, &machine); - if (is_elf64) + /* There are problems with ptrace when gdbserver is 32 bits and the + program being debugged is 64 bits. */ + if (sizeof (void *) == 4 && is_elf64) + error (_("Can't debug 64-bit process with 32-bit GDBserver")); + + if (machine == EM_AARCH64) return tdesc_aarch64; else return tdesc_arm_with_neon;