From patchwork Mon Dec 23 17:34:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 182414 Delivered-To: patch@linaro.org Received: by 2002:a92:a146:0:0:0:0:0 with SMTP id v67csp699986ili; Mon, 23 Dec 2019 09:34:51 -0800 (PST) X-Google-Smtp-Source: APXvYqxMUt6AI6f6BAD0btQ3Mfo28DeDKMsuN89QlCwqeQKP83Is+tslI9RM0sVu3X47XbUCBdMr X-Received: by 2002:a9d:12f1:: with SMTP id g104mr34880383otg.334.1577122491410; Mon, 23 Dec 2019 09:34:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577122491; cv=none; d=google.com; s=arc-20160816; b=lS+Etfh0O0PsEV0DF9iAIj7k9co/y7XZ4V7scvdcyHXHYfjR4WB6fbsJvffaixXun+ niI8CX/BMmDy0YdP45tTsMczSx9Lt0wb4HRQ479p/lGDlDyKn4Ttfz9m3v8TVyWQ2jza +Iun0yuavWiw6zK3V0TWA4bMliHg8ASYNb07WfpTDlFKI2EPdVciL1IBsjzeTSY8F2vE O031haRVYSgt26sq8NMY/tqkPF8wXxa66TcNxrRGKZKe2/8tjxukAPqW9mD5qpQP7dZT ipztHbluynGvQQZyl2IsMvz6bI3mFD5IStpKP+7VRazDhdcKZvC4xQRkDCbFpFqcQPtR aAVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:dkim-signature:delivered-to:sender :list-help:list-post:list-archive:list-subscribe:list-unsubscribe :list-id:precedence:mailing-list:dkim-signature:domainkey-signature; bh=fsd7TbQdEaEQGzNJsjBGdMJCBoc0FV1CbEYyjkMIUHU=; b=HcK6SCopKJE6qjY0+VcO5WSle+gdwZGOX64mhEyyM23u37kAj19L1OwKZ4f6cKH+mH uRRpknLdzQ4+OoD+S872HCD6HnW03/SDhNEloKD6YGeyl7FLbyaJ5vJC1eAlFf2i207N 6Xi8mrM9VWrsKodWYo1w4X1uCiB+HVlfby8vAGjot/Uilu6CFxhtR5yi0gHKZ+g4M0Hi d2HiURQKbR56534JAPImp8yliAX39p13tV2FT8oMVmVJ4sMJUY0nXdsAB2fH4+pclai+ NpNir1Pmo/+7ArliZ594g7U0tCKwNQ/DqJ7woMa1A+5/lFvuvNBgL0TO12qZ3mv6lXlb mQWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=j4m1UOZS; dkim=pass header.i=@linaro.org header.s=google header.b=YoZnPaxB; spf=pass (google.com: domain of gdb-patches-return-162579-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gdb-patches-return-162579-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id c21si5231919otj.260.2019.12.23.09.34.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Dec 2019 09:34:51 -0800 (PST) Received-SPF: pass (google.com: domain of gdb-patches-return-162579-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=j4m1UOZS; dkim=pass header.i=@linaro.org header.s=google header.b=YoZnPaxB; spf=pass (google.com: domain of gdb-patches-return-162579-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gdb-patches-return-162579-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=MCs5er1E5QgwLMgoVLtNtKlju70l3Nsxt14qjn9tlzT3P6ZVID8Si PoE6vkUC7F4nT5lu2YFoJ8+O1UFEHVqbQu6UkdXcaDwquWBBx1MSqgX5mdJePXQZ GY9cGi6rVBnn7BgIbRChmi5ZjGU0TGzFZovyOkiHpEe4QkOSH9d3Zk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=/3TAWZ00rpcQEFCa5s0PZZY/oN0=; b=j4m1UOZSzIWsGOKxqrXCZGPUtujQ 4GYMKZbLfarfaTRAmT6L8Tujyn3KFpL3hDrs6ma18GlHr/pCzYzt3UZ/1bGBwokq fztZrmLM47HlJ9cLC0GCOkMSAYb4oNO2S6JldpWfP9EDEOsod4TJtoaMixRdNM9B m55nWSfEHHbjjjM= Received: (qmail 83608 invoked by alias); 23 Dec 2019 17:34:45 -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 83599 invoked by uid 89); 23 Dec 2019 17:34:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=luis, Luis, H*p:D*org, ADDR X-HELO: mail-pg1-f169.google.com Received: from mail-pg1-f169.google.com (HELO mail-pg1-f169.google.com) (209.85.215.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Dec 2019 17:34:42 +0000 Received: by mail-pg1-f169.google.com with SMTP id s64so9129256pgb.9 for ; Mon, 23 Dec 2019 09:34:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=fsd7TbQdEaEQGzNJsjBGdMJCBoc0FV1CbEYyjkMIUHU=; b=YoZnPaxBZfq4QTVj6drnEPmdogPq5aeOyrHUBWa930QCFcVj33L4pJ59dQfFvSTmJG 4O6r5UmPBphcBQacpnT2z5f6LRoyQlXdoEdP4pf6sJ1xMrnr+jK5Cw3+x3Il/rD9fdZC M8BSXQ5QMkUfBpnGjbSE69LbA8G11onVwQanmA6gSdehBvYb6s0Fc2TGynYwcLKgDiSt QXtx33pfviByHVZLta8n43PGiH0Q+kYcir61T804ON/UMtiWvpjI1pNdSA6pM2VWZjLm RMxnzs4PWtk4Lp0v9Cnl2zUooabhWLTeOqZH8zITCkL1vMxpU29ZQyhDpzQLiZoA03T3 8hvA== Return-Path: Received: from localhost.localdomain ([2804:18:872:754:e0aa:310d:b742:862f]) by smtp.gmail.com with ESMTPSA id w20sm15645869pfi.86.2019.12.23.09.34.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2019 09:34:38 -0800 (PST) From: Luis Machado To: gdb-patches@sourceware.org Subject: [PATCH] [AArch64] Recognize more program breakpoint patterns Date: Mon, 23 Dec 2019 14:34:32 -0300 Message-Id: <20191223173432.16955-1-luis.machado@linaro.org> X-IsSubscribed: yes It was reported to me that program breakpoints (permanent ones inserted into the code itself) other than the one GDB uses for AArch64 (0xd4200000) do not generate visible stops when continuing, and GDB will continue spinning infinitely. This happens because GDB, upon hitting one of those program breakpoints, thinks the SIGTRAP came from a delayed breakpoint hit... (gdb) x/i $pc => 0x4005c0 : brk #0x90f (gdb) c Continuing. infrun: clear_proceed_status_thread (process 14198) infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT) infrun: proceed: resuming process 14198 infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0 infrun: infrun_async(1) infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 14198.14198.0 [process 14198], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: stop_pc = 0x4005c0 infrun: delayed software breakpoint trap, ignoring infrun: no stepping, continue infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 14198.14198.0 [process 14198], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: stop_pc = 0x4005c0 infrun: delayed software breakpoint trap, ignoring infrun: no stepping, continue infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 14198.14198.0 [process 14198], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: stop_pc = 0x4005c0 infrun: delayed software breakpoint trap, ignoring infrun: no stepping, continue infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 14198.14198.0 [process 14198], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: stop_pc = 0x4005c0 infrun: delayed software breakpoint trap, ignoring infrun: no stepping, continue infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 14198.14198.0 [process 14198], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP ... ... which is not the case. If the program breakpoint is one GDB recognizes, then it will stop when it hits it. (gdb) x/i $pc => 0x4005c0 : brk #0x0 (gdb) c Continuing. infrun: clear_proceed_status_thread (process 14193) infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT) infrun: proceed: resuming process 14193 infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14193] at 0x4005c0 infrun: infrun_async(1) infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 14193.14193.0 [process 14193], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: stop_pc = 0x4005c0 infrun: random signal (GDB_SIGNAL_TRAP) infrun: stop_waiting infrun: stop_all_threads infrun: stop_all_threads, pass=0, iterations=0 infrun: process 14193 not executing infrun: stop_all_threads, pass=1, iterations=1 infrun: process 14193 not executing infrun: stop_all_threads done Program received signal SIGTRAP, Trace/breakpoint trap. problem_function () at brk_0.c:7 7 asm("brk %0\n\t" ::"n"(0x0)); infrun: infrun_async(0) Otherwise GDB will keep trying to resume the inferior and will keep seeing the SIGTRAP's, without stopping. To the user it appears GDB has gone into an infinite loop, interruptible only by Ctrl-C. Also, windbg seems to use a different variation of AArch64 breakpoint compared to GDB. This causes problems when debugging Windows on ARM binaries, when program breakpoints are being used. The proposed patch creates a new gdbarch method (gdbarch_insn_is_breakpoint) that tells GDB whether the underlying instruction is a breakpoint instruction or not. This is more general than only checking for the instruction GDB uses as breakpoint. The existing logic is still preserved for targets that do not implement this new gdbarch method. The end result is like so: (gdb) x/i $pc => 0x4005c0 : brk #0x90f (gdb) c Continuing. infrun: clear_proceed_status_thread (process 16417) infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT) infrun: proceed: resuming process 16417 infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 16417] at 0x4005c0 infrun: infrun_async(1) infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 16417.16417.0 [process 16417], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: stop_pc = 0x4005c0 infrun: random signal (GDB_SIGNAL_TRAP) infrun: stop_waiting infrun: stop_all_threads infrun: stop_all_threads, pass=0, iterations=0 infrun: process 16417 not executing infrun: stop_all_threads, pass=1, iterations=1 infrun: process 16417 not executing infrun: stop_all_threads done Program received signal SIGTRAP, Trace/breakpoint trap. problem_function () at brk.c:7 7 asm("brk %0\n\t" ::"n"(0x900 + 0xf)); infrun: infrun_async(0) Does this change look ok? gdb/ChangeLog: 2019-12-23 Luis Machado * aarch64-tdep.c (BRK_INSN_MASK): Define to 0xd4200000. (aarch64_insn_is_breakpoint): New function. (aarch64_gdbarch_init): Set gdbarch_insn_is_breakpoint hook. * arch-utils.c (default_insn_is_breakpoint): New function. * arch-utils.h (default_insn_is_breakpoint): New prototype. * breakpoint.c (program_breakpoint_here): Updated to use gdbarch_insn_is_breakpoint. Update documentation to clarify behavior. * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * gdbarch.sh (gdbarch_insn_is_breakpoint): New method. Change-Id: I96eb27151442f435560a58c87eac48b0f68432bc --- gdb/aarch64-tdep.c | 25 +++++++++++++++++++++++++ gdb/arch-utils.c | 7 +++++++ gdb/arch-utils.h | 3 +++ gdb/breakpoint.c | 19 ++++++++++++++----- gdb/gdbarch.c | 23 +++++++++++++++++++++++ gdb/gdbarch.h | 7 +++++++ gdb/gdbarch.sh | 4 ++++ 7 files changed, 83 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 1d5fb2001d..c69361d4ea 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -1201,6 +1201,28 @@ aarch64_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op, return false; } +#define BRK_INSN_MASK 0xd4200000 + +/* Implementation of gdbarch_insn_is_breakpoint for aarch64. */ + +static bool +aarch64_insn_is_breakpoint (gdbarch *gdbarch, + const gdb_byte *insn, + unsigned int insn_size) +{ + gdb_assert (insn != nullptr); + + uint32_t i; + + i = (uint32_t) extract_unsigned_integer (insn, insn_size, + gdbarch_byte_order (gdbarch)); + + /* Check if INSN is a BRK instruction pattern. There are multiple choices + of such instructions with different immediate values. Different OS' may + use a different variation, but they have the same outcome. */ + return (i & BRK_INSN_MASK) == BRK_INSN_MASK; +} + /* When arguments must be pushed onto the stack, they go on in reverse order. The code below implements a FILO (stack) to do this. */ @@ -3357,6 +3379,9 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_execute_dwarf_cfa_vendor_op (gdbarch, aarch64_execute_dwarf_cfa_vendor_op); + /* Permanent/Program breakpoint handling. */ + set_gdbarch_insn_is_breakpoint (gdbarch, aarch64_insn_is_breakpoint); + /* Add some default predicates. */ frame_unwind_append_unwinder (gdbarch, &aarch64_stub_unwind); dwarf2_append_unwinders (gdbarch); diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index a1a003f91f..99c9f281be 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -876,6 +876,13 @@ int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr) return 0; } +bool default_insn_is_breakpoint (struct gdbarch *gdbarch, + const gdb_byte *insn, + unsigned int insn_size) +{ + return false; +} + void default_skip_permanent_breakpoint (struct regcache *regcache) { diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h index 48ff3bb9a1..77ffe8190c 100644 --- a/gdb/arch-utils.h +++ b/gdb/arch-utils.h @@ -227,6 +227,9 @@ extern int default_return_in_first_hidden_param_p (struct gdbarch *, extern int default_insn_is_call (struct gdbarch *, CORE_ADDR); extern int default_insn_is_ret (struct gdbarch *, CORE_ADDR); extern int default_insn_is_jump (struct gdbarch *, CORE_ADDR); +extern bool default_insn_is_breakpoint (struct gdbarch *gdbarch, + const gdb_byte *insn, + unsigned int insn_size); /* Do-nothing version of vsyscall_range. Returns false. */ diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 904abda8db..ffb7f7f8be 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8599,14 +8599,23 @@ program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) target_mem = (gdb_byte *) alloca (len); /* Enable the automatic memory restoration from breakpoints while - we read the memory. Otherwise we could say about our temporary - breakpoints they are permanent. */ + we read the memory. Otherwise we may find temporary breakpoints, ones + inserted by GDB, and flag them as permanent breakpoints. */ scoped_restore restore_memory = make_scoped_restore_show_memory_breakpoints (0); - if (target_read_memory (address, target_mem, len) == 0 - && memcmp (target_mem, bpoint, len) == 0) - return 1; + if (target_read_memory (address, target_mem, len) == 0) + { + /* Check if this is a breakpoint instruction for this architecture, + including ones used by GDB. + + Some architectures have more than one possible breakpoint + instruction, but GDB does not use all of them. We should detect those + as well. */ + if (gdbarch_insn_is_breakpoint (gdbarch, target_mem, len) + || memcmp (target_mem, bpoint, len) == 0) + return 1; + } return 0; } diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 59c97da985..9e21ba7eca 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -345,6 +345,7 @@ struct gdbarch gdbarch_insn_is_call_ftype *insn_is_call; gdbarch_insn_is_ret_ftype *insn_is_ret; gdbarch_insn_is_jump_ftype *insn_is_jump; + gdbarch_insn_is_breakpoint_ftype *insn_is_breakpoint; gdbarch_auxv_parse_ftype *auxv_parse; gdbarch_print_auxv_entry_ftype *print_auxv_entry; gdbarch_vsyscall_range_ftype *vsyscall_range; @@ -464,6 +465,7 @@ gdbarch_alloc (const struct gdbarch_info *info, gdbarch->insn_is_call = default_insn_is_call; gdbarch->insn_is_ret = default_insn_is_ret; gdbarch->insn_is_jump = default_insn_is_jump; + gdbarch->insn_is_breakpoint = default_insn_is_breakpoint; gdbarch->print_auxv_entry = default_print_auxv_entry; gdbarch->vsyscall_range = default_vsyscall_range; gdbarch->infcall_mmap = default_infcall_mmap; @@ -708,6 +710,7 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of insn_is_call, invalid_p == 0 */ /* Skip verify of insn_is_ret, invalid_p == 0 */ /* Skip verify of insn_is_jump, invalid_p == 0 */ + /* Skip verify of insn_is_breakpoint, invalid_p == 0 */ /* Skip verify of auxv_parse, has predicate. */ /* Skip verify of print_auxv_entry, invalid_p == 0 */ /* Skip verify of vsyscall_range, invalid_p == 0 */ @@ -1137,6 +1140,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) fprintf_unfiltered (file, "gdbarch_dump: inner_than = <%s>\n", host_address_to_string (gdbarch->inner_than)); + fprintf_unfiltered (file, + "gdbarch_dump: insn_is_breakpoint = <%s>\n", + host_address_to_string (gdbarch->insn_is_breakpoint)); fprintf_unfiltered (file, "gdbarch_dump: insn_is_call = <%s>\n", host_address_to_string (gdbarch->insn_is_call)); @@ -4928,6 +4934,23 @@ set_gdbarch_insn_is_jump (struct gdbarch *gdbarch, gdbarch->insn_is_jump = insn_is_jump; } +bool +gdbarch_insn_is_breakpoint (struct gdbarch *gdbarch, const gdb_byte *insn, unsigned int insn_size) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->insn_is_breakpoint != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_insn_is_breakpoint called\n"); + return gdbarch->insn_is_breakpoint (gdbarch, insn, insn_size); +} + +void +set_gdbarch_insn_is_breakpoint (struct gdbarch *gdbarch, + gdbarch_insn_is_breakpoint_ftype insn_is_breakpoint) +{ + gdbarch->insn_is_breakpoint = insn_is_breakpoint; +} + int gdbarch_auxv_parse_p (struct gdbarch *gdbarch) { diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index 78e05ecdcb..d94950b8f2 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -1545,6 +1545,13 @@ typedef int (gdbarch_insn_is_jump_ftype) (struct gdbarch *gdbarch, CORE_ADDR add extern int gdbarch_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr); extern void set_gdbarch_insn_is_jump (struct gdbarch *gdbarch, gdbarch_insn_is_jump_ftype *insn_is_jump); +/* Return true if INSN of size INSN_SIZE acts like a permanent breakpoint and + false otherwise. */ + +typedef bool (gdbarch_insn_is_breakpoint_ftype) (struct gdbarch *gdbarch, const gdb_byte *insn, unsigned int insn_size); +extern bool gdbarch_insn_is_breakpoint (struct gdbarch *gdbarch, const gdb_byte *insn, unsigned int insn_size); +extern void set_gdbarch_insn_is_breakpoint (struct gdbarch *gdbarch, gdbarch_insn_is_breakpoint_ftype *insn_is_breakpoint); + /* Read one auxv entry from *READPTR, not reading locations >= ENDPTR. Return 0 if *READPTR is already at the end of the buffer. Return -1 if there is insufficient buffer for a whole entry. diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh index 331eb39278..dbf31ee8ae 100755 --- a/gdb/gdbarch.sh +++ b/gdb/gdbarch.sh @@ -1152,6 +1152,10 @@ m;int;insn_is_ret;CORE_ADDR addr;addr;;default_insn_is_ret;;0 # Return non-zero if the instruction at ADDR is a jump; zero otherwise. m;int;insn_is_jump;CORE_ADDR addr;addr;;default_insn_is_jump;;0 +# Return true if INSN of size INSN_SIZE acts like a permanent breakpoint and +# false otherwise. +m;bool;insn_is_breakpoint;const gdb_byte *insn, unsigned int insn_size;insn, insn_size;;default_insn_is_breakpoint;;0 + # Read one auxv entry from *READPTR, not reading locations >= ENDPTR. # Return 0 if *READPTR is already at the end of the buffer. # Return -1 if there is insufficient buffer for a whole entry. From patchwork Mon Jan 13 17:03:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 182804 Delivered-To: patch@linaro.org Received: by 2002:ac9:44c4:0:0:0:0:0 with SMTP id t4csp4543748och; Mon, 13 Jan 2020 09:21:15 -0800 (PST) X-Google-Smtp-Source: APXvYqwkMd+RDyonNMAq/eb4S0y/JPdnoUDHm6R/WmAVmKf4Y9KKkMoMob2weiXUHIGy4JQsLt0y X-Received: by 2002:aca:c786:: with SMTP id x128mr12876102oif.2.1578935025901; Mon, 13 Jan 2020 09:03:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578935025; cv=none; d=google.com; s=arc-20160816; b=SaC42iCPEkWDmkZM8sz57CTphj30rvcMcn1HPFXn6VyhYigjueq4PA0+9r0m2U6ONm 3datUWrLDmChfKB6Gf89g5NC86Sn+zu3JcmhhGqPQ2htUEodcehXBRqR5uejs0ChyvsN efWCOpXizFnFe923PPBwFMMT0YxYt/kTDqZOMehaeLnOrZCBRSDb/We8CVolCrDGjkh1 VAZfAvc5bVjYiCHuXb2NjJA2ny/TW0XccvUNzVoNY4DYErCeCdsDv9aaTRCBCLv84B41 lpA6BvWVDUZDzejge6ZL9LT30giZsE8tR/eTrqYHkNlKdf7tCYNyhW3iNsJiBKrWVdqZ M5vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=WOPh4DRQhh8T7Yhxqxd1FwDs7xn3TNs1RgiDJMiBFls=; b=vqkGKZ9NtM588gXIxaSs/dFiA+q42vQNtUhg3xD9zIQE1l4+HntIK7Xz+ICboX9+bD BFQXb9RJKob7HOK5CqknBuKEDQweNTFtOBUGgKnrdScDrJghjeCo18dnsqjhFvY4oHjK GdUPh1fmk8F/aiIoo0rx3d0LFld6GNM+v2ixkmsJ2liBvf2bdbn76pRMhXIFhanxhSGu PuWCwX61T02BbUDK5Rg4PdoQZ3n8CDyMyxeOno2zm6BXQA2sM36me5gxyn+qkXJ6btnG eelvS2w5qug0ln0W1QkV20Kn1asp4/r0qT5klpJDsr2BjZ77YQ16hFba+VEKK++ssz7u 7zuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=veyfOhzK; dkim=pass header.i=@linaro.org header.s=google header.b="vBlj/jFP"; spf=pass (google.com: domain of gdb-patches-return-163017-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gdb-patches-return-163017-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id y22si6936893oti.269.2020.01.13.09.03.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Jan 2020 09:03:45 -0800 (PST) Received-SPF: pass (google.com: domain of gdb-patches-return-163017-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=veyfOhzK; dkim=pass header.i=@linaro.org header.s=google header.b="vBlj/jFP"; spf=pass (google.com: domain of gdb-patches-return-163017-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gdb-patches-return-163017-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=fnqsqH1+u+kl5ly7VshKf2ww0Y8asgb NwSls3HUkhRHTwgHIzq2uqRbqSpxyeEdOKzUTsoZPIW/r2/++fCVxc8eT/xoTWBQ QxFeRETDt4lgUnUUBMmG5ozSAkfNLa3JlBBqbahTNRqrjDCmpebQcMkD5TwoXgU6 wxEg0ejb60cA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=g4NngKnGkpzgpzddPVJlwQYiXdg=; b=veyfO hzKzl5nOgqjgNz6wE0YSjN1eE/bTA5WQAVKcrkGpnVHcvCGl90t42jbuwLVETq1x YCa5caTMqvKYV5YgpdNrp7BpA4DEAVHkGYJvNTBWN2FlwsvyVANaTf4VC6uT0Emu nuak+3swyX+NrKtTMJNWa/m61mAK3GgjnbUeJU= Received: (qmail 10151 invoked by alias); 13 Jan 2020 17:03:35 -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 10108 invoked by uid 89); 13 Jan 2020 17:03:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=Trace, exercises X-HELO: mail-qk1-f179.google.com Received: from mail-qk1-f179.google.com (HELO mail-qk1-f179.google.com) (209.85.222.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 13 Jan 2020 17:03:33 +0000 Received: by mail-qk1-f179.google.com with SMTP id r14so9116957qke.13 for ; Mon, 13 Jan 2020 09:03:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WOPh4DRQhh8T7Yhxqxd1FwDs7xn3TNs1RgiDJMiBFls=; b=vBlj/jFPY17+SyZ2dbCuEV2SpZS0/2jaKNp92DeLn5K6p4EvxIhuN8L7PAiB2SiN7z x7shqlOvyFdRbnnMBg2IZDb9NgvernikjEaOMXYCowcuCYsSn8r3ythYZpRkcTl0yNGw 6cSDBJUb483gdx55Hb0cWdTFODl9p6s+dWrW2tsmYIv/O4gm9ewy6AqIJ+vVffcDcZC/ o6ODiQFiEr6YuIAc31UDYbSLfUscad95hzQcsXFGdtD8YY/fkN8/AUduLK2imf7DNyFW 9JhB5qKWH02i+QSPPDXD0K3xn8JqcNSSzDS1Qven3T8Uk40PYhSA41j7Fkdu7N+3rZTK MVsg== Return-Path: Received: from localhost.localdomain ([179.183.9.215]) by smtp.gmail.com with ESMTPSA id g18sm5252703qki.13.2020.01.13.09.03.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 09:03:30 -0800 (PST) From: Luis Machado To: gdb-patches@sourceware.org Cc: alan.hayward@arm.com, tankut.baris.aktemur@intel.com Subject: [PATCH 2/2] [AArch64] Test handling of additional brk instruction patterns Date: Mon, 13 Jan 2020 14:03:18 -0300 Message-Id: <20200113170318.6335-2-luis.machado@linaro.org> In-Reply-To: <20200113170318.6335-1-luis.machado@linaro.org> References: <20191223173432.16955-1-luis.machado@linaro.org> <20200113170318.6335-1-luis.machado@linaro.org> X-IsSubscribed: yes This test exercises the previous patch's code and makes sure GDB can properly get a SIGTRAP from various brk instruction patterns. GDB needs to be able to see the program exiting normally. If GDB doesn't support the additional brk instructions, we will see timeouts. We bail out with the first timeout since we won't be able to step through the program breakpoint anyway, so it is no use carrying on. gdb/testsuite/ChangeLog: 2020-01-13 Luis Machado * gdb.arch/aarch64-brk-patterns.c: New source file. * gdb.arch/aarch64-brk-patterns.exp: New test. --- gdb/testsuite/gdb.arch/aarch64-brk-patterns.c | 30 +++++++++ .../gdb.arch/aarch64-brk-patterns.exp | 67 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 gdb/testsuite/gdb.arch/aarch64-brk-patterns.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-brk-patterns.exp -- 2.17.1 diff --git a/gdb/testsuite/gdb.arch/aarch64-brk-patterns.c b/gdb/testsuite/gdb.arch/aarch64-brk-patterns.c new file mode 100644 index 0000000000..ccf9a35a94 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-brk-patterns.c @@ -0,0 +1,30 @@ +/* This file is part of GDB, the GNU debugger. + + Copyright 2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int main(void) +{ + /* Dummy instruction just so GDB doesn't stop at the first breakpoint + instruction. */ + __asm __volatile ("nop\n\t"); + + /* Multiple BRK instruction patterns. */ + __asm __volatile ("brk %0\n\t" ::"n"(0x0)); + __asm __volatile ("brk %0\n\t" ::"n"(0x900 + 0xf)); + __asm __volatile ("brk %0\n\t" ::"n"(0xf000)); + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/aarch64-brk-patterns.exp b/gdb/testsuite/gdb.arch/aarch64-brk-patterns.exp new file mode 100644 index 0000000000..3532a0df95 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-brk-patterns.exp @@ -0,0 +1,67 @@ +# Copyright 2020 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# This file is part of the gdb testsuite. + +# Test if GDB stops at various BRK instruction patterns inserted into +# the code. + +if {![is_aarch64_target]} { + verbose "Skipping ${gdb_test_file_name}." + return +} + +standard_testfile +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { + return -1 +} + +if ![runto_main] { + untested "could not run to main" + return -1 +} + +set keep_going 1 +set count 0 +set old_timeout $timeout +set timeout 10 + +while { $keep_going } { + + set test "brk instruction $count causes SIGTRAP" + + # Continue to next program breakpoint instruction. + gdb_test_multiple "continue" $test { + -re "Program received signal SIGTRAP, Trace/breakpoint trap.*$gdb_prompt $" { + pass $test + + # Insert a breakpoint at the program breakpoint instruction so GDB + # can step over it. + gdb_test "break" \ + "Breakpoint $decimal at $hex: file .*$srcfile, line $decimal.*" \ + "insert breakpoint at brk instruction $count" + } + -re "exited normally.*$gdb_prompt $" { + set keep_going 0 + } + timeout { + fail $test + set keep_going 0 + } + } + set count [expr "$count + 1"] +} + +set timeout $old_timeout