From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by sourceware.org (Postfix) with ESMTPS id 71890383820A for ; Thu, 26 May 2022 19:29:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 71890383820A X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [10.0.0.7] ([192.164.130.188]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N3bWr-1nkVwG2Bz1-010ccv; Thu, 26 May 2022 21:28:59 +0200 Message-ID: <60bee27b-7aff-1ecd-25eb-fe19c8d684b8@gmx.at> Date: Thu, 26 May 2022 21:28:58 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: Removing old symbols when debugging code that relocates itself Content-Language: en-US To: Shahab Vahedi Cc: gdb@sourceware.org References: From: Wolfgang Wallner In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:XajrgFtRV+COkp2zyJP5C5h0zOPo00rQ4PM3mKAPE1YYZWl0BbT tVgYuod3IM07MwlM/SoT9KuMJmUu6JOLRTY+dxKW9q17B6mQeuy1Sfr30+kpAKa5nGkCupy z2/dVuOeerQs1I+qQfJvztwH3ZoHoOGR599RyZ3PjjSnZOzxSt4n9d+WInsSjvlzbdcK9Ka l+PgnH7bnXtofmMmeguhA== X-UI-Out-Filterresults: notjunk:1;V03:K0:iR0eLW7Dnlc=:A0SxINNHNFluCQmlduU7Mz vRy9DRni33BSpCzob4PwFVZdKVbVRy+/bgKlakN9AWWmCSuMzw9YpzIw0WOa3BTJHhlyb7QrO 3rpnM0yE/K8MHIcbEob5fAmXcPvzIeRUsBd0ZibZE0eMz0IGo2gNXFOF/ovsmEe2l3aPa2H52 Ao/oAwGINDJwVsTCVjjLb3nHXYW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NSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 May 2022 19:29:03 -0000 Hi Shahab, On 26.05.22 00:13, Shahab Vahedi wrote: > Hi Wolfgang, > > On Wed, May 25, 2022 at 11:14:28PM +0200, Wolfgang Wallner via Gdb wrot= e: >> It seems I can only remove the symbols that I have added with >> add-symbol-file, but not the initial ones ... > > Maybe you could extract the symbol file [1] and then strip it away from > the binary [2]. This way, you have to use "add-symbol-file" to add it > in different stages and according to what you say you should be able > to remove it after each adding. > > [1] > $ objcopy --only-keep-debug uboot.bin uboot.sym > > [2] > $ objcopy --strip-all uboot.bin uboot.strp Thanks for the feedback! I tried your recommendations, and while it seems to help somewhat, unfortunately it does not fully solve my troubles. Here is what I did: 1) Create the files as you described: arm-linux-gnueabihf-objcopy --strip-all u-boot u-boot.strp arm-linux-gnueabihf-objcopy --only-keep-debug u-boot my_u-boot.sym Remark: The U-Boot build already creates a file called 'u-boot.sym', so I gave my file another name (my_u-boot.sym). The already existing u-boot.sym file is the symbol table as text file created by calling 'objdump -t'. 2) I start QEMU as described in my first mail 3) I start GDB using the 'u-boot.strp' ELF file 4) As first command, I add 'my_u-boot.sym' via add-symbol-file I then step through the code as described in my last mail, but somehow in this configuration I cannot use GDB's 'until' command. Using 'until' continues execution, and the temporary breakpoint is never hit. It is interesting to note that this is *only in assembly*, using 'until' works fine in C-files! As a workaround for this issue I set explicit breakpoints. 5) I continue to step through the code, until I reach the relocated code. = I then drop all symbols via 'symbol-file', and add them back for the relocat= ed location via 'add-symbol-file'. Showing information about breakpoints shows that there are no duplicate breakpoints any more --> woohoo :) (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x47f3c668 arch/arm/lib/crt0.S:156 breakpoint already hit 1 time 2 breakpoint keep y 0x47f3c754 arch/arm/lib/relocate.S:134 breakpoint already hit 1 time While these breakpoints were set at the old locations, now they already point to the symbols at the relocated locations. But when I try to set a new breakpoint, it is again a duplicate: (gdb) break board_init_r Breakpoint 3 at 0x1dc28 (2 locations) (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x47f3c668 arch/arm/lib/crt0.S:156 breakpoint already hit 1 time 2 breakpoint keep y 0x47f3c754 arch/arm/lib/relocate.S:134 breakpoint already hit 1 time 3 breakpoint keep y 3.1 y 0x0001dc28 3.2 y 0x47f58c24 in board_init_r at common/board_r.c:817 So this leaves me with the following questions: *) Does anyone know why the 'until' command stopped working with this approach in assembly files? Is this expected, or is it a bug? *) Why are there still duplicate breakpoints? *) Are there other approaches to deal with relocated code? While the objcopy steps have helped me, for a more permanent workflow I would like to avoid them (e.g. it would be nice to directly set up a debug environment in an IDE, and any required extra steps between compilation and debugging would make that more complicated) regards, Wolfgang Remark: I think there was a typo in my initial mail. The breakpoint in relocate.S should be in line 134, not line 118.