Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1npeTV-0007Qx-9G for mharc-grub-devel@gnu.org; Fri, 13 May 2022 19:13:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npeTS-0007KC-Tw for grub-devel@gnu.org; Fri, 13 May 2022 19:13:31 -0400 Received: from mail-vk1-xa36.google.com ([2607:f8b0:4864:20::a36]:34406) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1npeTR-0007Sl-9T for grub-devel@gnu.org; Fri, 13 May 2022 19:13:30 -0400 Received: by mail-vk1-xa36.google.com with SMTP id b81so4922709vkf.1 for ; Fri, 13 May 2022 16:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nwNutQibeCGAfoF1nd/ajjkPojGNdln+FZNwUlfrl/w=; b=4LP7HMnr6gNAXoqvKu0s6Of22d52vtGmvn/t3ssPtSbfvtSi/CdemqjM/JCEP5zzVk 6PKDxBOu9us0q5iBuOU4SXeL9kfOhLRaJZvErVuU8G1PmqifCHXAXqxzr+XE1rz6qbVJ pBIJFrmCF5Dsfh67e6203vN0U1rXGef4+C8rMnDeL0ag7+p412icRaCQvp144258Lh5U uvq7z49PpIHhEriIl7QJAnoUiZtZR4uDEFSHBlU4KyoCpsyMHax552R3pdteeBHClxDX Ma8ZMUkB/ui4ayxCb4ZsBIyyb0QW4C93AxkUzDceHo1uiyVmK0gCBaxHttsJhsNG6/ci jiGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nwNutQibeCGAfoF1nd/ajjkPojGNdln+FZNwUlfrl/w=; b=PR4UrOWZJerVLsNiJbqiB7+BpiUSZC0/IR0UMPdzw4rLQv3c8jxLV0rLfO3xUZQGof OfyDs7ZC1RZqEzKP3zKcvvVI8WqqyHzbojksuHXF2HACZJwj9k1pQTH6nrDNBPyZpDWV /mRjKjzDGRcJQHJfSkykwHxDeM0SDsYnAmzzglHrMg369MHtzFvFC6jEZH1E1GATSm5k sbFX61BIjeB7TH1MEr7oQVm93St9fIZ5y9s73RHS5gedHrXvd6TMmDyvxmw/EKS3Lrc9 5jlzu6dtIGA/eVmgI5kgD3iOO9VmJZE+iUjyi2/SpcGnUum5iLBrrXnsD871mIo4Jlae fDSg== X-Gm-Message-State: AOAM530/V1/fvOqBSP+1lNN85YPGFE13qGsWk/Yli43sz0U1U/a0uRqw kvIece3xtO3bDZvgwtiUUeSa7vs34aQx5oHh X-Google-Smtp-Source: ABdhPJwhXpYYIRb0dd9/AUG0tAYlmEFcyU6F6WBzIUA58ObkPMp3YcIPJxIj74U5S0YLiMgZiJg/sA== X-Received: by 2002:a1f:6003:0:b0:34d:3d07:5827 with SMTP id u3-20020a1f6003000000b0034d3d075827mr3260994vkb.30.1652483608215; Fri, 13 May 2022 16:13:28 -0700 (PDT) Received: from localhost.localdomain ([37.218.244.249]) by smtp.gmail.com with ESMTPSA id 129-20020a1f1387000000b0034e6f1fd067sm423865vkt.49.2022.05.13.16.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 16:13:27 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Peter Jones , Robbie Harwood , Glenn Washburn Subject: [PATCH v2 10/15] gdb: Conditionally run GDB script logic for dynamically or statically positioned GRUB Date: Fri, 13 May 2022 18:12:43 -0500 Message-Id: <9fb80f98b447a95f30497de10d1330f99bc9b015.1652482822.git.development@efficientek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::a36; envelope-from=development@efficientek.com; helo=mail-vk1-xa36.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2022 23:13:31 -0000 There are broadly two classes of targets to consider when loading symbols for GRUB, targets that determine where to load GRUB at runtime (dynamically positioned) and those that do not (statically positioned). For statically poisitioned targets, symbol loading is determined at link time, so nothing more needs to be known to load the symbols. For dynamically positioned targets, such as EFI targets, at runtime symbols should be offset by an amount that depends on where the runtime chose to load GRUB. It is important to not load symbols statically for dynamic targets because then when subsequently loading the symbols correctly one must take care to remove the existing static symbols, otherwise there will be two sets of symbols and GDB seems to prefer the ones loaded first (ie the static ones). Use autoconf variables to generate a gdb_grub for a particular target, which conditionally run startup code depending on if the target uses static or dynamic loading. Signed-off-by: Glenn Washburn --- grub-core/gdb_grub.in | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/grub-core/gdb_grub.in b/grub-core/gdb_grub.in index eb4f7041b..a444000ff 100644 --- a/grub-core/gdb_grub.in +++ b/grub-core/gdb_grub.in @@ -149,7 +149,20 @@ end ### set confirm off -file kernel.exec -target remote :1234 -runtime_load_module +# Note: On EFI and other platforms that load GRUB to an address that is +# determined at runtime, the symbols in kernel.exec will be wrong. +# However, we must start by loading some executable file or GDB will +# fail. + +set $platform_efi = $_streq("@platform@", "efi") + +if $platform_efi + # Only load the executable file, not the symbols + exec-file kernel.exec +else + file kernel.exec + runtime_load_module +end + +target remote :1234 -- 2.34.1