From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QlyDKNj7EmAFewAAWB0awg (envelope-from ) for ; Thu, 28 Jan 2021 13:00:56 -0500 Received: by simark.ca (Postfix, from userid 112) id 97E521EF80; Thu, 28 Jan 2021 13:00:56 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 428091E945 for ; Thu, 28 Jan 2021 13:00:56 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC4A2386EC32; Thu, 28 Jan 2021 18:00:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC4A2386EC32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611856855; bh=KQCzVILwE6PvsxPc34NPQ5PaJa+x0FzeBcOyOFRRXPI=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=kH/QyJVW1YEuJwznWQiE8Y94jxqyn2iDecM2zAaQkOxJPfTloNB+It2U8YixktlbT 7Yu2DES7l4vJUh/gYbXvbCCB9bI0rSd2h4eii4JVG+znGVl5GZej7veP+Vc7nWXvZs JJ1MYKVzrOJGu8CgQeD3fRUs3VgLd1zf+SZzmhIo= Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 944D2386101D for ; Thu, 28 Jan 2021 18:00:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 944D2386101D Received: by mail-pl1-x62d.google.com with SMTP id j21so3771709pls.7 for ; Thu, 28 Jan 2021 10:00:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KQCzVILwE6PvsxPc34NPQ5PaJa+x0FzeBcOyOFRRXPI=; b=XevzBmVVAARTIwm3MGsIIZApcWX/GxJllow006fdANOGZQctfOvYG4Si6XIqfmqZr3 mqo51AejoX8/PbK1VlRHOvu13DM6COJ/4E7TFGLibz238I7YU39STenhyRel4l+EqQOM 3Gu2lZPOrJs8OTPQFFcodpWrqYZZO6CuZxEUwD3rcAgjqyurf+669sLSvxuIoPkULfCs ceZWHr3Pfgs3Tn3Fn/UYVC45OvMuN4l+cZoDsiDoo2oRhw0R4NkUUBHH7B8GpuOt5AMF uj7KOE6ggKkYwbSijl+piB7xk4HMnkNVwod/ItNwKPT18k798pIMoTQjfP2JUiFhf91y lWGg== X-Gm-Message-State: AOAM532j25R0p5XJ/kX/acAwzg9J0RoArmCs+os8RMYHvbee4XbfBz0E mGIgzIpxpphk/AAEDThx03kFD5gHmzAdhWbyBrU= X-Google-Smtp-Source: ABdhPJycmzl1K4fGHPj3XiCX7CmRmXM3u3q0XvA/0EcBx4VknsPYLbTVdUEK25An6mgbvjESbG4n0bOINgi7UdtU3N8= X-Received: by 2002:a17:902:7783:b029:df:fa69:3a34 with SMTP id o3-20020a1709027783b02900dffa693a34mr671661pll.21.1611856851757; Thu, 28 Jan 2021 10:00:51 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 28 Jan 2021 20:00:40 +0200 Message-ID: Subject: Re: How to display instructions around the current instuction? To: Peng Yu Content-Type: text/plain; charset="UTF-8" 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: , From: Stefan Puiu via Gdb Reply-To: Stefan Puiu Cc: gdb@sourceware.org Errors-To: gdb-bounces@sourceware.org Sender: "Gdb" On Thu, Jan 28, 2021 at 7:06 PM Peng Yu wrote: > > Hi Stefan, > > > display/10i $rip-10 > > > > I don't think x86-64 instructions have fixed width, so that won't > > always print the same number of instructions before the current one, > > but it's probably a good approximation. > > Have you tried it? If $rip-5 is not right at the start of an Well, I said "Have you tried...?", not "here, that's the answer". But since you ask so nicely, yes, I've tried it. It's something I use often on Linux, and it works. In fact, I've just tried it with a simple program and it works. On my Linux (Ubuntu 20.04 x86-64). But wait, you have MacOS; you didn't mention that in your initial email. > instruction, it does not even disassmble correctly. Please test your > recommendation before sending it out. It is not appropriate to waste > other people's time. Please don't be rude to people who are trying to help you. And what do you know, there's plenty of wrong answers on stackoverflow, and plenty that haven't been deleted. You still have to figure them out. > > (gdb) 1: x/10i $rip-5 > > (gdb) Temporary breakpoint 1 at 0x401134 > Starting program: /mnt/macosx/pengy/mrrdir/test/gnu/gdb/cmd/display/main.exe > > Temporary breakpoint 1, 0x0000000000401134 in main () > 1: x/10i $rip-5 > 0x40112f : add BYTE PTR [rbp+0x48],dl > 0x401132 : mov ebp,esp > => 0x401134 : sub rsp,0x10 > 0x401138 : movabs rdi,0x402004 > 0x401142 : mov al,0x0 > 0x401144 : call 0x401030 > 0x401149 : xor ecx,ecx > 0x40114b : mov DWORD PTR [rbp-0x4],eax > 0x40114e : mov eax,ecx > 0x401150 : add rsp,0x10 > (gdb) 0x0000000000401138 in main () > 1: x/10i $rip-5 > 0x401133 : in eax,0x48 > 0x401135 : sub esp,0x10 > => 0x401138 : movabs rdi,0x402004 > 0x401142 : mov al,0x0 > 0x401144 : call 0x401030 > 0x401149 : xor ecx,ecx > 0x40114b : mov DWORD PTR [rbp-0x4],eax > 0x40114e : mov eax,ecx > 0x401150 : add rsp,0x10 > 0x401154 : pop rbp > (gdb) 0x0000000000401142 in main () > 1: x/10i $rip-5 > 0x40113d : add BYTE PTR [rax],al > 0x40113f : add BYTE PTR [rax],al > 0x401141 : add BYTE PTR [rax-0x1181800],dh > 0x401147 : (bad) > 0x401148 : push QWORD PTR [rcx] > 0x40114a : leave > 0x40114b : mov DWORD PTR [rbp-0x4],eax > 0x40114e : mov eax,ecx > 0x401150 : add rsp,0x10 > 0x401154 : pop rbp > > -- > Regards, > Peng