From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id 0E3343858D20 for ; Mon, 12 Jun 2023 19:36:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E3343858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-33b4552e55cso17198735ab.0 for ; Mon, 12 Jun 2023 12:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1686598592; x=1689190592; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=h5VqnDNdVXmmYqLuW0tBv9tEvC8lDsz4ELGPQFWIkHU=; b=SvPXS6zMhOlkJoD5FRfO2E4GZ/wz9ly5mg8pFhutPgq4meY9SQaolww0Jsluyb9+oI X0i5p+QU/P45RDQ0BxcWQnfd7JeIEJ7YdeWwYCaFLOplCGZxn5FmjJrK41nX5QvSbwtA ViviedpxLfqCvlwSfLQGNjTek0frlst8WDpdSMvdBEpyFJWLctRXRbc+k53GS4OR2EP5 F3c+HnmBjBjYoWXBPjXnnMX2APvs6creMjjDwv2h3I+tpQXOlZAHImO8JevPTeKPGC4O b42+bRaC12kJAWtf3BUZzeyk4WhmnRyVj9iyhsH3DLsQFQkpMPSYt6ZrS5Z9bvb5GS+H 5rqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686598592; x=1689190592; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h5VqnDNdVXmmYqLuW0tBv9tEvC8lDsz4ELGPQFWIkHU=; b=ZKiaIulQaEv6DSvju/vBBTk0BzMopfKaZjK9EWD59uPCKGH79V4/ea1jdzUlhAHTw4 BKgDg7dLYoyLLus7gtl4Xe65dqmGQz+WA+LlpPz/JpyRKeFEy4qjWvr9WVjKvgvWMftc VqRzX0Ogqhb8GEzh+Qf9QzBN+bS5vuEcJjyzKPyzVO1D8ei7YhsGte0cMEI08/UStM3k 92ZdSKqoDxmwGPLKhtIc/KGp9YFT1VE1+1eHiw/5CB1jIHEGeX7pIzZwy2rJR/pOLi3W jmWXjbv29CCYTPXGFhWoQzc1n8f9ht46zeZl8IXCtFtVFolIO0n9znQmqKe2yQdUT2AE EGZQ== X-Gm-Message-State: AC+VfDwT8NQHOUwhS/+sbKcGNLzHwA4eyDCLJBi1lIwEwoZnBPfyYecw 9UUOIGiHewRQzsb7wFfzqz7i9C4rFLV8yq4XQb3n0A== X-Google-Smtp-Source: ACHHUZ5004uRfBZ25/wC+/Ot+hKzOACP17ae/1ZXA5tHpZQ/+Z9z1S2SwxNBhPaIvLlCf13zq05oSw== X-Received: by 2002:a05:6e02:1542:b0:33a:5439:2919 with SMTP id j2-20020a056e02154200b0033a54392919mr10103130ilu.14.1686598592148; Mon, 12 Jun 2023 12:36:32 -0700 (PDT) Received: from localhost.localdomain (75-166-136-83.hlrn.qwest.net. [75.166.136.83]) by smtp.gmail.com with ESMTPSA id m12-20020a056638224c00b00418a5e0e93esm2938091jas.162.2023.06.12.12.36.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 12:36:31 -0700 (PDT) From: Tom Tromey Date: Mon, 12 Jun 2023 13:36:30 -0600 Subject: [PATCH 3/7] Handle exceptions when creating DAP breakpoints MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230612-more-dap-v1-3-ad868f1a4cc0@adacore.com> References: <20230612-more-dap-v1-0-ad868f1a4cc0@adacore.com> In-Reply-To: <20230612-more-dap-v1-0-ad868f1a4cc0@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When creating a DAP breakpoint, a failure should be returned by setting "verified" to False. gdb didn't properly implement this, and there was a FIXME comment to this effect. This patch fixes the problem. --- gdb/python/lib/gdb/dap/breakpoint.py | 89 +++++++++++++++++++------------ gdb/testsuite/gdb.dap/catch-exception.exp | 24 ++++++--- gdb/testsuite/gdb.dap/cond-bp.exp | 19 +++++++ 3 files changed, 92 insertions(+), 40 deletions(-) diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index f15f905c5f3..3f40cfb7f63 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -20,7 +20,8 @@ import os from typing import Optional, Sequence from .server import request, capability -from .startup import send_gdb_with_response, in_gdb_thread +from .startup import send_gdb_with_response, in_gdb_thread, log_stack +from .typecheck import type_check # Map from the breakpoint "kind" (like "function") to a second map, of @@ -34,33 +35,35 @@ breakpoint_map = {} @in_gdb_thread def breakpoint_descriptor(bp): "Return the Breakpoint object descriptor given a gdb Breakpoint." + result = { + "id": bp.number, + # We always use True here, because this field just indicates + # that breakpoint creation was successful -- and if we have a + # breakpoint, the creation succeeded. + "verified": True, + } if bp.locations: # Just choose the first location, because DAP doesn't allow # multiple locations. See # https://github.com/microsoft/debug-adapter-protocol/issues/13 loc = bp.locations[0] (basename, line) = loc.source - result = { - "id": bp.number, - "verified": True, - "source": { - "name": os.path.basename(basename), - # We probably don't need this but it doesn't hurt to - # be explicit. - "sourceReference": 0, - }, - "line": line, - "instructionReference": hex(loc.address), - } + result.update( + { + "source": { + "name": os.path.basename(basename), + # We probably don't need this but it doesn't hurt to + # be explicit. + "sourceReference": 0, + }, + "line": line, + "instructionReference": hex(loc.address), + } + ) path = loc.fullname if path is not None: result["source"]["path"] = path - return result - else: - return { - "id": bp.number, - "verified": False, - } + return result # Extract entries from a hash table and return a list of them. Each @@ -91,22 +94,42 @@ def _set_breakpoints_callback(kind, specs, creator): (condition, hit_condition) = _remove_entries(spec, "condition", "hitCondition") keyspec = frozenset(spec.items()) - if keyspec in saved_map: - bp = saved_map.pop(keyspec) - else: - # FIXME handle exceptions here - bp = creator(**spec) - - bp.condition = condition - if hit_condition is None: - bp.ignore_count = 0 - else: - bp.ignore_count = int( - gdb.parse_and_eval(hit_condition, global_context=True) + # Create or reuse a breakpoint. If asked, set the condition + # or the ignore count. Catch errors coming from gdb and + # report these as an "unverified" breakpoint. + bp = None + try: + if keyspec in saved_map: + bp = saved_map.pop(keyspec) + else: + bp = creator(**spec) + + bp.condition = condition + if hit_condition is None: + bp.ignore_count = 0 + else: + bp.ignore_count = int( + gdb.parse_and_eval(hit_condition, global_context=True) + ) + + # Reaching this spot means success. + breakpoint_map[kind][keyspec] = bp + result.append(breakpoint_descriptor(bp)) + # Exceptions other than gdb.error are possible here. + except Exception as e: + log_stack() + # Maybe the breakpoint was made but setting an attribute + # failed. We still want this to fail. + if bp is not None: + bp.delete() + # Breakpoint creation failed. + result.append( + { + "verified": False, + "message": str(e), + } ) - breakpoint_map[kind][keyspec] = bp - result.append(breakpoint_descriptor(bp)) # Delete any breakpoints that were not reused. for entry in saved_map.values(): entry.delete() diff --git a/gdb/testsuite/gdb.dap/catch-exception.exp b/gdb/testsuite/gdb.dap/catch-exception.exp index 7f2e750b32e..95e65556cc6 100644 --- a/gdb/testsuite/gdb.dap/catch-exception.exp +++ b/gdb/testsuite/gdb.dap/catch-exception.exp @@ -31,22 +31,32 @@ if {[dap_launch $binfile] == ""} { set obj [dap_check_request_and_response "set exception catchpoints" \ setExceptionBreakpoints \ - {o filters [a [s assert]] \ + {o filters [a [s nosuchfilter] [s assert]] \ filterOptions [a [o filterId [s exception] \ condition [s "Global_Var = 23"]]]}] set bps [dict get [lindex $obj 0] body breakpoints] -gdb_assert {[llength $bps] == 2} "two breakpoints" +# We should get three responses, because we requested three +# breakpoints. However, one of them should fail. +gdb_assert {[llength $bps] == 3} "three breakpoints" # The "path" should never be "null". set i 1 foreach spec $bps { - # If "path" does not exist, then that is fine as well. - if {![dict exists $spec source path]} { - pass "breakpoint $i path" + if {$i == 1} { + # First one should fail. + gdb_assert {[dict get $spec verified] == "false"} \ + "invalid first exception" + gdb_assert {[dict get $spec message] != ""} \ + "first exception had message" } else { - gdb_assert {[dict get $spec source path] != "null"} \ - "breakpoint $i path" + # If "path" does not exist, then that is fine as well. + if {![dict exists $spec source path]} { + pass "breakpoint $i path" + } else { + gdb_assert {[dict get $spec source path] != "null"} \ + "breakpoint $i path" + } } incr i } diff --git a/gdb/testsuite/gdb.dap/cond-bp.exp b/gdb/testsuite/gdb.dap/cond-bp.exp index 6369b6f579c..262ab9d26c8 100644 --- a/gdb/testsuite/gdb.dap/cond-bp.exp +++ b/gdb/testsuite/gdb.dap/cond-bp.exp @@ -30,6 +30,25 @@ if {[dap_launch $testfile] == ""} { } set line [gdb_get_line_number "STOP"] + +# Test some breakpoint-setting failure modes. +set obj [dap_check_request_and_response "set invalid breakpoints" \ + setBreakpoints \ + [format {o source [o path [%s]] \ + breakpoints \ + [a [o line [i %d] condition [s "DEI@@++"]] \ + [o line [i %d] hitCondition [s "DEI@@++"]]]} \ + [list s $srcfile] $line $line]] + +set i 1 +foreach bp [dict get [lindex $obj 0] body breakpoints] { + gdb_assert {[dict get $bp verified] == "false"} \ + "breakpoint $i invalid" + gdb_assert {[dict get $bp message] != ""} \ + "breakpoint $i has message" + incr i +} + set obj [dap_check_request_and_response "set conditional breakpoint" \ setBreakpoints \ [format {o source [o path [%s]] \ -- 2.40.1