From patchwork Tue Nov 28 16:19:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 80934 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 61E853870898 for ; Tue, 28 Nov 2023 16:19:24 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id 3E8D83858C54 for ; Tue, 28 Nov 2023 16:19:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3E8D83858C54 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3E8D83858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701188351; cv=none; b=Lio15pHrdGjBq2OrOa5Z33I0hGrKwSXDOzjuXFF48o25Qwg48QMf0iXNSipUtAzyWDIQFH4xzdHvjkDXsd3KFMsx+1rzly8+07I+lIeZEcRoF3qfcy9X4oh94H7yl/3iPLjkrsu7JVKzaEYpLIFoOhoM1Vk6RGgloBzs7ksi29U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701188351; c=relaxed/simple; bh=bp/zLKS8gOXC+aVscSAZf+jTwLZ9hFQPqL9nlFmvXn8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PlOjasrCB5JV7ILUx3Il5qYMFf49lLCnqCwZavE1QFNSfldT4uhsq/v+5DkkuuPMbX9neW1NJAehWiGUumZzp+ps/sVpwVvb4fiAObwb9I4iKXDfRm29ENsM+bqqtQhg9XFrDi2+VpmvW2AFmauheAWBaaU57Zakfz7lIbL74j0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-35c9bca5600so10823635ab.3 for ; Tue, 28 Nov 2023 08:19:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1701188347; x=1701793147; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=yHi3zp7HU1O6ULv5exzYOoxqcgJK8mSy1K1hN/BbcVg=; b=C1y+c5e3X0zcl1+7qknrIokJMu5oqquQN9y8p7yrD8SmcX+RlVCTxhsFg075IWJDe3 xfyJb+3leBWAetDxxMrb3Mi2nqRXmVbw0uJUasOZsSH2Eoi02fq3BLBRexyA7/py9adg pP3Vj4Rsh8sqQYKdxJ0VHMslEDzrPg4RpYfiTImMl1JGKo10pm0v4jx43Oda3WQ1ypv8 1jLds75ToFeidLIilUpIqe0FzU/0r7g13QLk6KxUx33ZEuusJAd8nwoItpPrw56d1XUy dR1e8LZzUq+5dDU5bG2C9eQqyMUjT62DO2MA0SbfKG+KIN6am73RJdw2qP6yuZgMroAr 4pgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701188347; x=1701793147; 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=yHi3zp7HU1O6ULv5exzYOoxqcgJK8mSy1K1hN/BbcVg=; b=TvKvzJSGmTw2OCdkWeR+0sq1PzyCP9zChPFvahh2JdvdzdBHTqGjkcmUqg6eBKm+MX RKXI+iFRQSONWNfAEtMnK0Blf9LtUtvfR6Ru+7t76gcSh8glZ1EV4rU6XbV8OjjIAyqk w7GoIwDTOWoUcLrSwlYM2QUFEQxmdYAAZ8063ezhzKOecvmaAF6ssg5sa32TCYv/mj8j 7YQ4ycCXNa0ylbNJ7lZt3BQPzQFRHDQFqch0agOkRyG7Q7lojr2/JAK5EVAxLPu4kC+Y Xcpp3pT6OYUe8xAq9WIl38A/p0TSZbdvqbBIDPZYItDxMAhYGjkoiRMFVnP+W1z6JJNl ZB1w== X-Gm-Message-State: AOJu0Yx0ImpVzChf8rQWpQulyPoT7doNlQSVHCle7J5U2QKVgPc/ZpPz DCM07htBVQrkz8duhZZeWDqgPD2PeK4UpQof90t8SQ== X-Google-Smtp-Source: AGHT+IF3IkLTGDhycMcana2tmt6C7+gq4IhFIE95RZV7YDuEqnjP+x+bKB5eE/FcAC0/W7/5tSIg2w== X-Received: by 2002:a92:d9c8:0:b0:35c:c9fa:3da8 with SMTP id n8-20020a92d9c8000000b0035cc9fa3da8mr8798988ilq.18.1701188347583; Tue, 28 Nov 2023 08:19:07 -0800 (PST) Received: from localhost.localdomain (97-122-77-73.hlrn.qwest.net. [97.122.77.73]) by smtp.gmail.com with ESMTPSA id bk2-20020a056e02328200b0035af4a81ed5sm235544ilb.37.2023.11.28.08.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 08:19:07 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Remove some DAP helper functions Date: Tue, 28 Nov 2023 09:19:00 -0700 Message-ID: <20231128161900.1060935-1-tromey@adacore.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Now that DAP requests are normally run on the gdb thread, some DAP helper functions are no longer needed. Removing these simplifies the code. --- gdb/python/lib/gdb/dap/disassemble.py | 32 +++++++--------- gdb/python/lib/gdb/dap/evaluate.py | 53 +++++++++------------------ gdb/python/lib/gdb/dap/launch.py | 35 ++++++++---------- gdb/python/lib/gdb/dap/locations.py | 20 ++++------ gdb/python/lib/gdb/dap/modules.py | 17 +++------ gdb/python/lib/gdb/dap/scopes.py | 20 ++++------ 6 files changed, 66 insertions(+), 111 deletions(-) diff --git a/gdb/python/lib/gdb/dap/disassemble.py b/gdb/python/lib/gdb/dap/disassemble.py index 069549eb7f8..493c8de7fe4 100644 --- a/gdb/python/lib/gdb/dap/disassemble.py +++ b/gdb/python/lib/gdb/dap/disassemble.py @@ -16,11 +16,19 @@ import gdb from .server import request, capability -from .startup import in_gdb_thread -@in_gdb_thread -def _disassemble(pc, skip_insns, count): +@request("disassemble") +@capability("supportsDisassembleRequest") +def disassemble( + *, + memoryReference: str, + offset: int = 0, + instructionOffset: int = 0, + instructionCount: int, + **extra +): + pc = int(memoryReference, 0) + offset inf = gdb.selected_inferior() try: arch = gdb.selected_frame().architecture() @@ -28,8 +36,8 @@ def _disassemble(pc, skip_insns, count): # Maybe there was no frame. arch = inf.architecture() result = [] - total_count = skip_insns + count - for elt in arch.disassemble(pc, count=total_count)[skip_insns:]: + total_count = instructionOffset + instructionCount + for elt in arch.disassemble(pc, count=total_count)[instructionOffset:]: mem = inf.read_memory(elt["addr"], elt["length"]) result.append( { @@ -41,17 +49,3 @@ def _disassemble(pc, skip_insns, count): return { "instructions": result, } - - -@request("disassemble") -@capability("supportsDisassembleRequest") -def disassemble( - *, - memoryReference: str, - offset: int = 0, - instructionOffset: int = 0, - instructionCount: int, - **extra -): - pc = int(memoryReference, 0) + offset - return _disassemble(pc, instructionOffset, instructionCount) diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index 67e103e2ca7..d39e7879205 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -57,20 +57,6 @@ class _SetResult(VariableReference): super().__init__(None, value, "value") -# Helper function to perform an assignment. -@in_gdb_thread -def _set_expression(expression, value, frame_id, value_format): - with apply_format(value_format): - global_context = True - if frame_id is not None: - select_frame(frame_id) - global_context = False - lhs = gdb.parse_and_eval(expression, global_context=global_context) - rhs = gdb.parse_and_eval(value, global_context=global_context) - lhs.assign(rhs) - return _SetResult(lhs).to_object() - - # Helper function to evaluate a gdb command in a certain frame. @in_gdb_thread def _repl(command, frame_id): @@ -106,14 +92,6 @@ def eval_request( raise Exception('unknown evaluate context "' + context + '"') -@in_gdb_thread -def _variables(ref, start, count, value_format): - with apply_format(value_format): - var = find_variable(ref) - children = var.fetch_children(start, count) - return [x.to_object() for x in children] - - @request("variables") # Note that we ignore the 'filter' field. That seems to be # specific to javascript. @@ -125,7 +103,10 @@ def variables( if not client_bool_capability("supportsVariablePaging"): start = 0 count = 0 - return {"variables": _variables(variablesReference, start, count, format)} + with apply_format(format): + var = find_variable(variablesReference) + children = var.fetch_children(start, count) + return {"variables": [x.to_object() for x in children]} @capability("supportsSetExpression") @@ -133,18 +114,15 @@ def variables( def set_expression( *, expression: str, value: str, frameId: Optional[int] = None, format=None, **args ): - return _set_expression(expression, value, frameId, format) - - -# Helper function to perform an assignment. -@in_gdb_thread -def _set_variable(ref, name, value, value_format): - with apply_format(value_format): - var = find_variable(ref) - lhs = var.find_child_by_name(name) - rhs = gdb.parse_and_eval(value) + with apply_format(format): + global_context = True + if frameId is not None: + select_frame(frameId) + global_context = False + lhs = gdb.parse_and_eval(expression, global_context=global_context) + rhs = gdb.parse_and_eval(value, global_context=global_context) lhs.assign(rhs) - return lhs.to_object() + return _SetResult(lhs).to_object() @capability("supportsSetVariable") @@ -152,4 +130,9 @@ def _set_variable(ref, name, value, value_format): def set_variable( *, variablesReference: int, name: str, value: str, format=None, **args ): - return _set_variable(variablesReference, name, value, format) + with apply_format(format): + var = find_variable(variablesReference) + lhs = var.find_child_by_name(name) + rhs = gdb.parse_and_eval(value) + lhs.assign(rhs) + return lhs.to_object() diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index ee6ee05bac3..995641bd945 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -20,7 +20,7 @@ from typing import Mapping, Optional, Sequence from .events import exec_and_expect_stop, expect_process from .server import request, capability -from .startup import in_gdb_thread, exec_and_log +from .startup import exec_and_log # The program being launched, or None. This should only be accessed @@ -28,24 +28,6 @@ from .startup import in_gdb_thread, exec_and_log _program = None -@in_gdb_thread -def _launch_setup(program, cwd, args, env, stopAtBeginningOfMainSubprogram): - if cwd is not None: - exec_and_log("cd " + cwd) - if program is not None: - exec_and_log("file " + program) - inf = gdb.selected_inferior() - if stopAtBeginningOfMainSubprogram: - main = inf.main_name - if main is not None: - exec_and_log("tbreak " + main) - inf.arguments = args - if env is not None: - inf.clear_env() - for name, value in env.items(): - inf.set_env(name, value) - - # Any parameters here are necessarily extensions -- DAP requires this # from implementations. Any additions or changes here should be # documented in the gdb manual. @@ -61,7 +43,20 @@ def launch( ): global _program _program = program - _launch_setup(program, cwd, args, env, stopAtBeginningOfMainSubprogram) + if cwd is not None: + exec_and_log("cd " + cwd) + if program is not None: + exec_and_log("file " + program) + inf = gdb.selected_inferior() + if stopAtBeginningOfMainSubprogram: + main = inf.main_name + if main is not None: + exec_and_log("tbreak " + main) + inf.arguments = args + if env is not None: + inf.clear_env() + for name, value in env.items(): + inf.set_env(name, value) @request("attach") diff --git a/gdb/python/lib/gdb/dap/locations.py b/gdb/python/lib/gdb/dap/locations.py index 032174df9c8..30e9b6f5a76 100644 --- a/gdb/python/lib/gdb/dap/locations.py +++ b/gdb/python/lib/gdb/dap/locations.py @@ -20,18 +20,6 @@ from typing import Optional from .server import capability, request from .sources import decode_source -from .startup import in_gdb_thread - - -@in_gdb_thread -def _find_lines(source, start_line, end_line): - filename = decode_source(source) - lines = set() - for entry in gdb.execute_mi("-symbol-list-lines", filename)["lines"]: - line = entry["line"] - if line >= start_line and line <= end_line: - lines.add(line) - return {"breakpoints": [{"line": x} for x in sorted(lines)]} # Note that the spec says that the arguments to this are optional. @@ -46,4 +34,10 @@ def _find_lines(source, start_line, end_line): def breakpoint_locations(*, source, line: int, endLine: Optional[int] = None, **extra): if endLine is None: endLine = line - return _find_lines(source, line, endLine) + filename = decode_source(source) + lines = set() + for entry in gdb.execute_mi("-symbol-list-lines", filename)["lines"]: + this_line = entry["line"] + if this_line >= line and this_line <= endLine: + lines.add(this_line) + return {"breakpoints": [{"line": x} for x in sorted(lines)]} diff --git a/gdb/python/lib/gdb/dap/modules.py b/gdb/python/lib/gdb/dap/modules.py index 87a4f6be669..6f1d17bf6f3 100644 --- a/gdb/python/lib/gdb/dap/modules.py +++ b/gdb/python/lib/gdb/dap/modules.py @@ -45,22 +45,17 @@ def make_module(objf): return result -@in_gdb_thread -def _modules(start, count): +@capability("supportsModulesRequest") +@request("modules") +def modules(*, startModule: int = 0, moduleCount: int = 0, **args): # Don't count invalid objfiles or separate debug objfiles. objfiles = [x for x in gdb.objfiles() if is_module(x)] - if count == 0: + if moduleCount == 0: # Use all items. last = len(objfiles) else: - last = start + count + last = startModule + moduleCount return { - "modules": [make_module(x) for x in objfiles[start:last]], + "modules": [make_module(x) for x in objfiles[startModule:last]], "totalModules": len(objfiles), } - - -@capability("supportsModulesRequest") -@request("modules") -def modules(*, startModule: int = 0, moduleCount: int = 0, **args): - return _modules(startModule, moduleCount) diff --git a/gdb/python/lib/gdb/dap/scopes.py b/gdb/python/lib/gdb/dap/scopes.py index 63cd3255b8a..111fb824c62 100644 --- a/gdb/python/lib/gdb/dap/scopes.py +++ b/gdb/python/lib/gdb/dap/scopes.py @@ -107,14 +107,13 @@ class _RegisterReference(_ScopeReference): ) -# Helper function to create a DAP scopes for a given frame ID. -@in_gdb_thread -def _get_scope(id): +@request("scopes") +def scopes(*, frameId: int, **extra): global frame_to_scope - if id in frame_to_scope: - scopes = frame_to_scope[id] + if frameId in frame_to_scope: + scopes = frame_to_scope[frameId] else: - frame = frame_for_id(id) + frame = frame_for_id(frameId) scopes = [] # Make sure to handle the None case as well as the empty # iterator case. @@ -127,10 +126,5 @@ def _get_scope(id): if locs: scopes.append(_ScopeReference("Locals", "locals", frame, locs)) scopes.append(_RegisterReference("Registers", frame)) - frame_to_scope[id] = scopes - return [x.to_object() for x in scopes] - - -@request("scopes") -def scopes(*, frameId: int, **extra): - return {"scopes": _get_scope(frameId)} + frame_to_scope[frameId] = scopes + return {"scopes": [x.to_object() for x in scopes]}