Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nJSHg-0008LH-PL for mharc-grub-devel@gnu.org; Sun, 13 Feb 2022 22:44:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJSHf-0008IZ-DZ for grub-devel@gnu.org; Sun, 13 Feb 2022 22:44:15 -0500 Received: from [2607:f8b0:4864:20::735] (port=33683 helo=mail-qk1-x735.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nJSHc-0005at-EY for grub-devel@gnu.org; Sun, 13 Feb 2022 22:44:14 -0500 Received: by mail-qk1-x735.google.com with SMTP id o10so13452085qkg.0 for ; Sun, 13 Feb 2022 19:44:12 -0800 (PST) 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=DElIJQDC9XV1oW5M7Abv8yK1Dpruw2CXviLRIVfkM/Q=; b=8KT7IOvfbY95hlWhe0A+E/qANrl8wTdTIfdeNV1owRtA2Q2nrR+cf6YoK4I6iwsF1S zq8yebSEoYXCYVGzjn+9PnyurIaLJBZAoCG1Ig1Cxc2ApA/fnop3ryLFoEP/Znlf4kDi ZZtaoopgQx4z15f5wo/JDU+jWUpYc+LKJ499dbaw1dIpdmTl4LZwISvAwMG6ZP5rZezf OHVGqtzOEFQmlz/l5Ri92xWMgItIaXnshceI7b1aFHx9+iSraTBAJKxc4yOPrB8Odj7+ hs3yIbWTu20MuDHjj9U8MurjrXBxYliZPJlv3FxSFub3F9b3hnDKvnU82oPaGufPqeyS MWtw== 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=DElIJQDC9XV1oW5M7Abv8yK1Dpruw2CXviLRIVfkM/Q=; b=sOHHvdwaKazP6g7cDZz3qqKEFotKfU9NYjvHnGmfr5XUn0kT4bVqywB0ChDpeIVcrE DcGNjl5lU0cdcFXeTpI2Irr8kx4OaBZR08gNborA61wXtcpe9X11WrkSm6S/0Pscy46M ZhD1ldT/+spm0Rl2NKMIcVAMGglVpHxD6ffxzmFoHL/eqczw4mElsleypR9blTH0/mwo w68h6vPz+qHB6Iwkut69OlDc/Y0iTEPpiuX5POJL4T/rYbxKugWWUpoFhSwqW0Fic3oA L9lKKc8lGffOYfTd8J0kRxJbQAKGYRxwJhmuh7O1PWSDwiPdgaOeXJaCUnexeLNhUWyr g9Ig== X-Gm-Message-State: AOAM531zvrPkCXRidO991eWF2agpRsFOKixXwJBlvvQJDHdWmtbf1cC1 eAM8Melk8Ko5hKYW9ZU9QEP8Ew== X-Google-Smtp-Source: ABdhPJzJeisTGho+R2N54htbfEY6vgxIHORA1Tf5PW0y/wbu4gp6d/DB0g+CCp/I3qCR0FdW0zcS7g== X-Received: by 2002:ae9:e109:: with SMTP id g9mr6141013qkm.705.1644810251647; Sun, 13 Feb 2022 19:44:11 -0800 (PST) Received: from localhost.localdomain (garza.riseup.net. [198.252.153.109]) by smtp.gmail.com with ESMTPSA id z19sm17755800qtj.77.2022.02.13.19.44.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 19:44:10 -0800 (PST) From: Glenn Washburn To: Daniel Kiper , grub-devel@gnu.org Cc: Peter Jones , Robbie Harwood , Glenn Washburn Subject: [PATCH 7/8] gdb: Conditionally run GDB script logic for dynamically or statically positioned GRUB Date: Sun, 13 Feb 2022 21:42:44 -0600 Message-Id: <52351dacd38340b49ba1fec49c61183f2968faa1.1644738995.git.development@efficientek.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::735 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::735; envelope-from=development@efficientek.com; helo=mail-qk1-x735.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.785, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: Mon, 14 Feb 2022 03:44:15 -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. This is complicated by the fact that a subshell is used to check the autoconf variable and shells return 0 for success, but 0 is false in conditionals in GDB. So an inversion of the status code is needed. Signed-off-by: Glenn Washburn --- grub-core/gdb_grub.in | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/grub-core/gdb_grub.in b/grub-core/gdb_grub.in index f3c6faf94..4c2b8bf52 100644 --- a/grub-core/gdb_grub.in +++ b/grub-core/gdb_grub.in @@ -145,7 +145,23 @@ 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. + +# If this returns success, the exit code is 0, however, GDB's "if" +# considers 0 to be false. So invert the status code. +shell test "@platform@" == "efi" +set $platform_efi = ! $_shell_exitcode + +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.27.0