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 9B40DC433EF for ; Thu, 13 Jan 2022 09:41:47 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D582783282; Thu, 13 Jan 2022 10:41:44 +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="kKsamlTu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9559F832CD; Thu, 13 Jan 2022 10:41:43 +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 9F5BA8319A for ; Thu, 13 Jan 2022 10:41:35 +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 send001-relay.gov-dooray.com) (211.180.235.152) by 129.254.9.16 with ESMTP; 13 Jan 2022 18:41:31 +0900 X-Original-SENDERIP: 211.180.235.152 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 send001-relay.gov-dooray.com with SMTP id 078578af61dff3cb; Thu, 13 Jan 2022 18:41:31 +0900 DKIM-Signature: a=rsa-sha256; b=kKsamlTuAk/sL7A4xLMfJ1p6thBJfmiI/nxDqCDM5sqJ/jqvNuWjsGrhU8BeJxdFCKdn19fim4 AXEqVt/9P84M5obN+eO4RdnmJJUcRuzwZukyF/IP2W/kdsGVKe86xNuALC9TPooCpZeKVGoeR5Ng iKu8yNJ/dbs93E1ScDDX0zCwKg395Uf+tcpSvkRA5NKZjz/rzwm5pjgemF5QhYKrLPQolA3om7CB a1LrzdZwpDC+iB9mIKQLhS9aaepbUu+C/etJqoHH94t1XuhLtfKhoK0itacaimuZuBkEFosRqKz8 AFHLtBdwwX4qlk5koIUeCZHikRMS2Lc3u1tlZ+ew==; c=relaxed/relaxed; s=selector; d=dooray.com; v=1; bh=32GxhDAcQH/gSpPj9z9AMduRy42NkB1BsAtZEMt2S3A=; 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 a9489ec861dff3cb; Thu, 13 Jan 2022 18:41:31 +0900 From: "Chan Kim" To: "'U-Boot Mailing List'" References: <000c01d80788$1653b180$42fb1480$@etri.re.kr> In-Reply-To: Subject: RE: How to use add-symbol-file in gdb after the program jumped to linux? (both when PC is physical and virtual) Date: Thu, 13 Jan 2022 18:41:28 +0900 Message-ID: <011201d80861$bd25a340$3770e9c0$@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/T4ETVWMwDhnRpqq8vkPzA= 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 my kernel load address was wrong (__PHYS_OFFSET was below physical ddr address start). After fixing it the PC increments normally with kernel virtual address and I should just apply the add-symbol-file command using the virtual address. With this command(with new kernel image), I could follow the source using qemu and gdb step-by-step after __primary_switched. add-symbol-file images/vmlinux 0xffffffc010080800 -s .head.text 0xffffffc010080000 -s .init.text 0xffffffc010470000 Hope this helps someone later. Thanks! Chan Kim > -----Original Message----- > From: Chan Kim > Sent: Wednesday, January 12, 2022 5:31 PM > To: 'U-Boot Mailing List' > Subject: RE: How to use add-symbol-file in gdb after the program jumped to > linux? (both when PC is physical and virtual) > > 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 > > > > > >