Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 75F27C433F5 for ; Wed, 12 Jan 2022 08:31:29 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 006B383103; Wed, 12 Jan 2022 09:31:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=etri.re.kr Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=dooray.com header.i=@dooray.com header.b="UDgJ1wfL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D84A1830D9; Wed, 12 Jan 2022 09:31:25 +0100 (CET) Received: from mscreen.etri.re.kr (mscreen.etri.re.kr [129.254.9.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3147882F89 for ; Wed, 12 Jan 2022 09:31:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=etri.re.kr Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ckim@etri.re.kr Received: from unknown (HELO send002-relay.gov-dooray.com) (211.180.235.153) by 129.254.9.16 with ESMTP; 12 Jan 2022 17:31:14 +0900 X-Original-SENDERIP: 211.180.235.153 X-Original-MAILFROM: ckim@etri.re.kr X-Original-RCPTTO: u-boot@lists.denx.de Received: from [10.162.225.106] (HELO smtp001-imp.gov-dooray.com) ([10.162.225.106]) by send002-relay.gov-dooray.com with SMTP id 78668b0161de91d2; Wed, 12 Jan 2022 17:31:14 +0900 DKIM-Signature: a=rsa-sha256; b=UDgJ1wfLQt/lYjnBBwubfhNnvljGM1UT1j5MmLE0ZcpaSZVYQQE6/+nbDZjZ+gtQK7SHOueEJT fOEgEev2N+gWfV2xpVHRrO4/CcmQVDhmbj/sSVTO8vwNdbl9e7bYzGQMPYj7GTPWOzciUPIWhh0Z ln41XiYCOgGBXwv3MT/5HsgsVYsF42ApiluFhnhC0K/cK5mn7UBJMmp8s7BvpaD8BPfm/u68b5Pf FdJqwVU6Ae4QTQOWtofok2ugmErJVEieeaMG7gz4QYwVBdJK5jhVgxQwD9tUd2YO7n66dZwPJeyF /M5At5RDeLiuxh9GFY+ZGgArjkQA+GnYR5+XNqSg==; c=relaxed/relaxed; s=selector; d=dooray.com; v=1; bh=r8EfeMvz/Ghp3i9/rE9KHoBjMuXD3EkMFelHyGaHLo4=; h=From:To:Subject:Message-ID; Received: from [129.254.132.39] (HELO CHANKIMPC) ([129.254.132.39]) by smtp001-imp.gov-dooray.com with SMTP id 30b19d1b61de91d1; Wed, 12 Jan 2022 17:31:14 +0900 From: "Chan Kim" To: "'U-Boot Mailing List'" References: <000c01d80788$1653b180$42fb1480$@etri.re.kr> In-Reply-To: <000c01d80788$1653b180$42fb1480$@etri.re.kr> Subject: RE: How to use add-symbol-file in gdb after the program jumped to linux? (both when PC is physical and virtual) Date: Wed, 12 Jan 2022 17:31:12 +0900 Message-ID: <002001d8078e$c1ca7110$455f5330$@etri.re.kr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQIe6LwJ2BLXOHyJGos3M/T4ETVWM6vRQz6g Content-Language: ko X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean I found from gdb manual, "add-symbol-file filename [ -readnow | -readnever ] [ -o offset ] [ textaddress ] [ -s section address ... ] The add-symbol-file command reads additional symbol table information from the file filename. You would use this command when filename has been dynamically loaded (by some other means) into the program that is running. The textaddress parameter gives the memory address at which the file's text section has been loaded. You can additionally specify the base address of other sections using an arbitrary number of '-s section address' pairs. If a section is omitted, gdb will use its default addresses as found in filename. Any address or textaddress can be given as an expression. ..." I changed my program a little bit to fix a problem. The readelf shows the .text section starting at ffffffc010080800. So I adjusted the command to "add-symbol-file vmlinux 0x80000800" and gdb shows the kernel source correct after jump to linux. Still it doesn't show me the source code after __primary_switched. Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .head.text PROGBITS ffffffc010080000 00010000 0000000000000040 0000000000000000 AX 0 0 4 [ 2] .text PROGBITS ffffffc010080800 00010800 0000000000304370 0000000000000000 AX 0 0 2048 [ 3] .rodata PROGBITS ffffffc010390000 00320000 .... (skip) ... [12] .notes NOTE ffffffc01045be18 003ebe18 000000000000003c 0000000000000000 A 0 0 4 [13] .init.text PROGBITS ffffffc010470000 003f0000 0000000000027ec8 0000000000000000 AX 0 0 4 [14] .exit.text PROGBITS ffffffc010497ec8 00417ec8 000000000000046c 0000000000000000 AX 0 0 4 Since '__primary_switched' resides in section .init.text, I tried adding "-s .init.text 0xffffffc010470000" or "-s .init_text 0x803ef800"(physcial address) to the add-symbol-file command to no avail. Is my command wrong? Or could this be from page table (virtual -> Physical) problem because I see synchronous exception right after I enter __primary_switched (I see PC value has become 0x200. If the exception vector is located in 0x0, this is the vector entry for synch exception like undefined instruction. I should also check the vector base address has not been set correctly.) Any comment or advice will be deeply appreciated. Thank you! Chan Kim > -----Original Message----- > From: U-Boot On Behalf Of Chan Kim > Sent: Wednesday, January 12, 2022 4:43 PM > To: U-Boot Mailing List > Subject: How to use add-symbol-file in gdb after the program jumped to > linux? (both when PC is physical and virtual) > > Hello experts, > > > > I'm following linux boot-loading using u-boot (using SPL falcon mode, from > RAM) on a qemu virtual machine (now linux started in real board too). The > code jumped to linux kernel and because I have done `add-symbol-file > vmlinux 0x80081000` I can follow the kernel code step by step using gdb > connected to the virtual machine. Actually I loaded the kernel image to > 0x80080000 but I had to set the address to 0x80081000 to make the source > code appear on the gdb correctly according to the PC value(I don't know > why this difference of > 0x1000 is needed). > > Later I found the kernel sets up the page table (identity mapping and swap > table) and jumps to `__primary_switched` and this is where pure kernel > virtual address is used first time for the PC. This is where the call is > made at the end of the head.S file. > > > > ldr x8, =__primary_switched > > adrp x0, __PHYS_OFFSET > > br x8 > > > > In the symbol file (vmlinux, an elf file), the symbols before > __primary_switched are all mapped at virtual addresses (starting with > 0xffffffc0..... high addresses) but the gdb could follow the source even > when the PC value was using physical address. (The PC was initially loaded > with physical address of the kernel start and PC relative jumps were being > used until it jumps to `__primary_switched`, mmu disabled or using > identity > mapping) So does this mean, in doing `add-symbol-file` only the offset of > the symbols from the start of text matters? > > Another question : I can follow the kernel source with gdb but after > __primary_switched, I cannot see the source. The debugger doesn't show the > correct source location according to the now kernel virtual PC value. > Should I tell the debugger to use correct offset using add-symbol-file > again? if so how? > > > > I would be happy to hear any comment or advice. > > Thank you! > > > > Chan Kim > > >