From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 6FCA73835806 for ; Sat, 14 Aug 2021 13:06:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6FCA73835806 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 17ED5wJu026350 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 14 Aug 2021 09:06:03 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 17ED5wJu026350 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id B45431E813; Sat, 14 Aug 2021 09:05:58 -0400 (EDT) Subject: Re: GDB call and p func() on embedded target To: Maximilian Schneider , gdb@sourceware.org References: From: Simon Marchi Message-ID: <10f7f78c-ac4d-b54f-b250-c915203c6f47@polymtl.ca> Date: Sat, 14 Aug 2021 09:05:58 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 14 Aug 2021 13:05:59 +0000 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Sat, 14 Aug 2021 13:06:16 -0000 On 2021-08-14 6:28 a.m., Maximilian Schneider via Gdb wrote: > Hello, > > I am trying to call a function from withing a gdb debugging session on > an embedded target. However gdb never returns and when i stop it > manually the program counter is in a strange place. It appears that gdb > is not able to catch the return, and is continuing execution from > before the core was halted... > > assume the function I want to call has prototype int32_t Init(void); > > If I set the pc manually I can step throught the function until the > return without a problem. > > I can even set a breakpoint on Init and then use p Init(). The > breakpoint will fire and I can step throught the code manually. > > eg. > > target remote localhost:3333 > monitor reset halt > monitor reset init > file loader.elf > load loader.elf > set $sp=0x20010000 > set $pc=&Init > b Init > p Init() > n > n > n > ... > > However without the breakpoint gdb never returns. > Is this a known problem? Is there a workaround? > > Some background: > The purpose of this entire excercise is to arrive at a tool/set of > scripts that can be used to load and execute arbitrary code from RAM, > to fi. manipulate external memories or run tests. > > Regards, > M Hi Maximilian, I don't think there would be a way to solve this other than debugging GDB itself, stepping in the call_function_by_hand_dummy function to understand what it does, how it sets up the dummy stack frame, what technique it uses to put the breakpoint that should lead to the function call being completed, etc.. And also running with "set debug infrun 1" and possibly stepping through handle_inferior_event, to see why GDB doesn't realize the function call isn't over. The call_function_by_hand_dummy really lacks debug prints, making it hard to debug when it goes wrong. I was debugging another function call issue the other day, and thought to myself that it would be a good time to add some. Also, inferior function call has a lot of arch-specific components to it, so if you could mention the arch you are working on, it could help narrow things down. Simon