From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2972B3858D38 for ; Thu, 10 Nov 2022 15:08:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2972B3858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668092914; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jeGkvHYTemr1Tcojl9q4VcQw/wtgcZTMfipL/RrQ3Y8=; b=OdMtrLRV03cOpBfFoJqECeShVGl5dEFNUEjfpOyiCv4dfI+ACBTU/Mlganet7iYaNBIqio x/8x04pu/ujfY0AJqPCZaX9vW1CWkYfEYHwZjFZPGcGbPxje8ySdR3FPBnw4nScddoVZ9p lqR5sKU1zWFEgu/lXdZDbV2p3P9cUnE= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-490-VP0-PFcYPoGT8DEPc-eahw-1; Thu, 10 Nov 2022 10:08:33 -0500 X-MC-Unique: VP0-PFcYPoGT8DEPc-eahw-1 Received: by mail-qv1-f69.google.com with SMTP id mo15-20020a056214330f00b004b96d712bccso1636582qvb.22 for ; Thu, 10 Nov 2022 07:08:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jeGkvHYTemr1Tcojl9q4VcQw/wtgcZTMfipL/RrQ3Y8=; b=ZzVFFwnskl5kTBBUb3vjVWo222AqViQPAP7AK9h0jq/tGJUfXJJwKOXOjMsbXTno5Q uR+FQKMjGe/rG6ZdJHhyfhV04Y9EpCs92ueeUPFD+HhVLl9bmlrgRKj8+ev7d1ZZ3WqC dO438xqldh16m8JqMnjPyHBfEy18c6Al72+FL71qpoJHR9jZ4mMNS04pr3R7f0mnVgGz lXSmuC7KTa9ayfAimgSDOfYHI8Do83aD0sAmt0mSmk5ce7ZuzonuLSZdcdXiMUczuw6p ObLy/gnEi+XL7fFYteyuhwHxy/Et/85hLSkHzQSGwrSNnx9+E7bg+B/71AOgGuxQeOHZ f3CQ== X-Gm-Message-State: ACrzQf3FyWFoi9eiLq7cQmN8oxruGTWxmoex9KDKUbmY4sneeqfW/ezC 8v+903PeRq4If1Q1bfbVlM2hBFdoh/2fDWzKMHm3M7q4lDmSKZft0fKILohJGB9u8Wac3D6NXDU FnLglPcmiSP0= X-Received: by 2002:ad4:4ea2:0:b0:4b7:2741:11c5 with SMTP id ed2-20020ad44ea2000000b004b7274111c5mr60249240qvb.124.1668092913195; Thu, 10 Nov 2022 07:08:33 -0800 (PST) X-Google-Smtp-Source: AMsMyM6hbvI4XHTxMrhjhGOwwZFBEaOXjlZuH+Yn6rN3pMYgJsk0TbiifAwgFTgelI/DtRYJqvekdA== X-Received: by 2002:ad4:4ea2:0:b0:4b7:2741:11c5 with SMTP id ed2-20020ad44ea2000000b004b7274111c5mr60249202qvb.124.1668092912756; Thu, 10 Nov 2022 07:08:32 -0800 (PST) Received: from [10.202.9.92] (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id n16-20020a05620a295000b006f9ddaaf01esm13349073qkp.102.2022.11.10.07.08.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Nov 2022 07:08:32 -0800 (PST) Message-ID: <8b2bd550-b7bd-8015-5c6c-92bf890508d1@redhat.com> Date: Thu, 10 Nov 2022 16:08:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: some questions about the underlying implementation principle of gdb To: tangming chen , gdb@sourceware.org References: From: Bruno Larsen In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 09/11/2022 16:30, tangming chen via Gdb wrote: > Hello: > I am an undergraduate, and i am studying gdb. I have some questions > about the underlying implementation principle of gdb. > I learned that the implementation of gdb is related to ptrace. > Therefore,how does gdb debug programs through ptrace? More specifically, I > recently learned the awatch command,ignore command(ignore n number (n is > watchpoint number)),continue command. how does gdb implement the > commands(awatch ignore continue)? > Thank you! > Hello! I am not very familiar with how GDB uses ptrace, but I do know a tiny bit about the ignore command. Breakpoints are a data structure (defined in gdb/breakpoint.h:623), and one of the members of the struct is an ignore count (line 751). The function run when you use this command is defined in gdb/breakpoint.c:12905 (ignore_command). It just sets the number in the breakpoint and moves along. Once you set the inferior running again with 'continue' or anything else, the breakpoint will be hit and GDB will enter the function handle_signal_stop, which will set the status of the breakpoint by calling bpstat_stop_status, which (through other function calls) will check if the ignore_count is greater than 0 (gdb/breakpoint.c:5438), and if it isn't it will be decremented and say that GDB shouldn't stop. handle_signal_stop will then send a signal for the inferior to carry on as if nothing has happened. Essentially, GDB doesn't ignore the breakpoint, but it looks like it for the user :). Now keep in mind this is glossing over a lot of error checking and possibly other things related to ignored breakpoints, and I might just be straight up wrong since I haven't been working on GDB for long, but I hope this helps your understanding and gives enough substance for you to look more in-depth. -- Cheers, Bruno