From patchwork Wed Jan 15 11:51:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 182839 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp6783752ile; Wed, 15 Jan 2020 03:52:12 -0800 (PST) X-Google-Smtp-Source: APXvYqxs9AvFeA2iv2bkLlbcX591vaWovxM5KXfOl8lx9bmVbQs1o0/mot/gRcpl6Fn45YL8oK3o X-Received: by 2002:aca:ba46:: with SMTP id k67mr21138044oif.38.1579089132859; Wed, 15 Jan 2020 03:52:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579089132; cv=none; d=google.com; s=arc-20160816; b=pJQbzD9XD8uRf+EgfuAFEdyDqUl8uhZPqwxsM0GVdRV/DcHMyQawn9sm0MWVg46HAl 6p48pZl/suVb/wTUKT2emdq4eBySplZ6l4iruaMWnTzyx89UdA8AglFfPXzXTUIqu50S WtAyoqiOPy8Any1+vx0Zz+kx9V6Q2o9jsHJWEL427LHCNBFCk6DwOIxPabTd+J5qwZKx 1pSR8Y5ojkJD5+cTGJ9uACyCx6eYJhCntF49XDV+sgVwV0GsrD6u9CdNnDwrBUvv3i5x nVyf5v4wG/C8X6+KzMRz9AHc5TEycTDScNkVnKXUFKC1V8VpwYVSZXZoguFQPXWxx+d0 kY+w== 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=cAAT8Ccqlww5haqLtbwbjUv7Lf3coKHV4oiRzATxr4k=; b=bPEP84RK7vfYTocVC5/UFdN5Erq4U3CiGaflzATGf0Z5kkg50yt75uZO6H5DzQilHz gDf+4RtAbvKclK4VR731/Ef//jR5Zti7E6znk+nKOsA6Q8yv81Lijr096MfhVY4RIiDv WLYrPXZwqyEntIG0/2M/YWr86m0DYFtmvSIFVITUeiN8C4BHHsPVRNm3rCdv4fMuTYNM aCCjLAnciYdu6aAw9I685Ku3+s4VJP4jRsf6Fb+v5mCaqeS8hM0pYDUzMvuE/afkPTuH SNr3lTd69bw82qRevo8LMyrcWj33j1O/8BwRihFZLLVd0EsrN1ycYdL4/F1H29hSFppO au5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=nOUiO5+P; dkim=pass header.i=@linaro.org header.s=google header.b="jFMe/56u"; spf=pass (google.com: domain of gdb-patches-return-163100-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gdb-patches-return-163100-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 u21si9282640oic.263.2020.01.15.03.52.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jan 2020 03:52:12 -0800 (PST) Received-SPF: pass (google.com: domain of gdb-patches-return-163100-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=nOUiO5+P; dkim=pass header.i=@linaro.org header.s=google header.b="jFMe/56u"; spf=pass (google.com: domain of gdb-patches-return-163100-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gdb-patches-return-163100-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=eXBbe8tmEeBl0g87I58bQfuvCuxYp91 PGeBLz/eRmEePJh+xEGl1nDoMyYbOjlt5NDPC6xsCRyMM0dCPdaBzshMfsm8uN0M hCs2XI6liKoZ0hlWjZxScim1Z8pZFbOqTHv3RRT3ZPBtEpkLDJ0qsA1qpllQ+I/e kiLWI30KDZto= 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=wEPDESl8Wn+NPYy3RCA2cHjkOnM=; b=nOUiO 5+P69zLiHRJnkeYjOmFHjiGFYX7rXVlk8OKJifGlY8CjTeSBef/oz9pQJeWwrFP/ N2oqLAUNsL4GWPIlvO9FLUTd2JIZbgjogJ39U0KEkX22no37vgnwdbNBTEyQddjC jsYBliep7UEHJineNghC5KYS7JH+BmN5JYWogY= Received: (qmail 65714 invoked by alias); 15 Jan 2020 11:52:03 -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 65666 invoked by uid 89); 15 Jan 2020 11:52:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.0 required=5.0 tests=AWL, 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= X-HELO: mail-qk1-f170.google.com Received: from mail-qk1-f170.google.com (HELO mail-qk1-f170.google.com) (209.85.222.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Jan 2020 11:51:53 +0000 Received: by mail-qk1-f170.google.com with SMTP id c16so15313628qko.6 for ; Wed, 15 Jan 2020 03:51:52 -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=cAAT8Ccqlww5haqLtbwbjUv7Lf3coKHV4oiRzATxr4k=; b=jFMe/56uGwbWPDjPKI8uEys+5A7dc260SdHzK1sZSACxDpas6qzvwzG11P3MLEAlDe 728WsO2QUcYFBkMjVeCybczf8PCvN0DovTqP4b1QtAZwaZes98UFXxd0jcYUjWoNDeOj jGGEoabrt2VpCH7hVndgOv2buCBjabsaUEZHCdZCS3VZc9V5H3OZ6yyIDsNrbJcxfglH +GV3eh8nd3hNI5yZDc40Ro2guzKyr8u1heCfgFMkEGRozqaGeFV48Jjw7ctA2x7K9uec 8vXN/QweBARDtf0QYF2rcpaT00RCQIeVK03jd1PtqfKMprVB+w7/bR+sTl7rgZy4hAO1 b8fw== Return-Path: Received: from localhost.localdomain ([179.177.239.131]) by smtp.gmail.com with ESMTPSA id k14sm8231592qki.66.2020.01.15.03.51.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2020 03:51:50 -0800 (PST) From: Luis Machado To: gdb-patches@sourceware.org Cc: simark@simark.ca, tankut.baris.aktemur@intel.com, alan.hayward@arm.com Subject: [PATCH 1/2, v3] [AArch64] Recognize more program breakpoint patterns Date: Wed, 15 Jan 2020 08:51:36 -0300 Message-Id: <20200115115137.17771-2-luis.machado@linaro.org> In-Reply-To: <20200115115137.17771-1-luis.machado@linaro.org> References: <20200115115137.17771-1-luis.machado@linaro.org> X-IsSubscribed: yes New in v3: - Code cleanups based on reviews. New in v2: - Fixed misc problems based on reviews. - Switched to using gdbarch_program_breakpoint_here_p as opposed to gdbarch_insn_is_breakpoint. - Fixed matching of brk instructions. Previously the mask was incorrect, which was showing up as a few failures in the testsuite. Now it is clean. - New testcase (separate patch). - Moved program_breakpoint_here () to arch-utils.c and made it the default implementation of gdbarch_program_breakpoint_here_p. -- 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_program_breakpoint_here_p) 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) gdb/ChangeLog: 2020-01-15 Luis Machado * aarch64-tdep.c (BRK_INSN_MASK): Define to 0xffe0001f. (BRK_INSN_MASK): Define to 0xd4200000. (aarch64_program_breakpoint_here_p): New function. (aarch64_gdbarch_init): Set gdbarch_program_breakpoint_here_p hook. * arch-utils.c (default_program_breakpoint_here_p): Moved from breakpoint.c. * arch-utils.h (default_program_breakpoint_here_p): Moved from breakpoint.h * breakpoint.c (bp_loc_is_permanent): Changed return type to bool and call gdbarch_program_breakpoint_here_p. (program_breakpoint_here): Moved to arch-utils.c, renamed to default_program_breakpoint_here_p, changed return type to bool and simplified. * breakpoint.h (program_breakpoint_here): Moved prototype to arch-utils.h, renamed to default_program_breakpoint_here_p and changed return type to bool. * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * gdbarch.sh (program_breakpoint_here_p): New method. * infrun.c (handle_signal_stop): Call gdbarch_program_breakpoint_here_p. --- gdb/aarch64-tdep.c | 37 +++++++++++++++++++++++++++++++++++++ gdb/arch-utils.c | 32 ++++++++++++++++++++++++++++++++ gdb/arch-utils.h | 4 ++++ gdb/breakpoint.c | 46 +++++++--------------------------------------- gdb/breakpoint.h | 5 ----- gdb/gdbarch.c | 23 +++++++++++++++++++++++ gdb/gdbarch.h | 7 +++++++ gdb/gdbarch.sh | 4 ++++ gdb/infrun.c | 4 ++-- 9 files changed, 116 insertions(+), 46 deletions(-) -- 2.17.1 diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 8451a916dc..7f32df3ec0 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -1201,6 +1201,39 @@ aarch64_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op, return false; } +/* Used for matching BRK instructions for AArch64. */ +static constexpr uint32_t BRK_INSN_MASK = 0xffe0001f; +static constexpr uint32_t BRK_INSN_BASE = 0xd4200000; + +/* Implementation of gdbarch_program_breakpoint_here_p for aarch64. */ + +static bool +aarch64_program_breakpoint_here_p (gdbarch *gdbarch, CORE_ADDR address) +{ + const uint32_t insn_len = 4; + gdb_byte target_mem[4]; + + /* Enable the automatic memory restoration from breakpoints while + 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, insn_len) == 0) + { + uint32_t insn = + (uint32_t) extract_unsigned_integer (target_mem, insn_len, + gdbarch_byte_order_for_code (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 ((insn & BRK_INSN_MASK) == BRK_INSN_BASE); + } + + return false; +} + /* 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 +3390,10 @@ 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_program_breakpoint_here_p (gdbarch, + aarch64_program_breakpoint_here_p); + /* 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 92d7153ccb..04955ea847 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -876,6 +876,38 @@ int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr) return 0; } +/* See arch-utils.h. */ + +bool +default_program_breakpoint_here_p (struct gdbarch *gdbarch, + CORE_ADDR address) +{ + int len; + const gdb_byte *bpoint = gdbarch_breakpoint_from_pc (gdbarch, &address, &len); + + /* Software breakpoints unsupported? */ + if (bpoint == nullptr) + return false; + + gdb_byte *target_mem = (gdb_byte *) alloca (len); + + /* Enable the automatic memory restoration from breakpoints while + 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) + { + /* Check if this is a breakpoint instruction for this architecture, + including ones used by GDB. */ + if (memcmp (target_mem, bpoint, len) == 0) + return true; + } + + return false; +} + void default_skip_permanent_breakpoint (struct regcache *regcache) { diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h index 3fb9ad317a..43d64b1f4f 100644 --- a/gdb/arch-utils.h +++ b/gdb/arch-utils.h @@ -228,6 +228,10 @@ 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); +/* Default implementation of gdbarch_program_breakpoint_here_p. */ +extern bool default_program_breakpoint_here_p (struct gdbarch *gdbarch, + CORE_ADDR addr); + /* Do-nothing version of vsyscall_range. Returns false. */ extern int default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range); diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index a7a378131a..5a9352c26f 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8515,7 +8515,7 @@ mention (struct breakpoint *b) } -static int bp_loc_is_permanent (struct bp_location *loc); +static bool bp_loc_is_permanent (struct bp_location *loc); static struct bp_location * add_location_to_breakpoint (struct breakpoint *b, @@ -8581,42 +8581,10 @@ add_location_to_breakpoint (struct breakpoint *b, } -/* See breakpoint.h. */ - -int -program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) -{ - int len; - CORE_ADDR addr; - const gdb_byte *bpoint; - gdb_byte *target_mem; - - addr = address; - bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); - - /* Software breakpoints unsupported? */ - if (bpoint == NULL) - return 0; - - 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. */ - scoped_restore restore_memory - = make_scoped_restore_show_memory_breakpoints (0); +/* Return true if LOC is pointing to a permanent breakpoint, + return false otherwise. */ - if (target_read_memory (address, target_mem, len) == 0 - && memcmp (target_mem, bpoint, len) == 0) - return 1; - - return 0; -} - -/* Return 1 if LOC is pointing to a permanent breakpoint, - return 0 otherwise. */ - -static int +static bool bp_loc_is_permanent (struct bp_location *loc) { gdb_assert (loc != NULL); @@ -8624,14 +8592,14 @@ bp_loc_is_permanent (struct bp_location *loc) /* If we have a non-breakpoint-backed catchpoint or a software watchpoint, just return 0. We should not attempt to read from the addresses the locations of these breakpoint types point to. - program_breakpoint_here_p, below, will attempt to read + gdbarch_program_breakpoint_here_p, below, will attempt to read memory. */ if (!bl_address_is_meaningful (loc)) - return 0; + return false; scoped_restore_current_pspace_and_thread restore_pspace_thread; switch_to_program_space_and_thread (loc->pspace); - return program_breakpoint_here_p (loc->gdbarch, loc->address); + return gdbarch_program_breakpoint_here_p (loc->gdbarch, loc->address); } /* Build a command list for the dprintf corresponding to the current diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 13d8102c17..347aeb75f3 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -1194,11 +1194,6 @@ enum breakpoint_here /* Prototypes for breakpoint-related functions. */ -/* Return 1 if there's a program/permanent breakpoint planted in - memory at ADDRESS, return 0 otherwise. */ - -extern int program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address); - extern enum breakpoint_here breakpoint_here_p (const address_space *, CORE_ADDR); diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index cc8569f5c9..d763fc85e6 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_program_breakpoint_here_p_ftype *program_breakpoint_here_p; 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->program_breakpoint_here_p = default_program_breakpoint_here_p; 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 program_breakpoint_here_p, 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 */ @@ -1248,6 +1251,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) fprintf_unfiltered (file, "gdbarch_dump: process_record_signal = <%s>\n", host_address_to_string (gdbarch->process_record_signal)); + fprintf_unfiltered (file, + "gdbarch_dump: program_breakpoint_here_p = <%s>\n", + host_address_to_string (gdbarch->program_breakpoint_here_p)); fprintf_unfiltered (file, "gdbarch_dump: ps_regnum = %s\n", plongest (gdbarch->ps_regnum)); @@ -4928,6 +4934,23 @@ set_gdbarch_insn_is_jump (struct gdbarch *gdbarch, gdbarch->insn_is_jump = insn_is_jump; } +bool +gdbarch_program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->program_breakpoint_here_p != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_program_breakpoint_here_p called\n"); + return gdbarch->program_breakpoint_here_p (gdbarch, address); +} + +void +set_gdbarch_program_breakpoint_here_p (struct gdbarch *gdbarch, + gdbarch_program_breakpoint_here_p_ftype program_breakpoint_here_p) +{ + gdbarch->program_breakpoint_here_p = program_breakpoint_here_p; +} + int gdbarch_auxv_parse_p (struct gdbarch *gdbarch) { diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index 9f32ac23ab..800a4e8b16 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 there's a program/permanent breakpoint planted in + memory at ADDRESS, return false otherwise. */ + +typedef bool (gdbarch_program_breakpoint_here_p_ftype) (struct gdbarch *gdbarch, CORE_ADDR address); +extern bool gdbarch_program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address); +extern void set_gdbarch_program_breakpoint_here_p (struct gdbarch *gdbarch, gdbarch_program_breakpoint_here_p_ftype *program_breakpoint_here_p); + /* 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 0be3e88bb2..66b54dd700 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 there's a program/permanent breakpoint planted in +# memory at ADDRESS, return false otherwise. +m;bool;program_breakpoint_here_p;CORE_ADDR address;address;;default_program_breakpoint_here_p;;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. diff --git a/gdb/infrun.c b/gdb/infrun.c index a8636284f1..494324d72b 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -6157,8 +6157,8 @@ handle_signal_stop (struct execution_control_state *ecs) been removed. */ if (random_signal && target_stopped_by_sw_breakpoint ()) { - if (program_breakpoint_here_p (gdbarch, - ecs->event_thread->suspend.stop_pc)) + if (gdbarch_program_breakpoint_here_p (gdbarch, + ecs->event_thread->suspend.stop_pc)) { struct regcache *regcache; int decr_pc;