From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 20FD03858D1E for ; Mon, 26 Jun 2023 22:20:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20FD03858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-4f122ff663eso5125743e87.2 for ; Mon, 26 Jun 2023 15:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687818015; x=1690410015; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=HenHSU3tb/jVVT1WA2Y22pC5g588Nc7X1CMeYmCRo9E=; b=BfyKgTXNBFkrTZG5ONnEzV0vvkWcFD+SrpJ3mYqWj3relhNUZZQ18LHINpZofGEwjt m23cOA6f+DeoWh0Jv2A8p3C9O2VufRTnsPm1vRqgG8WNGdAwP9i3AvJI0rDVVipnGKpT FWLHpLyRJMcP5rpD7EE9x3bVqfK5pV8W3IiTTYQ3FpGyMzGF/GL+cY9ukJ7udADWlQ25 ErzhpwRezRY1lg44xHr5WUK0GkdK44aI5MAwIC9WOTzIPLuAf/Si2+cwIWa+5aXwadgz oLrACCaBmZpcuzRPXAx8ycN2wN00nzFhwU7fXAirJ9s3szat/2apGMjgR4s1ltww7vVL 2JhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687818015; x=1690410015; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HenHSU3tb/jVVT1WA2Y22pC5g588Nc7X1CMeYmCRo9E=; b=jfxAT3rW5eaYUfpTrkjnZbx6zwrI3bnSlahP3qezTOciPwlERvshcjlLF8J/j6vlO6 8oPaXMoPIFHFTjTALMZO2cXYsFp0hti7L6yEnmeUtp5JRjKYq730WbXzfy415giEJYbc imlzjcGOUmFL+s9f3sSqL8y1O5wLmFFJ0wblRGWzNU41PrDu8juLPF6Jq7DwhGisqQtJ ze1xuh72j2tNm4q1/wZS2OCXzzg6u2VmtMYtygEh2MbDU+WALQx+kfvsaUEBiDIz/Nyu M2zI4Ch3Ie7/2YJtm+cIuIjUGfYSTC7zuJP8+QKWwN7GiZOKAfgnY1DtlP9y8TNpPrDU S3HQ== X-Gm-Message-State: AC+VfDwpR2yak+FgLEGKSxNPxYHOv6fVirKlkLT/poPUzce/9twt4qwu Cy2c/G8kUVHsii7gDMWmSuL0l+Kndhg= X-Google-Smtp-Source: ACHHUZ4opEfk+Imt3ki+LN2PdxYu32U5fEw+QvfEVuJcBPgsA4v4mim/AypTEJ16Iv6cMWSWtDs5fw== X-Received: by 2002:ac2:5b9a:0:b0:4f8:582f:414e with SMTP id o26-20020ac25b9a000000b004f8582f414emr17034513lfn.15.1687818015096; Mon, 26 Jun 2023 15:20:15 -0700 (PDT) Received: from fedora.. (78-73-77-63-no2450.tbcn.telia.com. [78.73.77.63]) by smtp.gmail.com with ESMTPSA id m15-20020a19520f000000b004edc55d3900sm1288959lfb.0.2023.06.26.15.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 15:20:14 -0700 (PDT) From: Simon Farre To: gdb-patches@sourceware.org Cc: tom@tromey.com, Simon Farre Subject: [PATCH v2] gdb/DAP Fix disassemble bug Date: Tue, 27 Jun 2023 00:20:02 +0200 Message-ID: <20230626222002.39842-1-simon.farre.cx@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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: v2. Since GDB's current design apparently isn't well suited to backwards disassembly, I've changed the patch to just return "invalid values" prior to "current pc". Though one approach would be to use dwarf's line number program info to get "logical breakpoint locations" and disassemble from these as "sources of known truth". This would require that parts of my "next expression patch", that also works with DAP's "next statement" request gets accepted, so that the line number program stuff can be used) v1. Fixes disassembleRequest The field instructionOffset can be negative. Previous patch made it so that sometimes the request got calculated to 0 instructions, when it meant to retrieve disasm for -50 to 0 (current position). --- gdb/python/lib/gdb/dap/disassemble.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gdb/python/lib/gdb/dap/disassemble.py b/gdb/python/lib/gdb/dap/disassemble.py index bc091eb2c89..c82b2ffcff1 100644 --- a/gdb/python/lib/gdb/dap/disassemble.py +++ b/gdb/python/lib/gdb/dap/disassemble.py @@ -27,8 +27,12 @@ def _disassemble(pc, skip_insns, count): # Maybe there was no frame. arch = gdb.selected_inferior().architecture() result = [] - total_count = skip_insns + count - for elt in arch.disassemble(pc, count=total_count)[skip_insns:]: + if skip_insns < 0: + for i in range(0, -skip_insns): + result.append({"address": 0, "instruction": "unknown"}) + skip_insns = 0 + + for elt in arch.disassemble(pc, count=count + skip_insns)[skip_insns:]: result.append( { "address": hex(elt["addr"]), @@ -50,7 +54,7 @@ def disassemble( instructionCount: int, **extra ): - pc = int(memoryReference, 0) + offset + pc = int(memoryReference, 0) return send_gdb_with_response( lambda: _disassemble(pc, instructionOffset, instructionCount) ) -- 2.41.0