From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yfepNNqSDWBvZAAAWB0awg (envelope-from ) for ; Sun, 24 Jan 2021 10:31:38 -0500 Received: by simark.ca (Postfix, from userid 112) id CB0CB1EF80; Sun, 24 Jan 2021 10:31:38 -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 4C5821E945 for ; Sun, 24 Jan 2021 10:31:38 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 365F4386F808; Sun, 24 Jan 2021 15:31:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 365F4386F808 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611502297; bh=rUeGEa/aZBhN5iN+BKv1MjeyzN7q/DPFenI9MKv3IF0=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=kKkvrxTaxtb1RW1u2QZpLgRmc+V/jGqLDi11nCfnJm60UTNMytBf4EoUZN6Ca6Zhq vXV/RMrwSk4pTl1IIxlXpg36/AJYtg5kzjElH9xB1eaWt1vavski1lbgfFqqI/J0OS mLlnBu2iC2SIpP9tWGANAGmYpw1AwgLM58rurlbs= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 4CFFB3857C50 for ; Sun, 24 Jan 2021 15:31:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4CFFB3857C50 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 10OFVT3U013793 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 24 Jan 2021 10:31:33 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 10OFVT3U013793 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)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 0DFB21E945; Sun, 24 Jan 2021 10:31:28 -0500 (EST) Subject: Re: Why does `disassemble` behave differently on Linux and Mac? To: Peng Yu , gdb@sourceware.org References: Message-ID: Date: Sun, 24 Jan 2021 10:31:28 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 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 Sun, 24 Jan 2021 15:31:29 +0000 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: Simon Marchi via Gdb Reply-To: Simon Marchi Errors-To: gdb-bounces@sourceware.org Sender: "Gdb" On 2021-01-24 10:06 a.m., Peng Yu via Gdb wrote: > Hi, > > https://visualgdb.com/gdbreference/commands/set_disassembly-flavor > > I am trying to follow the above example, but it does behave the same > on Linux and Mac. Does anybody know how to make it work on Mac? > Thanks. > > On Linux: > > $ uname Linux $ cat func.c int func(int a, int b) { return a + b; } $ > gcc -c func.c $ gdb -q func.o Reading symbols from func.o... (No > debugging symbols found in func.o) (gdb) show disassembly-flavor The > disassembly flavor is "att". (gdb) disassemble func Dump of assembler > code for function func: 0x0000000000000000 <+0>: push %rbp > 0x0000000000000001 <+1>: mov %rsp,%rbp 0x0000000000000004 > <+4>: mov %edi,-0x4(%rbp) 0x0000000000000007 <+7>: mov > %esi,-0x8(%rbp) 0x000000000000000a <+10>: mov -0x4(%rbp),%edx > 0x000000000000000d <+13>: mov -0x8(%rbp),%eax > 0x0000000000000010 <+16>: add %edx,%eax 0x0000000000000012 > <+18>: pop %rbp 0x0000000000000013 <+19>: ret End of > assembler dump. > > On Mac: > > $ uname Darwin $ cat func.c int func(int a, int b) { return a + b; } $ > gcc -c func.c $ gdb -q func.o Reading symbols from func.o... (No > debugging symbols found in func.o) (gdb) show disassembly-flavor The > disassembly flavor is "att". (gdb) disassemble func No symbol table > is loaded. Use the "file" command. > It's probably not really the disassemble command that is different, it looks like the Mac version did not read the minimal symbols properly. You would have to debug GDB to understand why. On Linux the minimal symbols are read from the ELF executable, whereas on Mac it is from the Mach-O executable. Presumably, that happens in macho_symfile_read, in machoread.c. It looks like you can do "set debug mach-o 1" to enable some debug prints about reading Mach-O executables, I don't know if that will help or not. You could also try building with debug symbols, but passing -g to the compiled. Simon