Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nJSHY-0007vP-Dc for mharc-grub-devel@gnu.org; Sun, 13 Feb 2022 22:44:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJSHX-0007qu-CT for grub-devel@gnu.org; Sun, 13 Feb 2022 22:44:07 -0500 Received: from [2607:f8b0:4864:20::82f] (port=33513 helo=mail-qt1-x82f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nJSHV-0005Zu-DK for grub-devel@gnu.org; Sun, 13 Feb 2022 22:44:07 -0500 Received: by mail-qt1-x82f.google.com with SMTP id p14so14491748qtx.0 for ; Sun, 13 Feb 2022 19:44:04 -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=hspCmuyOP0VnO8clM824VqLWVM35+1IsGtIlT8rTqPc=; b=2JCRmWyRI/PlzViOQDi3KZ/FMR0qTdOpXjEZPj43eRfZ+wkBe8cK4mG37975t6Oi1U 79O6i8pmI9jwlJclm13xIfwK83hS3zvbgxL6+SgeCoQXYd6RM9AiblwhlGXtd4poV2+0 Duy1qfB39guVnwcgSSw4WMYQdjPMnhUg/9wBvAJeBQ1ZyCB1T8GWYXeW3ed368BqHOuG YZL7s9uQ63pYZ1YUqSmZK25NIgdJz1eEzTxrLugVp++qSwc71IUcv6Xn/0BRemA2XQsb qgj7J6moLwPuvxMrq/k5Y60xxPC7fNb0A+x+pd+17maG9XxyFxHjylPqrP1HhRcq8EbO VMxg== 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=hspCmuyOP0VnO8clM824VqLWVM35+1IsGtIlT8rTqPc=; b=JGra9P05N4ysEmk1C6Ezc2mvqZKFO2afRbGCDgHsA/+z1yG4gJbqPEEzblorsfADIz ZJU14uLwcCI6rkJ8JaYYiUeBzrxe44sWpGqwDOYGKTcFj7vwAI69nTasPqRRYZFEeND8 TSJ+7ll1nkoeg8sd8vB9MnvV5xT+4o8WwJ7BKOaXVaa54nyWKzezhxeLijTJfTqUleRR os/Zm8uVKg+WY7I/lL5IYlvpRfOBfVS7G1BQ9qJaESfSBmRTnxqUCwyzU9ttRj0Dp4O5 yRkLa/bq6GaodPodmTgAq5Xd7ul7hrKIBTrXaM64hFAWy/P8Qqa/ORS13u7p+TQ5e65x 9THQ== X-Gm-Message-State: AOAM533jmQx/vaOsufl27A4rCEwEoMDIm5wG9L41ZESuMFrY6v+lRcv9 5Onow5B1QwoAji6EWvaS+3rxuA== X-Google-Smtp-Source: ABdhPJwoQV5I/vxA2SUNCPcA2Odi5jw/kjCBm3uxS7cS3IIC2okEJ60pGmR1cnQ8PQNnqdTb3Rbdtg== X-Received: by 2002:ac8:5d90:: with SMTP id d16mr8242415qtx.142.1644810243589; Sun, 13 Feb 2022 19:44:03 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 19:44:02 -0800 (PST) From: Glenn Washburn To: Daniel Kiper , grub-devel@gnu.org Cc: Peter Jones , Robbie Harwood , Glenn Washburn Subject: [PATCH 5/8] gdb: Add functions to make loading from dynamically positioned targets easier Date: Sun, 13 Feb 2022 21:42:42 -0600 Message-Id: <157b732b67ee842fa656ddd8662da5c7b57ea84c.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::82f (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::82f; envelope-from=development@efficientek.com; helo=mail-qt1-x82f.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:07 -0000 Many targets, such as EFI, load GRUB at addresses that are determined at runtime. So the load addresses in kernel.exec will almost certainly be wrong. Given the address of the start of the text and data segments, these functions will tell GDB to load the symbols at the proper locations. It is left up to the user to determine how to get the test and data addresses. Signed-off-by: Glenn Washburn --- grub-core/gdb_grub.in | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/grub-core/gdb_grub.in b/grub-core/gdb_grub.in index dd1e86bf2..f3c6faf94 100644 --- a/grub-core/gdb_grub.in +++ b/grub-core/gdb_grub.in @@ -9,6 +9,60 @@ ### Lubomir Kundrak ### +define dynamic_load_kernel_exec_symbols + shell rm -f .remove-kernel.exec.symfile.gdb + + # Loading symbols is complicated by the fact that kernel.exec is an ELF + # ELF binary, but the UEFI runtime is PE32+. All the data sections of + # the ELF binary are concatenated (accounting for ELF section alignment) + # and put into one .data section in the PE32+ runtime image. So given + # the load address of the .data PE32+ section we can determine the + # addresses each ELF data section maps to. + shell bash -c ' \ + ( \ + export PE_TEXT=$1 PE_DATA=$2; \ + alignup() { \ + PAD=1; \ + if [ "$(($1%$2))" -eq 0 ]; then \ + PAD=0; \ + fi; \ + printf "0x%x\n" $(((($1/$2)+$PAD)*$2)); \ + }; \ + printf "add-symbol-file kernel.exec ${PE_TEXT}"; \ + objdump -h kernel.exec | tail -n +6 | \ + while read IDX NAME SIZE _ _ OFFSET ALIGN; do \ + read FLAGS; \ + if [ -n "$FLAGS" ] && [ -z "${FLAGS%%*DATA*}" -o "$NAME" = .bss ]; then \ + OFF=$(alignup ${OFF:-0} $ALIGN); \ + echo -n " -s $NAME (${PE_DATA}+$(printf "0x%x" $OFF))"; \ + OFF=$((${OFF} + 0x${SIZE})); \ + fi; \ + done \ + )' script $arg0 $arg1 >.kernel.exec.loadsym.gdb + source .kernel.exec.loadsym.gdb +end +document dynamic_load_kernel_exec_symbols + Load debugging symbols from kernel.exec given the address of the + .text and .data segments of the UEFI binary. +end + +define dynamic_load_symbols + dynamic_load_kernel_exec_symbols $arg0 $arg1 + + # We may have been very late to loading the kernel.exec symbols and + # and modules may already be loaded. So load symbols for any already + # loaded. + load_all_modules + + runtime_load_module +end +document dynamic_load_symbols + Load debugging symbols from kernel.exec and any loaded modules given + the address of the .text and .data segments of the UEFI binary. Also + setup session to automatically load module symbols for modules loaded + in the future. +end + # Add section numbers and addresses to .segments.tmp define dump_module_sections set $mod = $arg0 -- 2.27.0