From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 85F3E3858296 for ; Tue, 21 Feb 2023 02:51:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 85F3E3858296 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.11] (unknown [217.28.27.60]) (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 D69DF1E128; Mon, 20 Feb 2023 21:51:01 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1676947862; bh=o0sjLVeJTGPPuFz9asMqj9i/FeP+ctygsBtx/ttmpRc=; h=Date:Subject:To:References:From:In-Reply-To:From; b=T/QVfrVMbNly88PHxcq4npkXiA+ej7qflPeyD/R0V36RDrTIVcprKfxpY+sZoW4Pt QkUAtuY4J+j20mLzQ2BolYubIm9fOw8JdIQ4GVNp4o2J5ocYUJ4O7Qb+yDIbsC+535 61HNqgCpzFyZndYi2p7opYZEHElrDvrhX4LtNLZA= Message-ID: <25f6f329-8f75-4f05-c269-3000c0a4dde6@simark.ca> Date: Mon, 20 Feb 2023 21:51:00 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: TemporaryBreakpoint and FInishingbreakpoint issues Content-Language: en-US To: Ena Irtnanoelec , gdb@sourceware.org References: From: Simon Marchi In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2/15/23 08:22, Ena Irtnanoelec via Gdb wrote: > Dear all, > > I've got some troubles with both FinishingBreakpoint and > TemporaryBreakpoints I'm trying to set using the Python's API. > > My use case is as follows : I've added some breakpoints on particular code > of the linux kernel, on a syscall definition. This is the code in which I'm > placing a BP: > > SYSCALL_DEFINE3 > (execve > , const char > __user *, > filename , > const compat_uptr_t > __user > *, argv > , > const compat_uptr_t > __user > *, envp > ){ > return compat_do_execve > (getname > (filename > ), argv > , envp > );} > > So far no problems, thus, once there, I would like to have the exit code of > this function. This is where I have some difficulties. I first tried with a > FinishingBreakpoint as follows. Thus, it never each the "normal finish" and > always ends up in "out of scope", despite the fact it is placed at the > correct place (in an assembly file - entry-common.S). When I'm manually > stepping thru, I got there. > class ExecveBreakpoint(gdb.Breakpoint): > > def stop(self): > MyFinishBreakpoint(gdb.selected_frame()) > > > class MyFinishBreakpoint (gdb.FinishBreakpoint): > def stop (self): > print ("normal finish") > > def out_of_scope (): > print ("abnormal finish") > > > > > I was wondering if this was because there were no ret instruction at the > end of the block ? Not sure, I would have to play with it and debug it to know. > Anyway, I've tried to get around by computing the last > instruction before continuing in assembly > pc = gdb.selected_frame().pc() > addr = gdb.block_for_pc(pc).end > addr = addr - \ > gdb.selected_frame().architecture().disassemble(addr)[0][ > 'length'] > > TestBp(f"*0x{addr:02x}", temporary=True) > > class TestBp(gdb.Breakpoint): > def stop(self): > print(f"count = {self.hit_count}") > #self.delete()# <- this crashed gdb I think this is kind of expected (although not nice). The doc says: You should not alter the execution state of the inferior (i.e., step, next, etc.), alter the current frame context (i.e., change the current active frame), or alter, add or delete any breakpoint. As a general rule, you should not alter any data within GDB or the inferior at this time. > return False > > It happens that even though I made it temporary, it is never deleted. > Furthermore, the hit_count is always 0 even though I've got multiple print > calls on the console. I think it's because when the stop method returns true, the breakpoint is considered to not be hit. It's the same as if you have a conditional breakpoint whose condition evaluates to false. The breakpoint is therefore not deleted, the hit count not incremented. Unfortunately, I don't know of a way to do tell GDB that you consider the breakpoint hit, but don't want to stop the inferior. That would be useful to do some kind of internal accounting but not cause a stop. Simon