From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out-234.mta1.migadu.com (out-234.mta1.migadu.com [95.215.58.234]) by sourceware.org (Postfix) with ESMTPS id CD2773858D39 for ; Fri, 1 Sep 2023 21:04:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD2773858D39 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gpanders.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gpanders.com X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gpanders.com; s=key1; t=1693602270; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dpXlpCf0yNts5/JXxBJvoGv3jSLRj04mHoeONQ45oM0=; b=doT1EyiXyKngBXbHXK2PyWX6r255dvQPn+ouOeE1o3/0kkF/bDUl2wYebLyBtbXslOdhtN HlHn8Oup+AeukbF7neFBW8O1TjYTajGl0ZC8p7ydNpZGg76q7+jexI4+KnnN9/ASXLQ3Sx Pa4yo4b+RIrHKiqSc6+rWayMzI2rBW57f5uQV8vioY7ZabjumJd3q2l1ANJXmNkEeJWRG2 qQlsZmM54uzsIhaOnUSKcuZhYyHPL5O0aywjW62Pn/l4thf0JPZtxdtifk2d37Im93y86a Ye1+3+joY+FlKcBPRpO/Ge9sEgH7EDGwjiyw5MpJZ99hhpe94HTopyLZVmf8Ew== From: Gregory Anders To: gdb-patches@sourceware.org Cc: Gregory Anders Subject: [PATCH v2 1/4] gdb/dap: check for breakpoint source before unpacking Date: Fri, 1 Sep 2023 16:02:17 -0500 Message-ID: <20230901210422.58003-2-greg@gpanders.com> In-Reply-To: <20230901210422.58003-1-greg@gpanders.com> References: <20230901210422.58003-1-greg@gpanders.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP 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: Not all breakpoints have a source location. For example, a breakpoint set on a raw address will have only the "address" field populated, but "source" will be None, which leads to a RuntimeError when attempting to unpack the filename and line number. Before attempting to unpack the filename and line number from the breakpoint, ensure that the source information is not None. Also populate the source and line information separately from the "instructionReference" field, so that breakpoints that include only an address are still included. --- gdb/python/lib/gdb/dap/breakpoint.py | 20 ++++++++++++-------- gdb/testsuite/gdb.dap/bt-nodebug.exp | 7 +++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index 76ff129d..0ebb9597 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -106,14 +106,18 @@ def _breakpoint_descriptor(bp): # multiple locations. See # https://github.com/microsoft/debug-adapter-protocol/issues/13 loc = bp.locations[0] - (filename, line) = loc.source - result.update( - { - "source": make_source(filename, os.path.basename(filename)), - "line": line, - "instructionReference": hex(loc.address), - } - ) + if loc.source: + (filename, line) = loc.source + result.update( + { + "source": make_source(filename, os.path.basename(filename)), + "line": line, + } + ) + + if loc.address: + result["instructionReference"] = hex(loc.address), + path = loc.fullname if path is not None: result["source"]["path"] = path diff --git a/gdb/testsuite/gdb.dap/bt-nodebug.exp b/gdb/testsuite/gdb.dap/bt-nodebug.exp index e9726d2e..abd394ad 100644 --- a/gdb/testsuite/gdb.dap/bt-nodebug.exp +++ b/gdb/testsuite/gdb.dap/bt-nodebug.exp @@ -53,4 +53,11 @@ gdb_assert {[llength $frames] == 3} "three frames" gdb_assert {[dict get [lindex $frames 1] name] == "no_debug_info"} \ "name of no-debug frame" +# Breakpoint can be set without source file information +set obj [dap_check_request_and_response "set breakpoint on no_debug_info" \ + setFunctionBreakpoints \ + {o breakpoints [a [o name [s no_debug_info]]]}] +set breakpoints [dict get [lindex $obj 0] body breakpoints] +gdb_assert {[dict exists [lindex $breakpoints 0] instructionReference]} "breakpoint has instructionReference" + dap_shutdown -- 2.42.0